Added Special Stones
parent
7b0b1031c9
commit
6f0470f530
|
@ -1,6 +1,8 @@
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:bubbletwist/game/stone/quad_special_stone.dart';
|
||||||
import 'package:bubbletwist/game/stone/special_stone.dart';
|
import 'package:bubbletwist/game/stone/special_stone.dart';
|
||||||
|
import 'package:bubbletwist/game/stone/triple_special_stone.dart';
|
||||||
|
|
||||||
import '../enums/stone_color.dart';
|
import '../enums/stone_color.dart';
|
||||||
import 'game.dart';
|
import 'game.dart';
|
||||||
|
@ -11,13 +13,16 @@ import 'stone/stone_location.dart';
|
||||||
class Board {
|
class Board {
|
||||||
static const int boardSize = 8;
|
static const int boardSize = 8;
|
||||||
final Game game;
|
final Game game;
|
||||||
late final List<List<Stone?>> stones = List.generate(boardSize, (i) => List.generate(boardSize, (j) => Stone()));
|
late final List<List<Stone?>> stones =
|
||||||
|
List.generate(boardSize, (i) => List.generate(boardSize, (j) => Stone()));
|
||||||
|
bool specialStonesEnabled = false;
|
||||||
|
|
||||||
Board(this.game) {
|
Board(this.game) {
|
||||||
// The map generates with pairs of 3+ stones already in place.
|
// The map generates with pairs of 3+ stones already in place.
|
||||||
// To fix that we just let the game remove all 3+ stone pairs until none are left
|
// To fix that we just let the game remove all 3+ stone pairs until none are left
|
||||||
while (checkBoard()){}
|
while (checkBoard()) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateBoard() {
|
void updateBoard() {
|
||||||
game.updateBoard();
|
game.updateBoard();
|
||||||
}
|
}
|
||||||
|
@ -99,13 +104,13 @@ class Board {
|
||||||
removeStone(st);
|
removeStone(st);
|
||||||
stuffDeleted = true;
|
stuffDeleted = true;
|
||||||
}
|
}
|
||||||
if (counter == 3 && game.isRunning()) {
|
if (counter == 3 && game.isRunning() && specialStonesEnabled) {
|
||||||
//stones[row][startPosition] = TripleSpecialStone(this);
|
stones[row][startPosition] = TripleSpecialStone(this);
|
||||||
}
|
}
|
||||||
if (counter == 4 && game.isRunning()) {
|
if (counter == 4 && game.isRunning() && specialStonesEnabled) {
|
||||||
//stones[row][startPosition] = QuadSpecialStone(this, false);
|
stones[row][startPosition] = QuadSpecialStone(this, false);
|
||||||
}
|
}
|
||||||
if (counter == 5 && game.isRunning()) {
|
if (counter == 5 && game.isRunning() && specialStonesEnabled) {
|
||||||
stones[row][startPosition] = PentaSpecialStone(this);
|
stones[row][startPosition] = PentaSpecialStone(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,13 +153,13 @@ class Board {
|
||||||
removeStone(st);
|
removeStone(st);
|
||||||
stuffDeleted = true;
|
stuffDeleted = true;
|
||||||
}
|
}
|
||||||
if (counter == 3 && game.isRunning()) {
|
if (counter == 3 && game.isRunning() && specialStonesEnabled) {
|
||||||
//stones[startPosition][column] = TripleSpecialStone(this);
|
stones[startPosition][column] = TripleSpecialStone(this);
|
||||||
}
|
}
|
||||||
if (counter == 4 && game.isRunning()) {
|
if (counter == 4 && game.isRunning() && specialStonesEnabled) {
|
||||||
//stones[startPosition][column] = QuadSpecialStone(this, true);
|
stones[startPosition][column] = QuadSpecialStone(this, true);
|
||||||
}
|
}
|
||||||
if (counter == 5 && game.isRunning()) {
|
if (counter == 5 && game.isRunning() && specialStonesEnabled) {
|
||||||
stones[startPosition][column] = PentaSpecialStone(this);
|
stones[startPosition][column] = PentaSpecialStone(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,7 +186,7 @@ class Board {
|
||||||
if (!game.isRunning()) {
|
if (!game.isRunning()) {
|
||||||
// If game is not running, just give the stones a new color
|
// If game is not running, just give the stones a new color
|
||||||
stones[sl.row][sl.column]!.stoneColor =
|
stones[sl.row][sl.column]!.stoneColor =
|
||||||
StoneColors.values[Random().nextInt(StoneColors.values.length -1)];
|
StoneColors.values[Random().nextInt(StoneColors.values.length - 1)];
|
||||||
} else {
|
} else {
|
||||||
// Otherwise mark stones as deleted
|
// Otherwise mark stones as deleted
|
||||||
stones[sl.row][sl.column] = null;
|
stones[sl.row][sl.column] = null;
|
||||||
|
@ -209,9 +214,9 @@ class Board {
|
||||||
stonesHaveFallenDown); // Continue doing so until all deleted Stones are at the top most position
|
stonesHaveFallenDown); // Continue doing so until all deleted Stones are at the top most position
|
||||||
|
|
||||||
// Then generate new stones that rain from the sky)
|
// Then generate new stones that rain from the sky)
|
||||||
for (int i = 0; i < boardSize; i++){
|
for (int i = 0; i < boardSize; i++) {
|
||||||
for (int j = 0; j < boardSize; j++){
|
for (int j = 0; j < boardSize; j++) {
|
||||||
if (stones[i][j] == null){
|
if (stones[i][j] == null) {
|
||||||
stones[i][j] = Stone();
|
stones[i][j] = Stone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:bubbletwist/game/stone/triggerable_special_stone.dart';
|
||||||
|
|
||||||
import '../enums/stone_color.dart';
|
import '../enums/stone_color.dart';
|
||||||
import 'board.dart';
|
import 'board.dart';
|
||||||
import 'i_game_consumer.dart';
|
import 'i_game_consumer.dart';
|
||||||
|
@ -108,12 +110,12 @@ class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool performSpecialStone(StoneLocation sl) {
|
bool performSpecialStone(StoneLocation sl) {
|
||||||
/*Stone? s = getStone(sl);
|
Stone? s = getStone(sl);
|
||||||
if (s is TriggerableSpecialStone) {
|
if (s is TriggerableSpecialStone) {
|
||||||
s.setActivationLocation(sl);
|
s.setActivationLocation(sl);
|
||||||
board.performSpecialStone(s, sl);
|
board.performSpecialStone(s, sl);
|
||||||
return true;
|
return true;
|
||||||
}*/
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
import 'package:bubbletwist/game/stone/stone_location.dart';
|
||||||
|
import 'package:bubbletwist/game/stone/triggerable_special_stone.dart';
|
||||||
|
|
||||||
|
import '../board.dart';
|
||||||
|
|
||||||
|
class QuadSpecialStone extends TriggerableSpecialStone {
|
||||||
|
bool vertical;
|
||||||
|
|
||||||
|
QuadSpecialStone(super.board, this.vertical);
|
||||||
|
|
||||||
|
@override
|
||||||
|
int getSpecialStoneNumber() {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void performSpecialStoneAction() {
|
||||||
|
StoneLocation sl = StoneLocation(row: 0, column: 0);
|
||||||
|
if (vertical) {
|
||||||
|
for (int i = 0; i < Board.boardSize; ++i) {
|
||||||
|
if (i == row) {
|
||||||
|
continue; // Skip Stone itself to prevent self deleting
|
||||||
|
}
|
||||||
|
sl.row = i;
|
||||||
|
sl.column = column;
|
||||||
|
|
||||||
|
board.removeStone(sl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < Board.boardSize; ++i) {
|
||||||
|
if (i == column) {
|
||||||
|
continue; // Skip Stone itself to prevent self deleting
|
||||||
|
}
|
||||||
|
sl.row = row;
|
||||||
|
sl.column = i;
|
||||||
|
board.removeStone(sl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,14 @@
|
||||||
|
import 'package:bubbletwist/enums/stone_color.dart';
|
||||||
|
|
||||||
import '../board.dart';
|
import '../board.dart';
|
||||||
import 'stone.dart';
|
import 'stone.dart';
|
||||||
|
|
||||||
abstract class SpecialStone extends Stone {
|
abstract class SpecialStone extends Stone {
|
||||||
final Board board;
|
final Board board;
|
||||||
|
|
||||||
SpecialStone(this.board);
|
SpecialStone(this.board) {
|
||||||
|
setColor(StoneColors.special);
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the associated number of the special stone
|
/// Returns the associated number of the special stone
|
||||||
int getSpecialStoneNumber();
|
int getSpecialStoneNumber();
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
import 'package:bubbletwist/game/stone/special_stone.dart';
|
||||||
|
import 'package:bubbletwist/game/stone/stone_location.dart';
|
||||||
|
|
||||||
|
abstract class TriggerableSpecialStone extends SpecialStone {
|
||||||
|
late int row;
|
||||||
|
late int column;
|
||||||
|
|
||||||
|
TriggerableSpecialStone(super.board);
|
||||||
|
|
||||||
|
void setActivationLocation(StoneLocation sl) {
|
||||||
|
row = sl.row;
|
||||||
|
column = sl.column;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
import 'package:bubbletwist/game/stone/stone_location.dart';
|
||||||
|
import 'package:bubbletwist/game/stone/triggerable_special_stone.dart';
|
||||||
|
|
||||||
|
class TripleSpecialStone extends TriggerableSpecialStone {
|
||||||
|
TripleSpecialStone(super.board);
|
||||||
|
|
||||||
|
@override
|
||||||
|
int getSpecialStoneNumber() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void performSpecialStoneAction() {
|
||||||
|
// remove stone checks the array bounds
|
||||||
|
board.removeStone(StoneLocation(row: row + 1, column: column));
|
||||||
|
board.removeStone(StoneLocation(row: row + 1, column: column + 1));
|
||||||
|
board.removeStone(StoneLocation(row: row + 1, column: column - 1));
|
||||||
|
board.removeStone(StoneLocation(row: row, column: column));
|
||||||
|
board.removeStone(StoneLocation(row: row, column: column + 1));
|
||||||
|
board.removeStone(StoneLocation(row: row, column: column - 1));
|
||||||
|
board.removeStone(StoneLocation(row: row - 1, column: column));
|
||||||
|
board.removeStone(StoneLocation(row: row - 1, column: column + 1));
|
||||||
|
board.removeStone(StoneLocation(row: row - 1, column: column - 1));
|
||||||
|
}
|
||||||
|
}
|
|
@ -360,8 +360,15 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
|
|
||||||
void handleTap(int row, int col) {
|
void handleTap(int row, int col) {
|
||||||
if (sl1 == null) {
|
if (sl1 == null) {
|
||||||
sl1 = StoneLocation(row: row, column: col);
|
if (game.getStoneColor(StoneLocation(row: row, column: col)) ==
|
||||||
return;
|
StoneColors.special) {
|
||||||
|
game.performSpecialStone(StoneLocation(row: row, column: col));
|
||||||
|
sl1 = null;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
sl1 = StoneLocation(row: row, column: col);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
game.swapStones(sl1!, StoneLocation(row: row, column: col));
|
game.swapStones(sl1!, StoneLocation(row: row, column: col));
|
||||||
sl1 = null;
|
sl1 = null;
|
||||||
|
|
Loading…
Reference in New Issue