Skip to content

Commit

Permalink
add windows and assets
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinlim committed Jan 28, 2021
1 parent f588ca3 commit 1d7848c
Show file tree
Hide file tree
Showing 31 changed files with 2,273 additions and 0 deletions.
59 changes: 59 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.gmt4"
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Binary file added assets/greencheck.jpg
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/mazeimage2.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/redx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
330 changes: 330 additions & 0 deletions lib/Maze.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'dart:io';
import 'dart:convert';
import 'package:path_provider/path_provider.dart';
import 'PathGeneration.dart';
import 'package:permission_handler/permission_handler.dart';
import 'server.dart';
import 'main.dart';

class gameButton extends StatefulWidget {
int id;
//id represents id of button (top left button is 0 bottom right button is 99)
Color color;
bool displayImage;
int onPath=0;
//1 if square is on the path, 0 otherwise
bool testOnPath() {
if(this.onPath==1)
{
return true;

}
else
{
return false;
}
}

bool testIfLegal(lastMove)
{
return (((this.id - lastMove).abs() == 1) ^
((this.id - lastMove).abs() == 10));
}
//tests if move is legal
bool moveCheck()
{
if(lastMoveIncorrect)
{
if(this.id == lastMove)
{
lastMoveIncorrect = false;
return true;
}
else
{
return false;
}
}
else
{
if(this.testIfLegal(lastMove) & (this.id==path[correctMoves.length]))
{
lastMove = this.id;
return true;
}
else
{
lastMoveIncorrect=true;
return false;
}
}
}
//function above returns true if move user makes is correct (both a legal move and a square that is on the path) and false otherwise
@override
gameButton(this.id, this.color, this.displayImage);
//initialize state
gameButtonState createState() => gameButtonState(color);

}

class gameButtonState extends State<gameButton> {

Color color;

//initialize color state of buttons
gameButtonState(this.color);

//after user clicks next square the previous square should turn back to grey
void turnGrey() {
if (moves.length >= 2) {
if (widget.id == moves[moves.length - 2]) {
null;
}

else {
PressNotification(id: (moves[moves.length - 2]), color: Colors.grey)
.dispatch(context);
}
}
}

//if user makes 3 incorrect moves in a row then game shows the user the next correct move by turning it green
void mercyRule() {
if (consecErrors >= 3) {
timeOut = true;
PressNotification(id: lastMove, color: Colors.green).dispatch(context);
}

else {
null;
}
}
//once user reaches end of maze, game should be reset
void resetGame()
{
//reinitialize variables to default
moves = [];
correctMoves = {};
times=[];
errors = [];
consecErrors = 0;
lastMove = 0; //records last CORRECT move of user
lastMoveIncorrect = true;
clock.reset();
}

void newMaze()
{
fillMaze();
resetGame();
}

//function executed when any button pressed
void buttonPress()
{
//first prevent uesr from making new moves during 250 milisecond animation
timeOut = true;
times.add(clock.elapsedMilliseconds);
clock.reset();
setState(() {
//check if move is "correct"- if so square should turn green and display checkmark for 100 miliseconds
if(widget.moveCheck()) {
consecErrors = 0;
errors.add("correct");
maze1.button_grid[widget.id].color = Colors.green;
maze1.button_grid[widget.id].displayImage = true;
icon = Icons.check;
Timer(Duration(milliseconds: 75), () {
if (this.mounted) {
setState(() {
if(widget.id==99)
{
maze1.button_grid[widget.id].color = Colors.grey;
}
else
{
maze1.button_grid[widget.id].color = Colors.purple;
}
turnGrey();
maze1.button_grid[widget.id].displayImage = false;
timeOut = false;
});
}
});
//ending condition- if move is correct AND the last square on the path then game should display message congratulating them
if(widget.id==99) {
var dict = {"path":path, "moves": moves, "errors": errors, "times": times};
String data = json.encode(dict);
createData("GMLT-10x10", "KI", data, "1.0");
attemptNum++;
showDialog(
context: context,
builder: (BuildContext context) {
//return alert congratulating user if reach end of maze successfully
return AlertDialog(
title: new Text("Success!"),
actions: <Widget>[
new FlatButton(
onPressed: () {
resetGame();
Navigator.pop(context);
},
child: new Text("Same Maze")
),

new FlatButton(
onPressed: () {
newMaze();
Navigator.pop(context);
},
child: new Text("New Maze")
)

]
);
}
);

}
correctMoves.add(widget.id);
}
else //this code runs if move is INCORRECT- if move is incorrect then square turns red and displays an X
{
//keep track of how many consecutive errors user has made- if 3 then game should show next correct move
consecErrors++;
errors.add("incorrect");
maze1.button_grid[widget.id].color = Colors.red;
maze1.button_grid[widget.id].displayImage=true;
icon = Icons.clear;
Timer(Duration(milliseconds: 75), () {
if(this.mounted) {
setState(() {
maze1.button_grid[widget.id].color = Colors.purple;
turnGrey();
maze1.button_grid[widget.id].displayImage=false;
mercyRule();
timeOut=false;
});
}
});
}

});
moves.add(widget.id);
recentMove=widget.id;
}
@override
//build actual GUI of "gamebutton" - a flatbutton with an icon hidden within it (either check or X)
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,
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,
],
):null
));
}
}

//function allows color of buttons to be changed by sending that gameButton a notification
class PressNotification extends Notification {
final int id;
final Color color;

const PressNotification({this.id, this.color});
}
//maze is the collection of all 100 buttons- initialized here
class maze extends StatefulWidget {
List<gameButton> button_grid = [
for (var i = 0; i < 100; i++) new gameButton(i, Colors.grey, false)
];

@override
mazeState createState() => mazeState(button_grid);

}
//state of maze
class mazeState extends State<maze> {
List<gameButton> button_grid;
mazeState(this.button_grid);

//function utilizes PressNotification class and allows user to change the colors of individual squares on the maze
bool updateButton(PressNotification notification) {
setState(() {
button_grid[notification.id].color = notification.color;
});
return true;
}

//initialize state + start clock once
void initState()
{
super.initState();
clock.start();
}

@override
//build and return concrete implemenation of maze class
Widget build(BuildContext context) {
//wrapped in notification listener so each square can listen for color change event
return NotificationListener<PressNotification>(
onNotification: updateButton,
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];

}
),
]
),
),
);
}
}
//homepage class initialized as class that contains everything
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;

@override
//state set- shouldn't need to change much since maze class is thing thats changing
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Center(child: Text("GMT")),
),
body: Center(
child: maze1,
)
);
}
}
Loading

0 comments on commit 1d7848c

Please sign in to comment.