Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fix #210

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions docs/examples/Gaming/racingcars.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ service CarRacesService {

events {
RoundInfo: RoundInfo;
GameFinished: struct { player: actor_id };
Killed: struct { inheritor: actor_id };
}
};
Expand Down Expand Up @@ -274,7 +275,7 @@ pub async fn player_move(
game.current_turn = (game.current_turn + 1) % num_of_cars;

let mut round_info: Option<RoundInfo> = None;

let mut game_finished = false;
// Continue processing car turns until the player can act or the game finishes.
while !game.is_player_action_or_finished() {
game.process_car_turn().await?;
Expand All @@ -293,14 +294,24 @@ pub async fn player_move(
// If the game is finished, a delayed message is sent to remove the game instance.
if game.state == GameState::Finished {
send_msg_to_remove_game_instance(player);
game_finished = true;
}
}
}

// Return the round info as an event or handle an unexpected state.
match round_info {
Some(info) => Ok(Event::RoundInfo(info)),
None => Err(Error::UnexpectedState),
Some(info) => {
self.notify_on(Event::RoundInfo(info))
.expect("Notification Error");
if game_finished {
self.notify_on(Event::GameFinished { player: msg_src })
.expect("Notification Error");
}
}
None => {
panic(Error::UnexpectedState);
}
}
})
}
Expand Down
13 changes: 6 additions & 7 deletions docs/examples/Gaming/varaman.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ pub enum Event {
maximum_number_gold_coins: u16,
maximum_number_silver_coins: u16,
prize: u128,
player_address: ActorId,
},
NewTournamentCreated {
tournament_name: String,
Expand Down Expand Up @@ -281,6 +282,7 @@ pub enum Event {
maximum_possible_points: u128,
maximum_number_gold_coins: u16,
maximum_number_silver_coins: u16,
player_address: ActorId,
},
GameStarted,
AdminAdded(ActorId),
Expand Down Expand Up @@ -535,6 +537,7 @@ pub fn record_tournament_result(
maximum_possible_points,
maximum_number_gold_coins: storage.config.max_number_gold_coins,
maximum_number_silver_coins: storage.config.max_number_silver_coins,
player_address: msg_src,
})
}
```
Expand Down Expand Up @@ -636,13 +639,8 @@ pub async fn finish_single_game(
msg::send_with_gas(msg_src, "", 0, prize).expect("Error in sending value");
} else if let Status::StartedWithFungibleToken { ft_address } = storage.status {
let value: U256 = prize.into();
let request = [
"Vft".encode(),
"Mint".to_string().encode(),
(msg_src, value).encode(),
]
.concat();

let request = vft_io::Mint::encode_call(msg_src, value);

msg::send_bytes_with_gas_for_reply(
ft_address,
request,
Expand All @@ -662,6 +660,7 @@ pub async fn finish_single_game(
maximum_possible_points,
maximum_number_gold_coins: storage.config.max_number_gold_coins,
maximum_number_silver_coins: storage.config.max_number_silver_coins,
player_address: msg_src,
})
}
```
Expand Down