From a590a90f5604ffec3c5baa2a8ab93af0517e4d53 Mon Sep 17 00:00:00 2001 From: Mohammad Jamalianpour Date: Wed, 10 Aug 2022 12:09:29 +0430 Subject: [PATCH] Update flutter sdk version and refactoring code --- android/app/src/main/AndroidManifest.xml | 5 +- .../java/com/example/fourth/MainActivity.java | 9 +- .../com/srikanth7785/fourth/MainActivity.kt | 6 - lib/Computer.dart | 497 +++++++-------- lib/EasyBot.dart | 568 +++++++++--------- lib/GamePage.dart | 174 +++--- lib/IntroductionPage.dart | 268 +++++---- pubspec.yaml | 6 +- 8 files changed, 811 insertions(+), 722 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index d0f867e..926bac5 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> + diff --git a/android/app/src/main/java/com/example/fourth/MainActivity.java b/android/app/src/main/java/com/example/fourth/MainActivity.java index 3944ded..9ea73f1 100644 --- a/android/app/src/main/java/com/example/fourth/MainActivity.java +++ b/android/app/src/main/java/com/example/fourth/MainActivity.java @@ -1,13 +1,6 @@ package com.srikanth7785.othello; -import android.os.Bundle; -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; +import io.flutter.embedding.android.FlutterActivity; public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } } diff --git a/android/app/src/main/kotlin/com/srikanth7785/fourth/MainActivity.kt b/android/app/src/main/kotlin/com/srikanth7785/fourth/MainActivity.kt index 5e7fd46..b3377e6 100644 --- a/android/app/src/main/kotlin/com/srikanth7785/fourth/MainActivity.kt +++ b/android/app/src/main/kotlin/com/srikanth7785/fourth/MainActivity.kt @@ -1,12 +1,6 @@ package com.srikanth7785.fourth -import androidx.annotation.NonNull; import io.flutter.embedding.android.FlutterActivity -import io.flutter.embedding.engine.FlutterEngine -import io.flutter.plugins.GeneratedPluginRegistrant class MainActivity: FlutterActivity() { - override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { - GeneratedPluginRegistrant.registerWith(flutterEngine); - } } diff --git a/lib/Computer.dart b/lib/Computer.dart index ff2679e..bd40035 100644 --- a/lib/Computer.dart +++ b/lib/Computer.dart @@ -13,20 +13,19 @@ class Computer extends StatefulWidget { } } -class Computerstate extends State { +class Computerstate extends State { + @override + initState() { + super.initState(); + sysrow = -1; + syscol = -1; + } -@override -initState() -{ - super.initState(); - sysrow = -1; - syscol = -1; -} -List colors = [ - Colors.white, - Colors.black, - Colors.yellow, -]; + List colors = [ + Colors.white, + Colors.black, + Colors.yellow, + ]; int invalidEntries = 0; int invalidColorsIndex = 0; int initial = 0; @@ -35,7 +34,7 @@ List colors = [ String winnerName = ""; int complete = 0; int enter = 0; - int computerentry; + int? computerentry; int empty = 60; String currentPlayer = "User"; static int m = 8; @@ -45,26 +44,23 @@ List colors = [ void setcolor(int x) { enter = 0; - if(currentPlayer == "User") - { + if (currentPlayer == "User") { int rowno = x ~/ 8; int colno = x % 8; print("$rowno $colno"); setState(() { - if (colno < 7) east(rowno, colno, 'B',1); - if (colno > 0) west(rowno, colno, 'B',1); - if (rowno > 0) north(rowno, colno, 'B',1); - if (rowno < 7) south(rowno, colno, 'B',1); - if (rowno > 0 && colno < 7) northeast(rowno, colno, 'B',1); - if (rowno > 0 && colno > 0) northwest(rowno, colno, 'B',1); - if (rowno < 7 && colno < 7) southeast(rowno, colno, 'B',1); - if (rowno < 7 && colno > 0) southwest(rowno, colno, 'B',1); + if (colno < 7) east(rowno, colno, 'B', 1); + if (colno > 0) west(rowno, colno, 'B', 1); + if (rowno > 0) north(rowno, colno, 'B', 1); + if (rowno < 7) south(rowno, colno, 'B', 1); + if (rowno > 0 && colno < 7) northeast(rowno, colno, 'B', 1); + if (rowno > 0 && colno > 0) northwest(rowno, colno, 'B', 1); + if (rowno < 7 && colno < 7) southeast(rowno, colno, 'B', 1); + if (rowno < 7 && colno > 0) southwest(rowno, colno, 'B', 1); if (enter == 0) { showLongToast("Invalid Entry"); - invalidEntries = invalidEntries == 3 ? 3 : (invalidEntries+1)%4; - } - else - { + invalidEntries = invalidEntries == 3 ? 3 : (invalidEntries + 1) % 4; + } else { invalidEntries = 0; empty--; currentPlayer = "System"; @@ -72,94 +68,87 @@ List colors = [ print(" empty : $empty"); }); } - if((enter != 0 || currentPlayer == "System") && complete == 0) - { - if(currentPlayer == "User") currentPlayer = "System"; - enter = 0; - Timer(Duration(milliseconds: 500),(){ - print("Wait is Over"); - bool computerEnteredornot = computerturn('W'); - if(computerEnteredornot) - { - setState(() { - sysrow = computerentry ~/ 10; - syscol = computerentry % 10; + if ((enter != 0 || currentPlayer == "System") && complete == 0) { + if (currentPlayer == "User") currentPlayer = "System"; + enter = 0; + Timer(Duration(milliseconds: 500), () { + print("Wait is Over"); + bool computerEnteredornot = computerturn('W'); + if (computerEnteredornot) { + setState(() { + sysrow = computerentry! ~/ 10; + syscol = computerentry! % 10; // print("Computer Entry is : $rowno $colno"); - if (syscol < 7) east(sysrow, syscol, 'W',1); - if (syscol > 0) west(sysrow, syscol, 'W',1); - if (sysrow > 0) north(sysrow, syscol, 'W',1); - if (sysrow < 7) south(sysrow, syscol, 'W',1); - if (sysrow > 0 && syscol < 7) northeast(sysrow, syscol, 'W',1); - if (sysrow > 0 && syscol > 0) northwest(sysrow, syscol, 'W',1); - if (sysrow < 7 && syscol < 7) southeast(sysrow, syscol, 'W',1); - if (sysrow < 7 && syscol > 0) southwest(sysrow, syscol, 'W',1); - if(enter != 0) - { + if (syscol < 7) east(sysrow, syscol, 'W', 1); + if (syscol > 0) west(sysrow, syscol, 'W', 1); + if (sysrow > 0) north(sysrow, syscol, 'W', 1); + if (sysrow < 7) south(sysrow, syscol, 'W', 1); + if (sysrow > 0 && syscol < 7) northeast(sysrow, syscol, 'W', 1); + if (sysrow > 0 && syscol > 0) northwest(sysrow, syscol, 'W', 1); + if (sysrow < 7 && syscol < 7) southeast(sysrow, syscol, 'W', 1); + if (sysrow < 7 && syscol > 0) southwest(sysrow, syscol, 'W', 1); + if (enter != 0) { empty--; - if(countingColors("White") == 0 || countingColors("Black") == 0) - { + if (countingColors("White") == 0 || + countingColors("Black") == 0) { complete = 1; } currentPlayer = "User"; } - }); - } - else{ - setState((){ - currentPlayer = "User"; - showLongToast("Computer Turn Skipped"); - }); - } - print(" empty : $empty"); + }); + } else { + setState(() { + currentPlayer = "User"; + showLongToast("Computer Turn Skipped"); + }); + } + print( + " empty : $empty"); complete == 1 ? print("Game Completed") : print("not Completed"); - }); - } + }); + } } - - bool computerturn(String p) - { + bool computerturn(String p) { int highestflips = 0; bool possible = false; computerentry = 0; - for(int rowno = 0 ; rowno < 8 ;rowno++) - { - for(int colno = 0 ; colno < 8; colno++) - { - if(a[rowno][colno] == '-') - { - int currentflips = 0; - if (colno < 7) currentflips = currentflips + east(rowno, colno, p,0); - if (colno > 0) currentflips = currentflips + west(rowno, colno, p,0); - if (rowno > 0) currentflips = currentflips + north(rowno, colno, p,0); - if (rowno < 7) currentflips = currentflips + south(rowno, colno, p,0); - if (rowno > 0 && colno < 7) currentflips = currentflips + northeast(rowno, colno, p,0); - if (rowno > 0 && colno > 0) currentflips = currentflips + northwest(rowno, colno, p,0); - if (rowno < 7 && colno < 7) currentflips = currentflips + southeast(rowno, colno, p,0); - if (rowno < 7 && colno > 0) currentflips = currentflips + southwest(rowno, colno, p,0); - - if(currentflips > highestflips) - { - possible = true; - print(currentflips); - highestflips = currentflips; - computerentry = (rowno * 10) + colno; - } + for (int rowno = 0; rowno < 8; rowno++) { + for (int colno = 0; colno < 8; colno++) { + if (a[rowno][colno] == '-') { + int currentflips = 0; + if (colno < 7) currentflips = currentflips + east(rowno, colno, p, 0); + if (colno > 0) currentflips = currentflips + west(rowno, colno, p, 0); + if (rowno > 0) + currentflips = currentflips + north(rowno, colno, p, 0); + if (rowno < 7) + currentflips = currentflips + south(rowno, colno, p, 0); + if (rowno > 0 && colno < 7) + currentflips = currentflips + northeast(rowno, colno, p, 0); + if (rowno > 0 && colno > 0) + currentflips = currentflips + northwest(rowno, colno, p, 0); + if (rowno < 7 && colno < 7) + currentflips = currentflips + southeast(rowno, colno, p, 0); + if (rowno < 7 && colno > 0) + currentflips = currentflips + southwest(rowno, colno, p, 0); + + if (currentflips > highestflips) { + possible = true; + print(currentflips); + highestflips = currentflips; + computerentry = (rowno * 10) + colno; + } } } } return possible; } - - void truncate(){ - + void truncate() { setState(() { - for(int i = 0; i < 8; i++) - for(int j = 0; j < 8; j++) - a[i][j] = '-'; + for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) a[i][j] = '-'; firstSkip = 0; currentSkip = 1; @@ -170,12 +159,11 @@ List colors = [ a[3][3] = 'W'; a[3][4] = 'B'; a[4][3] = 'B'; - a[4][4] = 'W'; + a[4][4] = 'W'; }); } - - int east(int x, int y, String ch,int change) //right + int east(int x, int y, String ch, int change) //right { // print("right"); int l = y, f = 0; @@ -188,8 +176,7 @@ List colors = [ } } for (int j = l - 1; j >= y; j--) { - if(change == 1) - { + if (change == 1) { a[x][j] = ch; } f = f + 1; @@ -197,12 +184,12 @@ List colors = [ if (f != 0) { enter = 1; print("east done"); - return f-1; + return f - 1; } else return 0; } - int west(int x, int y, String ch,int change) //left + int west(int x, int y, String ch, int change) //left { // print("left"); int l = y, f = 0; @@ -215,8 +202,7 @@ List colors = [ } } for (int j = l + 1; j <= y; j++) { - if(change == 1) - { + if (change == 1) { a[x][j] = ch; } f = f + 1; @@ -224,12 +210,12 @@ List colors = [ if (f != 0) { print("west done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int north(int x, int y, String ch,int change) //up + int north(int x, int y, String ch, int change) //up { // print("up"); int l = x, f = 0; @@ -242,8 +228,7 @@ List colors = [ } } for (int j = l + 1; j <= x; j++) { - if(change == 1) - { + if (change == 1) { a[j][y] = ch; } f = f + 1; @@ -251,12 +236,12 @@ List colors = [ if (f != 0) { print("north done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int south(int x, int y, String ch,int change) //down + int south(int x, int y, String ch, int change) //down { // print("down"); int l = x, f = 0; @@ -269,8 +254,7 @@ List colors = [ } } for (int j = l - 1; j >= x; j--) { - if(change == 1) - { + if (change == 1) { a[j][y] = ch; } f = f + 1; @@ -278,12 +262,12 @@ List colors = [ if (f != 0) { print("south done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int northeast(int x, int y, String ch,int change) //upright + int northeast(int x, int y, String ch, int change) //upright { // print("upright"); int m = x, n = y, f = 0; @@ -297,8 +281,7 @@ List colors = [ } } for (int i = m + 1, j = n - 1; i <= x && j >= y; i++, j--) { - if(change == 1) - { + if (change == 1) { a[i][j] = ch; } f = f + 1; @@ -306,12 +289,12 @@ List colors = [ if (f != 0) { print("northeast done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int northwest(int x, int y, String ch,int change) //upleft + int northwest(int x, int y, String ch, int change) //upleft { // print("upleft"); int m = x, n = y, f = 0; @@ -325,8 +308,7 @@ List colors = [ } } for (int i = m + 1, j = n + 1; i <= x && j <= y; i++, j++) { - if(change == 1) - { + if (change == 1) { a[i][j] = ch; } f = f + 1; @@ -334,12 +316,12 @@ List colors = [ if (f != 0) { print("northwest done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int southeast(int x, int y, String ch,int change) //downright + int southeast(int x, int y, String ch, int change) //downright { // print("downright"); int m = x, n = y, f = 0; @@ -353,8 +335,7 @@ List colors = [ } } for (int i = m - 1, j = n - 1; i >= x && j >= y; i--, j--) { - if(change == 1) - { + if (change == 1) { a[i][j] = ch; } f = f + 1; @@ -362,12 +343,12 @@ List colors = [ if (f != 0) { print("southeast done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int southwest(int x, int y, String ch,int change) //downleft + int southwest(int x, int y, String ch, int change) //downleft { // print("downleft"); int m = x, n = y, f = 0; @@ -383,8 +364,7 @@ List colors = [ } } for (int i = m - 1, j = n + 1; i >= x && j <= y; i--, j++) { - if(change == 1) - { + if (change == 1) { a[i][j] = ch; } f = f + 1; @@ -392,7 +372,7 @@ List colors = [ if (f != 0) { print("southwest done"); enter = 1; - return f-1; + return f - 1; } else return 0; } @@ -443,12 +423,11 @@ List colors = [ appBar: AppBar( leading: IconButton( icon: Icon(Icons.keyboard_arrow_left), - onPressed: ()=>Navigator.pop(context), + onPressed: () => Navigator.pop(context), iconSize: MediaQuery.of(context).size.width * 0.12, ), elevation: 0.0, backgroundColor: Colors.transparent, - title: new Text( "Single Player", style: new TextStyle( @@ -475,154 +454,184 @@ List colors = [ ), body: new ListView( children: [ - invalidEntries == 3 ? Align( - alignment: Alignment.centerRight, - child: Card( - color: Colors.transparent, - elevation: 15.0, - child: GestureDetector( - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5.0), - color: Colors.blue, - ), - padding: EdgeInsets.all(2), - child: Text(" Skip\nmy Turn"), + invalidEntries == 3 + ? Align( + alignment: Alignment.centerRight, + child: Card( + color: Colors.transparent, + elevation: 15.0, + child: GestureDetector( + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5.0), + color: Colors.blue, ), - onTap: (){ - setState(() { - currentPlayer = "System"; - setcolor(50); //////***** DOESN'T MATTER WHAT NUMBER YOU ARE PASSING HERE AS A PARAMETER*****////// - firstSkip == 0 ? firstSkip = empty : currentSkip = empty; - print(empty); - complete = currentSkip == firstSkip ? 1 : complete; - invalidEntries = 0; - }); - }, + padding: EdgeInsets.all(2), + child: Text(" Skip\nmy Turn"), ), + onTap: () { + setState(() { + currentPlayer = "System"; + setcolor( + 50); //////***** DOESN'T MATTER WHAT NUMBER YOU ARE PASSING HERE AS A PARAMETER*****////// + firstSkip == 0 + ? firstSkip = empty + : currentSkip = empty; + print(empty); + complete = currentSkip == firstSkip ? 1 : complete; + invalidEntries = 0; + }); + }, ), - ) : Container(height: MediaQuery.of(context).size.height * 0.058), + ), + ) + : Container(height: MediaQuery.of(context).size.height * 0.058), new Stack( children: [ - new Column( - children: [ - new Container( - padding: new EdgeInsets.fromLTRB(2.0, 2.0, 2.0, 0.0), - child: new GridView.extent( - maxCrossAxisExtent: MediaQuery.of(context).size.width * 0.12, - mainAxisSpacing: 2.0, - crossAxisSpacing: 2.0, - children: customBox(), - ), - width: MediaQuery.of(context).size.width, - height: ((MediaQuery.of(context).size.width * 0.12) * 8.35), - color: Colors.orangeAccent.shade100, - ), - new Padding( - padding: new EdgeInsets.all(5.0), - ), - new Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + new Column( children: [ - new Text( - countingColors("White") < 10 ? "White: 0${countingColors("White")}" : "White: ${countingColors("White")}", - style: new TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - fontSize: MediaQuery.of(context).size.width * 0.04, - ), - ), new Container( - alignment: Alignment.center, - decoration: new BoxDecoration( - borderRadius: BorderRadius.circular(40.0), - color: currentPlayer == "User" ? Colors.black : Colors.white, + padding: new EdgeInsets.fromLTRB(2.0, 2.0, 2.0, 0.0), + child: new GridView.extent( + maxCrossAxisExtent: + MediaQuery.of(context).size.width * 0.12, + mainAxisSpacing: 2.0, + crossAxisSpacing: 2.0, + children: customBox(), ), - width: MediaQuery.of(context).size.width * 0.1, - height: MediaQuery.of(context).size.width * 0.1, - child: new Center( - child: new Text( - currentPlayer == "User" ? "Player\n Turn" : "System\n Turn", + width: MediaQuery.of(context).size.width, + height: ((MediaQuery.of(context).size.width * 0.12) * 8.35), + color: Colors.orangeAccent.shade100, + ), + new Padding( + padding: new EdgeInsets.all(5.0), + ), + new Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + new Text( + countingColors("White") < 10 + ? "White: 0${countingColors("White")}" + : "White: ${countingColors("White")}", style: new TextStyle( - color: currentPlayer == "User" ? Colors.white : Colors.black, - fontSize: MediaQuery.of(context).size.width * 0.025, + color: Colors.white, + fontWeight: FontWeight.bold, + fontSize: MediaQuery.of(context).size.width * 0.04, ), ), - ), - ), - new Text( - countingColors("Black") < 10 ? "Black: 0${countingColors("Black")}" : "Black: ${countingColors("Black")}", - style: new TextStyle( - color: Colors.black, - fontWeight: FontWeight.bold, - fontSize: MediaQuery.of(context).size.width * 0.04, - ), - ), - ], - ), - - Center( - child: new RaisedButton( - elevation: 5.0, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), - color: Colors.orangeAccent, - child: new Text( - empty == 0 || complete == 1 ? "Play Again" : "Reset Game", - style: new TextStyle( - fontSize: MediaQuery.of(context).size.width * 0.055, - color: Colors.redAccent, - fontStyle: FontStyle.italic, + new Container( + alignment: Alignment.center, + decoration: new BoxDecoration( + borderRadius: BorderRadius.circular(40.0), + color: currentPlayer == "User" + ? Colors.black + : Colors.white, + ), + width: MediaQuery.of(context).size.width * 0.1, + height: MediaQuery.of(context).size.width * 0.1, + child: new Center( + child: new Text( + currentPlayer == "User" + ? "Player\n Turn" + : "System\n Turn", + style: new TextStyle( + color: currentPlayer == "User" + ? Colors.white + : Colors.black, + fontSize: + MediaQuery.of(context).size.width * 0.025, + ), + ), + ), ), - ), - onPressed: () { - print("Reseting"); - truncate(); - }), + new Text( + countingColors("Black") < 10 + ? "Black: 0${countingColors("Black")}" + : "Black: ${countingColors("Black")}", + style: new TextStyle( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: MediaQuery.of(context).size.width * 0.04, + ), + ), + ], + ), + Center( + child: new RaisedButton( + elevation: 5.0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0)), + color: Colors.orangeAccent, + child: new Text( + empty == 0 || complete == 1 + ? "Play Again" + : "Reset Game", + style: new TextStyle( + fontSize: MediaQuery.of(context).size.width * 0.055, + color: Colors.redAccent, + fontStyle: FontStyle.italic, + ), + ), + onPressed: () { + print("Reseting"); + truncate(); + }), ), ], ), Positioned( top: MediaQuery.of(context).size.height * 0.15, left: MediaQuery.of(context).size.width * 0.01, - child: new Container( + child: new Container( width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height * 0.09, child: new Center( - child: empty == 0 || countingColors("White") == 0 || countingColors("Black") == 0 || complete == 1 + child: empty == 0 || + countingColors("White") == 0 || + countingColors("Black") == 0 || + complete == 1 ? (countingColors("White") == countingColors("Black") ? new Image.asset( 'images/Draw.gif', width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height * 0.2, + height: + MediaQuery.of(context).size.height * 0.2, ) : (countingColors("White") > countingColors("Black") ? new Image.asset( 'images/white.gif', width: MediaQuery.of(context).size.width, - height: - MediaQuery.of(context).size.height * 0.2, + height: MediaQuery.of(context).size.height * + 0.2, ) : new Image.asset( 'images/Black.gif', width: MediaQuery.of(context).size.width, - height: - MediaQuery.of(context).size.height * 0.2, + height: MediaQuery.of(context).size.height * + 0.2, ))) - : Container(width:0.0,height: 0.0,), - ), - ), - ), - - sysrow == -1 ? Container() : Positioned( - child: Container( - child: Image.asset('images/Pointing.png'), - height: 25.0, - width: 25.0, + : Container( + width: 0.0, + height: 0.0, + ), + ), ), - top: (MediaQuery.of(context).size.width * 0.127) * sysrow + 15.0 , - left: (MediaQuery.of(context).size.width * 0.127) * syscol + 7.0 , ), - + sysrow == -1 + ? Container() + : Positioned( + child: Container( + child: Image.asset('images/Pointing.png'), + height: 25.0, + width: 25.0, + ), + top: + (MediaQuery.of(context).size.width * 0.127) * sysrow + + 15.0, + left: + (MediaQuery.of(context).size.width * 0.127) * syscol + + 7.0, + ), ], ), ], @@ -657,7 +666,9 @@ List colors = [ child: new CircleAvatar( backgroundColor: a[row][col] == '-' ? Colors.green - : (a[row][col] == 'W') ? Colors.white : Colors.black, + : (a[row][col] == 'W') + ? Colors.white + : Colors.black, maxRadius: MediaQuery.of(context).size.width * 0.047, ), ), diff --git a/lib/EasyBot.dart b/lib/EasyBot.dart index 873094b..839fb3c 100644 --- a/lib/EasyBot.dart +++ b/lib/EasyBot.dart @@ -13,20 +13,19 @@ class EasyBot extends StatefulWidget { } } -class EasyBotstate extends State { +class EasyBotstate extends State { + @override + initState() { + super.initState(); + sysrow = -1; + syscol = -1; + } -@override -initState() -{ - super.initState(); - sysrow = -1; - syscol = -1; -} -List colors = [ - Colors.white, - Colors.black, - Colors.yellow, -]; + List colors = [ + Colors.white, + Colors.black, + Colors.yellow, + ]; int invalidEntries = 0; int invalidColorsIndex = 0; int initial = 0; @@ -35,7 +34,7 @@ List colors = [ String winnerName = ""; int complete = 0; int enter = 0; - int computerentry; + int? computerentry; int empty = 60; String currentPlayer = "User"; static int m = 8; @@ -45,31 +44,28 @@ List colors = [ void setcolor(int x) { enter = 0; - if(currentPlayer == "User") - { + if (currentPlayer == "User") { // bool userCanEnterOrNot = computerturn('B'); // print("USER CAN ENTER OR NOT : $userCanEnterOrNot"); int rowno = x ~/ 8; int colno = x % 8; print("$rowno $colno"); setState(() { - if (colno < 7) east(rowno, colno, 'B',1); - if (colno > 0) west(rowno, colno, 'B',1); - if (rowno > 0) north(rowno, colno, 'B',1); - if (rowno < 7) south(rowno, colno, 'B',1); - if (rowno > 0 && colno < 7) northeast(rowno, colno, 'B',1); - if (rowno > 0 && colno > 0) northwest(rowno, colno, 'B',1); - if (rowno < 7 && colno < 7) southeast(rowno, colno, 'B',1); - if (rowno < 7 && colno > 0) southwest(rowno, colno, 'B',1); + if (colno < 7) east(rowno, colno, 'B', 1); + if (colno > 0) west(rowno, colno, 'B', 1); + if (rowno > 0) north(rowno, colno, 'B', 1); + if (rowno < 7) south(rowno, colno, 'B', 1); + if (rowno > 0 && colno < 7) northeast(rowno, colno, 'B', 1); + if (rowno > 0 && colno > 0) northwest(rowno, colno, 'B', 1); + if (rowno < 7 && colno < 7) southeast(rowno, colno, 'B', 1); + if (rowno < 7 && colno > 0) southwest(rowno, colno, 'B', 1); if (enter == 0) { showLongToast("Invalid Entry"); - invalidEntries = invalidEntries == 3 ? 3 : (invalidEntries+1)%4; - } - else - { + invalidEntries = invalidEntries == 3 ? 3 : (invalidEntries + 1) % 4; + } else { invalidEntries = 0; empty--; - if(empty == 0){ + if (empty == 0) { setState(() { complete = 1; }); @@ -79,69 +75,67 @@ List colors = [ print(" empty : $empty"); }); } - if((enter != 0 || currentPlayer == "System") && complete == 0 && empty != 0) - { + if ((enter != 0 || currentPlayer == "System") && + complete == 0 && + empty != 0) { computerMoves(); } } - computerMoves(){ - if(currentPlayer == "User") currentPlayer = "System"; + computerMoves() { + if (currentPlayer == "User") currentPlayer = "System"; enter = 0; - Timer(Duration(milliseconds: 500),(){ + Timer(Duration(milliseconds: 500), () { print("Wait is Over"); bool computerEnteredornot = computerturn('W'); - if(computerEnteredornot) - { + if (computerEnteredornot) { setState(() { - sysrow = computerentry ~/ 10; - syscol = computerentry % 10; - - // print("Computer Entry is : $rowno $colno"); - - if (syscol < 7) east(sysrow, syscol, 'W',1); - if (syscol > 0) west(sysrow, syscol, 'W',1); - if (sysrow > 0) north(sysrow, syscol, 'W',1); - if (sysrow < 7) south(sysrow, syscol, 'W',1); - if (sysrow > 0 && syscol < 7) northeast(sysrow, syscol, 'W',1); - if (sysrow > 0 && syscol > 0) northwest(sysrow, syscol, 'W',1); - if (sysrow < 7 && syscol < 7) southeast(sysrow, syscol, 'W',1); - if (sysrow < 7 && syscol > 0) southwest(sysrow, syscol, 'W',1); - if(enter != 0) - { - empty--; - if(countingColors("White") == 0 || countingColors("Black") == 0 || empty == 0) - { - setState(() { - complete = 1; - }); - } - currentPlayer = "User"; - bool userCanEnterOrNot = computerturn('B'); - if(userCanEnterOrNot == false && complete == 0){ - showLongToast("User Entry not Possible"); - bool sysCanEnterOrNot = computerturn('W'); - if(sysCanEnterOrNot == false && complete == 0){ - showLongToast("Computer Entry not Possible"); + sysrow = computerentry! ~/ 10; + syscol = computerentry! % 10; + + // print("Computer Entry is : $rowno $colno"); + + if (syscol < 7) east(sysrow, syscol, 'W', 1); + if (syscol > 0) west(sysrow, syscol, 'W', 1); + if (sysrow > 0) north(sysrow, syscol, 'W', 1); + if (sysrow < 7) south(sysrow, syscol, 'W', 1); + if (sysrow > 0 && syscol < 7) northeast(sysrow, syscol, 'W', 1); + if (sysrow > 0 && syscol > 0) northwest(sysrow, syscol, 'W', 1); + if (sysrow < 7 && syscol < 7) southeast(sysrow, syscol, 'W', 1); + if (sysrow < 7 && syscol > 0) southwest(sysrow, syscol, 'W', 1); + if (enter != 0) { + empty--; + if (countingColors("White") == 0 || + countingColors("Black") == 0 || + empty == 0) { setState(() { complete = 1; }); } - setState(() { - currentPlayer = "System"; - }); - if(complete == 0) - computerMoves(); + currentPlayer = "User"; + bool userCanEnterOrNot = computerturn('B'); + if (userCanEnterOrNot == false && complete == 0) { + showLongToast("User Entry not Possible"); + bool sysCanEnterOrNot = computerturn('W'); + if (sysCanEnterOrNot == false && complete == 0) { + showLongToast("Computer Entry not Possible"); + setState(() { + complete = 1; + }); + } + setState(() { + currentPlayer = "System"; + }); + if (complete == 0) computerMoves(); + } } - } }); - } - else{ - setState((){ + } else { + setState(() { currentPlayer = "User"; showLongToast("Computer Entry not Possible"); bool userCanEnterOrNot = computerturn('B'); - if(userCanEnterOrNot == false && complete == 0){ + if (userCanEnterOrNot == false && complete == 0) { showLongToast("User Entry not Possible"); setState(() { complete = 1; @@ -150,59 +144,58 @@ List colors = [ }); } print(" empty : $empty"); - complete == 1 ? print("Game Completed") : print("not Completed"); + complete == 1 ? print("Game Completed") : print("not Completed"); }); } - bool computerturn(String p) - { + bool computerturn(String p) { // int highestflips = 0; bool possible = false; computerentry = 0; int cornerflips = 0; bool cornerDone = false; - if(a[0][0] == '-' && !cornerDone){ + if (a[0][0] == '-' && !cornerDone) { print("\nTOP LEFT CORNER\n"); - cornerflips = cornerflips + east(0,0,p,0); - cornerflips = cornerflips + south(0,0,p,0); - cornerflips = cornerflips + southeast(0,0,p,0); - if(cornerflips != 0){ + cornerflips = cornerflips + east(0, 0, p, 0); + cornerflips = cornerflips + south(0, 0, p, 0); + cornerflips = cornerflips + southeast(0, 0, p, 0); + if (cornerflips != 0) { cornerDone = true; print("SETTING\n"); computerentry = (0 * 10) + 0; return true; } } - if(a[0][7] == '-' && !cornerDone){ + if (a[0][7] == '-' && !cornerDone) { print("\nTOP RIGHT CORNER\n"); - cornerflips = cornerflips + west(0,7,p,0); - cornerflips = cornerflips + south(0,7,p,0); - cornerflips = cornerflips + southwest(0,7,p,0); - if(cornerflips != 0){ + cornerflips = cornerflips + west(0, 7, p, 0); + cornerflips = cornerflips + south(0, 7, p, 0); + cornerflips = cornerflips + southwest(0, 7, p, 0); + if (cornerflips != 0) { cornerDone = true; computerentry = (0 * 10) + 7; print("SETTING\n"); return true; } } - if(a[7][0] == '-' && !cornerDone){ + if (a[7][0] == '-' && !cornerDone) { print("\nBOTTOM LEFT CORNER\n"); - cornerflips = cornerflips + east(7,0,p,0); - cornerflips = cornerflips + north(7,0,p,0); - cornerflips = cornerflips + northeast(7,0,p,0); - if(cornerflips != 0){ + cornerflips = cornerflips + east(7, 0, p, 0); + cornerflips = cornerflips + north(7, 0, p, 0); + cornerflips = cornerflips + northeast(7, 0, p, 0); + if (cornerflips != 0) { cornerDone = true; computerentry = (7 * 10) + 0; print("SETTING\n"); return true; } } - if(a[7][7] == '-' && !cornerDone){ + if (a[7][7] == '-' && !cornerDone) { print("\nBOTTOM RIGHT CORNER\n"); - cornerflips = cornerflips + west(7,7,p,0); - cornerflips = cornerflips + north(7,7,p,0); - cornerflips = cornerflips + northwest(7,7,p,0); - if(cornerflips != 0){ + cornerflips = cornerflips + west(7, 7, p, 0); + cornerflips = cornerflips + north(7, 7, p, 0); + cornerflips = cornerflips + northwest(7, 7, p, 0); + if (cornerflips != 0) { cornerDone = true; computerentry = (7 * 10) + 7; print("SETTING\n"); @@ -210,44 +203,41 @@ List colors = [ } } - - for(int rowno = 0 ; rowno < 8 ;rowno++) - { - for(int colno = 0 ; colno < 8; colno++) - { - if(a[rowno][colno] == '-') - { - int currentflips = 0; - if (colno < 7) currentflips = currentflips + east(rowno, colno, p,0); - if (colno > 0) currentflips = currentflips + west(rowno, colno, p,0); - if (rowno > 0) currentflips = currentflips + north(rowno, colno, p,0); - if (rowno < 7) currentflips = currentflips + south(rowno, colno, p,0); - if (rowno > 0 && colno < 7) currentflips = currentflips + northeast(rowno, colno, p,0); - if (rowno > 0 && colno > 0) currentflips = currentflips + northwest(rowno, colno, p,0); - if (rowno < 7 && colno < 7) currentflips = currentflips + southeast(rowno, colno, p,0); - if (rowno < 7 && colno > 0) currentflips = currentflips + southwest(rowno, colno, p,0); - // print("CURRENT FLIPS ARE : $currentflips"); - - if(currentflips > 0) - { - possible = true; - // highestflips = currentflips; - computerentry = (rowno * 10) + colno; - return possible; - } + for (int rowno = 0; rowno < 8; rowno++) { + for (int colno = 0; colno < 8; colno++) { + if (a[rowno][colno] == '-') { + int currentflips = 0; + if (colno < 7) currentflips = currentflips + east(rowno, colno, p, 0); + if (colno > 0) currentflips = currentflips + west(rowno, colno, p, 0); + if (rowno > 0) + currentflips = currentflips + north(rowno, colno, p, 0); + if (rowno < 7) + currentflips = currentflips + south(rowno, colno, p, 0); + if (rowno > 0 && colno < 7) + currentflips = currentflips + northeast(rowno, colno, p, 0); + if (rowno > 0 && colno > 0) + currentflips = currentflips + northwest(rowno, colno, p, 0); + if (rowno < 7 && colno < 7) + currentflips = currentflips + southeast(rowno, colno, p, 0); + if (rowno < 7 && colno > 0) + currentflips = currentflips + southwest(rowno, colno, p, 0); + // print("CURRENT FLIPS ARE : $currentflips"); + + if (currentflips > 0) { + possible = true; + // highestflips = currentflips; + computerentry = (rowno * 10) + colno; + return possible; + } } } } return possible; } - - void truncate(){ - + void truncate() { setState(() { - for(int i = 0; i < 8; i++) - for(int j = 0; j < 8; j++) - a[i][j] = '-'; + for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) a[i][j] = '-'; firstSkip = 0; currentSkip = 1; @@ -258,12 +248,11 @@ List colors = [ a[3][3] = 'W'; a[3][4] = 'B'; a[4][3] = 'B'; - a[4][4] = 'W'; + a[4][4] = 'W'; }); } - - int east(int x, int y, String ch,int change) //right + int east(int x, int y, String ch, int change) //right { // print("right"); int l = y, f = 0; @@ -276,8 +265,7 @@ List colors = [ } } for (int j = l - 1; j >= y; j--) { - if(change == 1) - { + if (change == 1) { a[x][j] = ch; } f = f + 1; @@ -285,12 +273,12 @@ List colors = [ if (f != 0) { enter = 1; print("east done"); - return f-1; + return f - 1; } else return 0; } - int west(int x, int y, String ch,int change) //left + int west(int x, int y, String ch, int change) //left { // print("left"); int l = y, f = 0; @@ -303,8 +291,7 @@ List colors = [ } } for (int j = l + 1; j <= y; j++) { - if(change == 1) - { + if (change == 1) { a[x][j] = ch; } f = f + 1; @@ -312,12 +299,12 @@ List colors = [ if (f != 0) { print("west done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int north(int x, int y, String ch,int change) //up + int north(int x, int y, String ch, int change) //up { // print("up"); int l = x, f = 0; @@ -330,8 +317,7 @@ List colors = [ } } for (int j = l + 1; j <= x; j++) { - if(change == 1) - { + if (change == 1) { a[j][y] = ch; } f = f + 1; @@ -339,12 +325,12 @@ List colors = [ if (f != 0) { print("north done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int south(int x, int y, String ch,int change) //down + int south(int x, int y, String ch, int change) //down { // print("down"); int l = x, f = 0; @@ -357,8 +343,7 @@ List colors = [ } } for (int j = l - 1; j >= x; j--) { - if(change == 1) - { + if (change == 1) { a[j][y] = ch; } f = f + 1; @@ -366,12 +351,12 @@ List colors = [ if (f != 0) { print("south done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int northeast(int x, int y, String ch,int change) //upright + int northeast(int x, int y, String ch, int change) //upright { // print("upright"); int m = x, n = y, f = 0; @@ -385,8 +370,7 @@ List colors = [ } } for (int i = m + 1, j = n - 1; i <= x && j >= y; i++, j--) { - if(change == 1) - { + if (change == 1) { a[i][j] = ch; } f = f + 1; @@ -394,12 +378,12 @@ List colors = [ if (f != 0) { print("northeast done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int northwest(int x, int y, String ch,int change) //upleft + int northwest(int x, int y, String ch, int change) //upleft { // print("upleft"); int m = x, n = y, f = 0; @@ -413,8 +397,7 @@ List colors = [ } } for (int i = m + 1, j = n + 1; i <= x && j <= y; i++, j++) { - if(change == 1) - { + if (change == 1) { a[i][j] = ch; } f = f + 1; @@ -422,12 +405,12 @@ List colors = [ if (f != 0) { print("northwest done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int southeast(int x, int y, String ch,int change) //downright + int southeast(int x, int y, String ch, int change) //downright { // print("downright"); int m = x, n = y, f = 0; @@ -441,8 +424,7 @@ List colors = [ } } for (int i = m - 1, j = n - 1; i >= x && j >= y; i--, j--) { - if(change == 1) - { + if (change == 1) { a[i][j] = ch; } f = f + 1; @@ -450,12 +432,12 @@ List colors = [ if (f != 0) { print("southeast done"); enter = 1; - return f-1; + return f - 1; } else return 0; } - int southwest(int x, int y, String ch,int change) //downleft + int southwest(int x, int y, String ch, int change) //downleft { // print("downleft"); int m = x, n = y, f = 0; @@ -471,8 +453,7 @@ List colors = [ } } for (int i = m - 1, j = n + 1; i >= x && j <= y; i--, j++) { - if(change == 1) - { + if (change == 1) { a[i][j] = ch; } f = f + 1; @@ -480,7 +461,7 @@ List colors = [ if (f != 0) { print("southwest done"); enter = 1; - return f-1; + return f - 1; } else return 0; } @@ -531,12 +512,11 @@ List colors = [ appBar: AppBar( leading: IconButton( icon: Icon(Icons.keyboard_arrow_left), - onPressed: ()=>Navigator.pop(context), + onPressed: () => Navigator.pop(context), iconSize: MediaQuery.of(context).size.width * 0.12, ), elevation: 0.0, backgroundColor: Colors.transparent, - title: new Text( "Easy Bot", style: new TextStyle( @@ -563,154 +543,186 @@ List colors = [ ), body: new ListView( children: [ - invalidEntries == 3 ? Align( - alignment: Alignment.centerRight, - child: Card( - color: Colors.transparent, - elevation: 15.0, - child: GestureDetector( - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5.0), - color: Colors.blue, - ), - padding: EdgeInsets.all(2), - child: Text(" Skip\nmy Turn"), + invalidEntries == 3 + ? Align( + alignment: Alignment.centerRight, + child: Card( + color: Colors.transparent, + elevation: 15.0, + child: GestureDetector( + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5.0), + color: Colors.blue, ), - onTap: (){ - setState(() { - currentPlayer = "System"; - setcolor(50); //////***** DOESN'T MATTER WHAT NUMBER YOU ARE PASSING HERE AS A PARAMETER*****////// - firstSkip == 0 ? firstSkip = empty : currentSkip = empty; - print(empty); - complete = currentSkip == firstSkip ? 1 : complete; - invalidEntries = 0; - }); - }, + padding: EdgeInsets.all(2), + child: Text(" Skip\nmy Turn"), ), + onTap: () { + setState(() { + currentPlayer = "System"; + setcolor( + 50); //////***** DOESN'T MATTER WHAT NUMBER YOU ARE PASSING HERE AS A PARAMETER*****////// + firstSkip == 0 + ? firstSkip = empty + : currentSkip = empty; + print(empty); + complete = currentSkip == firstSkip ? 1 : complete; + invalidEntries = 0; + }); + }, ), - ) : Container(height: MediaQuery.of(context).size.height * 0.058), + ), + ) + : Container(height: MediaQuery.of(context).size.height * 0.058), new Stack( children: [ - new Column( - children: [ - new Container( - padding: new EdgeInsets.fromLTRB(2.0, 2.0, 2.0, 0.0), - child: new GridView.extent( - maxCrossAxisExtent: MediaQuery.of(context).size.width * 0.12, - mainAxisSpacing: 2.0, - crossAxisSpacing: 2.0, - children: customBox(), - ), - width: MediaQuery.of(context).size.width, - height: ((MediaQuery.of(context).size.width * 0.12) * 8.35), - color: Colors.orangeAccent.shade100, - ), - new Padding( - padding: new EdgeInsets.all(5.0), - ), - new Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + new Column( children: [ - new Text( - countingColors("White") < 10 ? "White: 0${countingColors("White")}" : "White: ${countingColors("White")}", - style: new TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - fontSize: MediaQuery.of(context).size.width * 0.04, - ), - ), new Container( - alignment: Alignment.center, - decoration: new BoxDecoration( - borderRadius: BorderRadius.circular(40.0), - color: currentPlayer == "User" ? Colors.black : Colors.white, + padding: new EdgeInsets.fromLTRB(2.0, 2.0, 2.0, 0.0), + child: new GridView.extent( + maxCrossAxisExtent: + MediaQuery.of(context).size.width * 0.12, + mainAxisSpacing: 2.0, + crossAxisSpacing: 2.0, + children: customBox(), ), - width: MediaQuery.of(context).size.width * 0.1, - height: MediaQuery.of(context).size.width * 0.1, - child: new Center( - child: new Text( - currentPlayer == "User" ? "Player\n Turn" : "System\n Turn", + width: MediaQuery.of(context).size.width, + height: ((MediaQuery.of(context).size.width * 0.12) * 8.35), + color: Colors.orangeAccent.shade100, + ), + new Padding( + padding: new EdgeInsets.all(5.0), + ), + new Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + new Text( + countingColors("White") < 10 + ? "White: 0${countingColors("White")}" + : "White: ${countingColors("White")}", style: new TextStyle( - color: currentPlayer == "User" ? Colors.white : Colors.black, - fontSize: MediaQuery.of(context).size.width * 0.025, + color: Colors.white, + fontWeight: FontWeight.bold, + fontSize: MediaQuery.of(context).size.width * 0.04, ), ), - ), - ), - new Text( - countingColors("Black") < 10 ? "Black: 0${countingColors("Black")}" : "Black: ${countingColors("Black")}", - style: new TextStyle( - color: Colors.black, - fontWeight: FontWeight.bold, - fontSize: MediaQuery.of(context).size.width * 0.04, - ), - ), - ], - ), - - Center( - child: new RaisedButton( - elevation: 5.0, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), - color: Colors.orangeAccent, - child: new Text( - empty == 0 || complete == 1 ? "Play Again" : "Reset Game", - style: new TextStyle( - fontSize: MediaQuery.of(context).size.width * 0.055, - color: Colors.redAccent, - fontStyle: FontStyle.italic, + new Container( + alignment: Alignment.center, + decoration: new BoxDecoration( + borderRadius: BorderRadius.circular(40.0), + color: currentPlayer == "User" + ? Colors.black + : Colors.white, + ), + width: MediaQuery.of(context).size.width * 0.1, + height: MediaQuery.of(context).size.width * 0.1, + child: new Center( + child: new Text( + currentPlayer == "User" + ? "Player\n Turn" + : "System\n Turn", + style: new TextStyle( + color: currentPlayer == "User" + ? Colors.white + : Colors.black, + fontSize: + MediaQuery.of(context).size.width * 0.025, + ), + ), + ), ), - ), - onPressed: () { - empty == 0 || complete == 1 ? print("playing again") : print("Reseting"); - truncate(); - }), + new Text( + countingColors("Black") < 10 + ? "Black: 0${countingColors("Black")}" + : "Black: ${countingColors("Black")}", + style: new TextStyle( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: MediaQuery.of(context).size.width * 0.04, + ), + ), + ], + ), + Center( + child: new RaisedButton( + elevation: 5.0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0)), + color: Colors.orangeAccent, + child: new Text( + empty == 0 || complete == 1 + ? "Play Again" + : "Reset Game", + style: new TextStyle( + fontSize: MediaQuery.of(context).size.width * 0.055, + color: Colors.redAccent, + fontStyle: FontStyle.italic, + ), + ), + onPressed: () { + empty == 0 || complete == 1 + ? print("playing again") + : print("Reseting"); + truncate(); + }), ), ], ), Positioned( top: MediaQuery.of(context).size.height * 0.15, left: MediaQuery.of(context).size.width * 0.01, - child: new Container( + child: new Container( width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height * 0.09, child: new Center( - child: empty == 0 || countingColors("White") == 0 || countingColors("Black") == 0 || complete == 1 + child: empty == 0 || + countingColors("White") == 0 || + countingColors("Black") == 0 || + complete == 1 ? (countingColors("White") == countingColors("Black") ? new Image.asset( 'images/Draw.gif', width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height * 0.2, + height: + MediaQuery.of(context).size.height * 0.2, ) : (countingColors("White") > countingColors("Black") ? new Image.asset( 'images/white.gif', width: MediaQuery.of(context).size.width, - height: - MediaQuery.of(context).size.height * 0.2, + height: MediaQuery.of(context).size.height * + 0.2, ) : new Image.asset( 'images/Black.gif', width: MediaQuery.of(context).size.width, - height: - MediaQuery.of(context).size.height * 0.2, + height: MediaQuery.of(context).size.height * + 0.2, ))) - : Container(width:0.0,height: 0.0,), - ), - ), - ), - - sysrow == -1 ? Container() : Positioned( - child: Container( - child: Image.asset('images/Pointing.png'), - height: 25.0, - width: 25.0, + : Container( + width: 0.0, + height: 0.0, + ), + ), ), - top: (MediaQuery.of(context).size.width * 0.127) * sysrow + 15.0 , - left: (MediaQuery.of(context).size.width * 0.127) * syscol + 7.0 , ), - + sysrow == -1 + ? Container() + : Positioned( + child: Container( + child: Image.asset('images/Pointing.png'), + height: 25.0, + width: 25.0, + ), + top: + (MediaQuery.of(context).size.width * 0.127) * sysrow + + 15.0, + left: + (MediaQuery.of(context).size.width * 0.127) * syscol + + 7.0, + ), ], ), ], @@ -745,7 +757,9 @@ List colors = [ child: new CircleAvatar( backgroundColor: a[row][col] == '-' ? Colors.green - : (a[row][col] == 'W') ? Colors.white : Colors.black, + : (a[row][col] == 'W') + ? Colors.white + : Colors.black, maxRadius: MediaQuery.of(context).size.width * 0.047, ), ), diff --git a/lib/GamePage.dart b/lib/GamePage.dart index 574b0e5..12c82fc 100644 --- a/lib/GamePage.dart +++ b/lib/GamePage.dart @@ -49,17 +49,15 @@ class Testappstate extends State { if (enter == 0) { showLongToast("Invalid Entry"); invalidEntries = invalidEntries == 3 ? 3 : (invalidEntries + 1) % 4; - } - - else - { + } else { invalidEntries = 0; currentPlayer = currentPlayer == "black" ? "white" : "black"; empty--; } - if(empty == 0 || countingColors("White") == 0 || countingColors("Black") == 0) - { + if (empty == 0 || + countingColors("White") == 0 || + countingColors("Black") == 0) { setState(() { complete = 1; }); @@ -68,14 +66,10 @@ class Testappstate extends State { }); } - - void truncate(){ - + void truncate() { setState(() { - for(int i = 0; i < 8; i++) - for(int j = 0; j < 8; j++) - a[i][j] = '-'; - + for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) a[i][j] = '-'; + firstSkip = 0; currentSkip = 1; complete = 0; @@ -84,11 +78,10 @@ class Testappstate extends State { a[3][3] = 'W'; a[3][4] = 'B'; a[4][3] = 'B'; - a[4][4] = 'W'; + a[4][4] = 'W'; }); } - int east(int x, int y, String ch) //right { //print("right"); @@ -317,12 +310,12 @@ class Testappstate extends State { void showLongToast(String message) { invalidColorsindex = invalidColorsindex + 1; - Fluttertoast.showToast( + Fluttertoast.showToast( gravity: ToastGravity.TOP, textColor: Colors.redAccent, backgroundColor: colors[invalidColorsindex % 3], msg: message, - timeInSecForIos: 1, + // timeInSecForIos: 1, toastLength: Toast.LENGTH_SHORT, ); } @@ -334,7 +327,7 @@ class Testappstate extends State { appBar: new AppBar( leading: IconButton( icon: Icon(Icons.keyboard_arrow_left), - onPressed: ()=>Navigator.pop(context), + onPressed: () => Navigator.pop(context), iconSize: MediaQuery.of(context).size.width * 0.12, ), elevation: 0.0, @@ -365,31 +358,38 @@ class Testappstate extends State { ), body: new ListView( children: [ - invalidEntries == 3 ? Align( - alignment: Alignment.centerRight, - child: Card( - color: Colors.transparent, - elevation: 15.0, - child: GestureDetector( - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5.0), - color: Colors.blue, - ), - padding: EdgeInsets.all(2), - child: Text(" Skip\nmy Turn"), + invalidEntries == 3 + ? Align( + alignment: Alignment.centerRight, + child: Card( + color: Colors.transparent, + elevation: 15.0, + child: GestureDetector( + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5.0), + color: Colors.blue, ), - onTap: (){ - setState(() { - firstSkip == 0 ? firstSkip = empty : currentSkip = empty; - complete = currentSkip == firstSkip ? 1 : complete; - invalidEntries = 0; - currentPlayer = currentPlayer == "black" ? "white" : "black"; - }); - }, + padding: EdgeInsets.all(2), + child: Text(" Skip\nmy Turn"), ), + onTap: () { + setState(() { + firstSkip == 0 + ? firstSkip = empty + : currentSkip = empty; + complete = currentSkip == firstSkip ? 1 : complete; + invalidEntries = 0; + currentPlayer = + currentPlayer == "black" ? "white" : "black"; + }); + }, ), - ) : Container(height: MediaQuery.of(context).size.height * 0.058,), + ), + ) + : Container( + height: MediaQuery.of(context).size.height * 0.058, + ), Stack( children: [ new Column( @@ -397,7 +397,8 @@ class Testappstate extends State { new Container( padding: new EdgeInsets.fromLTRB(2.0, 2.0, 2.0, 0.0), child: new GridView.extent( - maxCrossAxisExtent: MediaQuery.of(context).size.width * 0.12, + maxCrossAxisExtent: + MediaQuery.of(context).size.width * 0.12, mainAxisSpacing: 2.0, crossAxisSpacing: 2.0, children: customBox(), @@ -413,7 +414,9 @@ class Testappstate extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ new Text( - countingColors("White") < 10 ? "White: 0${countingColors("White")}" : "White: ${countingColors("White")}", + countingColors("White") < 10 + ? "White: 0${countingColors("White")}" + : "White: ${countingColors("White")}", style: new TextStyle( color: Colors.white, fontWeight: FontWeight.bold, @@ -424,22 +427,31 @@ class Testappstate extends State { alignment: Alignment.center, decoration: new BoxDecoration( borderRadius: BorderRadius.circular(40.0), - color: currentPlayer == "black" ? Colors.black : Colors.white, + color: currentPlayer == "black" + ? Colors.black + : Colors.white, ), width: MediaQuery.of(context).size.width * 0.1, height: MediaQuery.of(context).size.width * 0.1, child: new Center( child: new Text( - currentPlayer == "black" ? "Black\n Turn" : "White\n Turn", + currentPlayer == "black" + ? "Black\n Turn" + : "White\n Turn", style: new TextStyle( - color: currentPlayer == "black" ? Colors.white : Colors.black, - fontSize: MediaQuery.of(context).size.width * 0.025, + color: currentPlayer == "black" + ? Colors.white + : Colors.black, + fontSize: + MediaQuery.of(context).size.width * 0.025, ), ), ), ), new Text( - countingColors("Black") < 10 ? "Black: 0${countingColors("Black")}" : "White: ${countingColors("Black")}", + countingColors("Black") < 10 + ? "Black: 0${countingColors("Black")}" + : "White: ${countingColors("Black")}", style: new TextStyle( color: Colors.black, fontWeight: FontWeight.bold, @@ -450,11 +462,14 @@ class Testappstate extends State { ), Center( child: new RaisedButton( - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), - elevation: 10.0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0)), + elevation: 10.0, color: Colors.orangeAccent, child: new Text( - empty == 0 || complete == 1 ? "Play Again" : "Reset Game", + empty == 0 || complete == 1 + ? "Play Again" + : "Reset Game", style: new TextStyle( fontSize: MediaQuery.of(context).size.width * 0.055, color: Colors.redAccent, @@ -468,37 +483,38 @@ class Testappstate extends State { ), ], ), - Positioned( - top: MediaQuery.of(context).size.height * 0.15, - left: MediaQuery.of(context).size.width * 0.01, - child: new Container( - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height * 0.09, - child: new Center( - child: empty == 0 || complete == 1 - ? (countingColors("White") == countingColors("Black") + Positioned( + top: MediaQuery.of(context).size.height * 0.15, + left: MediaQuery.of(context).size.width * 0.01, + child: new Container( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height * 0.09, + child: new Center( + child: empty == 0 || complete == 1 + ? (countingColors("White") == countingColors("Black") + ? new Image.asset( + 'images/Draw.gif', + width: MediaQuery.of(context).size.width, + height: + MediaQuery.of(context).size.height * 0.2, + ) + : (countingColors("White") > countingColors("Black") ? new Image.asset( - 'images/Draw.gif', + 'images/white.gif', width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height * 0.2, + height: MediaQuery.of(context).size.height * + 0.2, ) - : (countingColors("White") > countingColors("Black") - ? new Image.asset( - 'images/white.gif', - width: MediaQuery.of(context).size.width, - height: - MediaQuery.of(context).size.height * 0.2, - ) - : new Image.asset( - 'images/Black.gif', - width: MediaQuery.of(context).size.width, - height: - MediaQuery.of(context).size.height * 0.2, - ))) - : null, - ), - ), + : new Image.asset( + 'images/Black.gif', + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height * + 0.2, + ))) + : null, ), + ), + ), // ], // ), ], @@ -535,7 +551,9 @@ class Testappstate extends State { child: new CircleAvatar( backgroundColor: a[row][col] == '-' ? Colors.green - : (a[row][col] == 'W') ? Colors.white : Colors.black, + : (a[row][col] == 'W') + ? Colors.white + : Colors.black, maxRadius: MediaQuery.of(context).size.width * 0.047, ), ), diff --git a/lib/IntroductionPage.dart b/lib/IntroductionPage.dart index 2ec01c0..a8e902f 100644 --- a/lib/IntroductionPage.dart +++ b/lib/IntroductionPage.dart @@ -8,58 +8,75 @@ import 'package:share/share.dart'; import 'package:firebase_admob/firebase_admob.dart'; - class IntroPage extends StatefulWidget { @override IntroPageState createState() => IntroPageState(); } class IntroPageState extends State { - -static List testDeviceIds = ["4768989DE9003C8EF583D7B60EC12B4B"]; + static List testDeviceIds = [ + "4768989DE9003C8EF583D7B60EC12B4B" + ]; // static List testDeviceIds = ["33BE2250B43518CCDA7DE426D04EE231"]; -static MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo( + static MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo( // RequestConfiguration configuration = // new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build(); // MobileAds.setRequestConfiguration(configuration); - keywords: ['games', 'pubg','food','taxi','ride','hotel','play','oyo','rapido','swiggy','uber','Goibibo','True Balance','Phone Pay','Lynk','IOT','AI','Machine Learning'], - // contentUrl: 'https://flutter.io', - // testDevices: ["90F3FC819896095375532EAC4070D216"], // Android emulators are considered test devices + keywords: [ + 'games', + 'pubg', + 'food', + 'taxi', + 'ride', + 'hotel', + 'play', + 'oyo', + 'rapido', + 'swiggy', + 'uber', + 'Goibibo', + 'True Balance', + 'Phone Pay', + 'Lynk', + 'IOT', + 'AI', + 'Machine Learning' + ], + // contentUrl: 'https://flutter.io', + // testDevices: ["90F3FC819896095375532EAC4070D216"], // Android emulators are considered test devices // testDevices: testDeviceIds, // Android emulators are considered test devices - testDevices: testDeviceIds != null ? testDeviceIds : null, -); - -BannerAd bannerAd = BannerAd( - adUnitId: "ca-app-pub-3781046810533099/1446430882", - size: AdSize.banner, - targetingInfo: targetingInfo, - listener: (MobileAdEvent event){ - print("\n\n\n\nBanner Event is : $event\n\n\n\n"); - } -); - + testDevices: testDeviceIds, + ); + BannerAd bannerAd = BannerAd( + adUnitId: "ca-app-pub-3781046810533099/1446430882", + size: AdSize.banner, + targetingInfo: targetingInfo, + listener: (MobileAdEvent event) { + print("\n\n\n\nBanner Event is : $event\n\n\n\n"); + }); -@override -initState() -{ - super.initState(); - FirebaseAdMob.instance.initialize(appId: "ca-app-pub-3781046810533099~6890329253"); - bannerAd..load()..show( - anchorType: AnchorType.bottom, - anchorOffset: 5.0, - horizontalCenterOffset: 0.0, - ); -} + @override + initState() { + super.initState(); + FirebaseAdMob.instance + .initialize(appId: "ca-app-pub-3781046810533099~6890329253"); + bannerAd + ..load() + ..show( + anchorType: AnchorType.bottom, + anchorOffset: 5.0, + horizontalCenterOffset: 0.0, + ); + } -@override -dispose() -{ - bannerAd?.dispose(); - super.dispose(); -} + @override + dispose() { + bannerAd.dispose(); + super.dispose(); + } @override Widget build(BuildContext context) { @@ -77,10 +94,7 @@ dispose() fontStyle: FontStyle.italic, ), ), - - actions: [ - new IconButton( icon: new Icon( Icons.info, @@ -89,22 +103,20 @@ dispose() tooltip: "About", onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (context) { - return AboutPage(); - })), + return AboutPage(); + })), ), - new IconButton( - icon: new Icon( - Icons.share, - color: Colors.black, + icon: new Icon( + Icons.share, + color: Colors.black, ), tooltip: "Share", - onPressed: () - { + onPressed: () { print("Sharing Game"); - Share.share("Feeling bored with Usual Games..? Try Playing This Game\n https://play.google.com/store/apps/details?id=com.srikanth7785.othello \nNow Updated with Single Player Mode..:)"); - } - ), + Share.share( + "Feeling bored with Usual Games..? Try Playing This Game\n https://play.google.com/store/apps/details?id=com.srikanth7785.othello \nNow Updated with Single Player Mode..:)"); + }), ], ), backgroundColor: Colors.orangeAccent.shade100, @@ -122,45 +134,52 @@ dispose() Row( children: [ Padding( - padding: EdgeInsets.only(left:MediaQuery.of(context).size.width * 0.09), + padding: EdgeInsets.only( + left: MediaQuery.of(context).size.width * 0.09), child: GestureDetector( - child: new Column( - children: [ - Image.asset('images/Multiplayer.png', + child: new Column(children: [ + Image.asset( + 'images/Multiplayer.png', color: Colors.brown, width: MediaQuery.of(context).size.width * 0.25, height: MediaQuery.of(context).size.height * 0.12, - ), - Text(" Multiplayer", + ), + Text( + " Multiplayer", style: TextStyle( - color: Colors.brown, - fontSize: MediaQuery.of(context).size.width * 0.05, - fontWeight: FontWeight.bold - ), - ), - ] - ), - onTap: ()=>Navigator.push(context, MaterialPageRoute(builder: (context) => Testapp())), + color: Colors.brown, + fontSize: + MediaQuery.of(context).size.width * 0.05, + fontWeight: FontWeight.bold), + ), + ]), + onTap: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => Testapp())), ), ), - SizedBox(width: MediaQuery.of(context).size.width*0.24), + SizedBox(width: MediaQuery.of(context).size.width * 0.24), GestureDetector( - child: new Column( - children: [ - SizedBox(height: MediaQuery.of(context).size.height * 0.012), - Icon(Icons.remove_from_queue, - size: MediaQuery.of(context).size.width * 0.24, - color: Colors.brown,), - Text(" Single Player", + child: new Column(children: [ + SizedBox( + height: + MediaQuery.of(context).size.height * 0.012), + Icon( + Icons.remove_from_queue, + size: MediaQuery.of(context).size.width * 0.24, + color: Colors.brown, + ), + Text( + " Single Player", style: TextStyle( - color: Colors.brown, - fontSize: MediaQuery.of(context).size.width * 0.05, - fontWeight: FontWeight.bold - ), - ), - ] - ), - onTap: (){ + color: Colors.brown, + fontSize: + MediaQuery.of(context).size.width * 0.05, + fontWeight: FontWeight.bold), + ), + ]), + onTap: () { showDialog( context: context, // barrierDismissible: false, @@ -170,35 +189,67 @@ dispose() borderRadius: BorderRadius.circular(15.0), ), backgroundColor: Colors.orangeAccent, - title: Center(child: Text("Choose Difficulty",style: TextStyle(color: Colors.brown,fontSize: 35.0,fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),)), + title: Center( + child: Text( + "Choose Difficulty", + style: TextStyle( + color: Colors.brown, + fontSize: 35.0, + fontStyle: FontStyle.italic, + fontWeight: FontWeight.bold), + )), content: Container( - height: MediaQuery.of(context).size.height * 0.22, + height: + MediaQuery.of(context).size.height * 0.22, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox(height: 10.0), ListTile( - title: Center(child: Text("Easy Level",style: TextStyle(color: Colors.black,fontSize: 28.0,fontStyle: FontStyle.italic))), - onTap: (){ - Navigator.pop(context); - Navigator.push(context, MaterialPageRoute(builder: (context) => EasyBot())); - } + title: Center( + child: Text("Easy Level", + style: TextStyle( + color: Colors.black, + fontSize: 28.0, + fontStyle: + FontStyle.italic))), + onTap: () { + Navigator.pop(context); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + EasyBot())); + }), + SizedBox( + height: 20.0, ), - SizedBox(height: 20.0,), ListTile( - title: Center(child: Text("Hard Level",style: TextStyle(color: Colors.black,fontSize: 28.0,fontStyle: FontStyle.italic))), - onTap: (){ - Navigator.pop(context); - Navigator.push(context, MaterialPageRoute(builder: (context) => Computer())); - } - ), + title: Center( + child: Text("Hard Level", + style: TextStyle( + color: Colors.black, + fontSize: 28.0, + fontStyle: + FontStyle.italic))), + onTap: () { + Navigator.pop(context); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + Computer())); + }), ], ), ), actions: [ FlatButton( - child: Text("BACK",style: TextStyle(color: Colors.brown,fontWeight: FontWeight.bold)), - onPressed: ()=>Navigator.pop(context), + child: Text("BACK", + style: TextStyle( + color: Colors.brown, + fontWeight: FontWeight.bold)), + onPressed: () => Navigator.pop(context), ), ], ); @@ -208,24 +259,29 @@ dispose() ), ], ), - SizedBox(height: MediaQuery.of(context).size.height * 0.05,), + SizedBox( + height: MediaQuery.of(context).size.height * 0.05, + ), GestureDetector( child: Column( children: [ - Icon(Icons.live_help, + Icon( + Icons.live_help, size: MediaQuery.of(context).size.width * 0.08, - color: Colors.brown,), - SizedBox(height: MediaQuery.of(context).size.height*0.01), - Text("How To Play", - style: TextStyle( color: Colors.brown, - fontSize: MediaQuery.of(context).size.width * 0.04, - fontWeight: FontWeight.bold - ) ), + SizedBox( + height: MediaQuery.of(context).size.height * 0.01), + Text("How To Play", + style: TextStyle( + color: Colors.brown, + fontSize: + MediaQuery.of(context).size.width * 0.04, + fontWeight: FontWeight.bold)), ], ), - onTap: () => Navigator.push(context, MaterialPageRoute(builder: (context) => HowToPlay())), + onTap: () => Navigator.push(context, + MaterialPageRoute(builder: (context) => HowToPlay())), ), ], ), diff --git a/pubspec.yaml b/pubspec.yaml index 2a72b48..c621833 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,10 +7,10 @@ description: A new Flutter project. # Both the version and the builder number may be overridden in flutter # build by specifying --build-name and --build-number, respectively. # Read more about versioning at semver.org. -version: 5.0.0+8 +version: 5.1.0+9 environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: ">=2.16.1 <3.0.0" dependencies: flutter: @@ -19,7 +19,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2 - fluttertoast: ^3.1.3 + fluttertoast: ^8.0.9 share: ^0.6.3+5 firebase_admob: ^0.9.0+10