Skip to content

Commit

Permalink
Merge pull request #16 from Robert3141/beta
Browse files Browse the repository at this point in the history
v2.2.1
  • Loading branch information
Robert3141 committed Nov 11, 2019
2 parents 6471a96 + 18cda82 commit ed88f0f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 42 deletions.
92 changes: 57 additions & 35 deletions lib/UI/UIsettings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,44 +179,66 @@ class _SettingsState extends State<SettingsPage> {
}

void onBtnRunGamePressed() {
//get inputs
globals.boardSize =
int.parse(globals.conBoardSize.text ?? globals.boardDefault);
globals.amountOfPlayers =
int.parse(globals.conAmountOfPlayers.text ?? globals.playerDefault);
globals.lineLength =
int.parse(globals.conLineLength.text ?? globals.lineDefault);
globals.amountOfRounds =
int.parse(globals.conNumberOfRounds.text ?? globals.roundDefault);
globals.recursionLimit =
int.parse(globals.conRecursion.text ?? globals.recursionDefault);
try {
//get inputs
//board
String _boardString =
globals.conBoardSize.text ?? globals.boardDefault.toString();
globals.boardSize = int.parse(_boardString == ""
? globals.boardDefault.toString()
: _boardString);
//player amount
String _playerString = globals
.conAmountOfPlayers.text;
globals.amountOfPlayers = int.parse(_playerString == ""
? globals.playerDefault.toString()
: _playerString);
//line length
String _lineString =
globals.conLineLength.text ?? globals.lineDefault.toString();
globals.lineLength = int.parse(
_lineString == "" ? globals.lineDefault.toString() : _lineString);
//round amount
String _roundString =
globals.conNumberOfRounds.text ?? globals.roundDefault.toString();
globals.amountOfRounds = int.parse(
_roundString == "" ? globals.roundDefault.toString() : _roundString);
//recursion amount
String _recursionString =
globals.conRecursion.text ?? globals.recursionDefault.toString();
globals.recursionLimit = int.parse(_recursionString == ""
? globals.recursionDefault.toString()
: _recursionString);

//check problem
bool issue = checkProblems();
//check problem
bool issue = checkProblems();

//no issues
if (!issue) {
//reset variables
if (globals.amountOfPlayers > 1) {
globals.playerBombs =
new List<bool>.generate(globals.amountOfPlayers, (i) => true);
} else {
globals.bombCounter = false;
}
globals.mainBoard = new List<List<int>>.generate(globals.boardSize,
(i) => List<int>.generate(globals.boardSize, (j) => 0));
globals.playerScores = globals.amountOfPlayers <= 1
? new List<int>.generate(2, (i) => 0)
: new List<int>.generate(globals.amountOfPlayers, (i) => 0);
globals.playerNumber = 1;
globals.roundNumber = 1;
globals.running = false;
//no issues
if (!issue) {
//reset variables
if (globals.amountOfPlayers > 1) {
globals.playerBombs =
new List<bool>.generate(globals.amountOfPlayers, (i) => true);
} else {
globals.bombCounter = false;
}
globals.mainBoard = new List<List<int>>.generate(globals.boardSize,
(i) => List<int>.generate(globals.boardSize, (j) => 0));
globals.playerScores = globals.amountOfPlayers <= 1
? new List<int>.generate(2, (i) => 0)
: new List<int>.generate(globals.amountOfPlayers, (i) => 0);
globals.playerNumber = 1;
globals.roundNumber = 1;
globals.running = false;

//Push interface
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => GamePage(title: globals.titleGame)));
//Push interface
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => GamePage(title: globals.titleGame)));
}
} catch (e) {
msgBox("Error", e.toString());
}
}

Expand Down
33 changes: 27 additions & 6 deletions lib/logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ List<List<int>> applyGravity(List<List<int>> board, int boardSize, int x) {
return board;
}

List<List<int>> boardGravity(List<List<int>> board, int boardSize, int x) {
//loop through entire array except bottom line
for (int i = 0; i < 2; i++) {
for (int y = boardSize-1; y > 0; y--) {
//if below is empty then drop down and replace
if (board[x][y] == 0) {
board[x][y] = board[x][y-1];
board[x][y-1] = 0;
}
}
}

return board;
}

List<List<int>> bombRemoval(int x, int y, List<List<int>> movedBoard) {
if (x>0) {
if (y>0) {
Expand Down Expand Up @@ -188,24 +203,30 @@ List<List<int>> playBomb(int x, List<List<int>> movedBoard) {

//bomb
movedBoard = bombRemoval(x, y, movedBoard);
movedBoard = applyGravity(movedBoard, globals.boardSize, x);
movedBoard = boardGravity(movedBoard, globals.boardSize, x);
if (x > 0) {
movedBoard = applyGravity(movedBoard, globals.boardSize, x-1);
//apply gravity on all tokens above
for (int i = 0; i < globals.boardSize-3;i++) {
movedBoard = boardGravity(movedBoard, globals.boardSize, x-1);
}
}
if (x < globals.boardSize-1) {
movedBoard = applyGravity(movedBoard, globals.boardSize, x+1);
//apply gravity on all tokens above
for (int i = 0; i < globals.boardSize-3;i++) {
movedBoard = boardGravity(movedBoard, globals.boardSize, x+1);
}
}
return movedBoard;
}
}

movedBoard = bombRemoval(x, globals.boardSize-1, movedBoard);
movedBoard = applyGravity(movedBoard, globals.boardSize, x);
movedBoard = boardGravity(movedBoard, globals.boardSize, x);
if (x > 0) {
movedBoard = applyGravity(movedBoard, globals.boardSize, x-1);
movedBoard = boardGravity(movedBoard, globals.boardSize, x-1);
}
if (x < globals.boardSize-1) {
movedBoard = applyGravity(movedBoard, globals.boardSize, x+1);
movedBoard = boardGravity(movedBoard, globals.boardSize, x+1);
}
return movedBoard;
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: Connect 4 style game
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 2.2.0+12
version: 2.2.1+13

environment:
sdk: ">=2.1.0 <3.0.0"
Expand Down

0 comments on commit ed88f0f

Please sign in to comment.