Compare commits
2 Commits
HAAAAAAAAA
...
b7f9ca8a98
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7f9ca8a98 | ||
| f47e4cc309 |
28
app/src/main/java/gui/AnimatedBackground.java
Normal file
28
app/src/main/java/gui/AnimatedBackground.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
|
import imgui.ImGui;
|
||||||
|
import imgui.ImVec2;
|
||||||
|
import imgui.flag.ImGuiWindowFlags;
|
||||||
|
|
||||||
|
public class AnimatedBackground {
|
||||||
|
|
||||||
|
private float backgroundOffset = 0;
|
||||||
|
|
||||||
|
public AnimatedBackground() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render() {
|
||||||
|
backgroundOffset += ImGui.getIO().getDeltaTime() / 10.0f * Options.BackgroundSpeed;
|
||||||
|
var displaySize = ImGui.getIO().getDisplaySize();
|
||||||
|
ImGui.setNextWindowPos(new ImVec2(0.0f, 0.0f));
|
||||||
|
ImGui.setNextWindowSize(displaySize);
|
||||||
|
ImGui.begin("Background", null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove
|
||||||
|
| ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBackground
|
||||||
|
| ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoInputs);
|
||||||
|
ImGui.image(Images.BACKGROUND, displaySize, new ImVec2(backgroundOffset, backgroundOffset),
|
||||||
|
new ImVec2(1.0f + backgroundOffset, 1.0f + backgroundOffset));
|
||||||
|
ImGui.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,5 +3,6 @@ package gui;
|
|||||||
public class Options {
|
public class Options {
|
||||||
|
|
||||||
public static Symbols Symboles = Symbols.Numbers;
|
public static Symbols Symboles = Symbols.Numbers;
|
||||||
|
public static float BackgroundSpeed = 1.0f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import imgui.type.ImInt;
|
|||||||
public class OptionsMenu extends BaseView {
|
public class OptionsMenu extends BaseView {
|
||||||
|
|
||||||
private ImInt currentValue = new ImInt();
|
private ImInt currentValue = new ImInt();
|
||||||
|
private float backgroundSpeed[] = new float[]{Options.BackgroundSpeed};
|
||||||
|
|
||||||
public OptionsMenu(StateMachine stateMachine) {
|
public OptionsMenu(StateMachine stateMachine) {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
@@ -19,6 +20,9 @@ public class OptionsMenu extends BaseView {
|
|||||||
if(ImGui.combo("Jeu de symboles", currentValue, Symbols.getSymbolsNames())){
|
if(ImGui.combo("Jeu de symboles", currentValue, Symbols.getSymbolsNames())){
|
||||||
Options.Symboles = Symbols.values()[currentValue.get()];
|
Options.Symboles = Symbols.values()[currentValue.get()];
|
||||||
}
|
}
|
||||||
|
if(ImGui.sliderFloat("Vitesse d'animation de l'arrière plan", backgroundSpeed, 0.0f, 10.0f)){
|
||||||
|
Options.BackgroundSpeed = backgroundSpeed[0];
|
||||||
|
}
|
||||||
renderReturnButton();
|
renderReturnButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package gui.menu;
|
|||||||
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import gui.Images;
|
import gui.AnimatedBackground;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.ImVec2;
|
import imgui.ImVec2;
|
||||||
import imgui.flag.ImGuiKey;
|
import imgui.flag.ImGuiKey;
|
||||||
@@ -11,9 +11,11 @@ import imgui.flag.ImGuiWindowFlags;
|
|||||||
public class StateMachine {
|
public class StateMachine {
|
||||||
|
|
||||||
private final Stack<BaseView> menus;
|
private final Stack<BaseView> menus;
|
||||||
|
private final AnimatedBackground background;
|
||||||
|
|
||||||
public StateMachine() {
|
public StateMachine() {
|
||||||
this.menus = new Stack<>();
|
this.menus = new Stack<>();
|
||||||
|
this.background = new AnimatedBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
@@ -40,12 +42,7 @@ public class StateMachine {
|
|||||||
|
|
||||||
public void render() {
|
public void render() {
|
||||||
var displaySize = ImGui.getIO().getDisplaySize();
|
var displaySize = ImGui.getIO().getDisplaySize();
|
||||||
ImGui.setNextWindowPos(new ImVec2(0.0f, 0.0f));
|
this.background.render();
|
||||||
ImGui.setNextWindowSize(displaySize);
|
|
||||||
ImGui.begin("Background", null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove
|
|
||||||
| ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoInputs);
|
|
||||||
ImGui.image(Images.BACKGROUND, displaySize, new ImVec2(0, 0));
|
|
||||||
ImGui.end();
|
|
||||||
ImGui.setNextWindowPos(new ImVec2(0.0f, 0.0f));
|
ImGui.setNextWindowPos(new ImVec2(0.0f, 0.0f));
|
||||||
ImGui.setNextWindowSize(displaySize);
|
ImGui.setNextWindowSize(displaySize);
|
||||||
ImGui.begin("##Main Window", null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove
|
ImGui.begin("##Main Window", null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ public class MixedSolver implements Solver{
|
|||||||
* backtracking.
|
* backtracking.
|
||||||
*
|
*
|
||||||
* @param doku MultiDoku, MultiDoku à résoudre.
|
* @param doku MultiDoku, MultiDoku à résoudre.
|
||||||
* @param rand Random, pour tester aléatoirement les symboles, lors du
|
|
||||||
* backtracking.
|
|
||||||
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
|
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -40,29 +38,20 @@ public class MixedSolver implements Solver{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Cell> cellsToFill = doku.getEmptyCells();
|
Cell cellToFill = doku.getFirstEmptyCell();
|
||||||
if (cellsToFill.isEmpty()) {
|
if (cellToFill == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Règles de déduction
|
|
||||||
for (Cell cellToFill : cellsToFill) {
|
|
||||||
|
|
||||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
|
||||||
if (possibleSymbols.size() != 1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
|
||||||
|
|
||||||
return this.solve(doku);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si ça ne marche pas
|
|
||||||
// On fait du backtracking
|
|
||||||
Cell cellToFill = doku.getRandomEmptyCell(rand);
|
|
||||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||||
|
|
||||||
|
if (possibleSymbols.size() == 1) {
|
||||||
|
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
||||||
|
if (this.solve(doku)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (!possibleSymbols.isEmpty()) {
|
while (!possibleSymbols.isEmpty()) {
|
||||||
int nextPossibleSymbolIndex = rand.nextInt(possibleSymbols.size());
|
int nextPossibleSymbolIndex = rand.nextInt(possibleSymbols.size());
|
||||||
int nextSymbol = possibleSymbols.get(nextPossibleSymbolIndex);
|
int nextSymbol = possibleSymbols.get(nextPossibleSymbolIndex);
|
||||||
@@ -71,9 +60,9 @@ public class MixedSolver implements Solver{
|
|||||||
if (this.solve(doku)) {
|
if (this.solve(doku)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||||
possibleSymbols.remove(nextPossibleSymbolIndex);
|
possibleSymbols.remove(nextPossibleSymbolIndex);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ public class SudokuFactory {
|
|||||||
cellsThatCanBeEmptied.remove(cellToEmpty);
|
cellsThatCanBeEmptied.remove(cellToEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newDokuFromFilledOne(doku, --nbCellsToEmpty, solver);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -181,21 +181,22 @@ public class SudokuFactory {
|
|||||||
* @param sudoku2 Sudoku, second sudoku à connecter.
|
* @param sudoku2 Sudoku, second sudoku à connecter.
|
||||||
* @param offset Coordinate, décalage entre les deux Sudokus.
|
* @param offset Coordinate, décalage entre les deux Sudokus.
|
||||||
*/
|
*/
|
||||||
private static void linkSquareSudokus(Sudoku sudoku1, Sudoku sudoku2, Coordinate offset) {
|
private static void linkRectangleSudokus(Sudoku sudoku1, Sudoku sudoku2, Coordinate offset) {
|
||||||
int blockWidth = sudoku1.getBlockWidth();
|
int blockWidth = sudoku1.getBlockWidth();
|
||||||
for (int dx = 0; dx < blockWidth; dx++) {
|
int blockHeight = sudoku1.getSize() / blockWidth;
|
||||||
|
for (int dx = 0; dx < blockHeight; dx++) {
|
||||||
for (int dy = 0; dy < blockWidth; dy++) {
|
for (int dy = 0; dy < blockWidth; dy++) {
|
||||||
int block1X = dx + offset.getX();
|
int block1X = dx + offset.getX();
|
||||||
int block1Y = dy + offset.getY();
|
int block1Y = dy + offset.getY();
|
||||||
int block2X = dx;
|
int block2X = dx;
|
||||||
int block2Y = dy;
|
int block2Y = dy;
|
||||||
|
|
||||||
if ((block1X < blockWidth) && (block1X >= 0) && (block1Y >= 0) && (block1Y < blockWidth)) {
|
if ((block1X < blockHeight) && (block1X >= 0) && (block1Y >= 0) && (block1Y < blockWidth)) {
|
||||||
Block block1 = sudoku1.getBlocks().get(block1Y * blockWidth + block1X);
|
Block block1 = sudoku1.getBlocks().get(block1Y * blockHeight + block1X);
|
||||||
Block block2 = sudoku2.getBlocks().get(block2Y * blockWidth + block2X);
|
Block block2 = sudoku2.getBlocks().get(block2Y * blockHeight + block2X);
|
||||||
|
|
||||||
// on remplace le bloc
|
// on remplace le bloc
|
||||||
sudoku2.getBlocks().set(block2Y * blockWidth + block2X, block1);
|
sudoku2.getBlocks().set(block2Y * blockHeight + block2X, block1);
|
||||||
block1.getSudokus().add(sudoku2);
|
block1.getSudokus().add(sudoku2);
|
||||||
|
|
||||||
// on remplace les cellules
|
// on remplace les cellules
|
||||||
@@ -231,10 +232,10 @@ public class SudokuFactory {
|
|||||||
Sudoku sudoku4 = createSquareSudoku(size, constraints);
|
Sudoku sudoku4 = createSquareSudoku(size, constraints);
|
||||||
Sudoku sudoku5 = createSquareSudoku(size, constraints);
|
Sudoku sudoku5 = createSquareSudoku(size, constraints);
|
||||||
|
|
||||||
linkSquareSudokus(sudoku1, sudoku2, new Coordinate(1 - size, 1 - size));
|
linkRectangleSudokus(sudoku1, sudoku2, new Coordinate(1 - size, 1 - size));
|
||||||
linkSquareSudokus(sudoku1, sudoku3, new Coordinate(size - 1, 1 - size));
|
linkRectangleSudokus(sudoku1, sudoku3, new Coordinate(size - 1, 1 - size));
|
||||||
linkSquareSudokus(sudoku1, sudoku4, new Coordinate(1 - size, size - 1));
|
linkRectangleSudokus(sudoku1, sudoku4, new Coordinate(1 - size, size - 1));
|
||||||
linkSquareSudokus(sudoku1, sudoku5, new Coordinate(size - 1, size - 1));
|
linkRectangleSudokus(sudoku1, sudoku5, new Coordinate(size - 1, size - 1));
|
||||||
|
|
||||||
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
||||||
}
|
}
|
||||||
@@ -263,10 +264,10 @@ public class SudokuFactory {
|
|||||||
Sudoku sudoku4 = createRectangleSudoku(width, height, constraints);
|
Sudoku sudoku4 = createRectangleSudoku(width, height, constraints);
|
||||||
Sudoku sudoku5 = createRectangleSudoku(width, height, constraints);
|
Sudoku sudoku5 = createRectangleSudoku(width, height, constraints);
|
||||||
|
|
||||||
linkSquareSudokus(sudoku1, sudoku2, new Coordinate(1 - width, 1 - height));
|
linkRectangleSudokus(sudoku1, sudoku2, new Coordinate(1 - height, 1 - width));
|
||||||
linkSquareSudokus(sudoku1, sudoku3, new Coordinate(width - 1, 1 - height));
|
linkRectangleSudokus(sudoku1, sudoku3, new Coordinate(height - 1, 1 - width));
|
||||||
linkSquareSudokus(sudoku1, sudoku4, new Coordinate(1 - width, height - 1));
|
linkRectangleSudokus(sudoku1, sudoku4, new Coordinate(1 - height, width - 1));
|
||||||
linkSquareSudokus(sudoku1, sudoku5, new Coordinate(width - 1, height - 1));
|
linkRectangleSudokus(sudoku1, sudoku5, new Coordinate(height - 1, width - 1));
|
||||||
|
|
||||||
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
||||||
}
|
}
|
||||||
@@ -276,9 +277,6 @@ public class SudokuFactory {
|
|||||||
solver.solve(doku);
|
solver.solve(doku);
|
||||||
int nbCellsToEmpty = (int) (difficulty.getFactor() * doku.getNbCells());
|
int nbCellsToEmpty = (int) (difficulty.getFactor() * doku.getNbCells());
|
||||||
boolean successfull = newDokuFromFilledOne(doku, nbCellsToEmpty, solver);
|
boolean successfull = newDokuFromFilledOne(doku, nbCellsToEmpty, solver);
|
||||||
if (!successfull) {
|
|
||||||
throw new Exception("Canno't create this doku with this difficulty");
|
|
||||||
}
|
|
||||||
doku.setFilledCellsImmutable();
|
doku.setFilledCellsImmutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user