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

Merge branch '21-normalize-game-architecture' into 'master'

Resolve "Normalize game architecture"

Closes #21

See merge request !20
parents 00eb251f 9451f9d5
Branches 22-improve-app-metadata
Tags Release_0.1.0_19
1 merge request!20Resolve "Normalize game architecture"
Pipeline #5809 passed
Showing
with 59 additions and 46 deletions
# Solitaire Game
Simple, easy, with 4 available layouts.
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.18
app.versionCode=18
app.versionName=0.1.0
app.versionCode=19
{
"app_name": "Solitaire",
"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": "Solitaire.",
"about_version": "Version: {version}"
"about_version": "Version: {version}",
"": ""
}
{
"app_name": "Solitaire",
"bottom_nav_home": "Jeu",
"bottom_nav_settings": "Réglages",
"bottom_nav_about": "Infos",
"settings_title": "Réglages",
"settings_label_theme": "Thème de couleurs",
"about_title": "Informations",
"about_content": "Solitaire.",
"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
assets/ui/game_fail.png

3.56 KiB

File moved
File moved
Improve/normalize game architecture.
Amélioration/normalisation de l'architecture du jeu.
import 'package:solitaire/utils/tools.dart';
import 'package:solitaire/utils/tools.dart';
class DefaultGameSettings {
// available game parameters codes
......@@ -21,6 +21,7 @@ class DefaultGameSettings {
// layout: default value
static const String defaultLayoutValue = layoutValueEnglish;
// available values from parameter code
static List<String> getAvailableValues(String parameterCode) {
switch (parameterCode) {
case parameterCodeLayout:
......@@ -30,4 +31,9 @@ class DefaultGameSettings {
printlog('Did not find any available value for game parameter "$parameterCode".');
return [];
}
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
}
import 'package:solitaire/utils/tools.dart';
import 'package:solitaire/utils/tools.dart';
class DefaultGlobalSettings {
// available global parameters codes
......@@ -15,6 +15,7 @@ class DefaultGlobalSettings {
// skin: default value
static const String defaultSkinValue = skinValueDefault;
// available values from parameter code
static List<String> getAvailableValues(String parameterCode) {
switch (parameterCode) {
case parameterCodeSkin:
......@@ -24,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:solitaire/ui/screens/page_game.dart';
import 'package:solitaire/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;
......@@ -2,10 +2,10 @@ import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:solitaire/models/cell_location.dart';
import 'package:solitaire/models/game.dart';
import 'package:solitaire/models/settings_game.dart';
import 'package:solitaire/models/settings_global.dart';
import 'package:solitaire/models/game/cell_location.dart';
import 'package:solitaire/models/game/game.dart';
import 'package:solitaire/models/settings/settings_game.dart';
import 'package:solitaire/models/settings/settings_global.dart';
import 'package:solitaire/utils/tools.dart';
part 'game_state.dart';
......@@ -13,7 +13,7 @@ part 'game_state.dart';
class GameCubit extends HydratedCubit<GameState> {
GameCubit()
: super(GameState(
currentGame: Game.createNull(),
currentGame: Game.createEmpty(),
));
void updateState(Game game) {
......@@ -24,11 +24,17 @@ class GameCubit extends HydratedCubit<GameState> {
void refresh() {
final Game game = Game(
// Settings
gameSettings: state.currentGame.gameSettings,
globalSettings: state.currentGame.globalSettings,
board: state.currentGame.board,
// State
isRunning: state.currentGame.isRunning,
isStarted: state.currentGame.isStarted,
isFinished: state.currentGame.isFinished,
animationInProgress: state.currentGame.animationInProgress,
// Base data
board: state.currentGame.board,
// Game data
movesCount: state.currentGame.movesCount,
remainingPegsCount: state.currentGame.remainingPegsCount,
allowedMovesCount: state.currentGame.allowedMovesCount,
......@@ -42,7 +48,8 @@ class GameCubit extends HydratedCubit<GameState> {
required GameSettings gameSettings,
required GlobalSettings globalSettings,
}) {
Game newGame = Game.createNew(
final Game newGame = Game.createNew(
// Settings
gameSettings: gameSettings,
globalSettings: globalSettings,
);
......@@ -62,12 +69,24 @@ 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 updatePegValue(CellLocation location, bool hasPeg) {
state.currentGame.board.cells[location.row][location.col].hasPeg = hasPeg;
refresh();
}
void incrementMovesCount() {
state.currentGame.isStarted = true;
state.currentGame.movesCount++;
refresh();
}
......@@ -111,7 +130,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,
};
}
......@@ -3,8 +3,7 @@ import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:solitaire/config/default_game_settings.dart';
import 'package:solitaire/models/settings_game.dart';
import 'package:solitaire/utils/tools.dart';
import 'package:solitaire/models/settings/settings_game.dart';
part 'settings_game_state.dart';
......@@ -28,14 +27,12 @@ class GameSettingsCubit extends HydratedCubit<GameSettingsState> {
case DefaultGameSettings.parameterCodeLayout:
return GameSettings.getLayoutValueFromUnsafe(state.settings.layout);
}
return '';
}
void setParameterValue(String code, String value) {
printlog('GameSettingsCubit.setParameterValue');
printlog('code: $code / value: $value');
String layout = code == DefaultGameSettings.parameterCodeLayout
final String layout = code == DefaultGameSettings.parameterCodeLayout
? value
: getParameterValue(DefaultGameSettings.parameterCodeLayout);
......@@ -46,7 +43,7 @@ class GameSettingsCubit extends HydratedCubit<GameSettingsState> {
@override
GameSettingsState? fromJson(Map<String, dynamic> json) {
String layout = json[DefaultGameSettings.parameterCodeLayout] as String;
final String layout = json[DefaultGameSettings.parameterCodeLayout] as String;
return GameSettingsState(
settings: GameSettings(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment