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

Shuffle available colors, improve colors theme

parent 7866301b
No related branches found
No related tags found
1 merge request!16Resolve "Shuffle available colors"
Pipeline #4950 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.14
app.versionCode=14
app.versionName=0.0.15
app.versionCode=15
Shuffle available colors, improve colors theme.
Mélange les couleurs disponibles, amélioration du thème de couleurs.
......@@ -24,6 +24,7 @@ class GameCubit extends HydratedCubit<GameState> {
final Game game = Game(
board: state.currentGame.board,
settings: state.currentGame.settings,
shuffledColors: state.currentGame.shuffledColors,
isRunning: state.currentGame.isRunning,
isFinished: state.currentGame.isFinished,
availableBlocksCount: state.currentGame.availableBlocksCount,
......
......@@ -4,10 +4,12 @@ import 'package:jeweled/models/game_board.dart';
import 'package:jeweled/models/game_cell.dart';
import 'package:jeweled/models/cell_location.dart';
import 'package:jeweled/models/game_settings.dart';
import 'package:jeweled/utils/color_theme.dart';
class Game {
final GameBoard board;
final GameSettings settings;
List<int> shuffledColors = [];
bool isRunning = false;
bool isFinished = false;
int availableBlocksCount = 0;
......@@ -17,6 +19,7 @@ class Game {
Game({
required this.board,
required this.settings,
required this.shuffledColors,
this.isRunning = false,
this.isFinished = false,
this.availableBlocksCount = 0,
......@@ -28,6 +31,7 @@ class Game {
return Game(
board: GameBoard.createNull(),
settings: GameSettings.createDefault(),
shuffledColors: shuffleColors(),
);
}
......@@ -37,10 +41,18 @@ class Game {
return Game(
board: GameBoard.createRandom(settings),
settings: settings,
shuffledColors: shuffleColors(),
isRunning: true,
);
}
static List<int> shuffleColors() {
List<int> values = new List<int>.generate(ColorTheme.getColorsCount(), (i) => i + 1);
values.shuffle();
return values;
}
GameCell getCell(CellLocation cellLocation) {
return this.board.cells[cellLocation.row][cellLocation.col];
}
......@@ -49,6 +61,11 @@ class Game {
return this.getCell(cellLocation).value;
}
int? getCellValueShuffled(CellLocation cellLocation) {
final int? value = this.getCell(cellLocation).value;
return value != null ? this.shuffledColors[value - 1] : null;
}
void updateCellValue(CellLocation locationToUpdate, int? value) {
this.board.cells[locationToUpdate.row][locationToUpdate.col].value = value;
}
......@@ -250,6 +267,7 @@ class Game {
print(' movesCount: ' + movesCount.toString());
print(' score: ' + score.toString());
print(' availableBlocksCount: ' + availableBlocksCount.toString());
print(' shuffledColors: ' + shuffledColors.toString());
print('');
}
......@@ -261,6 +279,7 @@ class Game {
return <String, dynamic>{
'board': this.board.toJson(),
'settings': this.settings.toJson(),
'shuffledColors': this.shuffledColors,
'isRunning': this.isRunning,
'isFinished': this.isFinished,
'availableBlocksCount': this.availableBlocksCount,
......
......@@ -2,7 +2,6 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:jeweled/models/game_cell.dart';
import 'package:jeweled/models/game.dart';
import 'package:jeweled/models/cell_location.dart';
import 'package:jeweled/utils/color_theme.dart';
......@@ -32,9 +31,9 @@ class GameBoardPainter extends CustomPainter {
final double x = cellSize * col;
final CellLocation cellLocation = CellLocation.go(row, col);
final GameCell cell = game.getCell(cellLocation);
if (cell.value != null) {
final int colorCode = ColorTheme.getColorCode(cell.value);
final int? cellValue = game.getCellValueShuffled(cellLocation);
if (cellValue != null) {
final int colorCode = ColorTheme.getColorCode(cellValue);
final Animation<double>? translation = this.animations[row][col];
final double y = yOrigin + (translation?.value ?? 0) * cellSize;
......
......@@ -3,26 +3,45 @@ import 'package:flutter/material.dart';
class ColorTheme {
static Map<String, List<int>> itemColors = {
'default': [
0xffffff,
0xe63a3f,
0x708cfd,
0x359c35,
0xffce2c,
0xff6f43,
0xa13cb1,
0x38ffff,
0xf2739d,
0x000000,
0x9D9D9D,
0xFFFFFF,
0xBE2633,
0xE06F8B,
0x493C2B,
0xA46422,
0xEB8931,
0xF7E26B,
0x2F484E,
0x44891A,
0xA3CE27,
0x1B2632,
0x005784,
0x31A2F2,
0xB2DCEF,
],
};
static int defaultItemColor = 0x808080;
static int getColorsCount() {
const skin = 'default';
if (itemColors.containsKey(skin) && null != itemColors[skin]) {
List<int> skinColors = itemColors[skin] ?? [];
return skinColors.length;
}
return 0;
}
static int getColorCode(int? value) {
const skin = 'default';
if (value != null && itemColors.containsKey(skin) && null != itemColors[skin]) {
List<int> skinColors = itemColors[skin] ?? [];
if (skinColors.length > value) {
return (skinColors[value]) | 0xFF000000;
return (skinColors[value % getColorsCount()]) | 0xFF000000;
}
}
return defaultItemColor | 0xFF000000;
......
......@@ -3,7 +3,7 @@ description: Jeweled Game
publish_to: 'none'
version: 0.0.14+14
version: 0.0.15+15
environment:
sdk: '^3.0.0'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment