Skip to content

Commit

Permalink
refactor health (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzn authored Nov 1, 2024
1 parent 30512cd commit ef49413
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/models/data/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ struct Beast {
struct PlayerBeast {
#[key]
game_id: u32,
health: u32,
energy: u8
}
2 changes: 2 additions & 0 deletions src/models/status/game/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct Game {
id: u32,
owner: ContractAddress,
player_name: felt252,
player_hp: u32,
max_hands: u8,
max_discard: u8,
max_jokers: u8,
Expand Down Expand Up @@ -58,6 +59,7 @@ impl DefaultGame of Default<Game> {
id: 1,
owner: Zeroable::zero(),
player_name: Zeroable::zero(),
player_hp: 500,
max_hands: 5,
max_discard: 5,
max_jokers: 5,
Expand Down
12 changes: 6 additions & 6 deletions src/models/status/round/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use jokers_of_neon::models::data::beast::{
};
use jokers_of_neon::models::data::events::{PlayWinGameEvent, PlayGameOverEvent};
use jokers_of_neon::models::data::game_deck::{GameDeckImpl, GameDeck, GameDeckStore};
use jokers_of_neon::models::status::game::game::{Game, GameState, GameSubState};
use jokers_of_neon::models::status::game::game::{Game, GameStore, GameState, GameSubState};
use jokers_of_neon::models::status::game::rage::{RageRound, RageRoundStore};
use jokers_of_neon::models::status::round::current_hand_card::{CurrentHandCard, CurrentHandCardTrait};
use jokers_of_neon::store::{Store, StoreTrait};
Expand Down Expand Up @@ -53,7 +53,7 @@ impl BeastImpl of BeastTrait {
BeastStore::set(@beast, world);
emit!(world, (beast));

let player_beast = PlayerBeast { game_id, health: 100, energy: game_mode_beast.energy_max_player };
let player_beast = PlayerBeast { game_id, energy: game_mode_beast.energy_max_player };
PlayerBeastStore::set(@player_beast, world);

let mut game_deck = GameDeckStore::get(world, game_id);
Expand Down Expand Up @@ -242,20 +242,20 @@ fn _attack_beast(
ref beast: Beast,
ref game_mode_beast: GameModeBeast
) {
player_beast.health = if beast.attack > player_beast.health {
game.player_hp = if beast.attack > game.player_hp {
0
} else {
player_beast.health - beast.attack
game.player_hp - beast.attack
};

if player_beast.health.is_zero() {
if game.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;
store.set_game(game);
} else {
// reset energy
player_beast.energy = game_mode_beast.energy_max_player;
}
store.set_game(game);
PlayerBeastStore::set(@player_beast, world);
}
1 change: 1 addition & 0 deletions src/systems/game_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ mod game_system {
id: game_id,
owner: player_id,
player_name,
player_hp: 500, // TODO: Obtain HP from adventurer
max_hands: 5,
max_discard: 5,
max_jokers: 5,
Expand Down

0 comments on commit ef49413

Please sign in to comment.