From e0c256d835658599ffb1f1eab5eda9151e2d774d Mon Sep 17 00:00:00 2001 From: "ludovic.castglia" Date: Tue, 15 Oct 2024 13:45:18 +0200 Subject: [PATCH] ajout logique du sudoku --- .../components/sudoku/sudoku.component.css | 56 ++++++++----------- .../components/sudoku/sudoku.component.html | 11 ++-- src/app/components/sudoku/sudoku.component.ts | 39 ++++++++++++- src/app/services/sudoku-service.ts | 49 +++++++++++----- 4 files changed, 102 insertions(+), 53 deletions(-) diff --git a/src/app/components/sudoku/sudoku.component.css b/src/app/components/sudoku/sudoku.component.css index d9ba953..b2bcd5d 100644 --- a/src/app/components/sudoku/sudoku.component.css +++ b/src/app/components/sudoku/sudoku.component.css @@ -1,14 +1,7 @@ :host { --cellSize: 50px; - --color1: #f00; - --color2: #0f0; - --color3: #00f; - --color4: #ff0; - --color5: #f0f; - --color6: #0ff; - --color7: #f77; - --color8: #7f7; - --color9: #77f; + --color: #ddd; + --color-faux: rgba(255,0,0,0.4); } .grille { @@ -33,44 +26,43 @@ width: var(--cellSize); text-align: center; outline: none; -} - -.grille { - display: flex; -} + background-color: transparent; +} -.column:nth-child(-n+9) div:nth-child(-n+9) { - border: solid 1px var(--color1); +.grid, .subgrid { + display: grid; + height: max-content; + width: max-content; } -.column:nth-child(-n+9) div:nth-child(-n+6) { - border: solid 1px var(--color2); +.sub0, .sub1, .sub2, .y0, .y1, .y2 { + grid-row: 1/2; } -.column:nth-child(-n+9) div:nth-child(-n+3) { - border: solid 1px var(--color3); +.sub3 , .sub4, .sub5, .y3, .y4, .y5{ + grid-row: 2/3; } -.column:nth-child(-n+6) div:nth-child(-n+9) { - border: solid 1px var(--color4); +.sub6 , .sub7, .sub8, .y6, .y7, .y8 { + grid-row: 3/4; } -.column:nth-child(-n+6) div:nth-child(-n+6) { - border: solid 1px var(--color5); +.sub0, .sub3, .sub6, .y0, .y3, .y6 { + grid-column: 1/2; } -.column:nth-child(-n+6) div:nth-child(-n+3) { - border: solid 1px var(--color6); +.sub1, .sub4, .sub7, .y1, .y4, .y7 { + grid-column: 2/3; } -.column:nth-child(-n+3) div:nth-child(-n+9) { - border: solid 1px var(--color7); +.sub2, .sub5, .sub8, .y2, .y5, .y8 { + grid-column: 3/4; } -.column:nth-child(-n+3) div:nth-child(-n+6) { - border: solid 1px var(--color8); +.sub1, .sub3, .sub5, .sub7 { + background-color: var(--color); } -.column:nth-child(-n+3) div:nth-child(-n+3) { - border: solid 1px var(--color9); +.faux { + background-color: var(--color-faux); } \ No newline at end of file diff --git a/src/app/components/sudoku/sudoku.component.html b/src/app/components/sudoku/sudoku.component.html index ea1649e..80ba123 100644 --- a/src/app/components/sudoku/sudoku.component.html +++ b/src/app/components/sudoku/sudoku.component.html @@ -1,11 +1,10 @@

sudoku works!

- -
-
-
- - +
+
+
+ +
diff --git a/src/app/components/sudoku/sudoku.component.ts b/src/app/components/sudoku/sudoku.component.ts index c2cc00f..af37a49 100644 --- a/src/app/components/sudoku/sudoku.component.ts +++ b/src/app/components/sudoku/sudoku.component.ts @@ -35,12 +35,47 @@ export class SudokuComponent { this.grille = this.sudokuService.getEasy(); break; } - console.log(this.grille); } public publish() { } public corriger() { - + this.resetError(); + if (this.sudokuService.isCorrect(this.getGrid())) { + alert("c'est correct mon ptit"); + return; + } + let error: number[][] = this.sudokuService.validationGrille(this.getGrid()); + for (let y=0; y