Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66491516
Ac3.dart
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jun 10, 21:34
Size
18 KB
Mime Type
text/x-c++
Expires
Wed, Jun 12, 21:34 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18230432
Attached To
R10646 Orchestration
Ac3.dart
View Options
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:student/widgets/onlineRobotMap.Dart';
import 'dart:async';
import 'dart:convert';
import 'package:student/Database.dart';
import 'package:student/model/Group.dart';
import 'package:student/model/Cellulo.dart';
import 'package:student/widgets/showAlertDialog.Dart';
import 'package:student/widgets/membersBar.Dart';
import 'package:student/widgets/inactivityDetector.Dart';
import 'package:flutter_appavailability/flutter_appavailability.dart';
import 'package:student/widgets/mapShapeMaker.dart';
import 'package:audioplayer/audioplayer.dart';
import 'package:tip_dialog/tip_dialog.dart';
import 'dart:math' as math;
class Ac3 extends StatefulWidget {
Ac3({Key key}) : super(key: key);
@override
_Ac3State createState() => _Ac3State();
}
class _Ac3State extends State<Ac3> {
// Activity_Independent
int currentTurn = 1;
var elapseTimer = new Stopwatch();
AnimationController controllerRobotPath;
Animation<double> animationRobotPath;
Timer timerCelluloPosition;
Timer timerCheckCelluloGame;
Timer timerCelluloPositiontoserver;
// Celulo
var celluloxPosition = [0.0, 0.0];
var celluloyPosition = [0.0, 0.0];
// Learning
List<int> progress = [0, -2, -2];
int tapCounter = 0;
List<int> progressElpasedTime = [0, 0, 0];
int inactivity = 0;
List<int> mistakesSlope = [0, 0, 0];
List<int> mistakesIntrepet = [0, 0, 0];
List<int> mistakesInitialPosition = [0, 0, 0];
// ACTIVITY Dependent
bool enterBorderX = false;
bool enterBorderY = false;
bool enterBorderpolygonX = false;
bool enterBorderpolygonY = false;
bool enterBorderRectX = false;
bool enterBorderRectY = false;
int scoreX = 6;
int scoreY = 6;
int trappedCircleX;
int trappedCircleY;
int trappedRectangleX;
int trappedRectangleY;
int trappedPolygonX;
int trappedPolygonY;
bool reachendY = false;
bool gameoverY = false;
final double mapSizeWidth = 860;
final double mapSizeHeight = 860;
double coeffScreenMapWidth;
double coeffScreenMapHeight;
var startPoint = ['B', 'A', 'B'];
var endPoint = ['C', 'D', 'C'];
var startPointorder = [2, 0, 2];
var endPointorder = [1, 3, 1];
double radiuosStart = 45;
var pointOrder = ['A', 'B', 'C', 'D'];
static List<Offset> pointPosition = [
Offset(80, 80),
Offset(760, 80),
Offset(80, 760),
Offset(760, 760)
];
var mapShape = [
{
'numCircles': 0,
'originCircles': [Offset(0, 0)],
'radiuosCircles': [0.0],
'numRectangles': 7,
'originRectangles': [
Offset(300, 30),
Offset(100, 560),
Offset(600, 630),
Offset(780, 360),
Offset(300, 300),
Offset(500, 260),
Offset(300, 560)
],
'widthRectangles': [150.0, 100.0, 50.0, 80.0, 150.0, 100.0, 100.0],
'heightRectangles': [70.0, 100.0, 200.0, 300.0, 40.0, 300.0, 200.0],
'numPolygons': 0,
'sidesofPolygon': [0],
'radiusPolygon': [0.0],
'centerPolygon': [Offset(0, 0)],
'startCenter': pointPosition[2],
'endCenter': pointPosition[1]
},
{
'numCircles': 0,
'originCircles': [Offset(0, 0)],
'radiuosCircles': [0.0],
'numRectangles': 6,
'originRectangles': [
Offset(690, 430),
Offset(500, 560),
Offset(430, 130),
Offset(300, 760),
Offset(100, 230),
Offset(100, 460)
],
'widthRectangles': [150.0, 100.0, 200.0, 100.0, 210.0, 210.0],
'heightRectangles': [150.0, 250.0, 50.0, 250.0, 50.0, 300.0],
'numPolygons': 0,
'sidesofPolygon': [3, 3, 5, 4, 4],
'radiusPolygon': [30.0, 40.0, 40.0, 40.0, 50.0],
'centerPolygon': [
Offset(40, 130),
Offset(700, 90),
Offset(600, 200),
Offset(600, 500),
Offset(780, 400)
],
'startCenter': pointPosition[0],
'endCenter': pointPosition[3]
},
{
'numCircles': 0,
'originCircles': [Offset(0, 0)],
'radiuosCircles': [0.0],
'numRectangles': 7,
'originRectangles': [
Offset(300, 130),
Offset(500, 460),
Offset(750, 530),
Offset(600, 130),
Offset(600, 730),
Offset(100, 530),
Offset(350, 460)
],
'widthRectangles': [160.0, 90.0, 150.0, 100.0, 150.0, 300.0, 50.0],
'heightRectangles': [130.0, 270.0, 150.0, 250.0, 100.0, 70.0, 250.0],
'numPolygons': 0,
'sidesofPolygon': [0],
'radiusPolygon': [0.0],
'centerPolygon': [Offset(0, 0)],
'startCenter': pointPosition[2],
'endCenter': pointPosition[1]
},
];
var mapShapeScreen;
@override
void initState() {
super.initState();
dbRef.child('groups').child(group.id).child('tabletStatus').set("YES");
dbRef.child('groups').child(group.id).child('currentActivity').set("Ac3");
elapseTimer.start();
timerCelluloPositiontoserver =
new Timer.periodic(new Duration(milliseconds: 2800), (time) {
dbRef.child("celluloPosition").push().set(json.encode({
"x": celluloxPosition[0],
"y": celluloyPosition[1],
"acID": "Ac3",
"turn": currentTurn,
"groupID": group.id,
}));
});
timerCelluloPosition =
new Timer.periodic(new Duration(milliseconds: 500), (time) {
if (totalRobots() > 1) {
cellulox.getrobotx().then((val) => setState(() {
if (val != null) {
celluloxPosition[0] = val;
print(celluloxPosition[0]);
// if (addtoprint == true) celluloxPositiontopaint.add(val);
}
// print(addtoprint.toString());
}));
cellulox.getroboty().then((val) => setState(() {
if (val != null) {
celluloxPosition[1] = val;
}
}));
celluloy.getrobotx().then((val) => setState(() {
if (val != null) {
celluloyPosition[0] = val;
}
}));
celluloy.getroboty().then((val) => setState(() {
if (val != null) {
celluloyPosition[1] = val;
// if (addtoprint == true) celluloyPositiontopaint.add(val);
}
}));
if (celluloxPosition[0] > 800 || celluloyPosition[1] > 800) {
cellulox.setVelocity(0, 0);
celluloy.setVelocity(0, 0);
}
}
});
timerCheckCelluloGame =
new Timer.periodic(new Duration(milliseconds: 500), (time) {
checkCelluloGame(
mapShape[currentTurn - 1],
Offset((celluloxPosition[0] + celluloyPosition[0]) / 2,
(celluloxPosition[1] + celluloyPosition[1]) / 2),
Offset(celluloxPosition[0], celluloxPosition[1]),
Offset(celluloyPosition[0], celluloyPosition[1]),
1);
});
}
void checkCelluloGame(var mapShape, Offset celluloTargetPosition,
Offset celluloXPosition, Offset celluloYPosition, int id) {
var insideBorder = false;
var insideShape = false;
final double coeffHaptic = 10;
double radiuosBorder = 40;
bool enterShape = false;
var XVelocityCelluloX;
var YVelocityCelluloX;
var XVelocityCelluloY;
var YVelocityCelluloY;
double celluloXYdistances = math.sqrt(
math.pow((celluloXPosition.dx - celluloYPosition.dx), 2) +
math.pow((celluloXPosition.dy - celluloYPosition.dy), 2));
double distanceThreshold = 120;
//print(score.toString());
//print(enterBorder.toString());
if (celluloXYdistances < distanceThreshold) {
cellulox.robotVibrate(10, 10, 0, 100, 100);
celluloy.robotVibrate(10, 10, 0, 100, 100);
// cellulox.setVelocity(-celluloxVelocity[0], -celluloxVelocity[1]);
// celluloy.setVelocity(-celluloyVelocity[0], -celluloyVelocity[1]);
}
var distancePointCenter = math.sqrt(math.pow(
(celluloTargetPosition.dx - mapShape['startCenter'].dx), 2) +
math.pow((celluloTargetPosition.dy - mapShape['startCenter'].dy), 2));
if (distancePointCenter <= radiuosStart) {
scoreY = 6;
scoreX = 6;
gameoverY = false;
reachendY = false;
}
if (scoreY <= 0 && gameoverY == false) {
tapCounter = tapCounter + 1;
onDataSend();
gameoverY = true;
showAlertDialog(context, 'BLue Robot Does not have energy',
'Tell your friend with Blue Robot to go start point');
}
var distancePointEnd = math.sqrt(
math.pow((celluloTargetPosition.dx - mapShape['endCenter'].dx), 2) +
math.pow((celluloTargetPosition.dy - mapShape['endCenter'].dy), 2));
if (distancePointEnd <= radiuosStart && reachendY == false) {
// scoreX = -1;
reachendY = true;
tapCounter = tapCounter + 1;
onDataSend();
showAlertDialog(context, 'Your Robot reached the goal point',
'Tell your friend to start again or you can go to next turn.');
}
for (int i = 0; i < mapShape['numRectangles']; i++) {
if ((Rect.fromCenter(
center: Offset(mapShape['originRectangles'][i].dx,
mapShape['originRectangles'][i].dy),
width: mapShape['widthRectangles'][i],
height: mapShape['heightRectangles'][i])
.contains(celluloTargetPosition) ==
true)) {
insideBorder = true;
XVelocityCelluloX = coeffHaptic *
(celluloXPosition.dx - mapShape['originRectangles'][i].dx);
YVelocityCelluloX = coeffHaptic *
(celluloXPosition.dy - mapShape['originRectangles'][i].dy);
XVelocityCelluloY = coeffHaptic *
(celluloYPosition.dx - mapShape['originRectangles'][i].dx);
YVelocityCelluloY = coeffHaptic *
(celluloYPosition.dy - mapShape['originRectangles'][i].dy);
cellulox.setVelocity(XVelocityCelluloX, 0);
celluloy.setVelocity(0, YVelocityCelluloY);
if (enterBorderRectY == false) {
scoreY = scoreY - 1;
scoreX = scoreX - 1;
enterBorderRectY = true;
}
trappedRectangleY = i;
break;
} else if (id == 1 && i == trappedRectangleY) {
enterBorderRectY = false;
}
// if (id == 0) cellulox.clearrobot();
//if (id == 1) celluloy.clearrobot();
}
if (enterBorderY == false &&
enterBorderRectY == false &&
enterBorderpolygonY == false) {
cellulox.clearrobot();
celluloy.clearrobot();
}
colorRobots();
/*
/*
/*
insideBorder = false;
if (distancePointCenter <= mapShape['radiuosCircles'][i]) {
insideShape = true;
} else {
insideShape = false;
enterShape = false;
}
if (insideShape == true) {
if (enterShape == false) {
score = score - 1;
enterShape = true;
}
}
*/
if (id == 0) cellulox.clearrobot();
if (id == 1) celluloy.clearrobot();
}
*/
}
*/
}
void colorRobots() {
for (int i = 0; i < 6; i++) {
cellulox.setColor(0, 0, 0, 0, 0);
}
for (int i = 0; i < scoreX; i++) {
cellulox.setColor(0, 255, 0, 1, i);
}
for (int i = 0; i < 6; i++) {
celluloy.setColor(0, 0, 0, 0, 0);
}
for (int i = 0; i < scoreY; i++) {
celluloy.setColor(0, 0, 255, 1, i);
}
}
@override
void dispose() {
elapseTimer.stop();
super.dispose();
timerCelluloPosition.cancel(); //
// timerCheckCelluloGame.cancel();
}
void onDataSend() {
dbRef.child('attempts').push().set(json.encode({
"numAttempts": tapCounter,
"groupID": group.id,
"acID": "Ac3",
"elpasedTime": elapseTimer.elapsedMilliseconds -
progressElpasedTime[currentTurn - 1],
"progress": {
"turn1": progress[0],
"turn2": progress[1],
"turn3": progress[2]
},
"progressElpasedTime": {
"turn1": progressElpasedTime[0],
"turn2": progressElpasedTime[1],
"turn3": progressElpasedTime[2],
},
"currentTurn": currentTurn,
"inactivity": inactivity,
"mistakes": {
"turn1": {
"slope": mistakesSlope[0],
"initialPoint": mistakesInitialPosition[0]
},
"turn2": {
"slope": mistakesSlope[1],
"initialPoint": mistakesInitialPosition[1]
},
"turn3": {
"slope": mistakesSlope[2],
"initialPoint": mistakesInitialPosition[2]
},
}
}));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Avoid the hidden obstacles'),
),
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Column(children: <Widget>[
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
Container(
height: 100,
width: 600,
child: Stack(children: <Widget>[
Card(
child: ListTile(
title: Text('Guide your friedns to go from ' +
startPoint[currentTurn - 1].toString() +
' to ' +
endPoint[currentTurn - 1].toString()),
),
),
])),
SizedBox(
width: 15,
),
SizedBox(width: 20),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(100)),
color: Colors.blue),
child: FlatButton(
child: Text(
"Next Turn",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
fontSize: 18),
),
onPressed: () => {
tapCounter = 0,
if (currentTurn <= 2)
{
setState(() {
currentTurn = currentTurn + 1;
}),
progress[currentTurn - 2] = 1,
// controller.reset(),
progress[currentTurn - 1] = 0,
onDataSend(),
}
else
{
progress[2] = 1,
onDataSend(),
showAlertDialog(
context, 'Wait for teacher', 'Game has finished! '),
},
},
),
)
]),
Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.65,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(100)),
// color: Colors.blue
),
child: Stack(
children: <Widget>[
CustomPaint(
//size: Size(200, 200),
painter:
//LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint),
MapShapeMaker(
MediaQuery.of(context).size.width *
0.9 /
mapSizeWidth,
MediaQuery.of(context).size.height *
0.65 /
mapSizeHeight,
mapShape[currentTurn - 1]['numRectangles'],
mapShape[currentTurn - 1]['originRectangles'],
mapShape[currentTurn - 1]['widthRectangles'],
mapShape[currentTurn - 1]['heightRectangles'],
mapShape[currentTurn - 1]['numCircles'],
mapShape[currentTurn - 1]['originCircles'],
mapShape[currentTurn - 1]['radiuosCircles'],
mapShape[currentTurn - 1]['numPolygons'],
mapShape[currentTurn - 1]['sidesofPolygon'],
mapShape[currentTurn - 1]['radiusPolygon'],
mapShape[currentTurn - 1]['centerPolygon'],
mapShape[currentTurn - 1]['startCenter'],
mapShape[currentTurn - 1]['endCenter']),
),
Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.65,
child: Align(
alignment: Alignment(
2 *
((celluloxPosition[0] + celluloyPosition[0]) /
2 /
mapSizeWidth) -
1,
2 *
((celluloxPosition[1] + celluloyPosition[1]) /
2 /
mapSizeHeight) -
1),
child: Card(
child: SvgPicture.asset(
"assets/images/celluloPurple.svg",
height: 60,
width: 60),
),
),
),
Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.65,
child: Align(
alignment: Alignment(
2 * ((celluloxPosition[0]) / mapSizeWidth) - 1,
2 * ((celluloxPosition[1]) / mapSizeHeight) - 1),
child: Card(
child: SvgPicture.asset("assets/images/celluloRed.svg",
height: 60, width: 60),
),
),
),
Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.65,
child: Align(
alignment: Alignment(
2 * ((celluloyPosition[0]) / mapSizeWidth) - 1,
2 * ((celluloyPosition[1]) / mapSizeHeight) - 1),
child: Card(
child: SvgPicture.asset("assets/images/celluloBlue.svg",
height: 60, width: 60),
),
),
)
],
)),
SizedBox(
height: 55,
),
MembersBar(),
])));
}
}
Event Timeline
Log In to Comment