Skip to content

Commit

Permalink
add current player hp (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinones authored Nov 1, 2024
1 parent 8a96664 commit 1f416f5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/models/status/game/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct Game {
owner: ContractAddress,
player_name: felt252,
player_hp: u32,
current_player_hp: u32,
max_hands: u8,
max_discard: u8,
max_jokers: u8,
Expand Down Expand Up @@ -60,6 +61,7 @@ impl DefaultGame of Default<Game> {
owner: Zeroable::zero(),
player_name: Zeroable::zero(),
player_hp: 500,
current_player_hp: 500,
max_hands: 5,
max_discard: 5,
max_jokers: 5,
Expand Down
14 changes: 8 additions & 6 deletions src/models/status/round/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,15 @@ fn _attack_beast(
ref game_mode_beast: GameModeBeast
) {
emit!(world, (BeastAttack { player: get_caller_address(), attack: beast.attack }));
game.player_hp = if beast.attack > game.player_hp {
0
} else {
game.player_hp - beast.attack
};
game
.current_player_hp =
if beast.attack > game.current_player_hp {
0
} else {
game.current_player_hp - beast.attack
};

if game.player_hp.is_zero() {
if game.current_player_hp.is_zero() {
let play_game_over_event = PlayGameOverEvent { player: get_caller_address(), game_id: game.id };
emit!(world, (play_game_over_event));
game.state = GameState::FINISHED;
Expand Down
1 change: 1 addition & 0 deletions src/systems/game_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ mod game_system {
owner: player_id,
player_name,
player_hp: 500, // TODO: Obtain HP from adventurer
current_player_hp: 500,
max_hands: 5,
max_discard: 5,
max_jokers: 5,
Expand Down

0 comments on commit 1f416f5

Please sign in to comment.