diff --git a/assets/aSpades.PNG b/assets/aSpades.PNG new file mode 100644 index 0000000..8b4b213 Binary files /dev/null and b/assets/aSpades.PNG differ diff --git a/assets/cardBack.PNG b/assets/cardBack.PNG new file mode 100644 index 0000000..ee7051f Binary files /dev/null and b/assets/cardBack.PNG differ diff --git a/lib/detection.dart b/lib/detection.dart new file mode 100644 index 0000000..b1b95e2 --- /dev/null +++ b/lib/detection.dart @@ -0,0 +1,133 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'dart:math'; +import 'dart:async'; +import 'package:rflutter_alert/rflutter_alert.dart'; +import 'dart:convert'; +import 'server.dart'; +import 'main.dart'; +import 'userIDD.dart'; +import 'package:uuid/uuid.dart'; +var uuid = Uuid(); +int detectAttemptNum = 1; +int pressNumber=0; +List times=[]; +Stopwatch clock= Stopwatch(); +//dumb name - pls rename +String detectionImage="assets/cardBack.PNG"; +int numberErrors=0; +var rng = new Random(); +bool hasBeenClicked = false; +bool gamerun= true; +//stop declaring global variables +// code for card detection task in app +class detectionTaskPage extends StatefulWidget { + @override + detectionTaskPageState createState() => detectionTaskPageState(); +} +class detectionTaskPageState extends State { + void detectionButtonPress() { + + if(detectionImage=="assets/aSpades.PNG") { + pressNumber++; + clock.start(); + clock.stop(); + times.add(clock.elapsedMilliseconds); + print(clock.elapsedMilliseconds); + detectionImage = "assets/cardBack.PNG"; + clock.reset(); + clock.stop(); + } + else { + print("Wait until the card flips"); + clock.stop(); + times.add(0); + numberErrors++; + print(clock.elapsedMilliseconds); + } + } + @override + void initState() { + Timer timer = Timer.periodic(Duration(milliseconds: 3500), (timer) { + //this is the end condition as of right now. + if(pressNumber>4) { + + var dict = {"times": times}; + String data = json.encode(dict); + createData("Detection", uuid.v1().toString(), data, "1.0.0"); + detectAttemptNum++; + timer.cancel(); + print(times); + new Alert( + context:context, + type:AlertType.success, + title: "Finished", + desc:"Number of errors: $numberErrors \n\n Times: $times", + buttons: [ + DialogButton( + child:Text("Restart"), + onPressed: () { + pressNumber=0; + numberErrors=0; + clock.reset(); + clock.stop(); + times=[]; + Navigator.pop(context); + timer.cancel(); + initState(); + + }, + ) + ] + ) + .show(); + } + //end of end condition + Timer(Duration(milliseconds: rng.nextInt(3000)), () + { + clock.start(); + if(this.mounted) { + clock.start(); + setState(() { + detectionImage = "assets/aSpades.PNG"; + }); + } + Timer(Duration(milliseconds: 1500), () { + clock.reset(); + clock.stop(); + if(this.mounted) { + setState(() { + detectionImage = "assets/cardBack.PNG"; + }); + } + }); + }); + }); + } + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Memory Maker'), + backgroundColor: Colors.cyan, + ), + backgroundColor: Colors.blue, + body: Center( + child: Container( + height: MediaQuery.of(context).size.height / 2, + width: MediaQuery.of(context).size.width / 2, + child: FlatButton( + color: Colors.blue, + onPressed:() { + detectionButtonPress(); + }, + child: Container ( + height: double.infinity, + width: double.infinity, + child: Image.asset(detectionImage, height: double.infinity, width:double.infinity) + ) + ) + ) + ), + ); + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 464bd16..fac9274 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -24,7 +24,8 @@ Set correctMoves = {}; List times=[]; List errors = []; //temporary test path - going to change to make dynamically generated -List path=[0,10,20,30,40,50,60,70,80,90,91,92,93,94,95,96,97,98,99]; +//List path=[0,10,20,30,40,50,60,70,80,90,91,92,93,94,95,96,97,98,99]; +List path= genPath(mat); bool timeOut = false; //when true, user is prohibited from entering new moves (so as not to overwhelm game) var dateTime = DateTime.now(); int attemptNum = 1; @@ -33,11 +34,16 @@ int recentMove; //records last move of user regardless of corectness void main() { //manually fill in maze - for(var i=0; i<19; i++) - { - maze1.button_grid[path[i]].onPath=1; + //for(var i=0; i<19; i++) + //{ + //maze1.button_grid[path[i]].onPath=1; + //} + + for(int j=0; j<27; j++) { + (maze1.button_grid[path[j]]).onPath=1; } + return runApp(MaterialApp( home: Scaffold( appBar: AppBar( diff --git a/lib/startingScreen.dart b/lib/startingScreen.dart index b791049..f5fbe11 100644 --- a/lib/startingScreen.dart +++ b/lib/startingScreen.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'main.dart'; import 'Maze.dart'; import 'MazeTest.dart'; - +import 'detection.dart'; class startingScreen extends StatefulWidget { @override @@ -84,6 +84,34 @@ class startingScreenState extends State { ], ), + + Column( + children: [ + Container( + margin:EdgeInsets.symmetric(horizontal:45.0,vertical: 10.0), + child: SizedBox( + width:55.0, + height:55.0, + child: new FlatButton( + color: Colors.blue, + padding: EdgeInsets.all(0.0), + child: Image.asset("assets/cardBack.PNG", fit:BoxFit.fill), + onPressed:() { + Navigator.push( + context, + new MaterialPageRoute(builder: (context) => detectionTaskPage()), + ); + } + ) + ), + ), + Container( + child: new Text("DetectionTask", style:new TextStyle(color:Colors.white)), + ) + + ], + ), + ], ) ], diff --git a/pubspec.yaml b/pubspec.yaml index 8dbc78d..197fc8d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -54,6 +54,8 @@ flutter: - assets/greencheck.jpg - assets/redx.jpg - assets/mazeimage2.PNG + - assets/aSpades.PNG + - assets/cardBack.PNG # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware.