parent
77455796c4
commit
9e0b8ad710
@ -0,0 +1,76 @@
|
||||
:host {
|
||||
--cellSize: 50px;
|
||||
--color1: #f00;
|
||||
--color2: #0f0;
|
||||
--color3: #00f;
|
||||
--color4: #ff0;
|
||||
--color5: #f0f;
|
||||
--color6: #0ff;
|
||||
--color7: #f77;
|
||||
--color8: #7f7;
|
||||
--color9: #77f;
|
||||
}
|
||||
|
||||
.grille {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translate(-50%);
|
||||
}
|
||||
|
||||
.cell::-webkit-outer-spin-button,
|
||||
.cell::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Firefox */
|
||||
.cell[type=number] {
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
|
||||
.cell {
|
||||
height: var(--cellSize);
|
||||
width: var(--cellSize);
|
||||
text-align: center;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.grille {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.column:nth-child(-n+9) div:nth-child(-n+9) {
|
||||
border: solid 1px var(--color1);
|
||||
}
|
||||
|
||||
.column:nth-child(-n+9) div:nth-child(-n+6) {
|
||||
border: solid 1px var(--color2);
|
||||
}
|
||||
|
||||
.column:nth-child(-n+9) div:nth-child(-n+3) {
|
||||
border: solid 1px var(--color3);
|
||||
}
|
||||
|
||||
.column:nth-child(-n+6) div:nth-child(-n+9) {
|
||||
border: solid 1px var(--color4);
|
||||
}
|
||||
|
||||
.column:nth-child(-n+6) div:nth-child(-n+6) {
|
||||
border: solid 1px var(--color5);
|
||||
}
|
||||
|
||||
.column:nth-child(-n+6) div:nth-child(-n+3) {
|
||||
border: solid 1px var(--color6);
|
||||
}
|
||||
|
||||
.column:nth-child(-n+3) div:nth-child(-n+9) {
|
||||
border: solid 1px var(--color7);
|
||||
}
|
||||
|
||||
.column:nth-child(-n+3) div:nth-child(-n+6) {
|
||||
border: solid 1px var(--color8);
|
||||
}
|
||||
|
||||
.column:nth-child(-n+3) div:nth-child(-n+3) {
|
||||
border: solid 1px var(--color9);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<p>sudoku works!</p>
|
||||
|
||||
|
||||
<div class="grille">
|
||||
<div *ngFor="let row of grille" class="column">
|
||||
<div *ngFor="let cell of row" class="row">
|
||||
<input *ngIf="cell != 0" type="number" value="{{cell}}" class="cell" max="9" min="0">
|
||||
<input *ngIf="cell == 0" type="number" value="" class="cell" max="9" min="0">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button (click)="publish()">
|
||||
valider la grille
|
||||
</button>
|
||||
|
||||
<button (click)="corriger()">
|
||||
corriger la grille
|
||||
</button>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { SudokuComponent } from './sudoku.component';
|
||||
|
||||
describe('SudokuComponent', () => {
|
||||
let component: SudokuComponent;
|
||||
let fixture: ComponentFixture<SudokuComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [SudokuComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(SudokuComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,46 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { NgFor,NgIf } from '@angular/common';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { SudokuService } from '../../services/sudoku-service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-sudoku',
|
||||
standalone: true,
|
||||
imports: [RouterModule, NgFor, NgIf],
|
||||
templateUrl: './sudoku.component.html',
|
||||
styleUrl: './sudoku.component.css'
|
||||
})
|
||||
export class SudokuComponent {
|
||||
grille: number[][] = [];
|
||||
nbIndice: number = 0;
|
||||
|
||||
constructor(protected sudokuService: SudokuService, private activatedRoute: ActivatedRoute) {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
console.log(this.grille);
|
||||
}
|
||||
public publish() {
|
||||
|
||||
}
|
||||
public corriger() {
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +1,25 @@
|
||||
<h2>User list</h2>
|
||||
|
||||
<ul>
|
||||
<li *ngFor="let user of users">
|
||||
<a routerLink="/user/{{ user.id }}">{{ user.login }}</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Pseudo</th>
|
||||
<th scope="col" (click)="changeWatchedvar('nbPts')">Nombre de points</th>
|
||||
<th scope="col" (click)="changeWatchedvar('streak')">Streak</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let user of users">
|
||||
<td >{{user.login}}</td>
|
||||
<td>{{user.points}}</td>
|
||||
<td>{{user.streak}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
<br>
|
||||
<button (click)="loadPage(-1)">
|
||||
<
|
||||
</button>
|
||||
<button (click)="loadPage(1)">
|
||||
>
|
||||
</button>
|
@ -0,0 +1,75 @@
|
||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
||||
import { Injectable } from "@angular/core";
|
||||
|
||||
@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';
|
||||
|
||||
public constructor(private http: HttpClient){
|
||||
this.correction = [];
|
||||
this.easy = [];
|
||||
this.medium = [];
|
||||
this.hard = [];
|
||||
|
||||
this.http.get<string>(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.correction = [[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 = [[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 = [[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 = [[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[][]{
|
||||
return this.correction;
|
||||
}
|
||||
|
||||
public getEasy(): number[][]{
|
||||
return this.easy;
|
||||
}
|
||||
|
||||
public getMedium(): number[][]{
|
||||
return this.medium;
|
||||
}
|
||||
|
||||
public getHard(): number[][]{
|
||||
return this.hard;
|
||||
}
|
||||
|
||||
public validationGrille(userGrille: number[][]): number[][] {
|
||||
let validation: number[][] = [];
|
||||
for (let x:number = 0; x<userGrille.length; x++) {
|
||||
validation.push([]);
|
||||
for (let y:number = 0; y<userGrille[x].length; y++) {
|
||||
if (userGrille[x][y] == 0) {
|
||||
validation[x].push(0);
|
||||
}
|
||||
if (userGrille[x][y] == this.correction[x][y]) {
|
||||
validation[x].push(1);
|
||||
} else {
|
||||
validation[x].push(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return validation;
|
||||
}
|
||||
|
||||
public isCorrect(userGrille: number[][]): boolean {
|
||||
for (let x:number = 0; x<userGrille.length; x++) {
|
||||
for (let y:number = 0; y<userGrille[x].length; y++) {
|
||||
if (userGrille[x][y] == 0 || userGrille[x][y] != this.correction[x][y]) return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue