Added Special Stones

main
Lachfrosch 2024-06-19 23:40:31 +02:00
parent 7b0b1031c9
commit 6f0470f530
7 changed files with 118 additions and 21 deletions

View File

@ -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()) {}
}
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);
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}
}
}

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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));
}
}

View File

@ -360,8 +360,15 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
void handleTap(int row, int col) {
if (sl1 == null) {
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;