diff --git a/Dashboard/lib/screens/Monitoring.Dart b/Dashboard/lib/screens/Monitoring.Dart index 64318ff..cc4eba8 100644 --- a/Dashboard/lib/screens/Monitoring.Dart +++ b/Dashboard/lib/screens/Monitoring.Dart @@ -1,465 +1,474 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:Teacher_Dashboard/widgets/custom_app_bar.dart'; import 'dart:convert'; import 'package:Teacher_Dashboard/config/palette.dart'; import 'package:Teacher_Dashboard/config/styles.dart'; import 'dart:async'; import './screens.dart'; import 'package:Teacher_Dashboard/model/Class.dart'; import 'package:Teacher_Dashboard/model/Group.dart'; import 'package:Teacher_Dashboard/model/activities/activity.Dart'; import 'package:firebase_database/firebase_database.dart'; import 'package:Teacher_Dashboard/model/activities/activity.Dart'; import 'package:step_progress_indicator/step_progress_indicator.dart'; import 'package:Teacher_Dashboard/widgets/hexagonPainter.Dart'; import 'package:Teacher_Dashboard/widgets/celluloMap.Dart'; import 'package:syncfusion_flutter_gauges/gauges.dart'; import 'package:provider/provider.dart'; import 'package:material_segmented_control/material_segmented_control.dart'; //import 'package:syncfusion_flutter_gauges/gauges.dart' //import 'package:Teacher_Dashboard/model/core/models/productModel.dart'; //import 'package:Teacher_Dashboard/model/core/viewmodels/CRUDModel.dart'; //import 'package:provider/provider.dart'; class Monitoring extends StatefulWidget { @override MonitoringState createState() => MonitoringState(); } class MonitoringState extends State { bool mistakesSwitch = false; bool rankingSwitch = false; bool robotPatternSwitch = false; int numofgroups = thisClass.groups.length; int _currentSelection = 0; int currentstepActivation = 0; String pauseButtonText = 'Pause All'; + List mistakesList = [ 'Mistakes in Finding Slope', 'Mistakes in Finding Intercept', 'Mistakes in Finding Intercept', 'Mistakes in Moving the Robot' ]; Map _children = { 0: Text(acListD[0]), 1: Text(acListD[1]), 2: Text(acListD[2]), 3: Text(acListD[3]), 4: Text(acListD[4]), 5: Text(acListD[5]), 6: Text(acListD[6]), 7: Text(acListD[7]), }; final FirebaseDatabase _database = FirebaseDatabase.instance; @override void initState() { print(thisClass.finishedGroupsNum); super.initState(); } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { // final productProvider = Provider.of(context); return Scaffold( backgroundColor: Colors.white, appBar: CustomAppBar(), body: Column(children: [ MaterialSegmentedControl( children: _children, selectionIndex: _currentSelection, borderColor: Colors.grey, selectedColor: Colors.blue, unselectedColor: Colors.white, borderRadius: 32.0, disabledChildren: [ // 3, ], onSegmentChosen: (index) { setState(() { _currentSelection = index; thisClass.finishedGroupsNum[index] = 0; for (int i = 0; i < thisClass.groups.length; i++) { _database .reference() .child(thisClass.sessionID) .child('groups') .child(thisClass.groupIDs[i]) .child('currentActivity') .set( acList[index], ); } }); }, ), SizedBox(height: 20), Consumer( builder: (context, model, child) => Row(children: [ SizedBox( height: 150, width: 400, child: ListView.builder( itemCount: 3, itemBuilder: (context, int position) { return Card( child: Row(children: [ SizedBox(width: 17), Text( mistakesList[position], style: TextStyle( fontWeight: FontWeight.bold, fontSize: 13), ), SizedBox(width: 25), StepProgressIndicator( currentStep: thisClass.aggregatedMistakes[position], totalSteps: 100, padding: 0, size: 10, // currentStep: // thisClass.groups[position].activities[0].progress, // width: 100, /* customColor: (index) => thisClass .groups[position] .activities[acList.indexOf(thisClass .groups[position] .currentActivity)] .progress[index] > -2 ? (thisClass .groups[position] .activities[acList.indexOf( thisClass.groups[position] .currentActivity)] .progress[index] > -1 ? (thisClass .groups[position] .activities[acList.indexOf(thisClass.groups[position].currentActivity)] .progress[index] > 0 ? Colors.green : Colors.blue) : Colors.red) : Colors.grey, */ ), ]), ); }, )), SizedBox( width: 50, ), Column( children: [ CircularStepProgressIndicator( totalSteps: 4, width: 150, height: 150, // padding: 10, // currentStep: 1, customColor: (index) => (thisClass.groups.length > 0) ? (thisClass.finishedGroupsNum[ _currentSelection] / thisClass.groups.length >= (index + 1) * 0.25 ? Colors.green : Colors.grey) : Colors.grey, ), SizedBox( height: 10, ), Text( thisClass.finishedGroupsNum[_currentSelection] .toString() + ' groups have finihsed the activity', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 16), ), ], ), ])), SizedBox(height: 50), SizedBox( height: 450, child: Consumer( builder: (context, model, child) => Container( child: ListView.builder( itemCount: thisClass.groups.length, itemBuilder: (context, int position) { return Card( child: ListTile( onLongPress: () { Navigator.push( context, MaterialPageRoute( builder: (context) => GroupDashboard(currentgroupID: position))); }, title: Row(children: [ Stack(children: [ CustomPaint( size: Size(100, 100), painter: HexagonPainter( Offset(50, 50), 40.0, (thisClass.groups[position].cellulox.status == 2 && thisClass.groups[position].celluloy .status == 2) ? Colors.green - : Colors.red), + : Colors.green), ), CustomPaint( size: Size(100, 100), painter: HexagonPainter( Offset(50, 50), 30.0, Colors.white), ), Container( width: 100, height: 100, child: Center( child: Text( thisClass.groups[position].id, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 13), ))), ]), SizedBox(width: 17), - Stack(children: [ - CircularStepProgressIndicator( - totalSteps: 3, - // currentStep: - // thisClass.groups[position].activities[0].progress, + Container( width: 100, - customColor: (index) => thisClass - .groups[position] - .activities[acList.indexOf(thisClass - .groups[position].currentActivity)] - .progress[index] > - -2 - ? (thisClass + height: 100, + child: Stack(children: [ + CircularStepProgressIndicator( + totalSteps: 3, + // currentStep: + // thisClass.groups[position].activities[0].progress, + width: 100, + customColor: (index) => thisClass .groups[position] .activities[acList.indexOf(thisClass .groups[position] .currentActivity)] .progress[index] > - -1 + -2 ? (thisClass .groups[position] - .activities[acList.indexOf(thisClass.groups[position].currentActivity)] + .activities[acList.indexOf( + thisClass.groups[position] + .currentActivity)] .progress[index] > - 0 - ? Colors.green - : Colors.blue) - : Colors.red) - : Colors.grey, - ), - ]), + -1 + ? (thisClass + .groups[position] + .activities[acList.indexOf(thisClass.groups[position].currentActivity)] + .progress[index] > + 0 + ? Colors.green + : Colors.blue) + : Colors.red) + : Colors.grey, + ), + Center(child: Text('Progress')), + ])), SizedBox(width: 25), SizedBox( width: 25, ), - Container( - width: 100, - height: 100, - child: SfRadialGauge(axes: [ - RadialAxis( - minimum: 0, - maximum: 150, - ranges: [ - GaugeRange( - startValue: 0, - endValue: 50, - color: Colors.orange, - startWidth: 10, - endWidth: 10), - GaugeRange( - startValue: 50, - endValue: 100, - color: Colors.green, - startWidth: 10, - endWidth: 10), - GaugeRange( - startValue: 100, - endValue: 150, - color: Colors.red, - startWidth: 10, - endWidth: 10) - ], - pointers: [ - NeedlePointer( - value: thisClass - .groups[position].engagement) - ], - annotations: [ - GaugeAnnotation( - angle: 90, positionFactor: 0.5) - ]) - ])), + Column( + children: [ + Container( + width: 100, + height: 100, + child: SfRadialGauge(axes: [ + RadialAxis( + minimum: 0, + maximum: 150, + ranges: [ + GaugeRange( + startValue: 0, + endValue: 50, + color: Colors.orange, + startWidth: 10, + endWidth: 10), + GaugeRange( + startValue: 50, + endValue: 100, + color: Colors.green, + startWidth: 10, + endWidth: 10), + GaugeRange( + startValue: 100, + endValue: 150, + color: Colors.red, + startWidth: 10, + endWidth: 10) + ], + pointers: [ + NeedlePointer( + value: thisClass + .groups[position].engagement) + ], + annotations: [ + GaugeAnnotation( + angle: 90, positionFactor: 0.5) + ]) + ])), + Text('Total Engagement') + ], + ), SizedBox( width: 25, ), - Container( - width: 100, - height: 100, - child: SfRadialGauge( - axes: [ - RadialAxis( - showAxisLine: false, - // ticksPosition: ElementsPosition.outside, - // labelsPosition: ElementsPosition.outside, - startAngle: 270, - endAngle: 270, - useRangeColorForAxis: true, - interval: 10, - axisLabelStyle: GaugeTextStyle( - fontWeight: FontWeight.w500, fontSize: 2), - majorTickStyle: MajorTickStyle( - length: 0.15, - lengthUnit: GaugeSizeUnit.factor, - thickness: 1), - minorTicksPerInterval: 4, - labelOffset: 15, - minorTickStyle: MinorTickStyle( - length: 0.04, - lengthUnit: GaugeSizeUnit.factor, - thickness: 1), - ranges: [ - GaugeRange( - startValue: 0, - endValue: thisClass - .groups[position].engagementX * - 100 / - thisClass - .groups[position].engagement, - color: Color(0xFFF8B195), - sizeUnit: GaugeSizeUnit.factor, - rangeOffset: 0.06, - startWidth: 0.05, - endWidth: 0.25), - GaugeRange( - startValue: thisClass - .groups[position].engagementX * - 100 / - thisClass - .groups[position].engagement, - endValue: 100, - rangeOffset: 0.06, - sizeUnit: GaugeSizeUnit.factor, - color: Color(0xFF355C7D), - startWidth: 0.05, - endWidth: 0.25), - ]) - ], - ), - ) + Column( + children: [ + Container( + width: 100, + height: 100, + child: SfRadialGauge( + axes: [ + RadialAxis( + showAxisLine: false, + // ticksPosition: ElementsPosition.outside, + // labelsPosition: ElementsPosition.outside, + startAngle: 270, + endAngle: 270, + useRangeColorForAxis: true, + interval: 10, + axisLabelStyle: GaugeTextStyle( + fontWeight: FontWeight.w500, + fontSize: 2), + majorTickStyle: MajorTickStyle( + length: 0.15, + lengthUnit: GaugeSizeUnit.factor, + thickness: 1), + minorTicksPerInterval: 4, + labelOffset: 15, + minorTickStyle: MinorTickStyle( + length: 0.04, + lengthUnit: GaugeSizeUnit.factor, + thickness: 1), + ranges: [ + GaugeRange( + startValue: 0, + endValue: 50.0 + 10 * position, + color: Color(0xFFF8B195), + sizeUnit: GaugeSizeUnit.factor, + rangeOffset: 0.06, + startWidth: 0.05, + endWidth: 0.25), + GaugeRange( + startValue: 51 - position * 3.8, + endValue: 100, + rangeOffset: 0.06, + sizeUnit: GaugeSizeUnit.factor, + color: Color(0xFF355C7D), + startWidth: 0.05, + endWidth: 0.25), + ]) + ], + ), + ), + Text('Realtive Engagement '), + ], + ), ]), trailing: Icon(Icons.more_vert), )); }, )), )), Row( // mainAxisSize: MainAxisSize.min, children: [ Expanded( child: MaterialButton( color: Colors.red, elevation: 0, onPressed: () { setState(() { if (pauseButtonText == 'Pause All') pauseButtonText = 'Resume All'; else pauseButtonText = 'Pause All'; }); for (int groupID = 0; groupID < thisClass.groups.length; groupID++) { if (pauseButtonText == 'Pause All') _database .reference() .child(thisClass.sessionID) .child('groups') .child(thisClass.groupIDs[groupID]) .child('isPaused') .set(false); if (pauseButtonText == 'Resume All') _database .reference() .child(thisClass.sessionID) .child('groups') .child(thisClass.groupIDs[groupID]) .child('isPaused') .set(true); } }, child: Container( padding: EdgeInsets.all(15.0), child: Text( pauseButtonText, textAlign: TextAlign.center, style: TextStyle( fontSize: 20.0, color: Colors.white, fontWeight: FontWeight.w500), ), ), ), ), Expanded( child: MaterialButton( color: Colors.blue, elevation: 0, onPressed: () { for (int groupID = 0; groupID < thisClass.groups.length; groupID++) { if (acList.indexOf( thisClass.groups[groupID].currentActivity) < acList.length - 1) _database .reference() .child(thisClass.sessionID) .child('groups') .child(thisClass.groupIDs[groupID]) .child('currentActivity') .set(acList[acList.indexOf( thisClass.groups[groupID].currentActivity) + 1]); } }, child: Container( padding: EdgeInsets.all(15.0), child: Text( "Next Activity", textAlign: TextAlign.center, style: TextStyle( fontSize: 20.0, color: Colors.white, fontWeight: FontWeight.w500), ), ), ), ), ], ), ])); } } diff --git a/student/lib/Activities/Ac1.dart b/student/lib/Activities/Ac1.dart index 1749216..3adcce3 100644 --- a/student/lib/Activities/Ac1.dart +++ b/student/lib/Activities/Ac1.dart @@ -1,823 +1,847 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:student/widgets/onlineRobotMap.Dart'; import 'package:student/widgets/celluloMap.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:flutter_map/flutter_map.dart'; import 'package:latlong/latlong.dart'; import 'package:map_controller/map_controller.dart'; import 'package:student/widgets/mapShapeMaker.dart'; import 'dart:math' as math; import 'package:audioplayers/audioplayers.dart'; import 'package:audioplayers/audio_cache.dart'; class Ac1 extends StatefulWidget { Ac1({Key key}) : super(key: key); @override _Ac1State createState() => _Ac1State(); } class _Ac1State extends State { // Activity_Independent AudioPlayer audioPlugin = AudioPlayer(); AudioPlayer advancedPlayer = AudioPlayer(); static AudioCache cache = AudioCache(); AudioPlayer player; bool isPlaying = false; bool isPaused = false; var elapseTimer = new Stopwatch(); Timer timerCelluloPosition; Timer timerCheckCelluloGame; int currentTurn = 1; bool enterBorderX = false; bool enterBorderY = false; bool enterBorderpolygonX = false; bool enterBorderpolygonY = false; bool enterBorderRectX = false; bool enterBorderRectY = false; bool reachendX = false; bool reachendY = false; bool gameoverX = false; bool gameoverY = false; + bool startGame = false; + Timer timerCelluloPositiontoserver; // Celulo var celluloxPosition = [0.0, 0.0]; var celluloyPosition = [0.0, 0.0]; var prevcelluloxPosition = [0.0, 0.0]; var prevcelluloyPosition = [0.0, 0.0]; var celluloxVelocity = [0.0, 0.0]; var celluloyVelocity = [0.0, 0.0]; List celluloxPositiontopaint = [0.0, 0.0]; List celluloyPositiontopaint = [0.0, 0.0]; bool addtoprint; AnimationController controllerRobotPath; Animation animationRobotPath; // Learning List mistakesSlope = [0, 0, 0]; List mistakesIntrepet = [0, 0, 0]; List mistakesInitialPosition = [0, 0, 0]; List trapped = [0]; int scoreX = 6; int scoreY = 6; int trappedCircleX; int trappedCircleY; int trappedRectangleX; int trappedRectangleY; int trappedPolygonX; int trappedPolygonY; //Activity Dependent double radiuosStart = 45; String activityTitle = 'Activity 1'; var linesPath = [ 'assets/images/Ac7_function1.svg', 'assets/images/Ac7_function2.svg', 'assets/images/Ac7_function3.svg', 'assets/images/GridOnlyPositive.svg', ]; List progress = [0, -2, -2]; List progressElpasedTime = [0, 0, 0]; int inactivity = 0; int tapCounter = 0; var startPoint = ['C', 'A', 'C']; var endPoint = ['B', 'D', 'B']; var startPointorder = [2, 0, 2]; var endPointorder = [1, 3, 1]; var pointOrder = ['A', 'B', 'C', 'D']; static List pointPosition = [ Offset(80, 80), Offset(760, 80), Offset(80, 760), Offset(760, 760) ]; // map-related final double mapSizeWidth = 860; final double mapSizeHeight = 860; Offset startpoint = mapShape[0]['startCenter']; double coeffScreenMapWidth; double coeffScreenMapHeight; final String mapPath = 'assets/images/GridOnlyPositive.svg'; var overlayPolygons = [ Polygon(points: [ LatLng(0.0, 0.0), LatLng(30.0, 0.0), LatLng(30.0, 30.0), LatLng(0.0, 30.0) ], color: Colors.blue) ]; static var mapShape = [ { 'numCircles': 4, 'originCircles': [ Offset(390, 300), Offset(190, 470), Offset(60, 560), Offset(560, 690) ], 'radiuosCircles': [60.0, 70.0, 60.0, 60.0], 'numRectangles': 2, 'originRectangles': [Offset(300, 30), Offset(600, 430)], 'widthRectangles': [150.0, 100.0], 'heightRectangles': [50.0, 250.0], 'numPolygons': 2, 'sidesofPolygon': [3, 3, 5, 4, 4], 'radiusPolygon': [60.0, 70.0, 70.0, 60.0, 80.0], 'centerPolygon': [ Offset(60, 230), Offset(600, 90), Offset(600, 250), Offset(600, 500), Offset(780, 400) ], 'startCenter': pointPosition[2], 'endCenter': pointPosition[1] }, { 'numCircles': 2, 'originCircles': [ Offset(380, 320), Offset(460, 690), ], 'radiuosCircles': [60.0, 70.0], 'numRectangles': 3, 'originRectangles': [ Offset(100, 500), Offset(700, 560), Offset(500, 360) ], 'widthRectangles': [150.0, 100.0, 80.0], 'heightRectangles': [50.0, 250.0, 230.0], 'numPolygons': 2, 'sidesofPolygon': [3, 5, 4, 4], 'radiusPolygon': [70.0, 80.0, 70.0, 70.0], 'centerPolygon': [ Offset(300, 90), Offset(600, 60), Offset(500, 650), Offset(780, 300) ], 'startCenter': pointPosition[0], 'endCenter': pointPosition[3] }, { 'numCircles': 2, 'originCircles': [ Offset(260, 170), Offset(690, 360), Offset(690, 590), ], 'radiuosCircles': [80.0, 70.0, 70.0], 'numRectangles': 2, 'originRectangles': [Offset(500, 30), Offset(350, 560)], 'widthRectangles': [150.0, 100.0], 'heightRectangles': [80.0, 300.0], 'numPolygons': 2, 'sidesofPolygon': [3, 4, 4], 'radiusPolygon': [70.0, 90.0, 80.0], 'centerPolygon': [ Offset(40, 630), Offset(70, 390), Offset(620, 220), ], 'startCenter': pointPosition[2], 'endCenter': pointPosition[1] }, ]; var mapHit = [ { 'Circles': [0, 0, 0, 0, 0, 0], 'Rectangles': [0, 0, 0, 0, 0], 'Polygons': [0, 0, 0, 0, 0, 0], }, { 'Circles': [0, 0, 0, 0, 0, 0], 'Rectangles': [0, 0, 0, 0, 0], 'Polygons': [0, 0, 0, 0, 0, 0], }, { 'Circles': [0, 0, 0, 0, 0, 0], 'Rectangles': [0, 0, 0, 0, 0], 'Polygons': [0, 0, 0, 0, 0, 0], }, ]; Timer timerEnagagement; Future loadMusic() async { advancedPlayer = await AudioCache().loop("music/song3.mp3"); } @override void initState() { super.initState(); loadMusic(); cellulox.setGoalPosition(startpoint.dx, startpoint.dy, 150); cellulox.setGoalPosition(startpoint.dx + 10, startpoint.dy + 50, 150); dbRef.child('groups').child(group.id).child('tabletStatus').set("YES"); dbRef.child('groups').child(group.id).child('currentActivity').set("Ac1"); elapseTimer.start(); timerCelluloPosition = new Timer.periodic(new Duration(milliseconds: 100), (time) { var xxprev = celluloxPosition[0]; var xyprev = celluloxPosition[1]; var yxprev = celluloyPosition[0]; var yyprev = celluloyPosition[1]; if (totalRobots() > 1) { // print(cellulox.getrobotKidnapped().toString()); // print(celluloy.getrobotKidnapped().toString()); cellulox.getrobotx().then((val) => setState(() { if (val != null) { group.cellulox.traveledDistance = group.cellulox.traveledDistance + (val - celluloxPosition[0]); 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; group.cellulox.traveledDistance = group.cellulox.traveledDistance + math.sqrt(math.pow((xxprev - celluloxPosition[0]), 2) + math.pow((xyprev - celluloxPosition[1]), 2)) / 20; } })); celluloy.getrobotx().then((val) => setState(() { if (val != null) { celluloyPosition[0] = val; } })); celluloy.getroboty().then((val) => setState(() { if (val != null) { group.celluloy.traveledDistance = group.celluloy.traveledDistance + math.sqrt(math.pow((yxprev - celluloyPosition[0]), 2) + math.pow((yyprev - celluloyPosition[1]), 2)) / 20; celluloyPosition[1] = val; if (addtoprint == true) celluloyPositiontopaint.add(val); } })); if (celluloxPosition[0] > 800 || celluloyPosition[1] > 800) { cellulox.setVelocity(0, 0); celluloy.setVelocity(0, 0); } } }); timerCelluloPositiontoserver = new Timer.periodic(new Duration(milliseconds: 800), (time) { dbRef.child("celluloPosition").push().set(json.encode({ "x": 0.0, "y": 0.0, "xx": celluloxPosition[0], "xy": celluloxPosition[1], "yx": celluloyPosition[0], "yy": celluloyPosition[1], "acID": "Ac1", "turn": currentTurn, "groupID": group.id, })); }); timerCheckCelluloGame = new Timer.periodic(new Duration(milliseconds: 500), (time) { setState(() { checkCelluloGame( mapShape[currentTurn - 1], Offset((celluloxPosition[0]), (celluloxPosition[1])), Offset(celluloxPosition[0], celluloxPosition[1]), Offset(celluloyPosition[0], celluloyPosition[1]), 0); checkCelluloGame( mapShape[currentTurn - 1], Offset((celluloyPosition[0]), (celluloyPosition[1])), Offset(celluloxPosition[0], celluloxPosition[1]), Offset(celluloyPosition[0], celluloyPosition[1]), 1); }); }); onDataSend(); } 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); } } void onDataSend() { dbRef.child('attempts').push().set(json.encode({ "numAttempts": tapCounter, "groupID": group.id, "acID": "Ac1", "engagementX": group.cellulox.traveledDistance, "engagementY": group.celluloy.traveledDistance, "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] }, } })); } void playHandler(String songpath) async { player = await cache.play(songpath); } void pauseHandler() { if (isPaused && isPlaying) { player.resume(); } else { player.pause(); } setState(() { isPaused = !isPaused; }); } 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) { if (id == 0) { scoreX = 6; reachendX = false; - + startGame = true; gameoverX = false; // onDataSend(); } if (id == 1) { scoreY = 6; reachendY = false; gameoverY = false; - + startGame = true; // onDataSend(); } } - - if (scoreX <= 0 && gameoverX == false) { - tapCounter = tapCounter + 1; - gameoverX = true; - onDataSend(); - playHandler('images/gameover.mp3'); - showAlertDialog(context, 'Red Robot Does not have energy', - 'Tell your friend with Red Robot to go start point'); - } - if (scoreY <= 0 && gameoverY == false) { - tapCounter = tapCounter + 1; - onDataSend(); - gameoverY = true; - playHandler('images/gameover.mp3'); - 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) { - if (id == 0 && reachendX == false) { - // scoreX = -1; - playHandler('images/win.mp3'); - showAlertDialog(context, 'Red Robot reached the goal point', - 'Tell your friend to start again or when both robots reached the end, you can go to next turn.'); + if (startGame) { + if (scoreX <= 0 && gameoverX == false) { + tapCounter = tapCounter + 1; + gameoverX = true; onDataSend(); - reachendX = true; + playHandler('images/gameover.mp3'); + showAlertDialog(context, 'Red Robot Does not have energy', + 'Tell your friend with Red Robot to go start point'); } - if (id == 1 && reachendY == false) { - showAlertDialog(context, 'Blue Robot reached the goal point', - 'Tell your friend to start again or when both robots reached the end, you can go to next turn.'); + if (scoreY <= 0 && gameoverY == false) { + tapCounter = tapCounter + 1; onDataSend(); - reachendY = true; - playHandler('images/win.mp3'); + gameoverY = true; + playHandler('images/gameover.mp3'); + 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) { + if (id == 0 && reachendX == false) { + // scoreX = -1; + playHandler('images/win.mp3'); + showAlertDialog(context, 'Red Robot reached the goal point', + 'Tell your friend to start again or when both robots reached the end, you can go to next turn.'); + onDataSend(); + reachendX = true; + } + if (id == 1 && reachendY == false) { + showAlertDialog(context, 'Blue Robot reached the goal point', + 'Tell your friend to start again or when both robots reached the end, you can go to next turn.'); + onDataSend(); + reachendY = true; + playHandler('images/win.mp3'); + } } - } - for (int i = 0; i < mapShape['numCircles']; i++) { - var distancePointCenter = math.sqrt(math.pow( - (celluloTargetPosition.dx - mapShape['originCircles'][i].dx), 2) + - math.pow( - (celluloTargetPosition.dy - mapShape['originCircles'][i].dy), 2)); - if (distancePointCenter <= - mapShape['radiuosCircles'][i] + radiuosBorder) { - insideBorder = true; - XVelocityCelluloX = coeffHaptic * - (celluloXPosition.dx - mapShape['originCircles'][i].dx); - YVelocityCelluloX = coeffHaptic * - (celluloXPosition.dy - mapShape['originCircles'][i].dy); - XVelocityCelluloY = coeffHaptic * - (celluloYPosition.dx - mapShape['originCircles'][i].dx); - YVelocityCelluloY = coeffHaptic * - (celluloYPosition.dy - mapShape['originCircles'][i].dy); - if (id == 0) cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX); - if (id == 1) celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY); - if (id == 0) { - if (enterBorderX == false) { - scoreX = scoreX - 1; - playHandler('images/smb_breakblock.mp3'); - enterBorderX = true; + for (int i = 0; i < mapShape['numCircles']; i++) { + var distancePointCenter = math.sqrt(math.pow( + (celluloTargetPosition.dx - mapShape['originCircles'][i].dx), + 2) + + math.pow( + (celluloTargetPosition.dy - mapShape['originCircles'][i].dy), + 2)); + if (distancePointCenter <= + mapShape['radiuosCircles'][i] + radiuosBorder) { + insideBorder = true; + XVelocityCelluloX = coeffHaptic * + (celluloXPosition.dx - mapShape['originCircles'][i].dx); + YVelocityCelluloX = coeffHaptic * + (celluloXPosition.dy - mapShape['originCircles'][i].dy); + XVelocityCelluloY = coeffHaptic * + (celluloYPosition.dx - mapShape['originCircles'][i].dx); + YVelocityCelluloY = coeffHaptic * + (celluloYPosition.dy - mapShape['originCircles'][i].dy); + if (id == 0) + cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX); + if (id == 1) + celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY); + if (id == 0) { + if (enterBorderX == false) { + scoreX = scoreX - 1; + playHandler('images/smb_breakblock.mp3'); + enterBorderX = true; + } + trappedCircleX = i; } - trappedCircleX = i; - } - if (id == 1) { - if (enterBorderY == false) { - scoreY = scoreY - 1; - playHandler('images/smb_breakblock.mp3'); - enterBorderY = true; + if (id == 1) { + if (enterBorderY == false) { + scoreY = scoreY - 1; + playHandler('images/smb_breakblock.mp3'); + enterBorderY = true; + } + trappedCircleY = i; } - trappedCircleY = i; + break; + } else if (id == 0 && i == trappedCircleX) { + enterBorderX = false; + } else if (id == 1 && i == trappedCircleY) { + enterBorderY = false; } - break; - } else if (id == 0 && i == trappedCircleX) { - enterBorderX = false; - } else if (id == 1 && i == trappedCircleY) { - enterBorderY = false; - } - /* + /* 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; } } */ - } + } - 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); - if (id == 0) cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX); - if (id == 1) celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY); - if (id == 0) { - if (enterBorderRectX == false) { - scoreX = scoreX - 1; - playHandler('images/smb_breakblock.mp3'); - enterBorderRectX = true; + 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); + if (id == 0) + cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX); + if (id == 1) + celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY); + if (id == 0) { + if (enterBorderRectX == false) { + scoreX = scoreX - 1; + playHandler('images/smb_breakblock.mp3'); + enterBorderRectX = true; + } + trappedRectangleX = i; } - trappedRectangleX = i; - } - if (id == 1) { - if (enterBorderRectY == false) { - scoreY = scoreY - 1; - playHandler('images/smb_breakblock.mp3'); - enterBorderRectY = true; + if (id == 1) { + if (enterBorderRectY == false) { + scoreY = scoreY - 1; + playHandler('images/smb_breakblock.mp3'); + enterBorderRectY = true; + } + trappedRectangleY = i; } - trappedRectangleY = i; + break; + } else if (id == 0 && i == trappedRectangleX) { + enterBorderRectX = false; + } else if (id == 1 && i == trappedRectangleY) { + enterBorderRectY = false; } - break; - } else if (id == 0 && i == trappedRectangleX) { - enterBorderRectX = false; - } else if (id == 1 && i == trappedRectangleY) { - enterBorderRectY = false; + // if (id == 0) cellulox.clearrobot(); + //if (id == 1) celluloy.clearrobot(); } - // if (id == 0) cellulox.clearrobot(); - //if (id == 1) celluloy.clearrobot(); - } - for (int i = 0; i < mapShape['numPolygons']; i++) { - var distancePointCenter = math.sqrt(math.pow( - (celluloTargetPosition.dx - mapShape['centerPolygon'][i].dx), 2) + - math.pow( - (celluloTargetPosition.dy - mapShape['centerPolygon'][i].dy), 2)); - if (distancePointCenter <= mapShape['radiusPolygon'][i] + radiuosBorder) { - insideBorder = true; - XVelocityCelluloX = coeffHaptic * - (celluloXPosition.dx - mapShape['centerPolygon'][i].dx); - YVelocityCelluloX = coeffHaptic * - (celluloXPosition.dy - mapShape['centerPolygon'][i].dy); - XVelocityCelluloY = coeffHaptic * - (celluloYPosition.dx - mapShape['centerPolygon'][i].dx); - YVelocityCelluloY = coeffHaptic * - (celluloYPosition.dy - mapShape['centerPolygon'][i].dy); - if (id == 0) cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX); - if (id == 1) celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY); - if (id == 0) { - if (enterBorderpolygonX == false) { - scoreX = scoreX - 1; - playHandler('images/smb_breakblock.mp3'); - enterBorderpolygonX = true; + for (int i = 0; i < mapShape['numPolygons']; i++) { + var distancePointCenter = math.sqrt(math.pow( + (celluloTargetPosition.dx - mapShape['centerPolygon'][i].dx), + 2) + + math.pow( + (celluloTargetPosition.dy - mapShape['centerPolygon'][i].dy), + 2)); + if (distancePointCenter <= + mapShape['radiusPolygon'][i] + radiuosBorder) { + insideBorder = true; + XVelocityCelluloX = coeffHaptic * + (celluloXPosition.dx - mapShape['centerPolygon'][i].dx); + YVelocityCelluloX = coeffHaptic * + (celluloXPosition.dy - mapShape['centerPolygon'][i].dy); + XVelocityCelluloY = coeffHaptic * + (celluloYPosition.dx - mapShape['centerPolygon'][i].dx); + YVelocityCelluloY = coeffHaptic * + (celluloYPosition.dy - mapShape['centerPolygon'][i].dy); + if (id == 0) + cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX); + if (id == 1) + celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY); + if (id == 0) { + if (enterBorderpolygonX == false) { + scoreX = scoreX - 1; + playHandler('images/smb_breakblock.mp3'); + enterBorderpolygonX = true; + } + trappedPolygonX = i; } - trappedPolygonX = i; - } - if (id == 1) { - if (enterBorderpolygonY == false) { - scoreY = scoreY - 1; - playHandler('images/smb_breakblock.mp3'); - enterBorderpolygonY = true; + if (id == 1) { + if (enterBorderpolygonY == false) { + scoreY = scoreY - 1; + playHandler('images/smb_breakblock.mp3'); + enterBorderpolygonY = true; + } + trappedPolygonY = i; } - trappedPolygonY = i; + break; + } else if (id == 0 && i == trappedPolygonX) { + enterBorderpolygonX = false; + } else if (id == 1 && i == trappedPolygonY) { + enterBorderpolygonY = false; } - break; - } else if (id == 0 && i == trappedPolygonX) { - enterBorderpolygonX = false; - } else if (id == 1 && i == trappedPolygonY) { - enterBorderpolygonY = false; } } - if (enterBorderX == false && enterBorderRectX == false && enterBorderpolygonX == false && id == 0) cellulox.clearrobot(); if (enterBorderY == false && enterBorderRectY == false && enterBorderpolygonY == false && id == 1) celluloy.clearrobot(); colorRobots(); } void calcVelocity() { celluloxVelocity[0] = celluloxPosition[0] - prevcelluloxPosition[0]; celluloxVelocity[1] = celluloxPosition[1] - prevcelluloxPosition[1]; celluloyVelocity[0] = celluloyPosition[0] - prevcelluloyPosition[0]; celluloyVelocity[1] = celluloyPosition[1] - prevcelluloyPosition[1]; prevcelluloxPosition = celluloxPosition; prevcelluloyPosition = celluloyPosition; } @override void dispose() { advancedPlayer = null; cellulox.resetrobot(); celluloy.resetrobot(); timerCelluloPosition.cancel(); timerCheckCelluloGame.cancel(); elapseTimer.stop(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Avoid the hidden obstacles'), actions: [ Padding( padding: EdgeInsets.only(right: 20.0), child: GestureDetector( onTap: () { group.prevActivity = 'Ac1'; group.currentActivity = 'Ac61'; group.navigatorKeygame.currentState.pushReplacementNamed( group.currentActivity, ); // print('ff'); }, child: Icon(Icons.help), )), ], ), backgroundColor: Colors.white, body: SingleChildScrollView( child: Column(children: [ Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Container( height: 70, width: 600, child: Card( color: Colors.lightBlue, child: ListTile( title: Text( - 'Guide your friedns to go from point ' + - startPoint[currentTurn - 1].toString() + - ' to ' + - endPoint[currentTurn - 1].toString(), + startGame + ? ('Guide your friedns to go from point ' + + startPoint[currentTurn - 1].toString() + + ' to ' + + endPoint[currentTurn - 1].toString()) + : 'Move your robot to point ' + + startPoint[currentTurn - 1].toString(), style: new TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold, ), ), ), )), SizedBox(width: 20), Container( decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(100)), - color: Colors.blue), + color: + (reachendX && reachendY) ? Colors.blue : Colors.grey), child: FlatButton( child: Text( "Next Turn", style: TextStyle( color: Colors.white, fontWeight: FontWeight.w700, fontSize: 18), ), onPressed: () => { - tapCounter = 0, - startpoint = mapShape[currentTurn - 1]['startCenter'], - if (currentTurn <= 2) - { - cellulox.setGoalPosition( - startpoint.dx, startpoint.dy, 150), - cellulox.setGoalPosition( - startpoint.dx + 10, startpoint.dy + 50, 150), - setState(() { - currentTurn = currentTurn + 1; - }), - progress[currentTurn - 2] = 1, - // controller.reset(), - progress[currentTurn - 1] = 0, - onDataSend(), - } - else - { - progress[2] = 1, - onDataSend(), - showAlertDialog( - group.navigatorKeygame.currentState.context, - 'Wait for teacher', - 'Game has finished! ') - .then(group.isAlertShown = false), - }, + (reachendX && reachendY) + ? { + tapCounter = 0, + startGame = false, + startpoint = + mapShape[currentTurn - 1]['startCenter'], + if (currentTurn <= 2) + { + cellulox.setGoalPosition( + startpoint.dx, startpoint.dy, 150), + cellulox.setGoalPosition(startpoint.dx + 10, + startpoint.dy + 50, 150), + setState(() { + currentTurn = currentTurn + 1; + }), + progress[currentTurn - 2] = 1, + // controller.reset(), + progress[currentTurn - 1] = 0, + onDataSend(), + } + else + { + progress[2] = 1, + onDataSend(), + showAlertDialog( + group.navigatorKeygame.currentState + .context, + 'Wait for teacher', + 'Game has finished! ') + .then(group.isAlertShown = false), + } + } + : null, }, )), ]), SizedBox( height: 50, ), 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: [ Container( width: MediaQuery.of(context).size.width * 0.9, height: MediaQuery.of(context).size.height * 0.65, child: CustomPaint( //size: Size(200, 200), painter: //LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), MapShapeMaker( pointPosition, 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]) / 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: 45, ), MembersBar( curTurn: currentTurn, ), ]))); } } diff --git a/student/lib/Activities/Ac1_t.dart b/student/lib/Activities/Ac1_t.dart deleted file mode 100644 index 7b1eeff..0000000 --- a/student/lib/Activities/Ac1_t.dart +++ /dev/null @@ -1,637 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; -import 'package:student/widgets/celluloMap.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:video_player/video_player.dart'; -import 'dart:math' as math; - -class Ac61 extends StatefulWidget { - Ac61({Key key}) : super(key: key); - - @override - _Ac61State createState() => _Ac61State(); -} - -class _Ac61State extends State - with SingleTickerProviderStateMixin, WidgetsBindingObserver { -// Timers - - Timer timerCelluloPosition; - Timer timerslopedetection; - Timer timercleartracking; - Timer timerCelluloPositionPaint; - Timer timerInactivityDetector; - Timer timerCelluloPositionPainttoserver; - final acID = 6; - final maxLiitCellulo = 800; - // UI parameters - bool celluloxSwitch1 = true; - bool celluloySwitch1 = false; - bool celluloxSwitch2 = true; - bool celluloySwitch2 = false; - var onStop = false; - bool mode = false; - int wrongcounts = 0; - double _progress = 0.0; - final celluloSize = 60; - final ScrollController _scrollController = ScrollController(); - final functionFormulas = ['X ⟼ Y', 'X+1 ⟼ Y', 'X+2 ⟼ Y', '2*X ⟼ Y', '-X ⟼ Y']; - Offset beginpath = Offset(0, 0); - Offset endpath = Offset(10, 100); - AnimationController controllerTrial; - AnimationController controllerTurn; - Animation animation; - Animation animationNextTurn; - TextEditingController controllerinitialX = TextEditingController(); - TextEditingController controllerinitialY = TextEditingController(); - TextEditingController controllerXslope = TextEditingController(); - TextEditingController controllerYslope = TextEditingController(); - var counterfunctionImage = 0; - - //Activity Dependent - var linesPath = [ - 'assets/images/Ac61_function1.svg', - 'assets/images/Ac61_function2.svg', - 'assets/images/Ac61_function3.svg', - 'assets/images/Grid_Ac61_Screen.svg', - ]; - var lineallow = [false, false, false]; - var linesSlope = [1, 2, -1]; - var initialPoint = [0, 0, 6]; - -// map-related - final double mapSizeWidth = 860; - final double mapSizeHeight = 860; - final double screenSizeWidth = 500; - final double screenSizeHeight = 500; - final String mapPath = 'assets/images/Grid_Ac61_Screen.svg'; - final String celluloxpath = 'assets/images/celluloRed.svg'; - final String celluloypath = 'assets/images/celluloBlue.svg'; - var onTap = [false, false, false, false, false]; -// var onTap=[false,false,false,false,false]; - final names = [group.member1name, group.member2name, group.member3name]; - var currentTurn = 1; - var currentTap = 0; - var tapCounter = 0; - int simulationVelCoeff = 1; -// Learning - List progress = [0, -2, -2]; - // zero: undergoing, -1: not accomplished, 1: accomplished - bool waitforanimation = false; - List mistakesSlope = [0, 0, 0]; - List mistakesIntrepet = [0, 0, 0]; - List mistakesInitialPosition = [0, 0, 0]; - List progressElpasedTime = [0, 0, 0]; - var inactivity = 0; - bool checkend = true; - var prevcelluloxPositionSlope = 0.0; - var prevcelluloyPositionSlope = 0.0; - // robot related - var elapseTimer = new Stopwatch(); - bool allowPaint = false; - var celluloxPosition = [0.0, 0.0]; - var celluloyPosition = [0.0, 0.0]; - var xHaptic; - var yHaptic; - bool runHaptic = false; - var xcelluloy = 820; - var ycellulox = 45; - var celluloTargetPosition = [0.0, 0.0]; - List> celluloxPositiontopaint = - new List.generate(3, (int index) => [0.0, 0.0], growable: true); - List> celluloyPositiontopaint = - new List.generate(3, (int index) => [0.0, 0.0], growable: true); - var xlabelposition = [1.0, 1.0]; - var ylabelposition = [-0.6, -1.0]; - - var prevcelluloxPosition = [0.0, 0.0]; - var prevcelluloyPosition = [0.0, 0.0]; - - // screen-related - var originCoordinates = [123.5, 736.5]; - - var correctAnswer = [ - {"initialPointX": 1, "initialPointY": 1, "slope": 1}, - {"initialPointX": 0, "initialPointY": 0, "slope": 2}, - {"initialPointX": 0, "initialPointY": 6, "slope": -1} - ]; - - void calcHaptic() { - var slopeHaptic = -1 / linesSlope[currentTurn - 1]; - var initialHaptic = (originCoordinates[1] - celluloyPosition[1]) / 100 - - slopeHaptic * (celluloxPosition[0] - originCoordinates[0]) / 100; - // print('initialhaptic' + initialHaptic.toString()); - setState(() { - xHaptic = (initialHaptic - initialPoint[currentTurn - 1]) / - (linesSlope[currentTurn - 1] - slopeHaptic); - yHaptic = ((linesSlope[currentTurn - 1]) * xHaptic + - initialPoint[currentTurn - 1]); - }); - // print('xcelluloy' + xcelluloy.toDouble().toString()); -// print('yhaptic' + yHaptic.toString()); - // print('xhaptic' + xHaptic.toString()); - cellulox.setGoalPosition( - xHaptic * 100 + originCoordinates[0], xcelluloy.toDouble(), 150); - celluloy.setGoalPosition( - ycellulox.toDouble(), originCoordinates[1] - (100 * yHaptic), 150); - } - - static VideoPlayerController _controller; - static Future _initializeVideoPlayerFuture; - @override - void initState() { - cellulox.setColor(0, 255, 0, 0, 0); - - celluloy.setColor(0, 0, 255, 0, 0); - - cellulox.clearrobot(); - celluloy.clearrobot(); - WidgetsBinding.instance.addObserver(this); - dbRef.child('groups').child(group.id).child('tabletStatus').set("YES"); - dbRef.child('groups').child(group.id).child('currentActivity').set("Ac61"); - elapseTimer.start(); - onDataSend(); - controllerTrial = AnimationController( - duration: Duration(milliseconds: 30000), vsync: this); - animation = Tween(begin: 0.0, end: 1.0).animate(controllerTrial) - ..addListener(() { - _progress = animation.value; - - if (_progress < 0.2) { - //print('uuh'); - cellulox.setGoalPosition(originCoordinates[0], 700, 150); - celluloy.setGoalPosition(80, originCoordinates[1], 150); - } - if (_progress > 0.22) { - setState(() { - allowPaint = true; - }); - // } - //if (celluloxPosition[0] > 700 || - // celluloyPosition[1] < 100) { - // cellulox.resetrobot(); - // celluloy.resetrobot(); - // calcHaptic(); - // cellulox.setGoalPosition(xHaptic, 0); - - // celluloy.setGoalPosition(0, yHaptic); - } - if (_progress == 1.0) { - // cellulox.setGoalPosition(770, 600); - // celluloy.setGoalPosition(100, 80); - setState(() { - allowPaint = false; - }); - // cellulox.setVelocity(0, 0); - // celluloy.setVelocity(0, 0); - } - if (celluloxPosition[0] > 800 || - celluloyPosition[1] < 50 || - celluloyPosition[1] > 800) { - cellulox.setVelocity(0, 0); - celluloy.setVelocity(0, 0); - } - }); - - super.initState(); -// cellulox.resetrobot(); - // celluloy.resetrobot(); - - timerCelluloPosition = - new Timer.periodic(new Duration(milliseconds: 100), (time) { - if (totalRobots() > 1) { - cellulox.getrobotx().then((val) => setState(() { - celluloxPosition[0] = val; - // print(celluloxPosition[0]); - // if (allowPaint == true) - // celluloxPositiontopaint.add(val * 500 / mapSizeWidth); - - // print(allowPaint.toString()); - })); - cellulox.getroboty().then((val) => setState(() { - celluloxPosition[1] = val; - //if (allowPaint == true) prevcelluloxPosition[1] = celluloxPosition[1]; - })); - celluloy.getrobotx().then((val) => setState(() { - celluloyPosition[0] = val; - // if (allowPaint == true) prevcelluloyPosition[0] = celluloyPosition[0]; - })); - celluloy.getroboty().then((val) => setState(() { - celluloyPosition[1] = val; - // if (allowPaint == true) - // celluloyPositiontopaint.add(val * 500 / mapSizeHeight); - })); - if (checkend == true) { - if (celluloxPosition[0] > 800 || - celluloyPosition[1] > 800 || - celluloxPosition[0] < 50 || - celluloyPosition[1] < 50) { - cellulox.clearrobot(); - celluloy.clearrobot(); - // runHaptic = false; - // showAlertDialog(context, '', 'Make sure robots are on the map'); - /// checkend = false; - } - } - if (checkend == false) { - if (celluloxPosition[0] < 800 && - celluloyPosition[1] < 800 && - celluloxPosition[0] > 50 && - celluloyPosition[1] > 50) { - // cellulox.clearrobot(); - // celluloy.clearrobot(); - // runHaptic = false; - // showAlertDialog(context, '', 'Make sure robots are on the map'); - checkend = true; - runHaptic = true; - } - } - } - if (true) { - var distancePointStartX = math.sqrt( - math.pow((celluloxPosition[0] - originCoordinates[0]), 2) + - math.pow((celluloxPosition[1] - xcelluloy), 2)); - var distancePointStartY = math.sqrt( - math.pow((celluloyPosition[0] - ycellulox), 2) + - math.pow((celluloyPosition[1] - originCoordinates[1]), 2)); - - if (distancePointStartY < 10 && distancePointStartX < 10) { - celluloy.clearrobot(); - cellulox.clearrobot(); - setState(() { - allowPaint = true; - runHaptic = true; - }); - } - } - - if (runHaptic == true) { - calcHaptic(); - } - }); - - timerCelluloPositionPainttoserver = - new Timer.periodic(new Duration(milliseconds: 1800), (time) { - if (allowPaint == true) { - dbRef.child("celluloPosition").push().set(json.encode({ - "x": celluloxPosition[0], - "y": celluloyPosition[1], - "acID": "Ac61", - "turn": currentTurn, - "groupID": group.id, - })); - } - }); - - timerCelluloPositionPaint = - new Timer.periodic(new Duration(seconds: 1), (time) { - setState(() { - if (allowPaint == true) { - celluloxPositiontopaint[tapCounter - 1] - .add(celluloxPosition[0] * screenSizeWidth / mapSizeWidth); - celluloyPositiontopaint[tapCounter - 1] - .add(celluloyPosition[1] * screenSizeHeight / mapSizeHeight); - } - }); - }); - - timerInactivityDetector = - new Timer.periodic(new Duration(seconds: 60), (time) { - onInactivityTimer(); - }); - - /// - /// Ask to be notified when messages related to the game - /// are sent by the server - /// - _controller = VideoPlayerController.asset('assets/images/IMG_0095.mp4'); - - _initializeVideoPlayerFuture = _controller.initialize(); - } - - void onDataSend() { - dbRef.child('attempts').push().set(json.encode({ - "numAttempts": tapCounter, - "groupID": group.id, - "acID": "Ac61", - "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] - }, - } - })); - } - - void slopeDtectionTimer() { - timerslopedetection = new Timer.periodic(new Duration(seconds: 1), (time) { - print("prev" + - (((celluloxPosition[0] - prevcelluloxPositionSlope).roundToDouble() > - 0) - .toString())); - // print("currwnt" + celluloxPosition[0].toString()); - - controllerXslope.text = 1.0.toString(); - if ((celluloxPosition[0] - prevcelluloxPositionSlope).abs() < 10) { - controllerYslope.text = "You sould move the RED robot faster"; - } else { - controllerYslope.text = - (((prevcelluloyPositionSlope - celluloyPosition[1])) / - (celluloxPosition[0] - prevcelluloxPositionSlope)) - .roundToDouble() - .toString(); - } - - prevcelluloxPositionSlope = celluloxPosition[0]; - prevcelluloyPositionSlope = celluloyPosition[1]; - // print(int.parse(controllerXslope.text) > 0); - print("cur" + - (((celluloxPosition[0] - prevcelluloxPositionSlope).roundToDouble() > - 0) - .toString())); - - if ((celluloxPosition[0] - prevcelluloxPositionSlope).roundToDouble() > - 1) { - setState(() { - celluloxSwitch2 = true; - print(celluloxSwitch2); - }); - } - if (((celluloxPosition[0] - prevcelluloxPositionSlope) / 100) - .roundToDouble() < - -1) { - setState(() { - celluloxSwitch2 = false; - print(celluloxSwitch2); - }); - } - if (celluloyPosition[1] - prevcelluloyPositionSlope > 0) { - setState(() { - celluloySwitch2 = true; - print(celluloySwitch2); - }); - } - if (celluloyPosition[1] - prevcelluloyPositionSlope < 1.0) { - setState(() { - celluloySwitch2 = false; - print(celluloySwitch2); - }); - } - }); - } - - void onInactivityTimer() { - group.inactivity = group.inactivity + 1; - } - - @override - void dispose() { - cellulox.clearrobot(); - celluloy.clearrobot(); - timer.cancel(); - timerCelluloPosition.cancel(); - timerCelluloPositionPaint.cancel(); - timerCelluloPositionPainttoserver.cancel(); - controllerTrial.dispose(); - _controller.dispose(); - super.dispose(); - } - - AppLifecycleState _notification; - - @override - void didChangeAppLifecycleState(AppLifecycleState state) { - if (state == AppLifecycleState.resumed) { - dbRef.child('groups').child(group.id).child('tabletStatus').set("YES"); - } else { - dbRef.child('groups').child(group.id).child('tabletStatus').set("NO"); - } - setState(() { - _notification = state; - }); - } - - void nextPLayer() { - setState(() { - currentTurn = currentTurn + 1; - // celluloyPositiontopaint = [0.0, 0.0]; - // celluloxPositiontopaint = [0.0, 0.0]; - }); - } - - void animationRunner(progress) {} - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Move your robots'), - ), - backgroundColor: Colors.white, - body: SingleChildScrollView( - child: Column(children: [ - Container( - // margin: const EdgeInsets.all(15.0), - padding: const EdgeInsets.all(5.0), - decoration: BoxDecoration(), - height: 290.0, - child: Column(children: [ - Card( - color: Colors.blue, - child: ListTile( - title: Text( - ' Each of you take one robot in each hand and try to follow the orange line', - style: new TextStyle( - color: Colors.white, - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - ), - SizedBox( - height: 10, - ), - Row( - //mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - width: 470, - child: Card( - color: Colors.blue, - child: ListTile( - title: Text( - (tapCounter == 0) - ? names[0] + 'Start the game' - : 'When you tried, start again with a next member', - style: new TextStyle( - color: Colors.white, - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - )), - SizedBox(width: 40), - Container( - decoration: BoxDecoration( - borderRadius: - BorderRadius.all(Radius.circular(100)), - color: Colors.green), - child: FlatButton( - child: Text( - (tapCounter == 0) ? "Start" : "Start Again", - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.w700, - fontSize: 18), - ), - // tooltip: 'Run the Robots', - onPressed: () => { - // avgActivation= - if (checkend == true) - { - if (tapCounter < 3) - { - setState(() { - checkend = true; - allowPaint = false; - runHaptic = false; - lineallow[tapCounter] = true; - tapCounter = tapCounter + 1; - }), - cellulox.setGoalPosition( - originCoordinates[0], - xcelluloy.toDouble(), - 150), - celluloy.setGoalPosition( - ycellulox.toDouble(), - originCoordinates[1], - 150), - onDataSend(), - // onDataSend(), - } - else - { - showAlertDialog( - context, - 'Lets go to next turn', - 'Lets try a new line'), - }, - } - - // controllerTrial.reset(), - // controllerTrial.forward(), - }, - )), - SizedBox(width: 15), - ]), - Row( - //mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - width: 470, - child: Card( - color: Colors.blue, - child: ListTile( - title: Text( - ' When you all tried, go to next turn.', - style: new TextStyle( - color: Colors.white, - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - )), - SizedBox(width: 25), - SizedBox(width: 15), - Container( - decoration: BoxDecoration( - borderRadius: - BorderRadius.all(Radius.circular(100)), - color: Colors.blue), - child: FlatButton( - child: Text( - "Play & Pause", - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.w700, - fontSize: 18), - ), - onPressed: () => { - setState(() { - // If the video is playing, pause it. - if (_controller.value.isPlaying) { - _controller.pause(); - } else { - // If the video is paused, play it. - _controller.play(); - } - }), - }, - )), - ]), - ])), - SizedBox( - height: 70, - ), - Container( - height: 700, - child: FutureBuilder( - future: _initializeVideoPlayerFuture, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - // If the VideoPlayerController has finished initialization, use - // the data it provides to limit the aspect ratio of the VideoPlayer. - return AspectRatio( - aspectRatio: _controller.value.aspectRatio, - // Use the VideoPlayer widget to display the video. - child: VideoPlayer(_controller), - ); - } else { - // If the VideoPlayerController is still initializing, show a - // loading spinner. - return Center(child: CircularProgressIndicator()); - } - }, - )), - SizedBox( - height: 125, - ), - MembersBar( - curTurn: currentTurn, - ), - ]))); - } -} diff --git a/student/lib/Activities/Ac1_tutorial.dart b/student/lib/Activities/Ac1_tutorial.dart deleted file mode 100644 index e69de29..0000000 diff --git a/student/lib/Activities/Ac2.dart b/student/lib/Activities/Ac2.dart index 09ae98f..c9059ee 100644 --- a/student/lib/Activities/Ac2.dart +++ b/student/lib/Activities/Ac2.dart @@ -1,707 +1,715 @@ import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:student/widgets/mapShapeMaker.dart'; import 'package:student/widgets/onlineRobotMap.Dart'; import 'package:student/widgets/celluloMap.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/ShapePainter.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:student/widgets/checkCelluloGame.dart'; import 'package:audioplayers/audioplayers.dart'; import 'package:tip_dialog/tip_dialog.dart'; import 'package:audioplayers/audio_cache.dart'; import 'dart:math' as math; class Ac2 extends StatefulWidget { Ac2({Key key}) : super(key: key); @override _Ac2State createState() => _Ac2State(); } class _Ac2State extends State { // Activity_Independent var elapseTimer = new Stopwatch(); Timer timerCelluloPosition; Timer timerCelluloPositiontoserver; Timer timerCheckCelluloGame; int currentTurn = 1; int inactivity = 0; int tapCounter = 0; List progress = [0, -2, -2]; List progressElpasedTime = [0, 0, 0]; bool isPlaying = false; bool isPaused = false; static AudioCache cache = AudioCache(); AudioPlayer player; // Celulo var celluloxPosition = [0.0, 0.0]; var celluloyPosition = [0.0, 0.0]; List celluloxPositiontopaint = [0.0, 0.0]; List celluloyPositiontopaint = [0.0, 0.0]; bool addtoprint; Animation animationRobotPath; // Learning List gameScore = [0, 0, 0]; List celluloEnergy = [6, 6, 6]; List mistakesSlope = [0, 0, 0]; List mistakesIntrepet = [0, 0, 0]; List mistakesInitialPosition = [0, 0, 0]; int score = 6; //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 reachendX = false; bool gameoverY = false; - + bool startGame = false; String activityTitle = 'Activity 2'; var linesPath = [ 'assets/images/Ac7_function1.svg', 'assets/images/Ac7_function2.svg', 'assets/images/Ac7_function3.svg', 'assets/images/GridOnlyPositive.svg', ]; var startPoint = ['C', 'A', 'C']; var endPoint = ['B', 'D', 'B']; var startPointorder = [2, 0, 2]; var endPointorder = [1, 3, 1]; var pointOrder = ['A', 'B', 'C', 'D']; static List pointPosition = [ Offset(80, 80), Offset(760, 80), Offset(80, 760), Offset(760, 760) ]; // map-related double radiuosStart = 45; //final Offset startPoint = new Offset(0.0, 0.0); //inal Offset endPoint = new Offset(0.0, 0.0); final double mapSizeWidth = 860; final double mapSizeHeight = 860; final String mapPath = 'assets/images/GridOnlyPositive.svg'; double coeffScreenMapWidth; double coeffScreenMapHeight; var mapShape = [ { 'numCircles': 0, 'originCircles': [ Offset(390, 300), Offset(160, 70), Offset(60, 360), Offset(560, 690) ], 'radiuosCircles': [60.0, 50.0, 50.0, 40.0], 'numRectangles': 3, 'originRectangles': [ Offset(300, 30), Offset(200, 560), Offset(400, 760), Offset(780, 460), Offset(650, 500) ], 'widthRectangles': [150.0, 100.0, 50.0, 100.0, 100.0], 'heightRectangles': [50.0, 250.0, 300.0, 50.0, 100.0], 'numPolygons': 2, 'sidesofPolygon': [4, 4, 4, 4], 'radiusPolygon': [70.0, 70.0, 50.0, 60.0, 50.0], 'centerPolygon': [ Offset(60, 280), Offset(500, 140), Offset(600, 200), Offset(500, 500), Offset(680, 400) ], 'startCenter': pointPosition[2], 'endCenter': pointPosition[1] }, { 'numCircles': 0, 'originCircles': [ Offset(390, 300), Offset(160, 70), Offset(60, 360), Offset(560, 690) ], 'radiuosCircles': [60.0, 50.0, 50.0, 40.0], 'numRectangles': 2, 'originRectangles': [ Offset(300, 30), Offset(300, 560), Offset(500, 560), Offset(750, 360) ], 'widthRectangles': [ 150.0, 100.0, 50.0, 150.0, ], 'heightRectangles': [50.0, 250.0, 250.0, 300.0], 'numPolygons': 2, 'sidesofPolygon': [4, 4, 4, 4], 'radiusPolygon': [80.0, 60.0, 50.0, 60.0], 'centerPolygon': [ Offset(100, 330), Offset(600, 90), Offset(500, 200), Offset(400, 350), ], 'startCenter': pointPosition[0], 'endCenter': pointPosition[3] }, { 'numCircles': 0, 'originCircles': [ Offset(390, 300), Offset(160, 70), Offset(60, 360), Offset(560, 690) ], 'radiuosCircles': [60.0, 50.0, 50.0, 40.0], 'numRectangles': 3, 'originRectangles': [Offset(350, 70), Offset(300, 560), Offset(700, 520)], 'widthRectangles': [350.0, 300.0, 100.0], 'heightRectangles': [50.0, 250.0, 100.0], 'numPolygons': 3, 'sidesofPolygon': [4, 4, 4], 'radiusPolygon': [100.0, 60.0, 70.0], 'centerPolygon': [ Offset(80, 230), Offset(650, 190), Offset(400, 250), ], 'startCenter': pointPosition[2], 'endCenter': pointPosition[1] }, ]; void playHandler(String songpath) async { player = await cache.play(songpath); } @override void initState() { super.initState(); dbRef.child('groups').child(group.id).child('tabletStatus').set("YES"); dbRef.child('groups').child(group.id).child('currentActivity').set("Ac2"); elapseTimer.start(); // coeffScreenMapHeight = // MediaQuery.of(context).size.width * 0.9 / mapSizeWidth; // coeffScreenMapHeight = // MediaQuery.of(context).size.height * 0.9 / mapSizeHeight; timerCelluloPosition = new Timer.periodic(new Duration(milliseconds: 500), (time) { var xxprev = celluloxPosition[0]; var xyprev = celluloxPosition[1]; var yxprev = celluloyPosition[0]; var yyprev = celluloyPosition[1]; if (totalRobots() > 1) { // print(cellulox.getrobotKidnapped().toString()); // print(celluloy.getrobotKidnapped().toString()); cellulox.getrobotx().then((val) => setState(() { if (val != null) { group.cellulox.traveledDistance = group.cellulox.traveledDistance + (val - celluloxPosition[0]); 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; group.cellulox.traveledDistance = group.cellulox.traveledDistance + math.sqrt(math.pow((xxprev - celluloxPosition[0]), 2) + math.pow((xyprev - celluloxPosition[1]), 2)) / 20; } })); celluloy.getrobotx().then((val) => setState(() { if (val != null) { celluloyPosition[0] = val; } })); celluloy.getroboty().then((val) => setState(() { if (val != null) { group.celluloy.traveledDistance = group.celluloy.traveledDistance + math.sqrt(math.pow((yxprev - celluloyPosition[0]), 2) + math.pow((yyprev - celluloyPosition[1]), 2)) / 20; celluloyPosition[1] = val; if (addtoprint == true) celluloyPositiontopaint.add(val); } })); if (celluloxPosition[0] > 800 || celluloyPosition[1] > 800) { cellulox.setVelocity(0, 0); celluloy.setVelocity(0, 0); } } }); timerCelluloPositiontoserver = new Timer.periodic(new Duration(milliseconds: 2800), (time) { dbRef.child("celluloPosition").push().set(json.encode({ "x": (celluloxPosition[0] + celluloyPosition[0]) / 2, "y": (celluloxPosition[1] + celluloyPosition[1]) / 2, "xx": celluloxPosition[0], "xy": celluloxPosition[1], "yx": celluloyPosition[0], "yy": celluloyPosition[1], "acID": "Ac2", "turn": currentTurn, "groupID": group.id, })); }); 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) { scoreX = 6; scoreY = 6; reachendX = false; gameoverY = false; + startGame = true; } + if (startGame) { + if (scoreY <= 0 && gameoverY == false) { + tapCounter = tapCounter + 1; + onDataSend(); + gameoverY = true; + showAlertDialog(context, 'Your Robot does not have energy', + 'Tell your friend with Blue Robot to go start point'); + playHandler('images/gameover.mp3'); + } + var distancePointEnd = math.sqrt(math.pow( + (celluloTargetPosition.dx - mapShape['endCenter'].dx), 2) + + math.pow((celluloTargetPosition.dy - mapShape['endCenter'].dy), 2)); + if (distancePointEnd <= radiuosStart && reachendX == false) { + tapCounter = tapCounter + 1; + onDataSend(); + showAlertDialog(context, 'Your Robot reached the goal point', + 'Tell your friend to start again or when both robots reached the end, you can go to next turn.'); + reachendX = true; + playHandler('images/win.mp3'); + } - if (scoreY <= 0 && gameoverY == false) { - tapCounter = tapCounter + 1; - onDataSend(); - gameoverY = true; - showAlertDialog(context, 'Your Robot does not have energy', - 'Tell your friend with Blue Robot to go start point'); - playHandler('images/gameover.mp3'); - } - var distancePointEnd = math.sqrt( - math.pow((celluloTargetPosition.dx - mapShape['endCenter'].dx), 2) + - math.pow((celluloTargetPosition.dy - mapShape['endCenter'].dy), 2)); - if (distancePointEnd <= radiuosStart && reachendX == false) { - tapCounter = tapCounter + 1; - onDataSend(); - showAlertDialog(context, 'Your Robot reached the goal point', - 'Tell your friend to start again or when both robots reached the end, you can go to next turn.'); - reachendX = true; - playHandler('images/win.mp3'); - } + 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 * + (celluloTargetPosition.dx - mapShape['originRectangles'][i].dx); + YVelocityCelluloX = coeffHaptic * + (celluloTargetPosition.dy - mapShape['originRectangles'][i].dy); + XVelocityCelluloY = coeffHaptic * + (celluloTargetPosition.dx - mapShape['originRectangles'][i].dx); + YVelocityCelluloY = coeffHaptic * + (celluloTargetPosition.dy - mapShape['originRectangles'][i].dy); + cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX); + celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY); + + if (enterBorderRectY == false) { + scoreY = scoreY - 1; + scoreX = scoreX - 1; + playHandler('images/smb_breakblock.mp3'); + enterBorderRectY = true; + } + trappedRectangleY = i; - 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 * - (celluloTargetPosition.dx - mapShape['originRectangles'][i].dx); - YVelocityCelluloX = coeffHaptic * - (celluloTargetPosition.dy - mapShape['originRectangles'][i].dy); - XVelocityCelluloY = coeffHaptic * - (celluloTargetPosition.dx - mapShape['originRectangles'][i].dx); - YVelocityCelluloY = coeffHaptic * - (celluloTargetPosition.dy - mapShape['originRectangles'][i].dy); - cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX); - celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY); - - if (enterBorderRectY == false) { - scoreY = scoreY - 1; - scoreX = scoreX - 1; - playHandler('images/smb_breakblock.mp3'); - enterBorderRectY = true; + break; + } else if (i == trappedRectangleY) { + enterBorderRectY = false; } - trappedRectangleY = i; - - break; - } else if (i == trappedRectangleY) { - enterBorderRectY = false; + // if (id == 0) cellulox.clearrobot(); + //if (id == 1) celluloy.clearrobot(); } - // if (id == 0) cellulox.clearrobot(); - //if (id == 1) celluloy.clearrobot(); - } - for (int i = 0; i < mapShape['numPolygons']; i++) { - var distancePointCenter = math.sqrt(math.pow( - (celluloTargetPosition.dx - mapShape['centerPolygon'][i].dx), 2) + - math.pow( - (celluloTargetPosition.dy - mapShape['centerPolygon'][i].dy), 2)); - if (distancePointCenter <= mapShape['radiusPolygon'][i] + radiuosBorder) { - insideBorder = true; - XVelocityCelluloX = coeffHaptic * - (celluloTargetPosition.dx - mapShape['centerPolygon'][i].dx); - YVelocityCelluloX = coeffHaptic * - (celluloTargetPosition.dy - mapShape['centerPolygon'][i].dy); - XVelocityCelluloY = coeffHaptic * - (celluloTargetPosition.dx - mapShape['centerPolygon'][i].dx); - YVelocityCelluloY = coeffHaptic * - (celluloTargetPosition.dy - mapShape['centerPolygon'][i].dy); - cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX); - celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY); - - if (enterBorderpolygonY == false) { - scoreY = scoreY - 1; - scoreX = scoreX - 1; - playHandler('images/smb_breakblock.mp3'); - enterBorderpolygonY = true; - } - trappedPolygonY = i; + for (int i = 0; i < mapShape['numPolygons']; i++) { + var distancePointCenter = math.sqrt(math.pow( + (celluloTargetPosition.dx - mapShape['centerPolygon'][i].dx), + 2) + + math.pow( + (celluloTargetPosition.dy - mapShape['centerPolygon'][i].dy), + 2)); + if (distancePointCenter <= + mapShape['radiusPolygon'][i] + radiuosBorder) { + insideBorder = true; + XVelocityCelluloX = coeffHaptic * + (celluloTargetPosition.dx - mapShape['centerPolygon'][i].dx); + YVelocityCelluloX = coeffHaptic * + (celluloTargetPosition.dy - mapShape['centerPolygon'][i].dy); + XVelocityCelluloY = coeffHaptic * + (celluloTargetPosition.dx - mapShape['centerPolygon'][i].dx); + YVelocityCelluloY = coeffHaptic * + (celluloTargetPosition.dy - mapShape['centerPolygon'][i].dy); + cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX); + celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY); + + if (enterBorderpolygonY == false) { + scoreY = scoreY - 1; + scoreX = scoreX - 1; + playHandler('images/smb_breakblock.mp3'); + enterBorderpolygonY = true; + } + trappedPolygonY = i; - break; - } else if (i == trappedPolygonY) { - enterBorderpolygonY = false; + break; + } else if (i == trappedPolygonY) { + enterBorderpolygonY = false; + } } - } - if (enterBorderY == false && - enterBorderRectY == false && - enterBorderpolygonY == false && - id == 1) { - cellulox.clearrobot(); - celluloy.clearrobot(); + if (enterBorderY == false && + enterBorderRectY == false && + enterBorderpolygonY == false && + id == 1) { + 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() { timerCelluloPosition.cancel(); timerCheckCelluloGame.cancel(); elapseTimer.stop(); super.dispose(); } void onDataSend() { dbRef.child('attempts').push().set(json.encode({ "numAttempts": tapCounter, "groupID": group.id, "acID": "Ac2", "engagementX": group.cellulox.traveledDistance, "engagementY": group.celluloy.traveledDistance, "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'), actions: [ Padding( padding: EdgeInsets.only(right: 20.0), child: GestureDetector( onTap: () { group.prevActivity = 'Ac2'; group.currentActivity = 'Ac61'; group.navigatorKeygame.currentState.pushReplacementNamed( group.currentActivity, ); // print('ff'); }, child: Icon(Icons.help), )), ], ), backgroundColor: Colors.white, body: SingleChildScrollView( child: Column(children: [ Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Container( height: 70, width: 600, child: Card( color: Colors.lightBlue, child: ListTile( title: Text( - 'Guide your friedns to go from point ' + - startPoint[currentTurn - 1].toString() + - ' to ' + - endPoint[currentTurn - 1].toString(), + startGame + ? ('Guide your friedns to go from point ' + + startPoint[currentTurn - 1].toString() + + ' to ' + + endPoint[currentTurn - 1].toString()) + : 'Move your robot to point ' + + startPoint[currentTurn - 1].toString(), style: new TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold, ), ), ), )), 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, + startGame = false, 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! '), }, }, )), ]), SizedBox( height: 50, ), 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: [ CustomPaint( //size: Size(200, 200), painter: //LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), MapShapeMaker( pointPosition, 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: 75, ), MembersBar( curTurn: currentTurn, ), ]))); } } diff --git a/student/lib/Activities/Ac3.dart b/student/lib/Activities/Ac3.dart index 93233e6..1ab09fb 100644 --- a/student/lib/Activities/Ac3.dart +++ b/student/lib/Activities/Ac3.dart @@ -1,634 +1,639 @@ 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:audioplayers/audioplayers.dart'; import 'package:tip_dialog/tip_dialog.dart'; import 'package:audioplayers/audio_cache.dart'; import 'dart:math' as math; class Ac3 extends StatefulWidget { Ac3({Key key}) : super(key: key); @override _Ac3State createState() => _Ac3State(); } class _Ac3State extends State { // Activity_Independent int currentTurn = 1; var elapseTimer = new Stopwatch(); AnimationController controllerRobotPath; Animation animationRobotPath; Timer timerCelluloPosition; Timer timerCheckCelluloGame; Timer timerCelluloPositiontoserver; static AudioCache cache = AudioCache(); AudioPlayer player; // Celulo var celluloxPosition = [0.0, 0.0]; var celluloyPosition = [0.0, 0.0]; // Learning List progress = [0, -2, -2]; int tapCounter = 0; List progressElpasedTime = [0, 0, 0]; int inactivity = 0; List mistakesSlope = [0, 0, 0]; List mistakesIntrepet = [0, 0, 0]; List mistakesInitialPosition = [0, 0, 0]; bool isPlaying = false; bool isPaused = false; // 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; + bool startGame = false; final double mapSizeWidth = 860; final double mapSizeHeight = 860; double coeffScreenMapWidth; double coeffScreenMapHeight; var startPoint = ['C', 'A', 'C']; var endPoint = ['B', 'D', 'B']; var startPointorder = [2, 0, 2]; var endPointorder = [1, 3, 1]; double radiuosStart = 45; var pointOrder = ['A', 'B', 'C', 'D']; static List 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] + celluloyPosition[0]) / 2, "y": (celluloxPosition[1] + celluloyPosition[1]) / 2, "xx": celluloxPosition[0], "xy": celluloxPosition[1], "yx": celluloyPosition[0], "yy": celluloyPosition[1], "acID": "Ac3", "turn": currentTurn, "groupID": group.id, })); }); timerCelluloPosition = new Timer.periodic(new Duration(milliseconds: 500), (time) { var xxprev = celluloxPosition[0]; var xyprev = celluloxPosition[1]; var yxprev = celluloyPosition[0]; var yyprev = celluloyPosition[1]; if (totalRobots() > 1) { // print(cellulox.getrobotKidnapped().toString()); // print(celluloy.getrobotKidnapped().toString()); cellulox.getrobotx().then((val) => setState(() { if (val != null) { group.cellulox.traveledDistance = group.cellulox.traveledDistance + (val - celluloxPosition[0]); 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; group.cellulox.traveledDistance = group.cellulox.traveledDistance + math.sqrt(math.pow((xxprev - celluloxPosition[0]), 2) + math.pow((xyprev - celluloxPosition[1]), 2)) / 20; } })); celluloy.getrobotx().then((val) => setState(() { if (val != null) { celluloyPosition[0] = val; } })); celluloy.getroboty().then((val) => setState(() { if (val != null) { group.celluloy.traveledDistance = group.celluloy.traveledDistance + math.sqrt(math.pow((yxprev - celluloyPosition[0]), 2) + math.pow((yyprev - celluloyPosition[1]), 2)) / 20; 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; - + startGame = true; gameoverY = false; reachendY = false; } + if (startGame) { + 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'); + playHandler('images/gameover.mp3'); + } - 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'); - playHandler('images/gameover.mp3'); - } + 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.'); + playHandler('images/win.mp3'); + } - 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.'); - playHandler('images/win.mp3'); - } + 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; + playHandler('images/smb_breakblock.mp3'); + enterBorderRectY = true; + } + trappedRectangleY = i; - 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; - playHandler('images/smb_breakblock.mp3'); - enterBorderRectY = true; + break; + } else if (id == 1 && i == trappedRectangleY) { + enterBorderRectY = false; } - trappedRectangleY = i; - - break; - } else if (id == 1 && i == trappedRectangleY) { - enterBorderRectY = false; + // if (id == 0) cellulox.clearrobot(); + //if (id == 1) celluloy.clearrobot(); } - // if (id == 0) cellulox.clearrobot(); - //if (id == 1) celluloy.clearrobot(); - } - if (enterBorderY == false && - enterBorderRectY == false && - enterBorderpolygonY == false) { - cellulox.clearrobot(); - 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); } } void playHandler(String songpath) async { player = await cache.play(songpath); } @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", "engagementX": group.cellulox.traveledDistance, "engagementY": group.celluloy.traveledDistance, "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'), actions: [ Padding( padding: EdgeInsets.only(right: 20.0), child: GestureDetector( onTap: () { group.prevActivity = 'Ac3'; group.currentActivity = 'Ac61'; group.navigatorKeygame.currentState.pushReplacementNamed( group.currentActivity, ); }, child: Icon(Icons.help), )), ], ), backgroundColor: Colors.white, body: SingleChildScrollView( child: Column(children: [ Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Container( height: 70, width: 600, child: Card( color: Colors.lightBlue, child: ListTile( title: Text( - 'Guide your friedns to go from point' + - startPoint[currentTurn - 1].toString() + - ' to ' + - endPoint[currentTurn - 1].toString(), + startGame + ? ('Guide your friedns to go from point' + + startPoint[currentTurn - 1].toString() + + ' to ' + + endPoint[currentTurn - 1].toString()) + : 'Move your robot to point ' + + startPoint[currentTurn - 1].toString(), style: new TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold, ), ), ), ), ), 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, + startGame = false, 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: [ CustomPaint( //size: Size(200, 200), painter: //LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), MapShapeMaker( pointPosition, 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( curTurn: currentTurn, ), ]))); } } diff --git a/student/lib/Activities/Ac4.dart b/student/lib/Activities/Ac4.dart index de2fd9f..ee5d265 100644 --- a/student/lib/Activities/Ac4.dart +++ b/student/lib/Activities/Ac4.dart @@ -1,630 +1,651 @@ import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:student/widgets/onlineRobotMap.Dart'; import 'dart:async'; import 'dart:convert'; import 'package:student/widgets/arrow.dart'; 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/bezierCurvePainter.dart'; import 'package:bezier/bezier.dart'; import 'package:student/widgets/mapShapeMaker.dart'; import 'package:bezier/bezier.dart'; import "dart:math" as math; import "package:vector_math/vector_math.dart" as vector; +import 'package:audioplayers/audioplayers.dart'; + +import 'package:audioplayers/audio_cache.dart'; class Ac4 extends StatefulWidget { Ac4({Key key}) : super(key: key); @override _Ac4State createState() => _Ac4State(); } class _Ac4State extends State { // Activity_Independent int currentTurn = 1; var elapseTimer = new Stopwatch(); var timeOutofBorder; AnimationController controllerRobotPath; Animation animationRobotPath; Timer timerCelluloPosition; Timer timerCelluloPositionPainttoserver; + AudioPlayer audioPlugin = AudioPlayer(); + AudioPlayer advancedPlayer = AudioPlayer(); + static AudioCache cache = AudioCache(); + AudioPlayer player; // Celulo var celluloxPosition = [0.0, 0.0]; var celluloyPosition = [0.0, 0.0]; var xHaptic; var yHaptic; var xyHapticG = [0.0, 0.0]; // Learning bool gameover = false; bool startGame = false; int score = 6; bool outofborder = false; bool reachend = false; double radiuosStart = 45; List mistakesSlope = [0, 0, 0]; List mistakesIntrepet = [0, 0, 0]; List mistakesInitialPosition = [0, 0, 0]; int tapCounter = 0; List progress = [0, -2, -2]; List progressElpasedTime = [0, 0, 0]; //Activity Dependent final double mapSizeWidth = 860; final double mapSizeHeight = 860; static List pointPosition = [ Offset(80, 80), Offset(760, 80), Offset(80, 760), Offset(760, 760) ]; var midddlePoint1 = [ Offset(291.1, 176.2), Offset(110.2, 632.8), Offset(610.2, 732.8) ]; var midddlePoint2 = [ Offset(410.2, 532.8), Offset(356, 357), Offset(110.2, 232.8) ]; var startPoint = ['C', 'A', 'C']; var endPoint = ['B', 'D', 'B']; var mapShape = [ { 'numCircles': 0, 'originCircles': [Offset(0, 0)], 'radiuosCircles': [0.0], 'numRectangles': 0, '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': 0, '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': 0, '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] }, ]; + void playHandler(String songpath) async { + player = await cache.play(songpath); + } + void onDataSend() { dbRef.child('attempts').push().set(json.encode({ "numAttempts": tapCounter, "groupID": group.id, "acID": "Ac4", "engagementX": group.cellulox.traveledDistance, "engagementY": group.celluloy.traveledDistance, "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] }, } })); } void calcHaptic() { Offset beginpath = mapShape[currentTurn - 1]['startCenter']; Offset endpath = mapShape[currentTurn - 1]['endCenter']; final curve = new CubicBezier([ new vector.Vector2(beginpath.dx, beginpath.dy), new vector.Vector2( midddlePoint1[currentTurn - 1].dx, midddlePoint1[currentTurn - 1].dy), new vector.Vector2( midddlePoint2[currentTurn - 1].dx, midddlePoint2[currentTurn - 1].dy), new vector.Vector2(endpath.dx, endpath.dy) ]); var tHaptic = curve.nearestTValue(new vector.Vector2( (celluloxPosition[0] + celluloyPosition[0]) / 2, (celluloxPosition[1] + celluloyPosition[1]) / 2)); var xyHaptic = curve.pointAt(tHaptic); xyHapticG[0] = xyHaptic[0].toDouble(); xyHapticG[1] = xyHaptic[1].toDouble(); //print('thaptic' + tHaptic.toString()); // print('xyhaptic' + xyHaptic.toString()); cellulox.setGoalPosition(2 * xyHaptic[0].toDouble() - celluloyPosition[0], celluloxPosition[1], 150); celluloy.setGoalPosition(celluloyPosition[0], 2 * xyHaptic[1].toDouble() - celluloxPosition[1], 150); var distancePointCurve = math.sqrt(math.pow( ((celluloxPosition[0] + celluloyPosition[0]) / 2 - xyHaptic[0]), 2) + math.pow( ((celluloxPosition[1] + celluloyPosition[1]) / 2 - xyHaptic[1]), 2)); if (distancePointCurve > 50 && outofborder == false) { outofborder = true; timeOutofBorder = elapseTimer.elapsedMilliseconds; // console.log(timeStart) } var timeNow = elapseTimer.elapsedMilliseconds; //console.log( timeNow- timeStart) if (outofborder == true && timeNow - timeOutofBorder < 3000 && distancePointCurve < 10) { outofborder = false; // console.log("outofbordrfalse") } if (outofborder == true && timeNow - timeOutofBorder > 3000) { outofborder = false; score = score - 1; //console.log("battey reduced") } } @override void initState() { super.initState(); cellulox.setColor(0, 255, 0, 0, 0); celluloy.setColor(0, 0, 255, 0, 0); Offset beginpath = mapShape[currentTurn - 1]['startCenter']; cellulox.setGoalPosition(beginpath.dx, beginpath.dy, 150); celluloy.setGoalPosition(beginpath.dx + 100, beginpath.dy, 150); dbRef.child('groups').child(group.id).child('tabletStatus').set("YES"); dbRef.child('groups').child(group.id).child('currentActivity').set("Ac4"); timerCelluloPositionPainttoserver = new Timer.periodic(new Duration(milliseconds: 1800), (time) { if (true) { dbRef.child("celluloPosition").push().set(json.encode({ "x": (celluloxPosition[0] + celluloyPosition[0]) / 2, "y": (celluloxPosition[1] + celluloyPosition[1]) / 2, "xx": celluloxPosition[0], "xy": celluloxPosition[1], "yx": celluloyPosition[0], "yy": celluloyPosition[1], "acID": "Ac4", "turn": currentTurn, "groupID": group.id, })); } }); timerCelluloPosition = new Timer.periodic(new Duration(milliseconds: 200), (time) { var xxprev = celluloxPosition[0]; var xyprev = celluloxPosition[1]; var yxprev = celluloyPosition[0]; var yyprev = celluloyPosition[1]; if (totalRobots() > 1) { // print(cellulox.getrobotKidnapped().toString()); // print(celluloy.getrobotKidnapped().toString()); cellulox.getrobotx().then((val) => setState(() { if (val != null) { group.cellulox.traveledDistance = group.cellulox.traveledDistance + (val - celluloxPosition[0]); 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; group.cellulox.traveledDistance = group.cellulox.traveledDistance + math.sqrt(math.pow((xxprev - celluloxPosition[0]), 2) + math.pow((xyprev - celluloxPosition[1]), 2)) / 20; } })); celluloy.getrobotx().then((val) => setState(() { if (val != null) { celluloyPosition[0] = val; } })); celluloy.getroboty().then((val) => setState(() { if (val != null) { group.celluloy.traveledDistance = group.celluloy.traveledDistance + math.sqrt(math.pow((yxprev - celluloyPosition[0]), 2) + math.pow((yyprev - celluloyPosition[1]), 2)) / 20; celluloyPosition[1] = val; // if (addtoprint == true) celluloyPositiontopaint.add(val); } })); if (celluloxPosition[0] > 800 || celluloyPosition[1] > 800) { cellulox.setVelocity(0, 0); celluloy.setVelocity(0, 0); } } //if (runHaptic == true) { calcHaptic(); checkCelluloGame(); }); elapseTimer.start(); onDataSend(); } void checkCelluloGame() { Offset beginpath = mapShape[currentTurn - 1]['startCenter']; Offset endpath = mapShape[currentTurn - 1]['endCenter']; double celluloXYdistances = math.sqrt( math.pow((celluloxPosition[0] - celluloyPosition[0]), 2) + math.pow((celluloxPosition[1] - celluloyPosition[1]), 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( ((celluloxPosition[0] + celluloyPosition[0]) / 2 - beginpath.dx), 2) + math.pow( ((celluloxPosition[1] + celluloyPosition[1]) / 2 - beginpath.dy), 2)); if (distancePointCenter <= radiuosStart) { score = 6; gameover = false; reachend = false; + startGame = true; } + if (startGame) { + if (score <= 0 && gameover == false) { + tapCounter = tapCounter + 1; + onDataSend(); + gameover = true; + playHandler('images/gameover.mp3'); + showAlertDialog(context, 'Your Robot does not have energy', + 'Tell your friend to go start point to get energy'); - if (score <= 0 && gameover == false) { - tapCounter = tapCounter + 1; - onDataSend(); - gameover = true; - showAlertDialog(context, 'Your Robot does not have energy', - 'Tell your friend to go start point to get energy') - .then(group.isAlertShown = false); - print(group.isAlertShown.toString()); - } + // print(group.isAlertShown.toString()); + } - var distancePointEnd = math.sqrt(math.pow( - ((celluloxPosition[0] + celluloyPosition[0]) / 2 - endpath.dx), 2) + - math.pow( - ((celluloxPosition[1] + celluloyPosition[1]) / 2 - endpath.dy), 2)); - if (distancePointEnd <= radiuosStart && reachend == false) { - // scoreX = -1; - reachend = 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.'); + var distancePointEnd = math.sqrt(math.pow( + ((celluloxPosition[0] + celluloyPosition[0]) / 2 - endpath.dx), + 2) + + math.pow( + ((celluloxPosition[1] + celluloyPosition[1]) / 2 - endpath.dy), + 2)); + if (distancePointEnd <= radiuosStart && reachend == false) { + // scoreX = -1; + reachend = true; + tapCounter = tapCounter + 1; + onDataSend(); + playHandler('images/win.mp3'); + showAlertDialog(context, 'Your Robot reached the goal point', + 'Tell your friend to start again or you can go to next turn.'); + } } colorRobots(); } void colorRobots() { for (int i = 0; i < 6; i++) { cellulox.setColor(0, 0, 0, 0, 0); } for (int i = 0; i < score; 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 < score; i++) { celluloy.setColor(0, 0, 255, 1, i); } } @override void dispose() { elapseTimer.stop(); timerCelluloPosition.cancel(); // timerCelluloPositionPainttoserver.cancel(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Follow the Line Together'), actions: [ IconButton( tooltip: 'Help for this activity', onPressed: () { group.prevActivity = 'Ac4'; group.currentActivity = 'Ac61'; group.navigatorKeygame.currentState.pushReplacementNamed( group.currentActivity, ); // print('ff'); }, icon: Icon(Icons.help), ), ], ), backgroundColor: Colors.white, body: SingleChildScrollView( child: Column(children: [ Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Container( height: 70, width: 600, child: Card( color: Colors.lightBlue, child: ListTile( title: Text( - 'Follow the curve from point ' + - startPoint[currentTurn - 1].toString() + - ' to ' + - endPoint[currentTurn - 1].toString(), + startGame + ? ('Follow the curve from point ' + + startPoint[currentTurn - 1].toString() + + ' to ' + + endPoint[currentTurn - 1].toString()) + : 'Move the purple robot to point ' + + startPoint[currentTurn - 1].toString(), style: new TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold, ), ), ), ), ), SizedBox( width: 25, ), //SizedBox(width: 20), Container( decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(100)), color: reachend ? Colors.blue : Colors.grey), child: FlatButton( child: Text( "Next Turn", style: TextStyle( color: Colors.white, fontWeight: FontWeight.w700, fontSize: 18), ), onPressed: () => { reachend ? { tapCounter = 0, + startGame = false, 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! '), } } : null, }, ), ) ]), 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: [ CustomPaint( //size: Size(200, 200), painter: BezierCurvePainter( mapShape[currentTurn - 1]['startCenter'], mapShape[currentTurn - 1]['endCenter'], MediaQuery.of(context).size.width * 0.9 / mapSizeWidth, MediaQuery.of(context).size.height * 0.65 / mapSizeHeight, currentTurn, 10) //LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), ), CustomPaint( //size: Size(200, 200), painter: //LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), MapShapeMaker( pointPosition, 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), ), ), ), CustomPaint( //size: Size(200, 200), painter: //LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), Arrow( celluloxPosition, celluloyPosition, MediaQuery.of(context).size.width * 0.9 / mapSizeWidth, MediaQuery.of(context).size.height * 0.65 / mapSizeHeight, (xyHapticG[0] - celluloxPosition[0]), xyHapticG[1] - celluloyPosition[1]), ), ], )), SizedBox( height: 65, ), MembersBar( curTurn: currentTurn, ), ]))); } } diff --git a/student/lib/Activities/Ac5.dart b/student/lib/Activities/Ac5.dart index e778589..6ddd8f5 100644 --- a/student/lib/Activities/Ac5.dart +++ b/student/lib/Activities/Ac5.dart @@ -1,789 +1,832 @@ import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.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/bezierCurvePainter.dart'; import 'package:bezier/bezier.dart'; import 'package:student/widgets/mapShapeMaker.dart'; import 'package:bezier/bezier.dart'; import "dart:math" as math; import "package:vector_math/vector_math.dart" as vector; import 'package:student/widgets/guidegrid.dart'; import 'package:student/widgets/stopdrawer.dart'; +import 'package:audioplayers/audioplayers.dart'; +import 'package:audioplayers/audio_cache.dart'; class Ac5 extends StatefulWidget { Ac5({Key key}) : super(key: key); @override _Ac5State createState() => _Ac5State(); } class _Ac5State extends State { // Activity_Independent int currentTurn = 1; var elapseTimer = new Stopwatch(); var timeOutofBorder; AnimationController controllerRobotPath; Animation animationRobotPath; Timer timerCelluloPosition; Timer timerCelluloPositionPainttoserver; + AudioPlayer audioPlugin = AudioPlayer(); + AudioPlayer advancedPlayer = AudioPlayer(); + static AudioCache cache = AudioCache(); + AudioPlayer player; // Celulo var celluloxPosition = [0.0, 0.0]; var celluloyPosition = [0.0, 0.0]; var xHaptic; var yHaptic; final String mapPath = 'assets/images/Grid_Ac5_Screen.svg'; // Learning bool gameover = false; bool startGame = false; int score = 6; bool outofborder = false; bool reachend = false; bool stopend = false; double radiuosStart = 45; List mistakesSlope = [0, 0, 0]; List mistakesIntrepet = [0, 0, 0]; List mistakesInitialPosition = [0, 0, 0]; int tapCounter = 0; List progress = [0, -2, -2]; List progressElpasedTime = [0, 0, 0]; //Activity Dependent final double mapSizeWidth = 860; final double mapSizeHeight = 860; final List initialpointList = ['0', '1', '2', '3']; String initialPointXvalue; String initialPointYvalue; + String guessvalue; + static List> pointPosition = [ [ Offset(530, 132), Offset(125, 525), ], [ Offset(690, 532), Offset(125, 135), ], [ Offset(530, 132), Offset(125, 735), ], ]; var midddlePoint1 = [ Offset(291.1, 176.2), Offset(110.2, 632.8), Offset(610.2, 732.8) ]; var midddlePoint2 = [ Offset(410.2, 532.8), Offset(356, 357), Offset(110.2, 232.8) ]; var startPoint = ['A', 'A', 'C']; var endPoint = ['B', 'D', 'B']; List stopBoxCenter = [ Offset(330, 340), Offset(520, 490), Offset(380, 250) ]; Offset origin = new Offset(106, 572.0); // should be calibrated for a new map var step = 75.0; var mapShape = [ { 'numCircles': 0, 'originCircles': [Offset(0, 0)], 'radiuosCircles': [0.0], 'numRectangles': 0, '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[0][1], 'endCenter': pointPosition[0][0] }, { 'numCircles': 0, 'originCircles': [Offset(0, 0)], 'radiuosCircles': [0.0], 'numRectangles': 0, '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[1][1], 'endCenter': pointPosition[1][0] }, { 'numCircles': 0, 'originCircles': [Offset(0, 0)], 'radiuosCircles': [0.0], 'numRectangles': 0, '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][1], 'endCenter': pointPosition[2][0] }, ]; void onDataSend() { dbRef.child('attempts').push().set(json.encode({ "numAttempts": tapCounter, "groupID": group.id, "acID": "Ac5", "engagementX": group.cellulox.traveledDistance, "engagementY": group.celluloy.traveledDistance, "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] }, } })); } + void playHandler(String songpath) async { + player = await cache.play(songpath); + } + void checkCelluloGame() { Offset beginpath = mapShape[currentTurn - 1]['startCenter']; Offset endpath = mapShape[currentTurn - 1]['endCenter']; double celluloXYdistances = math.sqrt( math.pow((celluloxPosition[0] - celluloyPosition[0]), 2) + math.pow((celluloxPosition[1] - celluloyPosition[1]), 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( ((celluloxPosition[0] + celluloxPosition[0]) / 2 - beginpath.dx), 2) + math.pow( ((celluloyPosition[1] + celluloyPosition[1]) / 2 - beginpath.dy), 2)); - if (distancePointCenter <= radiuosStart) { + if (distancePointCenter <= radiuosStart / 4) { score = 6; gameover = false; reachend = false; startGame = true; } if (startGame) { if (score <= 0 && gameover == false) { tapCounter = tapCounter + 1; onDataSend(); gameover = true; + playHandler('images/gameover.mp3'); showAlertDialog(context, 'Your Robot does not have energy', 'Tell your friend to go start point to get energy'); } var distancePointEnd = math.sqrt(math.pow( ((celluloxPosition[0] + celluloxPosition[0]) / 2 - endpath.dx), 2) + math.pow( ((celluloyPosition[1] + celluloyPosition[1]) / 2 - endpath.dy), 2)); - if (distancePointEnd <= radiuosStart && reachend == false) { + if (distancePointEnd <= radiuosStart / 4 && reachend == false) { // scoreX = -1; reachend = true; tapCounter = tapCounter + 1; onDataSend(); + playHandler('images/win.mp3'); showAlertDialog(context, 'Your Robot reached the goal point', 'Tell your friend to start again or you can go to next turn.'); } var distancePointStop = math.sqrt(math.pow( ((celluloxPosition[0] + celluloxPosition[0]) / 2 - stopBoxCenter[currentTurn - 1].dx), 2) + math.pow( ((celluloyPosition[1] + celluloyPosition[1]) / 2 - stopBoxCenter[currentTurn - 1].dy), 2)); - if (distancePointStop <= radiuosStart && stopend == false) { + if (distancePointStop <= radiuosStart / 4 && stopend == false) { // scoreX = -1; stopend = true; tapCounter = tapCounter + 1; onDataSend(); showAlertDialog(context, 'Your Robot reached the middle stop point', 'Put where should red and blue robot should go in continue.'); } } colorRobots(); } void colorRobots() { for (int i = 0; i < 6; i++) { cellulox.setColor(0, 0, 0, 0, 0); } for (int i = 0; i < score; 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 < score; i++) { celluloy.setColor(0, 0, 255, 1, i); } } void calcHaptic() { Offset beginpath = mapShape[currentTurn - 1]['startCenter']; Offset endpath = mapShape[currentTurn - 1]['endCenter']; final curve = new CubicBezier([ new vector.Vector2(beginpath.dx, beginpath.dy), new vector.Vector2( midddlePoint1[currentTurn - 1].dx, midddlePoint1[currentTurn - 1].dy), new vector.Vector2( midddlePoint2[currentTurn - 1].dx, midddlePoint2[currentTurn - 1].dy), new vector.Vector2(endpath.dx, endpath.dy) ]); var tHaptic = curve.nearestTValue(new vector.Vector2( (celluloxPosition[0] + celluloxPosition[0]) / 2, (celluloyPosition[1] + celluloyPosition[1]) / 2)); var xyHaptic = curve.pointAt(tHaptic); // print('thaptic' + tHaptic.toString()); //print('xyhaptic' + xyHaptic.toString()); cellulox.setGoalPosition(xyHaptic[0].toDouble(), 800, 150); celluloy.setGoalPosition(60, xyHaptic[1].toDouble(), 150); var distancePointCurve = math.sqrt(math.pow( ((celluloxPosition[0] + celluloxPosition[0]) / 2 - xyHaptic[0]), 2) + math.pow( ((celluloyPosition[1] + celluloyPosition[1]) / 2 - xyHaptic[1]), 2)); if (distancePointCurve > 50 && outofborder == false) { outofborder = true; timeOutofBorder = elapseTimer.elapsedMilliseconds; // console.log(timeStart) } var timeNow = elapseTimer.elapsedMilliseconds; //console.log( timeNow- timeStart) if (outofborder == true && timeNow - timeOutofBorder < 3000 && distancePointCurve < 10) { outofborder = false; // console.log("outofbordrfalse") } if (outofborder == true && timeNow - timeOutofBorder > 3000) { outofborder = false; score = score - 1; //console.log("battey reduced") } } @override void initState() { super.initState(); cellulox.setColor(0, 255, 0, 0, 0); timerCelluloPositionPainttoserver = new Timer.periodic(new Duration(milliseconds: 1800), (time) { if (true) { dbRef.child("celluloPosition").push().set(json.encode({ "x": celluloxPosition[0], "y": celluloyPosition[1], "xx": celluloxPosition[0], "xy": celluloxPosition[1], "yx": celluloyPosition[0], "yy": celluloyPosition[1], "acID": "Ac5", "turn": currentTurn, "groupID": group.id, })); } }); celluloy.setColor(0, 0, 255, 0, 0); dbRef.child('groups').child(group.id).child('tabletStatus').set("YES"); dbRef.child('groups').child(group.id).child('currentActivity').set("Ac5"); timerCelluloPosition = new Timer.periodic(new Duration(milliseconds: 500), (time) { var xxprev = celluloxPosition[0]; var xyprev = celluloxPosition[1]; var yxprev = celluloyPosition[0]; var yyprev = celluloyPosition[1]; if (totalRobots() > 1) { // print(cellulox.getrobotKidnapped().toString()); // print(celluloy.getrobotKidnapped().toString()); cellulox.getrobotx().then((val) => setState(() { if (val != null) { group.cellulox.traveledDistance = group.cellulox.traveledDistance + (val - celluloxPosition[0]); 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; group.cellulox.traveledDistance = group.cellulox.traveledDistance + math.sqrt(math.pow((xxprev - celluloxPosition[0]), 2) + math.pow((xyprev - celluloxPosition[1]), 2)) / 20; } })); celluloy.getrobotx().then((val) => setState(() { if (val != null) { celluloyPosition[0] = val; } })); celluloy.getroboty().then((val) => setState(() { if (val != null) { group.celluloy.traveledDistance = group.celluloy.traveledDistance + math.sqrt(math.pow((yxprev - celluloyPosition[0]), 2) + math.pow((yyprev - celluloyPosition[1]), 2)) / 20; celluloyPosition[1] = val; // if (addtoprint == true) celluloyPositiontopaint.add(val); } })); if (celluloxPosition[0] > 800 || celluloyPosition[1] > 800) { cellulox.setVelocity(0, 0); celluloy.setVelocity(0, 0); } } //if (runHaptic == true) { - calcHaptic(); + if (startGame) calcHaptic(); checkCelluloGame(); }); elapseTimer.start(); onDataSend(); } @override void dispose() { elapseTimer.stop(); timerCelluloPosition.cancel(); // super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Follow the Curve'), actions: [ Padding( padding: EdgeInsets.only(right: 20.0), child: GestureDetector( onTap: () { group.prevActivity = 'Ac5'; group.currentActivity = 'Ac61'; group.navigatorKeygame.currentState.pushReplacementNamed( group.currentActivity, ); // print('ff'); }, child: Icon(Icons.help), )), ], ), backgroundColor: Colors.white, body: SingleChildScrollView( child: Column(children: [ Row( //mainAxisAlignment: MainAxisAlignment.center, children: [ Container( height: 70, width: 600, child: Card( color: Colors.lightBlue, child: ListTile( title: Text( startGame ? ('Follow the curve from Point ' + 'A' + ' to ' + 'B') : ('Move the prurple robot to point A'), style: new TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold, ), ), ), ), ), SizedBox( width: 25, ), // SizedBox(width: 20), Container( decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(100)), color: reachend ? Colors.blue : Colors.grey), child: FlatButton( disabledColor: Colors.grey, child: Text( "Next Turn", style: TextStyle( color: Colors.white, fontWeight: FontWeight.w700, fontSize: 18), ), onPressed: () => { reachend ? { + cellulox.resetrobot(), + celluloy.resetrobot(), tapCounter = 0, startGame = false, + stopend = false, + reachend = false, 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! '), }, } : null }, ), ) ]), SizedBox( height: 30, ), (stopend) ? Row( // crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Container( - width: 290, + height: 70, + width: 300, + child: Card( + color: Colors.lightBlue, child: ListTile( title: Text( - 'Where the purple robot should go to reach point B:'), - )), + ('Where the purple robot should go to reach point B'), + style: new TextStyle( + color: Colors.white, + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + ), + SizedBox(width: 20), Container( width: 200, child: DropdownButton( hint: Text('RED robot goes to: '), value: initialPointXvalue, icon: Icon(Icons.arrow_downward), iconSize: 24, elevation: 16, style: TextStyle(color: Colors.deepPurple), onChanged: (String newValue) { setState(() { initialPointXvalue = newValue; }); }, items: initialpointList .map>((String value) { return DropdownMenuItem( value: value, child: Text(value), ); }).toList(), )), SizedBox(width: 38), Container( width: 200, child: DropdownButton( hint: Text('BLUE robot goes to: '), value: initialPointYvalue, icon: Icon(Icons.arrow_downward), iconSize: 24, elevation: 16, style: TextStyle(color: Colors.deepPurple), onChanged: (String newValue) { setState(() { initialPointYvalue = newValue; }); }, items: initialpointList .map>((String value) { return DropdownMenuItem( value: value, child: Text(value), ); }).toList(), )), ]) : SizedBox( height: 10, ), (reachend && stopend) ? Row( // crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Container( - width: 290, + height: 70, + width: 300, + child: Card( + color: Colors.lightBlue, child: ListTile( - title: Text('Did you guess correctly?'), - )), + title: Text( + ('Did you guess correctly?'), + style: new TextStyle( + color: Colors.white, + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + ), + SizedBox(width: 50), Container( - width: 200, + width: 100, child: DropdownButton( hint: Text(''), - value: initialPointXvalue, + value: guessvalue, icon: Icon(Icons.arrow_downward), iconSize: 24, elevation: 16, style: TextStyle(color: Colors.deepPurple), onChanged: (String newValue) { setState(() { - initialPointXvalue = newValue; + guessvalue = newValue; }); }, items: ['Yes', 'No'] .map>((String value) { return DropdownMenuItem( value: value, child: Text(value), ); }).toList(), )), SizedBox(width: 38), ]) : SizedBox( height: 1, ), SizedBox( height: 10, ), 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: [ CustomPaint( //size: Size(200, 200), painter: //LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), MapShapeMaker2( pointPosition[currentTurn - 1], 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: SvgPicture.asset( mapPath, ), ), CustomPaint( //size: Size(200, 200), painter: GuideGrid( origin, step, MediaQuery.of(context).size.width * 0.9 / mapSizeWidth, MediaQuery.of(context).size.height * 0.65 / mapSizeHeight, celluloxPosition, celluloyPosition, ) //LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), ), CustomPaint( //size: Size(200, 200), painter: StopDrawer( MediaQuery.of(context).size.width * 0.9 / mapSizeWidth, MediaQuery.of(context).size.height * 0.65 / mapSizeHeight, stopBoxCenter[currentTurn - 1], ) //LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), ), 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), ), ), ), CustomPaint( //size: Size(200, 200), painter: BezierCurvePainter( mapShape[currentTurn - 1]['startCenter'], mapShape[currentTurn - 1]['endCenter'], MediaQuery.of(context).size.width * 0.9 / mapSizeWidth, MediaQuery.of(context).size.height * 0.65 / mapSizeHeight, currentTurn, 5) //LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), ), Container( width: MediaQuery.of(context).size.width * 0.9, height: MediaQuery.of(context).size.height * 0.65, child: Align( alignment: Alignment( 2 * ((celluloxPosition[0] + celluloxPosition[0]) / 2 / mapSizeWidth) - 1, 2 * ((celluloyPosition[1] + celluloyPosition[1]) / 2 / mapSizeHeight) - 1), child: Card( child: SvgPicture.asset( "assets/images/celluloPurple.svg", height: 60, width: 60), ), ), ), ], )), SizedBox( height: 15, ), MembersBar( curTurn: currentTurn, ), ]))); } } diff --git a/student/lib/Activities/Ac6_1.dart b/student/lib/Activities/Ac6_t.dart similarity index 100% rename from student/lib/Activities/Ac6_1.dart rename to student/lib/Activities/Ac6_t.dart diff --git a/student/lib/Game.dart b/student/lib/Game.dart index 9fb5234..24dd5af 100644 --- a/student/lib/Game.dart +++ b/student/lib/Game.dart @@ -1,42 +1,41 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:student/model/Group.dart'; import 'dart:convert'; import './ui/router.dart'; import 'package:firebase_database/firebase_database.dart'; class Game extends StatefulWidget { Game({Key key}) : super(key: key); @override _GameState createState() => _GameState(); } class _GameState extends State with SingleTickerProviderStateMixin { final dbRef = FirebaseDatabase.instance.reference().child(group.sessionID); @override void initState() { super.initState(); } Widget build(BuildContext context) { return new WillPopScope( onWillPop: () async => false, child: Consumer( builder: (context, model, child) => MaterialApp( - //title: 'N', // Start the app with the "/" named route. In this case, the app starts // on the FirstScreen widget. onGenerateRoute: Router.generateRoute, // initialRoute: '/Ac7', navigatorKey: group.navigatorKeygame, // routes: { // '/Ac7': (context) => Ac7(), // '/Ac8': (context) => Ac8(), // '/Ac9': (context) => Ac9(), // }, ))); } } diff --git a/student/lib/loginpage_names.dart b/student/lib/loginpage_names.dart index 6167a5e..6f9c8b9 100644 --- a/student/lib/loginpage_names.dart +++ b/student/lib/loginpage_names.dart @@ -1,185 +1,185 @@ import 'package:flutter/material.dart'; import 'package:student/loginpage_robots.dart'; import 'dart:convert'; import 'dart:async'; import 'package:firebase_core/firebase_core.dart'; import 'package:student/Database.dart'; import 'package:student/model/Group.dart'; import 'package:student/model/Cellulo.dart'; import 'package:student/Game.dart'; import 'package:student/Database.dart'; import 'package:student/widgets/showAlertDialog.Dart'; import 'package:firebase_database/firebase_database.dart'; class LoginPage extends StatefulWidget { LoginPage({Key key}) : super(key: key); @override _LoginPageState createState() => _LoginPageState(); } class _LoginPageState extends State { TextEditingController controller1 = TextEditingController(); TextEditingController controller2 = TextEditingController(); TextEditingController controller3 = TextEditingController(); TextEditingController controller4 = TextEditingController(); TextEditingController controllersessionID = TextEditingController(); Timer timerEnagagement; final teamname = "1"; @override void initState() { cellulox.setColor(0, 255, 0, 0, 0); celluloy.setColor(0, 0, 255, 0, 0); cellulox.clearrobot(); celluloy.clearrobot(); super.initState(); } @override void dispose() { super.dispose(); } Widget nextButton() { return InkWell( onTap: () { if (controllersessionID.text != null && controller4.text != null && controllersessionID.text != '' && controller4.text != '') { group.sessionID = controllersessionID.text; //print(controller4.text); group.member1name = controller1.text; group.member2name = controller2.text; group.member3name = controller3.text; group.id = controller4.text; - group.currentActivity = 'Ac5'; + group.currentActivity = 'Ac4'; final dbRef = FirebaseDatabase.instance.reference().child(group.sessionID); dbRef.child('groups').child(controller4.text).set(group.toJson()); group.setupDatabse(); group.cellulox = cellulox; group.celluloy = celluloy; cellulox.setup(); //setting up the robots Navigator.push( context, MaterialPageRoute(builder: (context) => Game())); } else - showAlertDialog(context, 'What is your session ID', + showAlertDialogmain(context, 'What is your session ID', 'Fill the session ID and team name'); }, child: Container( width: MediaQuery.of(context).size.width, padding: EdgeInsets.symmetric(vertical: 13), alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(5)), boxShadow: [ BoxShadow( color: Color(0xffdf8e33).withAlpha(100), offset: Offset(2, 4), blurRadius: 8, spreadRadius: 2) ], color: Colors.white), child: Text( 'Lets go', style: TextStyle(fontSize: 20, color: Color(0xfff7892b)), ), ), ); } Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Login'), ), backgroundColor: Colors.white, body: SingleChildScrollView( child: Padding( padding: EdgeInsets.all(30.0), child: Column(children: [ Container( padding: EdgeInsets.all(8.0), decoration: BoxDecoration( border: Border( bottom: BorderSide(color: Colors.grey[100]))), child: TextField( controller: controller1, decoration: InputDecoration( border: InputBorder.none, hintText: "Member 1: Enter your name", hintStyle: TextStyle(color: Colors.grey[400])), ), ), SizedBox( height: 100, ), Container( padding: EdgeInsets.all(8.0), decoration: BoxDecoration( border: Border( bottom: BorderSide(color: Colors.grey[100]))), child: TextField( controller: controller2, decoration: InputDecoration( border: InputBorder.none, hintText: "Member 2: Enter your name", hintStyle: TextStyle(color: Colors.grey[400])), ), ), SizedBox( height: 100, ), Container( padding: EdgeInsets.all(8.0), decoration: BoxDecoration( border: Border( bottom: BorderSide(color: Colors.grey[100]))), child: TextField( controller: controller3, decoration: InputDecoration( border: InputBorder.none, hintText: "Member 3: Enter your name", hintStyle: TextStyle(color: Colors.grey[400])), ), ), SizedBox( height: 100, ), Container( padding: EdgeInsets.all(8.0), decoration: BoxDecoration( border: Border( bottom: BorderSide(color: Colors.grey[100]))), child: TextField( controller: controller4, decoration: InputDecoration( border: InputBorder.none, hintText: "Enter your group name", hintStyle: TextStyle(color: Colors.grey[400])), ), ), SizedBox( height: 50, ), Container( padding: EdgeInsets.all(8.0), decoration: BoxDecoration( border: Border( bottom: BorderSide(color: Colors.grey[100]))), child: TextField( controller: controllersessionID, decoration: InputDecoration( border: InputBorder.none, hintText: "Enter session ID", hintStyle: TextStyle(color: Colors.grey[400])), ), ), nextButton() ])))); } } diff --git a/student/lib/ui/router.dart b/student/lib/ui/router.dart index 235a3b6..ec46bd8 100644 --- a/student/lib/ui/router.dart +++ b/student/lib/ui/router.dart @@ -1,51 +1,51 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:student/ui/router.dart'; import 'package:student/Activities/Ac7.Dart'; import 'package:student/Activities/Ac8.Dart'; import 'package:student/Activities/Ac9.Dart'; import 'package:student/Activities/Ac6.dart'; -import 'package:student/Activities/Ac6_1.dart'; +import 'package:student/Activities/Ac6_t.dart'; import 'package:student/Activities/Ac5.dart'; import 'package:student/Activities/Ac4.dart'; import 'package:student/Activities/Ac3.dart'; import 'package:student/Activities/Ac2.dart'; import 'package:student/Activities/Ac1.dart'; import 'package:student/model/Group.dart'; //import 'package:Teacher_Dashboard/screens/bottom_nav_screen.dart'; class Router { static Route generateRoute(RouteSettings settings) { switch (group.currentActivity) { case 'Ac7': return MaterialPageRoute(builder: (_) => Ac7()); case 'Ac8': return MaterialPageRoute(builder: (_) => Ac8()); case 'Ac9': return MaterialPageRoute(builder: (_) => Ac9()); case 'Ac6': return MaterialPageRoute(builder: (_) => Ac6()); case 'Ac61': return MaterialPageRoute(builder: (_) => Ac61()); case 'Ac5': return MaterialPageRoute(builder: (_) => Ac5()); case 'Ac4': return MaterialPageRoute(builder: (_) => Ac4()); case 'Ac3': return MaterialPageRoute(builder: (_) => Ac3()); case 'Ac2': return MaterialPageRoute(builder: (_) => Ac2()); case 'Ac1': return MaterialPageRoute(builder: (_) => Ac1()); case 'Idle': return MaterialPageRoute(builder: (_) => Ac7()); default: return MaterialPageRoute( builder: (_) => Scaffold( body: Center( child: Text('No route defined for '), ), )); } } } diff --git a/student/lib/widgets/guidegrid.dart b/student/lib/widgets/guidegrid.dart index 83d4be6..616dfed 100644 --- a/student/lib/widgets/guidegrid.dart +++ b/student/lib/widgets/guidegrid.dart @@ -1,69 +1,93 @@ import 'package:flutter/material.dart'; class GuideGrid extends CustomPainter { Paint _paintBlue; Paint _paintRed; double _progress; Offset beginpath; Offset endpath; Offset origin; var step = 0.0; List celluloxposition; List celluloyposition; double coeffScreenMapHeight; double coeffScreenMapWidth; double xaxis = 750; double yaxis = 80; int axisX; int axisY; var steps = [0.0, 80.0, 157.0, 235.0, 312.0, 389.0, 467.0]; GuideGrid(this.origin, this.step, this.coeffScreenMapWidth, this.coeffScreenMapHeight, this.celluloxposition, this.celluloyposition) { _paintBlue = Paint() ..color = Colors.blue ..strokeWidth = 1.0 ..style = PaintingStyle.fill; _paintRed = Paint() ..color = Colors.red ..strokeWidth = 1.0 ..style = PaintingStyle.fill; - axisX = ((celluloxposition[0] - origin.dx / coeffScreenMapWidth) ~/ - (2 * step)) - - 1; - axisY = ((origin.dy - celluloyposition[1] / coeffScreenMapHeight) ~/ - (2 * step)) + - 1; - if (axisX < 0) axisX = 0; - if (axisY < 0) axisY = 0; - if (axisX > 6) axisX = 6; - if (axisY > 6) axisY = 6; + axisX = 0; + axisY = 0; + for (int i = 1; i < 4; i++) { + if (steps[2 * (i - 1)] / coeffScreenMapWidth < + (celluloxposition[0] - (origin.dx / coeffScreenMapWidth)) && + (celluloxposition[0] - (origin.dx / coeffScreenMapWidth)) < + steps[2 * i] / coeffScreenMapWidth) { + axisX = 2 * (i - 1); + break; + } + } + + if ((celluloxposition[0] - origin.dx / coeffScreenMapWidth) < 0) axisX = 0; + + if ((celluloxposition[0] - origin.dx / coeffScreenMapWidth) > + steps[6] / coeffScreenMapHeight) axisX = 6; + + for (int i = 1; i < 4; i++) { + if (steps[2 * (i - 1)] / coeffScreenMapHeight < + (-celluloyposition[1] + origin.dy / coeffScreenMapHeight) && + (-celluloyposition[1] + origin.dy / coeffScreenMapHeight) < + steps[2 * i] / coeffScreenMapHeight) { + axisY = 2 * (i - 1); + break; + } + } + + if ((-celluloyposition[1] + origin.dy / coeffScreenMapHeight) < 0) + axisY = 0; + + if ((-celluloyposition[1] + origin.dy / coeffScreenMapHeight) > + steps[6] / coeffScreenMapHeight) axisY = 6; } @override void paint(Canvas canvas, Size size) { + // print('axisX' + axisX.toString()); + //print('axisY' + axisY.toString()); canvas.drawCircle( - Offset(origin.dx + 2 * steps[axisX], origin.dy), 11.0, _paintRed); + Offset(origin.dx + steps[axisX], origin.dy), 11.0, _paintRed); canvas.drawCircle( - Offset(origin.dx, origin.dy - 2 * steps[axisY]), 11.0, _paintBlue); + Offset(origin.dx, origin.dy - steps[axisY]), 11.0, _paintBlue); canvas.drawLine( Offset(celluloxposition[0] * coeffScreenMapWidth, celluloyposition[1] * coeffScreenMapHeight), Offset(celluloxposition[0] * coeffScreenMapWidth, xaxis * coeffScreenMapHeight), _paintRed); canvas.drawLine( Offset(celluloxposition[0] * coeffScreenMapWidth, celluloyposition[1] * coeffScreenMapHeight), Offset(yaxis * coeffScreenMapWidth, celluloyposition[1] * coeffScreenMapHeight), _paintBlue); } @override bool shouldRepaint(GuideGrid oldDelegate) { return oldDelegate._progress != _progress; } } diff --git a/student/lib/widgets/mapShapeMaker.dart b/student/lib/widgets/mapShapeMaker.dart index 1422452..46995d9 100644 --- a/student/lib/widgets/mapShapeMaker.dart +++ b/student/lib/widgets/mapShapeMaker.dart @@ -1,470 +1,472 @@ import 'package:flutter/material.dart'; import 'dart:math' as math; class MapShapeMaker extends CustomPainter { Paint _paint; Paint _paintStartEnd; int numCircles; List originCircles; List radiuosCircles; int numRectangles; List originRectangles; List widthRectangles; List heightRectangles; int numPolygons; List sidesofPolygon; List radiusPolygon; List centerPolygon; List colorHexagon; Offset startCenter; Offset endCenter; double radiuosStart = 45; var pointOrder = ['A', 'B', 'C', 'D']; List pointPosition = [ Offset(80.0, 80.0), Offset(760.0, 80.0), Offset(80.0, 760.0), Offset(760.0, 760.0) ]; List pointPositionM = [ Offset(80.0, 80.0), Offset(760.0, 80.0), Offset(80.0, 760.0), Offset(760.0, 760.0) ]; List originCirclesM; List radiuosCirclesM; List originRectanglesM; List widthRectanglesM; List heightRectanglesM; List radiusPolygonM; List centerPolygonM; Offset startCenterM; Offset endCenterM; double radiuosStartM = 45; final _textPainter = TextPainter(textDirection: TextDirection.ltr); final _textPainter2 = TextPainter(textDirection: TextDirection.ltr); final _textPainter3 = TextPainter(textDirection: TextDirection.ltr); final _textPainter4 = TextPainter(textDirection: TextDirection.ltr); double coeffScreenMapHeight; double coeffScreenMapWidth; MapShapeMaker( this.pointPosition, coeffScreenMapWidth, this.coeffScreenMapHeight, this.numRectangles, this.originRectangles, this.widthRectangles, this.heightRectangles, this.numCircles, this.originCircles, this.radiuosCircles, this.numPolygons, this.sidesofPolygon, this.radiusPolygon, this.centerPolygon, this.startCenter, this.endCenter) { _paint = Paint() ..color = Colors.blue ..strokeWidth = 10.0 ..style = PaintingStyle.fill; _paintStartEnd = Paint() ..color = Colors.green ..strokeWidth = 10.0 ..style = PaintingStyle.fill; // print(originRectangles[0].dx); // print('coeff' + coeffScreenMapWidth.toString()); originCirclesM = new List(numCircles); radiuosCirclesM = new List(numCircles); for (int i = 0; i < numCircles; i++) { originCirclesM[i] = Offset(originCircles[i].dx * coeffScreenMapWidth, originCircles[i].dy * coeffScreenMapHeight); radiuosCirclesM[i] = radiuosCircles[i] * coeffScreenMapWidth; } originRectanglesM = new List(numRectangles); widthRectanglesM = new List(numRectangles); heightRectanglesM = new List(numRectangles); for (int i = 0; i < numRectangles; i++) { originRectanglesM[i] = Offset( originRectangles[i].dx * coeffScreenMapWidth, originRectangles[i].dy * coeffScreenMapHeight); widthRectanglesM[i] = widthRectangles[i] * coeffScreenMapWidth; heightRectanglesM[i] = heightRectangles[i] * coeffScreenMapHeight; } centerPolygonM = new List(numPolygons); radiusPolygonM = new List(numPolygons); startCenterM = Offset(startCenter.dx * coeffScreenMapWidth, startCenter.dy * coeffScreenMapHeight); endCenterM = Offset(endCenter.dx * coeffScreenMapWidth, endCenter.dy * coeffScreenMapHeight); - + radiuosStartM = + radiuosStart * ((coeffScreenMapHeight + coeffScreenMapWidth) / 2); for (int i = 0; i < numPolygons; i++) { centerPolygonM[i] = Offset(centerPolygon[i].dx * coeffScreenMapWidth, centerPolygon[i].dy * coeffScreenMapHeight); radiusPolygonM[i] = radiusPolygon[i] * coeffScreenMapWidth; } for (int i = 0; i < pointPosition.length; i++) { pointPositionM[i] = Offset(pointPosition[i].dx * coeffScreenMapWidth, pointPosition[i].dy * coeffScreenMapHeight); } } Path createPolygonPath(int i) { final path = Path(); var angle = (math.pi * 2) / sidesofPolygon[i]; Offset firstPoint = Offset( radiusPolygonM[i] * math.cos(0.0), radiusPolygonM[i] * math.sin(0.0)); path.moveTo(firstPoint.dx + centerPolygonM[i].dx, firstPoint.dy + centerPolygonM[i].dy); for (int j = 1; j <= sidesofPolygon[i]; j++) { double x = radiusPolygonM[i] * math.cos(angle * j) + centerPolygonM[i].dx; double y = radiusPolygonM[i] * math.sin(angle * j) + centerPolygonM[i].dy; path.lineTo(x, y); } path.close(); return path; } Path createStartPath(Offset center, double radius) { final path = Path(); var angle = (math.pi * 2) / 6; Offset firstPoint = Offset(radius * math.cos(0.0), radius * math.sin(0.0)); path.moveTo(firstPoint.dx + center.dx, firstPoint.dy + center.dy); for (int j = 1; j <= 6; j++) { double x = radius * math.cos(angle * j) + center.dx; double y = radius * math.sin(angle * j) + center.dy; path.lineTo(x, y); } path.close(); return path; } @override void paint(Canvas canvas, Size size) { for (int i = 0; i < numCircles; i++) { double x = ((originCirclesM[i].dx)); double y = (originCirclesM[i].dy); canvas.drawCircle(Offset(x, y), radiuosCirclesM[i], _paint); } for (int i = 0; i < numRectangles; i++) { // canvas.translate(0, 90); // canvas.rotate(1.3); canvas.drawRect( Rect.fromCenter( center: Offset(originRectanglesM[i].dx, originRectanglesM[i].dy), width: widthRectanglesM[i], height: heightRectanglesM[i]), _paint); } for (int i = 0; i < numPolygons; i++) { Path path = createPolygonPath(i); canvas.drawPath(path, _paint); } _textPainter2.text = TextSpan( text: pointOrder[1], style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black)); _textPainter2.layout( minWidth: 0, maxWidth: double.maxFinite, ); _textPainter.text = TextSpan( text: pointOrder[0], style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black)); _textPainter.layout( minWidth: 0, maxWidth: double.maxFinite, ); _textPainter3.text = TextSpan( text: pointOrder[2], style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black)); _textPainter3.layout( minWidth: 0, maxWidth: double.maxFinite, ); _textPainter4.text = TextSpan( text: pointOrder[3], style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black)); _textPainter4.layout( minWidth: 0, maxWidth: double.maxFinite, ); for (int i = 0; i < pointPosition.length; i++) { canvas.drawPath( createStartPath(pointPositionM[i], radiuosStartM), Paint() ..color = Colors.green ..strokeWidth = 10.0 ..style = PaintingStyle.fill); canvas.drawPath( createStartPath(pointPositionM[i], radiuosStartM - 10), Paint() ..color = Colors.white ..strokeWidth = 10.0 ..style = PaintingStyle.fill); } _textPainter.paint( canvas, Offset(pointPositionM[0].dx - 6, pointPositionM[0].dy - 5)); _textPainter2.paint( canvas, Offset(pointPositionM[1].dx - 6, pointPositionM[1].dy - 5)); _textPainter3.paint( canvas, Offset(pointPositionM[2].dx - 6, pointPositionM[2].dy - 5)); _textPainter4.paint( canvas, Offset(pointPositionM[3].dx - 6, pointPositionM[3].dy - 5)); } @override bool shouldRepaint(CustomPainter oldDelegate) { return false; } } class MapShapeMaker2 extends CustomPainter { Paint _paint; Paint _paintStartEnd; int numCircles; List originCircles; List radiuosCircles; int numRectangles; List originRectangles; List widthRectangles; List heightRectangles; int numPolygons; List sidesofPolygon; List radiusPolygon; List centerPolygon; List colorHexagon; Offset startCenter; Offset endCenter; double radiuosStart = 45; var pointOrder = ['A', 'B', 'C', 'D']; List pointPosition = [ Offset(80.0, 80.0), Offset(760.0, 80.0), Offset(80.0, 760.0), Offset(760.0, 760.0) ]; List pointPositionM = [ Offset(80.0, 80.0), Offset(760.0, 80.0), Offset(80.0, 760.0), Offset(760.0, 760.0) ]; List originCirclesM; List radiuosCirclesM; List originRectanglesM; List widthRectanglesM; List heightRectanglesM; List radiusPolygonM; List centerPolygonM; Offset startCenterM; Offset endCenterM; double radiuosStartM = 45; final _textPainter = TextPainter(textDirection: TextDirection.ltr); final _textPainter2 = TextPainter(textDirection: TextDirection.ltr); final _textPainter3 = TextPainter(textDirection: TextDirection.ltr); final _textPainter4 = TextPainter(textDirection: TextDirection.ltr); double coeffScreenMapHeight; double coeffScreenMapWidth; MapShapeMaker2( this.pointPosition, coeffScreenMapWidth, this.coeffScreenMapHeight, this.numRectangles, this.originRectangles, this.widthRectangles, this.heightRectangles, this.numCircles, this.originCircles, this.radiuosCircles, this.numPolygons, this.sidesofPolygon, this.radiusPolygon, this.centerPolygon, this.startCenter, this.endCenter) { _paint = Paint() ..color = Colors.blue ..strokeWidth = 10.0 ..style = PaintingStyle.fill; _paintStartEnd = Paint() ..color = Colors.green ..strokeWidth = 10.0 ..style = PaintingStyle.fill; // print(originRectangles[0].dx); // print('coeff' + coeffScreenMapWidth.toString()); originCirclesM = new List(numCircles); radiuosCirclesM = new List(numCircles); for (int i = 0; i < numCircles; i++) { originCirclesM[i] = Offset(originCircles[i].dx * coeffScreenMapWidth, originCircles[i].dy * coeffScreenMapHeight); radiuosCirclesM[i] = radiuosCircles[i] * coeffScreenMapWidth; } originRectanglesM = new List(numRectangles); widthRectanglesM = new List(numRectangles); heightRectanglesM = new List(numRectangles); for (int i = 0; i < numRectangles; i++) { originRectanglesM[i] = Offset( originRectangles[i].dx * coeffScreenMapWidth, originRectangles[i].dy * coeffScreenMapHeight); widthRectanglesM[i] = widthRectangles[i] * coeffScreenMapWidth; heightRectanglesM[i] = heightRectangles[i] * coeffScreenMapHeight; } centerPolygonM = new List(numPolygons); radiusPolygonM = new List(numPolygons); startCenterM = Offset(startCenter.dx * coeffScreenMapWidth, startCenter.dy * coeffScreenMapHeight); endCenterM = Offset(endCenter.dx * coeffScreenMapWidth, endCenter.dy * coeffScreenMapHeight); - + radiuosStartM = + radiuosStart * ((coeffScreenMapWidth + coeffScreenMapHeight) / 2); for (int i = 0; i < numPolygons; i++) { centerPolygonM[i] = Offset(centerPolygon[i].dx * coeffScreenMapWidth, centerPolygon[i].dy * coeffScreenMapHeight); radiusPolygonM[i] = radiusPolygon[i] * coeffScreenMapWidth; } for (int i = 0; i < pointPosition.length; i++) { pointPositionM[i] = Offset(pointPosition[i].dx * coeffScreenMapWidth, pointPosition[i].dy * coeffScreenMapHeight); } } Path createPolygonPath(int i) { final path = Path(); var angle = (math.pi * 2) / sidesofPolygon[i]; Offset firstPoint = Offset( radiusPolygonM[i] * math.cos(0.0), radiusPolygonM[i] * math.sin(0.0)); path.moveTo(firstPoint.dx + centerPolygonM[i].dx, firstPoint.dy + centerPolygonM[i].dy); for (int j = 1; j <= sidesofPolygon[i]; j++) { double x = radiusPolygonM[i] * math.cos(angle * j) + centerPolygonM[i].dx; double y = radiusPolygonM[i] * math.sin(angle * j) + centerPolygonM[i].dy; path.lineTo(x, y); } path.close(); return path; } Path createStartPath(Offset center, double radius) { final path = Path(); var angle = (math.pi * 2) / 6; Offset firstPoint = Offset(radius * math.cos(0.0), radius * math.sin(0.0)); path.moveTo(firstPoint.dx + center.dx, firstPoint.dy + center.dy); for (int j = 1; j <= 6; j++) { double x = radius * math.cos(angle * j) + center.dx; double y = radius * math.sin(angle * j) + center.dy; path.lineTo(x, y); } path.close(); return path; } @override void paint(Canvas canvas, Size size) { for (int i = 0; i < numCircles; i++) { double x = ((originCirclesM[i].dx)); double y = (originCirclesM[i].dy); canvas.drawCircle(Offset(x, y), radiuosCirclesM[i], _paint); } for (int i = 0; i < numRectangles; i++) { // canvas.translate(0, 90); // canvas.rotate(1.3); canvas.drawRect( Rect.fromCenter( center: Offset(originRectanglesM[i].dx, originRectanglesM[i].dy), width: widthRectanglesM[i], height: heightRectanglesM[i]), _paint); } for (int i = 0; i < numPolygons; i++) { Path path = createPolygonPath(i); canvas.drawPath(path, _paint); } _textPainter2.text = TextSpan( text: pointOrder[0], style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black)); _textPainter2.layout( minWidth: 0, maxWidth: double.maxFinite, ); _textPainter.text = TextSpan( text: pointOrder[1], style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black)); _textPainter.layout( minWidth: 0, maxWidth: double.maxFinite, ); _textPainter3.text = TextSpan( text: pointOrder[2], style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black)); _textPainter3.layout( minWidth: 0, maxWidth: double.maxFinite, ); _textPainter4.text = TextSpan( text: pointOrder[3], style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black)); _textPainter4.layout( minWidth: 0, maxWidth: double.maxFinite, ); for (int i = 0; i < pointPosition.length; i++) { canvas.drawPath( createStartPath(pointPositionM[i], radiuosStartM), Paint() ..color = Colors.green ..strokeWidth = 10.0 ..style = PaintingStyle.fill); canvas.drawPath( createStartPath(pointPositionM[i], radiuosStartM - 10), Paint() ..color = Colors.white ..strokeWidth = 10.0 ..style = PaintingStyle.fill); } _textPainter.paint( canvas, Offset(pointPositionM[0].dx - 40, pointPositionM[0].dy - 50)); _textPainter2.paint( canvas, Offset(pointPositionM[1].dx - 40, pointPositionM[1].dy - 50)); } @override bool shouldRepaint(CustomPainter oldDelegate) { return false; } } diff --git a/student/lib/widgets/showAlertDialog.Dart b/student/lib/widgets/showAlertDialog.Dart index 0f38cd0..9178ca0 100644 --- a/student/lib/widgets/showAlertDialog.Dart +++ b/student/lib/widgets/showAlertDialog.Dart @@ -1,53 +1,80 @@ import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:student/model/Group.dart'; import 'package:provider/provider.dart'; showAlertDialog(BuildContext context, String title, String content) { // set up the button // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text(title), content: Text(content), backgroundColor: Colors.white, actions: [ FlatButton( color: Colors.deepPurple, child: Text('Ok'), onPressed: () { group.isAlertShown = false; Navigator.of(group.navigatorKeygame.currentState.context, rootNavigator: true) .pop(); }, ) ]); showDialog( barrierDismissible: false, context: context, builder: (BuildContext context) { return alert; }, ); } showPauseDialog(BuildContext context) { AlertDialog alert = AlertDialog( title: Text('Pay Atttention'), content: Text('Wait until teacher continues the activity'), backgroundColor: Colors.white, ); // show the dialog showDialog( barrierDismissible: false, context: context, builder: (BuildContext context) { final provider = Provider.of(context); if (provider.ispaused == false) Navigator.of(context, rootNavigator: true).pop(); // Navigator.currentState.pop(); return alert; }, ); } + +showAlertDialogmain(BuildContext context, String title, String content) { + // set up the button + + // set up the AlertDialog + AlertDialog alert = AlertDialog( + title: Text(title), + content: Text(content), + backgroundColor: Colors.white, + actions: [ + FlatButton( + color: Colors.deepPurple, + child: Text('Ok'), + onPressed: () { + group.isAlertShown = false; + Navigator.of(context, rootNavigator: true).pop(); + }, + ) + ]); + showDialog( + barrierDismissible: false, + context: context, + builder: (BuildContext context) { + return alert; + }, + ); +}