Skip to content

Commit

Permalink
feat: set initial game status after creation to Pending
Browse files Browse the repository at this point in the history
  • Loading branch information
0xibs committed Feb 8, 2025
1 parent 168eaee commit 5ab6f80
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
5 changes: 2 additions & 3 deletions onchain/src/models/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use starkludo::models::player::{Player};
// Can either be Ongoing or Ended
#[derive(Serde, Copy, Drop, Introspect, PartialEq, Debug)]
pub enum GameStatus {
Initialised, // Game has been created
Pending, // Waiting for players to join (in multiplayer mode)
Ongoing, // Game is ongoing
Ended // Game has ended
Expand Down Expand Up @@ -69,7 +68,7 @@ pub struct Game {
pub b0: felt252, // blue piece position on board
pub b1: felt252, // blue piece position on board
pub b2: felt252, // blue piece position on board
pub b3: felt252, // blue piece position on board
pub b3: felt252,
}

pub trait GameTrait {
Expand Down Expand Up @@ -104,7 +103,7 @@ impl GameImpl of GameTrait {
id,
created_by,
is_initialised: true,
status: GameStatus::Initialised,
status: GameStatus::Pending,
mode: game_mode,
ready_to_start: false,
player_green,
Expand Down
18 changes: 1 addition & 17 deletions onchain/src/tests/test_game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ mod tests {
assert(created_game.number_of_players == 3, 'Wrong number of players');
assert(created_game.player_blue == username, 'Wrong player color assignment');
assert(created_game.player_red == 0, 'Red should not be assigned');
assert(created_game.status == GameStatus::Initialised, 'Wrong game status');
assert(created_game.status == GameStatus::Pending, 'Wrong game status');
}

#[test]
Expand Down Expand Up @@ -771,22 +771,6 @@ mod tests {
game_action_system.join(PlayerColor::Red, game_id);
}

#[test]
#[should_panic(expected: ('GAME NOT PENDING', 'ENTRYPOINT_FAILED'))]
fn test_join_game_not_pending() {
let (_, game_action_system) = setup_world();
let caller = contract_address_const::<'test_gamer'>();
let username = 'gamer';

testing::set_contract_address(caller);
game_action_system.create_new_player(username, false);

let game_id = game_action_system
.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);

game_action_system.join(PlayerColor::Red, game_id);
}

#[test]
#[should_panic(expected: ('PLAYER NOT REGISTERED', 'ENTRYPOINT_FAILED'))]
fn test_join_game_unregistered_player() {
Expand Down

0 comments on commit 5ab6f80

Please sign in to comment.