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
Branches
Tags
1 merge request!40Resolve "Normalize game architecture"
Pipeline #5692 passed
Showing
with 64 additions and 50 deletions
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.39
app.versionCode=39
app.versionName=0.1.0
app.versionCode=40
{
"app_name": "Colors",
"bottom_nav_home": "Game",
"bottom_nav_settings": "Settings",
"bottom_nav_about": "About",
"settings_title": "Settings",
"settings_label_theme": "Theme mode",
"about_title": "About",
"about_content": "Colors, a colorful flood game.",
"about_version": "Version: {version}"
"about_version": "Version: {version}",
"": ""
}
{
"app_name": "Colors",
"bottom_nav_home": "Jeu",
"bottom_nav_settings": "Réglages",
"bottom_nav_about": "Infos",
"app_name": "Couleurs",
"settings_title": "Réglages",
"settings_label_theme": "Thème de couleurs",
"about_title": "Informations",
"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 {
return values[parameterLevel] ??
getMovesCountLimitDeltaFromLevelCode(DefaultGameSettings.defaultDifficultyLevelValue);
}
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
}
......@@ -25,4 +25,9 @@ class DefaultGlobalSettings {
printlog('Did not find any available value for global parameter "$parameterCode".');
return [];
}
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
}
......@@ -6,12 +6,10 @@ import 'package:colors/ui/screens/page_game.dart';
import 'package:colors/ui/screens/page_settings.dart';
class MenuItem {
final String code;
final Icon icon;
final Widget page;
const MenuItem({
required this.code,
required this.icon,
required this.page,
});
......@@ -20,21 +18,18 @@ class MenuItem {
class Menu {
static const indexGame = 0;
static const menuItemGame = MenuItem(
code: 'bottom_nav_game',
icon: Icon(UniconsLine.home),
page: PageGame(),
);
static const indexSettings = 1;
static const menuItemSettings = MenuItem(
code: 'bottom_nav_settings',
icon: Icon(UniconsLine.setting),
page: PageSettings(),
);
static const indexAbout = 2;
static const menuItemAbout = MenuItem(
code: 'bottom_nav_about',
icon: Icon(UniconsLine.info_circle),
page: PageAbout(),
);
......
......@@ -39,11 +39,9 @@ final ColorScheme lightColorScheme = ColorScheme.light(
secondary: primarySwatch.shade500,
onSecondary: Colors.white,
error: errorColor,
background: textSwatch.shade200,
onBackground: textSwatch.shade500,
onSurface: textSwatch.shade500,
surface: textSwatch.shade50,
surfaceVariant: Colors.white,
surfaceContainerHighest: Colors.white,
shadow: textSwatch.shade900.withOpacity(.1),
);
......@@ -52,11 +50,9 @@ final ColorScheme darkColorScheme = ColorScheme.dark(
secondary: primarySwatch.shade500,
onSecondary: Colors.white,
error: errorColor,
background: const Color(0xFF171724),
onBackground: textSwatch.shade400,
onSurface: textSwatch.shade300,
surface: const Color(0xFF262630),
surfaceVariant: const Color(0xFF282832),
surfaceContainerHighest: const Color(0xFF282832),
shadow: textSwatch.shade900.withOpacity(.2),
);
......@@ -192,5 +188,3 @@ final ThemeData darkTheme = lightTheme.copyWith(
),
),
);
final ThemeData appTheme = darkTheme;
......@@ -6,17 +6,16 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:colors/models/game.dart';
import 'package:colors/models/settings_game.dart';
import 'package:colors/models/settings_global.dart';
import 'package:colors/utils/tools.dart';
import 'package:colors/models/game/game.dart';
import 'package:colors/models/settings/settings_game.dart';
import 'package:colors/models/settings/settings_global.dart';
part 'game_state.dart';
class GameCubit extends HydratedCubit<GameState> {
GameCubit()
: super(GameState(
currentGame: Game.createNull(),
currentGame: Game.createEmpty(),
));
void updateState(Game game) {
......@@ -27,19 +26,25 @@ class GameCubit extends HydratedCubit<GameState> {
void refresh() {
final Game game = Game(
board: state.currentGame.board,
// Settings
gameSettings: state.currentGame.gameSettings,
globalSettings: state.currentGame.globalSettings,
// State
isRunning: state.currentGame.isRunning,
isStarted: state.currentGame.isStarted,
isFinished: state.currentGame.isFinished,
gameWon: state.currentGame.gameWon,
movesCount: state.currentGame.movesCount,
maxMovesCount: state.currentGame.maxMovesCount,
animationInProgress: state.currentGame.animationInProgress,
// Base data
board: state.currentGame.board,
// Game data
maxMovesCount: state.currentGame.maxMovesCount,
movesCount: state.currentGame.movesCount,
progress: state.currentGame.progress,
progressTotal: state.currentGame.progressTotal,
progressDelta: state.currentGame.progressDelta,
gameWon: state.currentGame.gameWon,
);
// game.dump();
updateState(game);
}
......@@ -48,12 +53,8 @@ class GameCubit extends HydratedCubit<GameState> {
required GameSettings gameSettings,
required GlobalSettings globalSettings,
}) {
printlog('Starting new game:');
printlog('- level: ${gameSettings.difficultyLevel}');
printlog('- size: ${gameSettings.parameterSize}');
printlog('- colors: ${gameSettings.parameterColorsCount}');
Game newGame = Game.createNew(
final Game newGame = Game.createNew(
// Settings
gameSettings: gameSettings,
globalSettings: globalSettings,
);
......@@ -62,6 +63,8 @@ class GameCubit extends HydratedCubit<GameState> {
updateState(newGame);
updateGameIsRunning(true);
refresh();
}
void quitGame() {
......@@ -69,6 +72,17 @@ class GameCubit extends HydratedCubit<GameState> {
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) {
state.currentGame.board.cells[row][col].value = value;
refresh();
......@@ -99,6 +113,11 @@ class GameCubit extends HydratedCubit<GameState> {
refresh();
}
void updateGameIsStarted(bool gameIsStarted) {
state.currentGame.isStarted = gameIsStarted;
refresh();
}
void updateGameIsFinished(bool gameIsFinished) {
state.currentGame.isFinished = gameIsFinished;
refresh();
......@@ -110,6 +129,8 @@ class GameCubit extends HydratedCubit<GameState> {
}
fillBoardFromFirstCell(int value) {
updateGameIsStarted(true);
List<List<int>> cellsToFill = state.currentGame.board.getSiblingFillableCells(0, 0, []);
final int progressBeforeMove = cellsToFill.length;
......@@ -154,7 +175,7 @@ class GameCubit extends HydratedCubit<GameState> {
@override
GameState? fromJson(Map<String, dynamic> json) {
Game currentGame = json['currentGame'] as Game;
final Game currentGame = json['currentGame'] as Game;
return GameState(
currentGame: currentGame,
......
......@@ -12,8 +12,4 @@ class GameState extends Equatable {
List<dynamic> get props => <dynamic>[
currentGame,
];
Map<String, dynamic> get values => <String, dynamic>{
'currentGame': currentGame,
};
}
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.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';
......@@ -36,6 +35,7 @@ class GameSettingsCubit extends HydratedCubit<GameSettingsState> {
case DefaultGameSettings.parameterCodeColorsCount:
return GameSettings.getColorsValueFromUnsafe(state.settings.parameterColorsCount);
}
return '';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment