Skip to content

Commit

Permalink
lots of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KhalidIshani committed Jul 7, 2021
1 parent 9437bf3 commit f534e8c
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 71 deletions.
76 changes: 47 additions & 29 deletions lib/Maze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import 'main.dart';
import 'instructions.dart';
import 'package:uuid/uuid.dart';
import 'userIDD.dart';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:just_audio/just_audio.dart';


var uuid = Uuid();
DateTime startTime = DateTime.now();
Expand Down Expand Up @@ -76,6 +76,16 @@ class gameButton extends StatefulWidget {

class gameButtonState extends State<gameButton> {

//initialize audioplayer
AudioPlayer player;
@override
void initState() {
super.initState();
player = AudioPlayer();
}
// stop initializing audioplayer


Color color;

//initialize color state of buttons
Expand Down Expand Up @@ -115,7 +125,7 @@ class gameButtonState extends State<gameButton> {
times=[];
errors = [];
consecErrors = 0;
lastMove = 0; //records last CORRECT move of user
lastMove = 0; //records last COR user
lastMoveIncorrect = true;
clock.reset();
}
Expand All @@ -142,8 +152,9 @@ class gameButtonState extends State<gameButton> {
errors.add("correct");
maze1.button_grid[widget.id].color = Colors.green;
maze1.button_grid[widget.id].displayImage = true;
audioCache.play('ding2.mp3');
icon = Icons.check;
player.setAsset('assets/audio/ding2.mp3');
player.play();
icon= Icons.check;
Timer(Duration(milliseconds: 75), () {
if (this.mounted) {
setState(() {
Expand All @@ -168,6 +179,7 @@ class gameButtonState extends State<gameButton> {
"trial": attemptNum.toString() };
String data = json.encode(dict);
createData("GMLT-10x10", uuid.v1().toString(), data, "1.0.0");
player.dispose();
attemptNum++;
showDialog(
context: context,
Expand All @@ -176,15 +188,15 @@ class gameButtonState extends State<gameButton> {
return AlertDialog(
title: new Text("Success!"),
actions: <Widget>[
new FlatButton(
new TextButton(
onPressed: () {
resetGame();
Navigator.pop(context);
},
child: new Text("Same Maze")
),

new FlatButton(
new TextButton(
onPressed: () {
newMaze();
Navigator.pop(context);
Expand All @@ -205,9 +217,12 @@ class gameButtonState extends State<gameButton> {
//keep track of how many consecutive errors user has made- if 3 then game should show next correct move
consecErrors++;
errors.add("incorrect");
audioCache.play('buzz2.mp3');


maze1.button_grid[widget.id].color = Colors.red;
maze1.button_grid[widget.id].displayImage=true;
player.setAsset('assets/audio/buzz2.mp3');
player.play();
icon = Icons.clear;
Timer(Duration(milliseconds: 75), () {
if(this.mounted) {
Expand All @@ -230,16 +245,17 @@ class gameButtonState extends State<gameButton> {
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(border: Border.all(color: Colors.black)),
child: FlatButton(
color: maze1.button_grid[widget.id].color,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: maze1.button_grid[widget.id].color,
),
onPressed: () {
//what happens on buttonPress event- either nothing (if animation is taking place) or buttonPress function (defined above) called
timeOut?null:buttonPress();
},
child: maze1.button_grid[widget.id].displayImage?Column(// Replace with a Row for horizontal icon + text
children: <Widget>[
maze1.button_grid[widget.id].displayImage?Icon(icon):null,
Expanded(child: maze1.button_grid[widget.id].displayImage?Icon(icon, color:Colors.black):null),
],
):null
));
Expand Down Expand Up @@ -286,29 +302,31 @@ class mazeState extends State<maze> {
@override
//build and return concrete implemenation of maze class
Widget build(BuildContext context) {
//get size of screen
//wrapped in notification listener so each square can listen for color change event
return NotificationListener<PressNotification>(
onNotification: updateButton,
child:
Scaffold(
child: Scaffold(
backgroundColor: Colors.cyan,
body: Column(
children: <Widget>[
GridView.builder(
//uniqueKey utilized so buttons that need to change color can dynamically rebuild
key: UniqueKey(),
itemCount: 100,
//squares kept in 10x10 gridview
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 10,
crossAxisSpacing: 0,
mainAxisSpacing: 0
),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return maze1.button_grid[index];

}
Expanded(
child: GridView.builder(
//uniqueKey utilized so buttons that need to change color can dynamically rebuild
key: UniqueKey(),
itemCount: 100,
//squares kept in 10x10 gridview
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 10,
crossAxisSpacing: 0,
mainAxisSpacing: 0
),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return maze1.button_grid[index];

}
),
),
Align(
alignment: Alignment.bottomRight,
Expand Down
66 changes: 41 additions & 25 deletions lib/MazeTest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'server.dart';
import 'instructions.dart';
import 'package:uuid/uuid.dart';
import 'userIDD.dart';
import 'package:just_audio/just_audio.dart';

var uuid = Uuid();

Expand All @@ -28,7 +29,7 @@ List<dynamic> path2=[0,1,2,8,14,13,19,20,21,22,28,29,35];
bool timeOut2 = false; //when true, user is prohibited from entering new moves (so as not to overwhelm game)
int attemptNum2 = 1;
int consecErrors2 = 0;
int recentMove2; //records last move of user regardless of corectness
int recentMove2=0; //records last move of user regardless of corectness


void main() {
Expand All @@ -49,7 +50,7 @@ class MyApp extends StatelessWidget {
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
home: MyHomePage(title: 'Flutter Demo Home Page', key: null,),
);
}
}
Expand Down Expand Up @@ -117,6 +118,15 @@ class gameButton extends StatefulWidget {

class gameButtonState extends State<gameButton> {

//initialize audioplayer
AudioPlayer player2;
@override
void initState() {
super.initState();
player2 = AudioPlayer();
}
// stop initializing audioplayer

Color color;

//initialize color state of buttons
Expand Down Expand Up @@ -173,7 +183,8 @@ class gameButtonState extends State<gameButton> {
if(widget.moveCheck()) {
consecErrors2 = 0;
maze2.button_grid[widget.id].color = Colors.green;
audioCache.play('ding2.mp3');
player2.setAsset('assets/audio/ding2.mp3');
player2.play();
errors2.add("correct");
maze2.button_grid[widget.id].displayImage = true;
icon = Icons.check;
Expand Down Expand Up @@ -201,6 +212,7 @@ class gameButtonState extends State<gameButton> {
"trial": attemptNum.toString() };
String data = json.encode(dict2);
createData("GMLT-6x6", uuid.v1().toString(), data, "1.0.0");
player2.dispose();

showDialog(
context: context,
Expand All @@ -209,15 +221,15 @@ class gameButtonState extends State<gameButton> {
return AlertDialog(
title: new Text("Success!"),
actions: <Widget>[
new FlatButton(
new TextButton(
onPressed: () {
resetGame();
Navigator.pop(context);
},
child: new Text("Practice Again")
),

new FlatButton(
new TextButton(
onPressed: () {
Navigator.push(
context,
Expand All @@ -240,7 +252,8 @@ class gameButtonState extends State<gameButton> {
//keep track of how many consecutive errors user has made- if 3 then game should show next correct move
consecErrors2++;
maze2.button_grid[widget.id].color = Colors.red;
audioCache.play('buzz2.mp3');
player2.setAsset('assets/audio/buzz2.mp3');
player2.play();
errors2.add("incorrect");
maze2.button_grid[widget.id].displayImage=true;
icon = Icons.clear;
Expand All @@ -266,16 +279,17 @@ class gameButtonState extends State<gameButton> {
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(border: Border.all(color: Colors.black)),
child: FlatButton(
color: maze2.button_grid[widget.id].color,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: maze2.button_grid[widget.id].color,
),
onPressed: () {
//what happens on buttonPress event- either nothing (if animation is taking place) or buttonPress function (defined above) called
timeOut2?null:buttonPress();
},
child: maze2.button_grid[widget.id].displayImage?Column(// Replace with a Row for horizontal icon + text
children: <Widget>[
maze2.button_grid[widget.id].displayImage?Icon(icon):null,
maze2.button_grid[widget.id].displayImage?Icon(icon, color:Colors.black):null,
],
):null
));
Expand Down Expand Up @@ -365,21 +379,23 @@ class mazeState extends State<maze> {
backgroundColor:Colors.cyan,
body: Column(
children: <Widget>[
GridView.builder(
//uniqueKey utilized so buttons that need to change color can dynamically rebuild
key: UniqueKey(),
itemCount: 36,
//squares kept in 10x10 gridview
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 6,
crossAxisSpacing: 0,
mainAxisSpacing: 0
),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return maze2.button_grid[index];

}
Expanded(
child: GridView.builder(
//uniqueKey utilized so buttons that need to change color can dynamically rebuild
key: UniqueKey(),
itemCount: 36,
//squares kept in 10x10 gridview
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 6,
crossAxisSpacing: 0,
mainAxisSpacing: 0
),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return maze2.button_grid[index];

}
),
),
Align(
alignment: Alignment.bottomRight,
Expand Down
9 changes: 5 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'startingScreen.dart';
import 'Maze.dart';
import 'userIDD.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';

import 'package:just_audio/just_audio.dart';

//initialize new maze
maze maze1= new maze();
Expand All @@ -33,8 +33,9 @@ bool timeOut = false; //when true, user is prohibited from entering new moves (s
var dateTime = DateTime.now();
int attemptNum = 1;
int consecErrors = 0;
int recentMove; //records last move of user regardless of corectness
final AudioCache audioCache = AudioCache(prefix: "audio/", fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP));
int recentMove=0; //records last move of user regardless of corectness
//final AudioCache audioCache = AudioCache(prefix: "audio/", fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP));


void main() {

Expand Down
13 changes: 9 additions & 4 deletions lib/startingScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class startingScreenState extends State<startingScreen> {
child: SizedBox(
width:55.0,
height:55.0,
child: new FlatButton(
color: Colors.blue,
padding: EdgeInsets.all(0.0),
child: new TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.blue,
padding: EdgeInsets.all(0.0),
),
child: Image.asset("assets/mazeimage2.PNG", fit:BoxFit.fill),
onPressed:() {
Navigator.push(
Expand All @@ -67,8 +69,11 @@ class startingScreenState extends State<startingScreen> {
child: SizedBox(
width:55.0,
height:55.0,
child: new RaisedButton(
child: new TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.all(0.0),
),

child: Image.asset("assets/mazeimage2.PNG", fit:BoxFit.fill),
onPressed:() {
Navigator.push(
Expand Down
Loading

0 comments on commit f534e8c

Please sign in to comment.