From aab6fc4af5419cbe17b99fc5f56624c160fd139a Mon Sep 17 00:00:00 2001 From: Lachfrosch Date: Mon, 17 Jun 2024 16:24:51 +0200 Subject: [PATCH] Refactoring --- lib/enums/{StoneColor.dart => stone_color.dart} | 0 lib/game/{Board.dart => board.dart} | 12 ++++++------ lib/game/{Game.dart => game.dart} | 12 ++++++------ .../{IGameConsumer.dart => i_game_consumer.dart} | 0 ...SpecialStone.dart => penta_special_stone.dart} | 12 +++++++----- .../{SpecialStone.dart => special_stone.dart} | 4 ++-- lib/game/stone/{Stone.dart => stone.dart} | 2 +- .../{StoneLocation.dart => stone_location.dart} | 0 lib/main.dart | 15 ++++++++------- 9 files changed, 30 insertions(+), 27 deletions(-) rename lib/enums/{StoneColor.dart => stone_color.dart} (100%) rename lib/game/{Board.dart => board.dart} (97%) rename lib/game/{Game.dart => game.dart} (90%) rename lib/game/{IGameConsumer.dart => i_game_consumer.dart} (100%) rename lib/game/stone/{PentaSpecialStone.dart => penta_special_stone.dart} (69%) rename lib/game/stone/{SpecialStone.dart => special_stone.dart} (85%) rename lib/game/stone/{Stone.dart => stone.dart} (93%) rename lib/game/stone/{StoneLocation.dart => stone_location.dart} (100%) diff --git a/lib/enums/StoneColor.dart b/lib/enums/stone_color.dart similarity index 100% rename from lib/enums/StoneColor.dart rename to lib/enums/stone_color.dart diff --git a/lib/game/Board.dart b/lib/game/board.dart similarity index 97% rename from lib/game/Board.dart rename to lib/game/board.dart index 85aa161..99ef9da 100644 --- a/lib/game/Board.dart +++ b/lib/game/board.dart @@ -1,12 +1,12 @@ import 'dart:math'; -import 'package:bubbletwist/game/stone/SpecialStone.dart'; +import 'package:bubbletwist/game/stone/special_stone.dart'; -import '../enums/StoneColor.dart'; -import 'Game.dart'; -import 'stone/PentaSpecialStone.dart'; -import 'stone/Stone.dart'; -import 'stone/StoneLocation.dart'; +import '../enums/stone_color.dart'; +import 'game.dart'; +import 'stone/penta_special_stone.dart'; +import 'stone/stone.dart'; +import 'stone/stone_location.dart'; class Board { static const int boardSize = 8; diff --git a/lib/game/Game.dart b/lib/game/game.dart similarity index 90% rename from lib/game/Game.dart rename to lib/game/game.dart index 4921864..d225da2 100644 --- a/lib/game/Game.dart +++ b/lib/game/game.dart @@ -1,10 +1,10 @@ import 'dart:async'; -import '../enums/StoneColor.dart'; -import 'Board.dart'; -import 'IGameConsumer.dart'; -import 'stone/Stone.dart'; -import 'stone/StoneLocation.dart'; +import '../enums/stone_color.dart'; +import 'board.dart'; +import 'i_game_consumer.dart'; +import 'stone/stone.dart'; +import 'stone/stone_location.dart'; class Game { IGameConsumer gameConsumer; @@ -67,7 +67,7 @@ class Game { points = 0; board = Board(this); gameConsumer.updateStones(); - counterTimer = Timer.periodic(Duration(seconds: 1), (_) => countDown()); + counterTimer = Timer.periodic(const Duration(seconds: 1), (_) => countDown()); gameConsumer.updatePoints(); running = true; } diff --git a/lib/game/IGameConsumer.dart b/lib/game/i_game_consumer.dart similarity index 100% rename from lib/game/IGameConsumer.dart rename to lib/game/i_game_consumer.dart diff --git a/lib/game/stone/PentaSpecialStone.dart b/lib/game/stone/penta_special_stone.dart similarity index 69% rename from lib/game/stone/PentaSpecialStone.dart rename to lib/game/stone/penta_special_stone.dart index b7e1283..7f1d346 100644 --- a/lib/game/stone/PentaSpecialStone.dart +++ b/lib/game/stone/penta_special_stone.dart @@ -1,14 +1,16 @@ -import '../Board.dart'; -import 'SpecialStone.dart'; -import 'StoneLocation.dart'; +import '../board.dart'; +import 'special_stone.dart'; +import 'stone_location.dart'; class PentaSpecialStone extends SpecialStone { - PentaSpecialStone(Board board) : super(board); + PentaSpecialStone(super.board); + @override int getSpecialStoneNumber() { return 5; } + @override void performSpecialStoneAction() { StoneLocation sl = StoneLocation(row: -1, column: -1); for (int i = 0; i < Board.boardSize; ++i) { @@ -18,7 +20,7 @@ class PentaSpecialStone extends SpecialStone { if (this == board.getStone(sl)) { continue; } - if (board.getStone(sl)?.getStoneColor() == this.getStoneColor()) { + if (board.getStone(sl)?.getStoneColor() == getStoneColor()) { board.removeStone(sl); } } diff --git a/lib/game/stone/SpecialStone.dart b/lib/game/stone/special_stone.dart similarity index 85% rename from lib/game/stone/SpecialStone.dart rename to lib/game/stone/special_stone.dart index fc06995..24aa73e 100644 --- a/lib/game/stone/SpecialStone.dart +++ b/lib/game/stone/special_stone.dart @@ -1,5 +1,5 @@ -import '../Board.dart'; -import 'Stone.dart'; +import '../board.dart'; +import 'stone.dart'; abstract class SpecialStone extends Stone { final Board board; diff --git a/lib/game/stone/Stone.dart b/lib/game/stone/stone.dart similarity index 93% rename from lib/game/stone/Stone.dart rename to lib/game/stone/stone.dart index cbaa7e8..27d9525 100644 --- a/lib/game/stone/Stone.dart +++ b/lib/game/stone/stone.dart @@ -1,6 +1,6 @@ import 'dart:math'; -import '../../enums/StoneColor.dart'; +import '../../enums/stone_color.dart'; /// Class to represent a stone on the board. class Stone { diff --git a/lib/game/stone/StoneLocation.dart b/lib/game/stone/stone_location.dart similarity index 100% rename from lib/game/stone/StoneLocation.dart rename to lib/game/stone/stone_location.dart diff --git a/lib/main.dart b/lib/main.dart index 44a297f..9c5a0e6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,10 +1,10 @@ -import 'package:bubbletwist/enums/StoneColor.dart'; -import 'package:bubbletwist/game/Game.dart'; -import 'package:bubbletwist/game/IGameConsumer.dart'; +import 'package:bubbletwist/enums/stone_color.dart'; +import 'package:bubbletwist/game/game.dart'; +import 'package:bubbletwist/game/i_game_consumer.dart'; import 'package:flutter/material.dart'; -import 'game/stone/Stone.dart'; -import 'game/stone/StoneLocation.dart'; +import 'game/stone/stone.dart'; +import 'game/stone/stone_location.dart'; void main() { runApp(const MyApp()); @@ -20,11 +20,12 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Bubble-Twist', + debugShowCheckedModeBanner: false, // This removes the debug banner theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), - home: const MyHomePage(title: 'Flutter Demo Home Page', gridSize: 8), + home: const MyHomePage(title: 'Bubble-Twist', gridSize: 8), ); } } @@ -71,7 +72,7 @@ class _MyHomePageState extends State implements IGameConsumer { title: Text(widget.title), actions: [ Padding( - padding: EdgeInsets.only(right: 20.0), + padding: const EdgeInsets.only(right: 20.0), child: Text("Time: $_time s"), ), ],