-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b93f104
commit 1bde8ec
Showing
12 changed files
with
541 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// NewGameSheet.swift | ||
// iosApp | ||
// | ||
// Created by Thomas Bernard on 17/07/2024. | ||
// Copyright © 2024 orgName. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import Shared | ||
|
||
struct NewGameSheet: View { | ||
|
||
@Binding var players : [PlayerModel] | ||
@Binding var selectedPlayers : Set<PlayerModel> | ||
var onCreateGame : () -> Void | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 12) { | ||
Text("Nouvelle partie") | ||
.font(.title2) | ||
.padding() | ||
|
||
Text("Sélectionner les joueurs à ajouter dans la partie") | ||
.font(.title3) | ||
.padding(.horizontal) | ||
|
||
List(players, id: \.id) { player in | ||
HStack(spacing: 12) { | ||
Image(systemName: selectedPlayers.contains(player) ? "checkmark.circle.fill" : "circle") | ||
.foregroundColor(selectedPlayers.contains(player) ? player.color.toColor() : .gray) | ||
Text(player.name) | ||
Spacer() | ||
} | ||
.contentShape(Rectangle()) | ||
.onTapGesture { | ||
if selectedPlayers.contains(player) { | ||
selectedPlayers.remove(player) | ||
} | ||
else { | ||
selectedPlayers.insert(player) | ||
} | ||
} | ||
} | ||
|
||
Button(action: { onCreateGame() }) { | ||
Text("Démarrer la partie") | ||
.frame(maxWidth: .infinity) | ||
} | ||
.buttonStyle(.borderedProminent) | ||
.controlSize(.large) | ||
.disabled(selectedPlayers.isEmpty) | ||
.padding([.horizontal, .bottom]) | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
shared/src/commonTest/kotlin/CalculateDefenderScoreUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import commons.calculateDefenderScore | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class CalculateDefenderScoreUnitTest { | ||
@Test | ||
fun calculateDefendersScoreOne(){ | ||
val takerScore = -80 | ||
val mateScore = -40 | ||
val defendersScore = calculateDefenderScore(takerScore + mateScore, numberOfDefenders = 3) | ||
|
||
assertEquals(defendersScore, 40) | ||
} | ||
|
||
@Test | ||
fun calculateDefendersScoreTwo(){ | ||
val takerScore = -160 | ||
val defendersScore = calculateDefenderScore(takerScore, numberOfDefenders = 4) | ||
|
||
assertEquals(defendersScore, 40) | ||
} | ||
|
||
@Test | ||
fun calculateDefendersScoreThree(){ | ||
val takerScore = -224 | ||
val defendersScore = calculateDefenderScore(takerScore, numberOfDefenders = 4) | ||
|
||
assertEquals(56, defendersScore) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
shared/src/commonTest/kotlin/CalculatePartnerScoreUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import commons.calculatePartnerScore | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class CalculatePartnerScoreUnitTest { | ||
|
||
@Test | ||
fun calculatePartnerScoreSmallOne(){ | ||
val takerScore = -80 | ||
val partnerScore = calculatePartnerScore(takerScore) | ||
|
||
assertEquals(partnerScore, -40) | ||
} | ||
|
||
@Test | ||
fun calculatePartnerScoreGuardOne(){ | ||
val takerScore = 200 | ||
val partnerScore = calculatePartnerScore(takerScore) | ||
|
||
assertEquals(partnerScore, 100) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
shared/src/commonTest/kotlin/CalculateTakerCalledHimSelfUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import commons.calculateTakerScore | ||
import domain.models.Bid | ||
import domain.models.Oudler | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class CalculateTakerCalledHimSelfUnitTest { | ||
@Test | ||
fun calculateTakerCalledHimSelfOne(){ | ||
val points = 30 | ||
val bid = Bid.SMALL | ||
val oudlers : List<Oudler> = listOf() | ||
|
||
val takerScore = calculateTakerScore(points, bid, oudlers.size, calledHimSelf = true) | ||
assertEquals(-204, takerScore) | ||
} | ||
|
||
@Test | ||
fun calculateTakerCalledHimSelfTwo(){ | ||
val points = 36 | ||
val bid = Bid.SMALL | ||
val oudlers : List<Oudler> = listOf(Oudler.EXCUSE) | ||
|
||
val takerScore = calculateTakerScore(points, bid, oudlers.size, calledHimSelf = true) | ||
assertEquals(-160, takerScore) | ||
} | ||
|
||
|
||
@Test | ||
fun negativeScoreSmallZeroOudler(){ | ||
val points = 23 | ||
val bid = Bid.SMALL | ||
val oudlers : List<Oudler> = listOf() | ||
|
||
val takerScore = calculateTakerScore(points, bid, oudlers.size, calledHimSelf = true) | ||
assertEquals(-232, takerScore) | ||
} | ||
|
||
@Test | ||
fun negativeScoreSmallOneOudler(){ | ||
val points = 27 | ||
val bid = Bid.SMALL | ||
val oudlers : List<Oudler> = listOf(Oudler.PETIT) | ||
|
||
val takerScore = calculateTakerScore(points, bid, oudlers.size, calledHimSelf = true) | ||
assertEquals(-196, takerScore) | ||
} | ||
|
||
@Test | ||
fun negativeScoreGuardTwoOudler(){ | ||
val points = 38 | ||
val bid = Bid.GUARD | ||
val oudlers : List<Oudler> = listOf(Oudler.PETIT, Oudler.EXCUSE) | ||
|
||
val takerScore = calculateTakerScore(points, bid, oudlers.size, calledHimSelf = true) | ||
assertEquals(-224, takerScore) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
shared/src/commonTest/kotlin/CalculateTakerScoreUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import commons.calculateTakerScore | ||
import domain.models.Bid | ||
import domain.models.Oudler | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class CalculateTakerScoreUnitTest { | ||
@Test | ||
fun checkTakerPointSmallOne(){ | ||
val points = 57 | ||
val bid = Bid.SMALL | ||
val oudlers : List<Oudler> = listOf() | ||
|
||
val score = calculateTakerScore(points, bid, oudlers.size) | ||
|
||
assertEquals(52, score) | ||
} | ||
|
||
@Test | ||
fun checkTakerPointSmallTwo(){ | ||
val points = 24 | ||
val bid = Bid.SMALL | ||
val oudlers : List<Oudler> = listOf() | ||
|
||
val score = calculateTakerScore(points, bid, oudlers.size) | ||
assertEquals(-114, score) | ||
} | ||
|
||
|
||
@Test | ||
fun checkTakerPointGuardOne(){ | ||
val points = 61 | ||
val bid = Bid.GUARD | ||
val oudlers : List<Oudler> = listOf(Oudler.EXCUSE) | ||
|
||
val score = calculateTakerScore(points, bid, oudlers.size) | ||
assertEquals(140, score) | ||
} | ||
|
||
@Test | ||
fun checkTakerPointGuardWithoutOne(){ | ||
val points = 63 | ||
val bid = Bid.GUARD_WITHOUT | ||
val oudlers : List<Oudler> = listOf(Oudler.PETIT, Oudler.EXCUSE) | ||
|
||
val score = calculateTakerScore(points, bid, oudlers.size) | ||
assertEquals(376, score) | ||
} | ||
|
||
@Test | ||
fun checkTakerPointGuardWithoutTwo(){ | ||
val points = 71 | ||
val bid = Bid.GUARD_WITHOUT | ||
val oudlers : List<Oudler> = listOf(Oudler.PETIT, Oudler.EXCUSE, Oudler.GRAND) | ||
|
||
val score = calculateTakerScore(points, bid, oudlers.size) | ||
assertEquals(480, score) | ||
} | ||
} |
Oops, something went wrong.