Skip to content
Snippets Groups Projects
Commit 1d91fff4 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Normalize game architecture

parent a07e3de4
No related branches found
No related tags found
1 merge request!40Resolve "Normalize game architecture"
Pipeline #5692 passed
Showing
with 64 additions and 50 deletions
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.0.39 app.versionName=0.1.0
app.versionCode=39 app.versionCode=40
{ {
"app_name": "Colors", "app_name": "Colors",
"bottom_nav_home": "Game",
"bottom_nav_settings": "Settings",
"bottom_nav_about": "About",
"settings_title": "Settings", "settings_title": "Settings",
"settings_label_theme": "Theme mode", "settings_label_theme": "Theme mode",
"about_title": "About", "about_title": "About",
"about_content": "Colors, a colorful flood game.", "about_content": "Colors, a colorful flood game.",
"about_version": "Version: {version}" "about_version": "Version: {version}",
"": ""
} }
{ {
"app_name": "Colors", "app_name": "Couleurs",
"bottom_nav_home": "Jeu",
"bottom_nav_settings": "Réglages",
"bottom_nav_about": "Infos",
"settings_title": "Réglages", "settings_title": "Réglages",
"settings_label_theme": "Thème de couleurs", "settings_label_theme": "Thème de couleurs",
"about_title": "Informations", "about_title": "Informations",
"about_content": "Colors, un jeu de remplissage haut en couleurs.", "about_content": "Colors, un jeu de remplissage haut en couleurs.",
"about_version": "Version : {version}" "about_version": "Version : {version}",
"": ""
} }
File moved
assets/ui/button_delete_saved_game.png

5.68 KiB

assets/ui/button_resume_game.png

3.57 KiB

File moved
File moved
File moved
assets/ui/placeholder.png

170 B

Improve/normalize game architecture.
Amélioration/normalisation de l'architecture du jeu.
File moved
...@@ -78,4 +78,9 @@ class DefaultGameSettings { ...@@ -78,4 +78,9 @@ class DefaultGameSettings {
return values[parameterLevel] ?? return values[parameterLevel] ??
getMovesCountLimitDeltaFromLevelCode(DefaultGameSettings.defaultDifficultyLevelValue); getMovesCountLimitDeltaFromLevelCode(DefaultGameSettings.defaultDifficultyLevelValue);
} }
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
} }
...@@ -25,4 +25,9 @@ class DefaultGlobalSettings { ...@@ -25,4 +25,9 @@ class DefaultGlobalSettings {
printlog('Did not find any available value for global parameter "$parameterCode".'); printlog('Did not find any available value for global parameter "$parameterCode".');
return []; return [];
} }
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
} }
...@@ -6,12 +6,10 @@ import 'package:colors/ui/screens/page_game.dart'; ...@@ -6,12 +6,10 @@ import 'package:colors/ui/screens/page_game.dart';
import 'package:colors/ui/screens/page_settings.dart'; import 'package:colors/ui/screens/page_settings.dart';
class MenuItem { class MenuItem {
final String code;
final Icon icon; final Icon icon;
final Widget page; final Widget page;
const MenuItem({ const MenuItem({
required this.code,
required this.icon, required this.icon,
required this.page, required this.page,
}); });
...@@ -20,21 +18,18 @@ class MenuItem { ...@@ -20,21 +18,18 @@ class MenuItem {
class Menu { class Menu {
static const indexGame = 0; static const indexGame = 0;
static const menuItemGame = MenuItem( static const menuItemGame = MenuItem(
code: 'bottom_nav_game',
icon: Icon(UniconsLine.home), icon: Icon(UniconsLine.home),
page: PageGame(), page: PageGame(),
); );
static const indexSettings = 1; static const indexSettings = 1;
static const menuItemSettings = MenuItem( static const menuItemSettings = MenuItem(
code: 'bottom_nav_settings',
icon: Icon(UniconsLine.setting), icon: Icon(UniconsLine.setting),
page: PageSettings(), page: PageSettings(),
); );
static const indexAbout = 2; static const indexAbout = 2;
static const menuItemAbout = MenuItem( static const menuItemAbout = MenuItem(
code: 'bottom_nav_about',
icon: Icon(UniconsLine.info_circle), icon: Icon(UniconsLine.info_circle),
page: PageAbout(), page: PageAbout(),
); );
......
...@@ -39,11 +39,9 @@ final ColorScheme lightColorScheme = ColorScheme.light( ...@@ -39,11 +39,9 @@ final ColorScheme lightColorScheme = ColorScheme.light(
secondary: primarySwatch.shade500, secondary: primarySwatch.shade500,
onSecondary: Colors.white, onSecondary: Colors.white,
error: errorColor, error: errorColor,
background: textSwatch.shade200,
onBackground: textSwatch.shade500,
onSurface: textSwatch.shade500, onSurface: textSwatch.shade500,
surface: textSwatch.shade50, surface: textSwatch.shade50,
surfaceVariant: Colors.white, surfaceContainerHighest: Colors.white,
shadow: textSwatch.shade900.withOpacity(.1), shadow: textSwatch.shade900.withOpacity(.1),
); );
...@@ -52,11 +50,9 @@ final ColorScheme darkColorScheme = ColorScheme.dark( ...@@ -52,11 +50,9 @@ final ColorScheme darkColorScheme = ColorScheme.dark(
secondary: primarySwatch.shade500, secondary: primarySwatch.shade500,
onSecondary: Colors.white, onSecondary: Colors.white,
error: errorColor, error: errorColor,
background: const Color(0xFF171724),
onBackground: textSwatch.shade400,
onSurface: textSwatch.shade300, onSurface: textSwatch.shade300,
surface: const Color(0xFF262630), surface: const Color(0xFF262630),
surfaceVariant: const Color(0xFF282832), surfaceContainerHighest: const Color(0xFF282832),
shadow: textSwatch.shade900.withOpacity(.2), shadow: textSwatch.shade900.withOpacity(.2),
); );
...@@ -192,5 +188,3 @@ final ThemeData darkTheme = lightTheme.copyWith( ...@@ -192,5 +188,3 @@ final ThemeData darkTheme = lightTheme.copyWith(
), ),
), ),
); );
final ThemeData appTheme = darkTheme;
...@@ -6,17 +6,16 @@ import 'package:flutter/foundation.dart'; ...@@ -6,17 +6,16 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart'; import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:colors/models/game.dart'; import 'package:colors/models/game/game.dart';
import 'package:colors/models/settings_game.dart'; import 'package:colors/models/settings/settings_game.dart';
import 'package:colors/models/settings_global.dart'; import 'package:colors/models/settings/settings_global.dart';
import 'package:colors/utils/tools.dart';
part 'game_state.dart'; part 'game_state.dart';
class GameCubit extends HydratedCubit<GameState> { class GameCubit extends HydratedCubit<GameState> {
GameCubit() GameCubit()
: super(GameState( : super(GameState(
currentGame: Game.createNull(), currentGame: Game.createEmpty(),
)); ));
void updateState(Game game) { void updateState(Game game) {
...@@ -27,19 +26,25 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -27,19 +26,25 @@ class GameCubit extends HydratedCubit<GameState> {
void refresh() { void refresh() {
final Game game = Game( final Game game = Game(
board: state.currentGame.board, // Settings
gameSettings: state.currentGame.gameSettings, gameSettings: state.currentGame.gameSettings,
globalSettings: state.currentGame.globalSettings, globalSettings: state.currentGame.globalSettings,
// State
isRunning: state.currentGame.isRunning, isRunning: state.currentGame.isRunning,
isStarted: state.currentGame.isStarted,
isFinished: state.currentGame.isFinished, isFinished: state.currentGame.isFinished,
gameWon: state.currentGame.gameWon,
movesCount: state.currentGame.movesCount,
maxMovesCount: state.currentGame.maxMovesCount,
animationInProgress: state.currentGame.animationInProgress, animationInProgress: state.currentGame.animationInProgress,
// Base data
board: state.currentGame.board,
// Game data
maxMovesCount: state.currentGame.maxMovesCount,
movesCount: state.currentGame.movesCount,
progress: state.currentGame.progress, progress: state.currentGame.progress,
progressTotal: state.currentGame.progressTotal, progressTotal: state.currentGame.progressTotal,
progressDelta: state.currentGame.progressDelta, progressDelta: state.currentGame.progressDelta,
gameWon: state.currentGame.gameWon,
); );
// game.dump();
updateState(game); updateState(game);
} }
...@@ -48,12 +53,8 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -48,12 +53,8 @@ class GameCubit extends HydratedCubit<GameState> {
required GameSettings gameSettings, required GameSettings gameSettings,
required GlobalSettings globalSettings, required GlobalSettings globalSettings,
}) { }) {
printlog('Starting new game:'); final Game newGame = Game.createNew(
printlog('- level: ${gameSettings.difficultyLevel}'); // Settings
printlog('- size: ${gameSettings.parameterSize}');
printlog('- colors: ${gameSettings.parameterColorsCount}');
Game newGame = Game.createNew(
gameSettings: gameSettings, gameSettings: gameSettings,
globalSettings: globalSettings, globalSettings: globalSettings,
); );
...@@ -62,6 +63,8 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -62,6 +63,8 @@ class GameCubit extends HydratedCubit<GameState> {
updateState(newGame); updateState(newGame);
updateGameIsRunning(true); updateGameIsRunning(true);
refresh();
} }
void quitGame() { void quitGame() {
...@@ -69,6 +72,17 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -69,6 +72,17 @@ class GameCubit extends HydratedCubit<GameState> {
refresh(); refresh();
} }
void resumeSavedGame() {
state.currentGame.isRunning = true;
refresh();
}
void deleteSavedGame() {
state.currentGame.isRunning = false;
state.currentGame.isFinished = true;
refresh();
}
void updateCellValue(int col, int row, int value) { void updateCellValue(int col, int row, int value) {
state.currentGame.board.cells[row][col].value = value; state.currentGame.board.cells[row][col].value = value;
refresh(); refresh();
...@@ -99,6 +113,11 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -99,6 +113,11 @@ class GameCubit extends HydratedCubit<GameState> {
refresh(); refresh();
} }
void updateGameIsStarted(bool gameIsStarted) {
state.currentGame.isStarted = gameIsStarted;
refresh();
}
void updateGameIsFinished(bool gameIsFinished) { void updateGameIsFinished(bool gameIsFinished) {
state.currentGame.isFinished = gameIsFinished; state.currentGame.isFinished = gameIsFinished;
refresh(); refresh();
...@@ -110,6 +129,8 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -110,6 +129,8 @@ class GameCubit extends HydratedCubit<GameState> {
} }
fillBoardFromFirstCell(int value) { fillBoardFromFirstCell(int value) {
updateGameIsStarted(true);
List<List<int>> cellsToFill = state.currentGame.board.getSiblingFillableCells(0, 0, []); List<List<int>> cellsToFill = state.currentGame.board.getSiblingFillableCells(0, 0, []);
final int progressBeforeMove = cellsToFill.length; final int progressBeforeMove = cellsToFill.length;
...@@ -154,7 +175,7 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -154,7 +175,7 @@ class GameCubit extends HydratedCubit<GameState> {
@override @override
GameState? fromJson(Map<String, dynamic> json) { GameState? fromJson(Map<String, dynamic> json) {
Game currentGame = json['currentGame'] as Game; final Game currentGame = json['currentGame'] as Game;
return GameState( return GameState(
currentGame: currentGame, currentGame: currentGame,
......
...@@ -12,8 +12,4 @@ class GameState extends Equatable { ...@@ -12,8 +12,4 @@ class GameState extends Equatable {
List<dynamic> get props => <dynamic>[ List<dynamic> get props => <dynamic>[
currentGame, currentGame,
]; ];
Map<String, dynamic> get values => <String, dynamic>{
'currentGame': currentGame,
};
} }
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart'; import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:colors/config/default_game_settings.dart'; import 'package:colors/config/default_game_settings.dart';
import 'package:colors/models/settings_game.dart'; import 'package:colors/models/settings/settings_game.dart';
part 'settings_game_state.dart'; part 'settings_game_state.dart';
...@@ -36,6 +35,7 @@ class GameSettingsCubit extends HydratedCubit<GameSettingsState> { ...@@ -36,6 +35,7 @@ class GameSettingsCubit extends HydratedCubit<GameSettingsState> {
case DefaultGameSettings.parameterCodeColorsCount: case DefaultGameSettings.parameterCodeColorsCount:
return GameSettings.getColorsValueFromUnsafe(state.settings.parameterColorsCount); return GameSettings.getColorsValueFromUnsafe(state.settings.parameterColorsCount);
} }
return ''; return '';
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment