Skip to content

Commit 117f965

Browse files
authored
Minor fix (#210)
1 parent d66c805 commit 117f965

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

docs/examples/Gaming/racingcars.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ service CarRacesService {
152152
153153
events {
154154
RoundInfo: RoundInfo;
155+
GameFinished: struct { player: actor_id };
155156
Killed: struct { inheritor: actor_id };
156157
}
157158
};
@@ -274,7 +275,7 @@ pub async fn player_move(
274275
game.current_turn = (game.current_turn + 1) % num_of_cars;
275276

276277
let mut round_info: Option<RoundInfo> = None;
277-
278+
let mut game_finished = false;
278279
// Continue processing car turns until the player can act or the game finishes.
279280
while !game.is_player_action_or_finished() {
280281
game.process_car_turn().await?;
@@ -293,14 +294,24 @@ pub async fn player_move(
293294
// If the game is finished, a delayed message is sent to remove the game instance.
294295
if game.state == GameState::Finished {
295296
send_msg_to_remove_game_instance(player);
297+
game_finished = true;
296298
}
297299
}
298300
}
299301

300302
// Return the round info as an event or handle an unexpected state.
301303
match round_info {
302-
Some(info) => Ok(Event::RoundInfo(info)),
303-
None => Err(Error::UnexpectedState),
304+
Some(info) => {
305+
self.notify_on(Event::RoundInfo(info))
306+
.expect("Notification Error");
307+
if game_finished {
308+
self.notify_on(Event::GameFinished { player: msg_src })
309+
.expect("Notification Error");
310+
}
311+
}
312+
None => {
313+
panic(Error::UnexpectedState);
314+
}
304315
}
305316
})
306317
}

docs/examples/Gaming/varaman.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ pub enum Event {
254254
maximum_number_gold_coins: u16,
255255
maximum_number_silver_coins: u16,
256256
prize: u128,
257+
player_address: ActorId,
257258
},
258259
NewTournamentCreated {
259260
tournament_name: String,
@@ -281,6 +282,7 @@ pub enum Event {
281282
maximum_possible_points: u128,
282283
maximum_number_gold_coins: u16,
283284
maximum_number_silver_coins: u16,
285+
player_address: ActorId,
284286
},
285287
GameStarted,
286288
AdminAdded(ActorId),
@@ -535,6 +537,7 @@ pub fn record_tournament_result(
535537
maximum_possible_points,
536538
maximum_number_gold_coins: storage.config.max_number_gold_coins,
537539
maximum_number_silver_coins: storage.config.max_number_silver_coins,
540+
player_address: msg_src,
538541
})
539542
}
540543
```
@@ -636,13 +639,8 @@ pub async fn finish_single_game(
636639
msg::send_with_gas(msg_src, "", 0, prize).expect("Error in sending value");
637640
} else if let Status::StartedWithFungibleToken { ft_address } = storage.status {
638641
let value: U256 = prize.into();
639-
let request = [
640-
"Vft".encode(),
641-
"Mint".to_string().encode(),
642-
(msg_src, value).encode(),
643-
]
644-
.concat();
645-
642+
let request = vft_io::Mint::encode_call(msg_src, value);
643+
646644
msg::send_bytes_with_gas_for_reply(
647645
ft_address,
648646
request,
@@ -662,6 +660,7 @@ pub async fn finish_single_game(
662660
maximum_possible_points,
663661
maximum_number_gold_coins: storage.config.max_number_gold_coins,
664662
maximum_number_silver_coins: storage.config.max_number_silver_coins,
663+
player_address: msg_src,
665664
})
666665
}
667666
```

0 commit comments

Comments
 (0)