Skip to content

Commit

Permalink
Adding bonuses for time, difficulty and lives left
Browse files Browse the repository at this point in the history
  • Loading branch information
alopezo committed Apr 1, 2024
1 parent 0d6cacf commit ff2fc39
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
<style>*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}*,:before,:after{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgb(59 130 246 / .5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }html,body{height:100%}body{margin:0;font-family:Roboto,Helvetica Neue,sans-serif}</style><link rel="stylesheet" href="styles.e6f2eb426653e7e2.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles.e6f2eb426653e7e2.css"></noscript></head>
<body class="mat-typography">
<app-root></app-root>
<script src="runtime.ebaabf86d08a7789.js" type="module"></script><script src="polyfills.75186c7b7fc1d123.js" type="module"></script><script src="scripts.a1e2309b4257c7b3.js" defer></script><script src="main.8703da188731491b.js" type="module"></script>
<script src="runtime.ebaabf86d08a7789.js" type="module"></script><script src="polyfills.75186c7b7fc1d123.js" type="module"></script><script src="scripts.a1e2309b4257c7b3.js" defer></script><script src="main.a6ba4ebe3385876a.js" type="module"></script>

</body></html>

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions src/app/game/service/snoguess.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface Game {
rules: any; // Rules and settings for the game
startTimestamp: number; // Timestamp when the game started
endTimestamp: number; // Timestamp when the game ended
difficultyBonus: number; // Bonus points for difficulty level
livesBonus: number; // Bonus points for remaining lives
timeBonus: number; // Bonus points for time remaining
}

interface SnomedConcept {
Expand All @@ -40,15 +43,15 @@ export class SnoguessService {
difficultyLevels: any[] = [
{
name: 'Easy',
rules: { maxHitPoints: 5, hitpointsAwardedForGuessingfullTerm: 1, freeHints: 2, pointsPerGuessedLetter: 1, goals: this.goals }
rules: { maxHitPoints: 5, hitpointsAwardedForGuessingfullTerm: 1, freeHints: 2, pointsPerGuessedLetter: 1, goals: this.goals, difficultyBonus: 0 }
},
{
name: 'Medium',
rules: { maxHitPoints: 4, hitpointsAwardedForGuessingfullTerm: 1, freeHints: 1, pointsPerGuessedLetter: 2, goals: this.goals }
rules: { maxHitPoints: 4, hitpointsAwardedForGuessingfullTerm: 1, freeHints: 1, pointsPerGuessedLetter: 2, goals: this.goals, difficultyBonus: 50}
},
{
name: 'Hard',
rules: { maxHitPoints: 3, hitpointsAwardedForGuessingfullTerm: 1, freeHints: 0, pointsPerGuessedLetter: 3, goals: this.goals }
rules: { maxHitPoints: 3, hitpointsAwardedForGuessingfullTerm: 1, freeHints: 0, pointsPerGuessedLetter: 3, goals: this.goals, difficultyBonus: 100}
}
];

Expand Down Expand Up @@ -216,7 +219,10 @@ export class SnoguessService {
rules: this.rules,
difficultyLevel: '',
startTimestamp: 0,
endTimestamp: 0
endTimestamp: 0,
difficultyBonus: 0,
livesBonus: 0,
timeBonus: 0
};
}

Expand All @@ -234,7 +240,10 @@ export class SnoguessService {
rules: this.rules,
difficultyLevel: difficulty,
startTimestamp: Date.now(),
endTimestamp: 0
endTimestamp: 0,
difficultyBonus: 0,
livesBonus: 0,
timeBonus: 0
});
this.newRound(true);
}
Expand Down Expand Up @@ -317,6 +326,12 @@ export class SnoguessService {
if (newState.score > this.goals[this.goals.length - 1].score) {
newState.state = 'won'; // Update the state to 'won'
newState.endTimestamp = Date.now();
// Add bonuses to the score
newState.difficultyBonus = this.rules.difficultyBonus;
newState.livesBonus = newState.hitPoints * 10;
const elapsedTime = Math.round((newState.endTimestamp - newState.startTimestamp) / 1000);
newState.timeBonus = Math.max(0, 180 - elapsedTime);
newState.score += newState.difficultyBonus + newState.livesBonus + newState.timeBonus;
} else {
newState.hitPoints = newState.hitPoints + this.rules.hitpointsAwardedForGuessingfullTerm; // Add a hit points for winning
if (newState.hitPoints > this.rules.maxHitPoints) {
Expand Down
12 changes: 11 additions & 1 deletion src/app/game/snoguess-main/snoguess-main.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,17 @@ <h3>Score Progression</h3>
<mat-icon class="large-icon diamond shadow-local">emoji_events</mat-icon>
<mat-icon class="large-icon diamond shadow-local">grade</mat-icon>
</div>
<div class="reveal won">Final score: {{ gameState.score }} - Difficulty: {{ gameState.difficultyLevel }} - Time: {{ (gameState.endTimestamp - gameState.startTimestamp) | elapsedTime }}</div>
<div class="text-lg">Lives left: {{ gameState.hitPoints }}
<span *ngIf="gameState.livesBonus > 0">→ Bonus: {{ gameState.livesBonus }}</span>
</div>
<div class="text-lg">Difficulty: {{ gameState.difficultyLevel }}
<span *ngIf="gameState.difficultyBonus > 0">→ Bonus: {{ gameState.difficultyBonus }}</span>
</div>
<div class="text-lg">Time: {{ (gameState.endTimestamp - gameState.startTimestamp) | elapsedTime }}
<span *ngIf="gameState.timeBonus > 0">→ Bonus: {{ gameState.timeBonus }}</span>
</div>
<div class="reveal won">Final score: {{ gameState.score }}</div>

<div *ngIf="highScore" class="flex flex-col items-center gap-4 w-full">
<p class="font-bold text-lg text-blue-900">This is a High Score! Save a message to the public leaderboard!</p>
<div class="flex flex-row align-middle justify-center w-full">
Expand Down

0 comments on commit ff2fc39

Please sign in to comment.