Skip to content

Commit

Permalink
added detection task after testing
Browse files Browse the repository at this point in the history
  • Loading branch information
KhalidIshani committed Mar 16, 2021
1 parent f837477 commit 94404d4
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 5 deletions.
Binary file added assets/aSpades.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cardBack.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 133 additions & 0 deletions lib/detection.dart
Original file line number Diff line number Diff line change
@@ -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<int> 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<detectionTaskPage> {
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)
)
)
)
),
);
}
}
14 changes: 10 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Set <int> correctMoves = {};
List<dynamic> times=[];
List errors = [];
//temporary test path - going to change to make dynamically generated
List<dynamic> path=[0,10,20,30,40,50,60,70,80,90,91,92,93,94,95,96,97,98,99];
//List<dynamic> path=[0,10,20,30,40,50,60,70,80,90,91,92,93,94,95,96,97,98,99];
List<dynamic> 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;
Expand All @@ -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(
Expand Down
30 changes: 29 additions & 1 deletion lib/startingScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,6 +84,34 @@ class startingScreenState extends State<startingScreen> {
],
),


Column(
children: <Widget>[
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)),
)

],
),

],
)
],
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 94404d4

Please sign in to comment.