diff --git a/backend/backend/Models/Game.cs b/backend/backend/Models/Game.cs index 8ca1638..22770fd 100755 --- a/backend/backend/Models/Game.cs +++ b/backend/backend/Models/Game.cs @@ -14,7 +14,7 @@ public class Game { public int Hints { get; set; } public ushort[]? Hand { get; set; } public ushort[]? Deck { get; set; } - public ushort[]? Found { get; set; } + public ushort[] Found { get; set; } = Array.Empty(); public void ShuffleDeck() { if (Deck == null) return; @@ -108,7 +108,10 @@ public class Game { // (From the top may cause the indices to be off by one) if (remove) { foreach (var index in indices.OrderByDescending(i => i)) { - Console.WriteLine(Hand.Length); + var foundList = Found.ToList(); + foundList.Add(Hand[index]); + Found = foundList.ToArray(); + if (Hand.Length < 13) { ReplaceCardInHand(index); diff --git a/frontend/src/app/finish-screen/finish-screen.component.html b/frontend/src/app/finish-screen/finish-screen.component.html new file mode 100644 index 0000000..c3c7d10 --- /dev/null +++ b/frontend/src/app/finish-screen/finish-screen.component.html @@ -0,0 +1 @@ +

finish-screen works!

diff --git a/frontend/src/app/finish-screen/finish-screen.component.scss b/frontend/src/app/finish-screen/finish-screen.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/finish-screen/finish-screen.component.spec.ts b/frontend/src/app/finish-screen/finish-screen.component.spec.ts new file mode 100644 index 0000000..94a5875 --- /dev/null +++ b/frontend/src/app/finish-screen/finish-screen.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { FinishScreenComponent } from './finish-screen.component'; + +describe('FinishScreenComponent', () => { + let component: FinishScreenComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [FinishScreenComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(FinishScreenComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/finish-screen/finish-screen.component.ts b/frontend/src/app/finish-screen/finish-screen.component.ts new file mode 100644 index 0000000..bdca5e1 --- /dev/null +++ b/frontend/src/app/finish-screen/finish-screen.component.ts @@ -0,0 +1,11 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-finish-screen', + imports: [], + templateUrl: './finish-screen.component.html', + styleUrl: './finish-screen.component.scss' +}) +export class FinishScreenComponent { + +} diff --git a/frontend/src/app/game/game.component.html b/frontend/src/app/game/game.component.html index 233f105..d6779d1 100755 --- a/frontend/src/app/game/game.component.html +++ b/frontend/src/app/game/game.component.html @@ -1,61 +1,98 @@ -
-
-
- @for(card of gameService.hand; track card.id) { - - } +@if(gameService.finishedAt) { +
+

Fin.

+
+
+ Started on + {{ gameService.startDate | date:'dd-MM-YYYY HH:mm' }} +
+
+ Finished on + {{ gameService.finishedAt | date:'dd-MM-YYYY HH:mm' }} +
+ +
+ Incorrect Matches + {{ gameService.stats().fails }} +
+
+ Hints Requested + {{ gameService.stats().hints }} +
-
-
- - -
-

Hint

- @for(card of hint; track card.id) { - - } -
- -

- Deck Size - {{ gameService.stats().size }} -

-

- Incorrect Matches - {{ gameService.stats().fails }} -

-

- Started on - {{ gameService.stats().dateStarted | date:'dd-MM-YYYY HH:mm' }} -

-
-

Upcoming Cards

-
- @for(card of gameService.deck; track card.id) { - - } +
+ +
+
+} + +
+
+
+ @for(card of gameService.hand; track card.id) { + + }
-
-

Available Sets

-
- @for(row of this.gameService.possibleSets; track row) { + +
+
+ + +
+

Hint

+ @for(card of hint; track card.id) { + + } +
+ +

+ Deck Size + {{ gameService.stats().size }} +

+

+ Incorrect Matches + {{ gameService.stats().fails }} +

+

+ Hints Requested + {{ gameService.stats().hints }} +

+

+ Started on + {{ gameService.stats().dateStarted | date:'dd-MM-YYYY HH:mm' }} +

+ +
+

Upcoming Cards

+
+ @for(card of gameService.deck; track card.id) { + + } +
+ +
+
+

Available Sets

+
+ @for(row of this.gameService.possibleSets; track row) {

Set {{$index + 1}}

@for(card of row; track card.id) { @@ -67,9 +104,27 @@ /> }
- } -
+ } +
+
+
+

Found Sets

+
+ @for(row of this.gameService.foundSets; track row) { +
+

Set {{$index + 1}}

+ @for(card of row; track card.id) { + + } +
+ } +
+
+
-
-
\ No newline at end of file +
\ No newline at end of file diff --git a/frontend/src/service/game/game.service.ts b/frontend/src/service/game/game.service.ts index a65a0f7..c578d10 100755 --- a/frontend/src/service/game/game.service.ts +++ b/frontend/src/service/game/game.service.ts @@ -7,11 +7,14 @@ import axios from 'axios'; export class GameService { public deck: Card[] = []; public hand: Card[] = []; + public foundSets: Card[][] = []; public possibleSets: Card[][] = []; - public gameId: number = 0; public fails: number = 0; + public hints: number = 0; + public gameId: number = 0; public startDate: Date = new Date(); + public finishedAt?: Date; public selectedCards: Card[] = []; constructor() { @@ -25,7 +28,7 @@ export class GameService { public stats(): any { const formattedDate = `${this.startDate.getDate().toString().padStart(2, '0')}-${(this.startDate.getMonth() + 1).toString().padStart(2, '0')}-${this.startDate.getFullYear()} ${this.startDate.getHours().toString().padStart(2, '0')}:${this.startDate.getMinutes().toString().padStart(2, '0')}`; - return { size: this.deck.length, fails: this.fails, dateStarted: formattedDate }; + return { size: this.deck.length, fails: this.fails, hints: this.hints, dateStarted: formattedDate }; } public async initializeExistingGame(gameId: string): Promise { @@ -39,6 +42,13 @@ export class GameService { }); this.startDate = new Date(req.data.startedAt); this.fails = req.data.fails; + this.hints = req.data.hints; + this.finishedAt = req.data.finishedAt; + this.foundSets = []; + for (let i = 0; i < req.data.found.length; i += 3) { + this.foundSets.push(req.data.found.slice(i, i + 3).map((card: number) => toCard(card))); + } + this.gameId = req.data.id; await this.updateSets(); @@ -58,7 +68,13 @@ export class GameService { this.startDate = new Date(res.data.startedAt); this.fails = res.data.fails; + this.hints = res.data.hints; this.gameId = res.data.id; + this.finishedAt = res.data.finishedAt; + this.foundSets = []; + for (let i = 0; i < res.data.newState.found.length; i += 3) { + this.foundSets.push(res.data.newState.found.slice(i, i + 3).map((card: number) => toCard(card))); + } await this.updateSets(); @@ -84,27 +100,33 @@ export class GameService { } public async updateSets(): Promise { - const req = await axios.get('http://localhost:5224/api/v1/Games/SetsInHand/' + this.gameId); - const cards = req.data.map((set: number[]) => set.map((card: number) => this.hand[card])); + const req = await axios.get(`http://localhost:5224/api/v1/Games/SetsInHand/${this.gameId}`); + const cards = req.data + .map((set: number[]) => + set.map((card: number) => this.hand[card]) + ); this.possibleSets = cards; return cards; } - private isSet(cards: number[]): boolean { - console.log(this.possibleSets); - // return (['shape', 'color', 'count', 'shade'] as (keyof Card)[]).every(attr => { - // const values = new Set([card1[attr], card2[attr], card3[attr]]); - // return values.size === 1 || values.size === 3; - // }); - this.selectedCards = []; - axios.post('http://localhost:5224/api/v1/Games/CheckSet/' + this.gameId, cards).then((response) => { + this.selectedCards = []; + + axios.post(`http://localhost:5224/api/v1/Games/CheckSet/${this.gameId}`, cards).then((response) => { this.hand = response.data.newState.hand.map((card: number) => toCard(card)); this.deck = response.data.newState.deck.map((card: number) => toCard(card)); this.fails = response.data.newState.fails; + this.hints = response.data.newState.hints; + this.finishedAt = response.data.newState.finishedAt; + this.foundSets = []; + for (let i = 0; i < response.data.newState.found.length; i += 3) { + this.foundSets.push(response.data.newState.found.slice(i, i + 3).map((card: number) => toCard(card))); + } + this.updateSets(); + return response.data.isSet; });