From 54041923018139f5a2abf750002e855be7cdb01f Mon Sep 17 00:00:00 2001 From: "ludovic.castglia" Date: Tue, 15 Oct 2024 15:40:57 +0200 Subject: [PATCH] modifi --- .../components/sudoku/sudoku.component.css | 4 ++ .../components/sudoku/sudoku.component.html | 12 ++++-- src/app/components/sudoku/sudoku.component.ts | 39 ++++++++++++------- src/app/services/sudoku-service.ts | 30 +++++++------- 4 files changed, 55 insertions(+), 30 deletions(-) diff --git a/src/app/components/sudoku/sudoku.component.css b/src/app/components/sudoku/sudoku.component.css index b2bcd5d..40702d6 100644 --- a/src/app/components/sudoku/sudoku.component.css +++ b/src/app/components/sudoku/sudoku.component.css @@ -65,4 +65,8 @@ .faux { background-color: var(--color-faux); +} + +input:disabled { + color: #000; } \ 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 80ba123..4853b6d 100644 --- a/src/app/components/sudoku/sudoku.component.html +++ b/src/app/components/sudoku/sudoku.component.html @@ -3,16 +3,22 @@
- +
+ +

nombre d'indice: {{nbIndice}}

+ + \ No newline at end of file diff --git a/src/app/components/sudoku/sudoku.component.ts b/src/app/components/sudoku/sudoku.component.ts index af37a49..98cf7f2 100644 --- a/src/app/components/sudoku/sudoku.component.ts +++ b/src/app/components/sudoku/sudoku.component.ts @@ -19,22 +19,12 @@ export class SudokuComponent { constructor(protected sudokuService: SudokuService, private activatedRoute: ActivatedRoute) { } + public a() { + console.log(this.sudokuService.getEasy()); + } ngOnInit() { const difficulty = this.activatedRoute.snapshot.params["difficulty"]; - switch (difficulty) { - case 'easy': - this.grille = this.sudokuService.getEasy(); - break; - case 'medium': - this.grille = this.sudokuService.getMedium(); - break; - case 'hard': - this.grille = this.sudokuService.getHard(); - break; - default: - this.grille = this.sudokuService.getEasy(); - break; - } + this.Request(difficulty); } public publish() { @@ -45,6 +35,7 @@ export class SudokuComponent { alert("c'est correct mon ptit"); return; } + this.nbIndice += 1; let error: number[][] = this.sudokuService.validationGrille(this.getGrid()); for (let y=0; y {this.Request(difficulty);console.log("a")},100); + } // lancer un await ici si possible + } } \ No newline at end of file diff --git a/src/app/services/sudoku-service.ts b/src/app/services/sudoku-service.ts index 644c7cb..5188ca9 100644 --- a/src/app/services/sudoku-service.ts +++ b/src/app/services/sudoku-service.ts @@ -1,13 +1,20 @@ import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { Injectable } from "@angular/core"; +interface apiResponseInterface { + data: number[][], + easy: number[][], + medium: number[][], + hard: number[][] +} + @Injectable() export class SudokuService { private correction: number[][]; private easy: number[][]; private medium: number[][]; private hard: number[][]; - private readonly userApiUrl = 'https://sudoku-game-and-api.netlify.app/api/sudoku'; + private readonly userApiUrl = 'https://664ba07f35bbda10987d9f99.mockapi.io/api/sudoku/1'; public constructor(private http: HttpClient){ this.correction = []; @@ -15,18 +22,12 @@ export class SudokuService { this.medium = []; this.hard = []; - this.http.get(this.userApiUrl).subscribe(apiResponse => { - let jsonResponse = JSON.parse(apiResponse); - this.correction = jsonResponse["data"]; - this.easy = jsonResponse["easy"]; - this.medium = jsonResponse["medium"]; - this.hard = jsonResponse["hard"]; + this.http.get(this.userApiUrl).subscribe(apiResponse => { + this.correction = this.transformFormat(apiResponse["data"]); + this.easy = this.transformFormat(apiResponse["easy"]); + this.medium = this.transformFormat(apiResponse["medium"]); + this.hard = this.transformFormat(apiResponse["hard"]); }); - - this.correction = this.transformFormat([[3,8,7,1,2,6,5,4,9],[2,1,6,9,4,5,8,7,3],[5,9,4,3,8,7,6,2,1],[4,2,8,5,9,1,7,3,6],[7,5,1,2,6,3,9,8,4],[6,3,9,8,7,4,1,5,2],[1,7,5,6,3,2,4,9,8],[9,4,3,7,1,8,2,6,5],[8,6,2,4,5,9,3,1,7]]); - this.easy = this.transformFormat([[3,8,0,1,2,0,5,0,9],[2,1,6,9,0,0,8,0,0],[5,9,4,3,8,0,0,0,1],[4,2,8,5,0,0,7,3,6],[7,5,1,2,6,3,9,0,4],[0,3,0,0,0,0,1,5,2],[1,7,5,6,3,0,4,9,0],[9,4,3,0,1,8,0,0,5],[8,6,0,4,5,0,3,1,7]]); - this.medium = this.transformFormat([[3,0,0,0,0,0,0,4,0],[0,1,6,0,4,5,0,0,3],[0,9,0,3,8,0,0,2,0],[4,2,0,5,0,0,0,3,6],[7,5,0,2,6,0,0,8,4],[0,0,0,0,0,0,0,5,0],[1,0,5,6,3,0,0,9,8],[0,0,0,7,1,8,0,6,5],[0,0,2,4,0,0,0,0,0]]); - this.hard = this.transformFormat([[0,0,0,1,0,0,0,0,0],[0,1,6,9,0,0,8,0,0],[0,0,0,0,8,0,6,0,0],[0,0,0,5,0,0,0,0,0],[0,0,0,0,6,3,0,0,0],[0,0,0,0,0,0,0,0,0],[0,7,5,0,0,0,0,0,0],[9,0,3,0,0,0,0,0,5],[8,0,0,0,5,0,3,1,0]]); } public getCorrection(): number[][]{ @@ -63,6 +64,7 @@ export class SudokuService { } public isCorrect(userGrille: number[][]): boolean { + // for (let x:number = 0; x