Added Special Stones
parent
7b0b1031c9
commit
6f0470f530
|
@ -1,6 +1,8 @@
|
|||
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/triple_special_stone.dart';
|
||||
|
||||
import '../enums/stone_color.dart';
|
||||
import 'game.dart';
|
||||
|
@ -11,13 +13,16 @@ import 'stone/stone_location.dart';
|
|||
class Board {
|
||||
static const int boardSize = 8;
|
||||
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) {
|
||||
// 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
|
||||
while (checkBoard()){}
|
||||
while (checkBoard()) {}
|
||||
}
|
||||
|
||||
void updateBoard() {
|
||||
game.updateBoard();
|
||||
}
|
||||
|
@ -99,13 +104,13 @@ class Board {
|
|||
removeStone(st);
|
||||
stuffDeleted = true;
|
||||
}
|
||||
if (counter == 3 && game.isRunning()) {
|
||||
//stones[row][startPosition] = TripleSpecialStone(this);
|
||||
if (counter == 3 && game.isRunning() && specialStonesEnabled) {
|
||||
stones[row][startPosition] = TripleSpecialStone(this);
|
||||
}
|
||||
if (counter == 4 && game.isRunning()) {
|
||||
//stones[row][startPosition] = QuadSpecialStone(this, false);
|
||||
if (counter == 4 && game.isRunning() && specialStonesEnabled) {
|
||||
stones[row][startPosition] = QuadSpecialStone(this, false);
|
||||
}
|
||||
if (counter == 5 && game.isRunning()) {
|
||||
if (counter == 5 && game.isRunning() && specialStonesEnabled) {
|
||||
stones[row][startPosition] = PentaSpecialStone(this);
|
||||
}
|
||||
}
|
||||
|
@ -148,13 +153,13 @@ class Board {
|
|||
removeStone(st);
|
||||
stuffDeleted = true;
|
||||
}
|
||||
if (counter == 3 && game.isRunning()) {
|
||||
//stones[startPosition][column] = TripleSpecialStone(this);
|
||||
if (counter == 3 && game.isRunning() && specialStonesEnabled) {
|
||||
stones[startPosition][column] = TripleSpecialStone(this);
|
||||
}
|
||||
if (counter == 4 && game.isRunning()) {
|
||||
//stones[startPosition][column] = QuadSpecialStone(this, true);
|
||||
if (counter == 4 && game.isRunning() && specialStonesEnabled) {
|
||||
stones[startPosition][column] = QuadSpecialStone(this, true);
|
||||
}
|
||||
if (counter == 5 && game.isRunning()) {
|
||||
if (counter == 5 && game.isRunning() && specialStonesEnabled) {
|
||||
stones[startPosition][column] = PentaSpecialStone(this);
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +186,7 @@ class Board {
|
|||
if (!game.isRunning()) {
|
||||
// If game is not running, just give the stones a new color
|
||||
stones[sl.row][sl.column]!.stoneColor =
|
||||
StoneColors.values[Random().nextInt(StoneColors.values.length -1)];
|
||||
StoneColors.values[Random().nextInt(StoneColors.values.length - 1)];
|
||||
} else {
|
||||
// Otherwise mark stones as deleted
|
||||
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
|
||||
|
||||
// Then generate new stones that rain from the sky)
|
||||
for (int i = 0; i < boardSize; i++){
|
||||
for (int j = 0; j < boardSize; j++){
|
||||
if (stones[i][j] == null){
|
||||
for (int i = 0; i < boardSize; i++) {
|
||||
for (int j = 0; j < boardSize; j++) {
|
||||
if (stones[i][j] == null) {
|
||||
stones[i][j] = Stone();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:bubbletwist/game/stone/triggerable_special_stone.dart';
|
||||
|
||||
import '../enums/stone_color.dart';
|
||||
import 'board.dart';
|
||||
import 'i_game_consumer.dart';
|
||||
|
@ -108,12 +110,12 @@ class Game {
|
|||
}
|
||||
|
||||
bool performSpecialStone(StoneLocation sl) {
|
||||
/*Stone? s = getStone(sl);
|
||||
Stone? s = getStone(sl);
|
||||
if (s is TriggerableSpecialStone) {
|
||||
s.setActivationLocation(sl);
|
||||
board.performSpecialStone(s, sl);
|
||||
return true;
|
||||
}*/
|
||||
}
|
||||
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 'stone.dart';
|
||||
|
||||
abstract class SpecialStone extends Stone {
|
||||
final Board board;
|
||||
|
||||
SpecialStone(this.board);
|
||||
SpecialStone(this.board) {
|
||||
setColor(StoneColors.special);
|
||||
}
|
||||
|
||||
/// Returns the associated number of the special stone
|
||||
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) {
|
||||
if (sl1 == null) {
|
||||
sl1 = StoneLocation(row: row, column: col);
|
||||
return;
|
||||
if (game.getStoneColor(StoneLocation(row: row, column: col)) ==
|
||||
StoneColors.special) {
|
||||
game.performSpecialStone(StoneLocation(row: row, column: col));
|
||||
sl1 = null;
|
||||
return;
|
||||
} else {
|
||||
sl1 = StoneLocation(row: row, column: col);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
game.swapStones(sl1!, StoneLocation(row: row, column: col));
|
||||
sl1 = null;
|
||||
|
|
Loading…
Reference in New Issue