konnektoren_core/game/
game_state.rs1use serde::{Deserialize, Serialize};
2
3use crate::{game::Game, prelude::Challenge};
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6pub struct GameState {
7 pub game: Game,
8 pub challenge: Challenge,
9 pub current_game_path: usize,
10 pub current_challenge_index: usize,
11 pub current_task_index: usize,
12}
13
14impl GameState {
15 pub fn new(game: Game) -> Self {
16 let challenge = game.create_challenge("konnektoren-1").unwrap();
17
18 GameState {
19 game,
20 challenge,
21 current_game_path: 0,
22 current_challenge_index: 0,
23 current_task_index: 0,
24 }
25 }
26}
27
28impl Default for GameState {
29 fn default() -> Self {
30 GameState::new(Game::default())
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37
38 #[test]
39 fn new_state() {
40 let state = GameState::default();
41 assert_eq!(state.game.game_paths[0].challenge_ids().len(), 8);
42 }
43
44 #[test]
45 fn default_state() {
46 let state = GameState::default();
47 assert_eq!(state.current_challenge_index, 0);
48
49 let challenge = state.game.create_challenge("konnektoren-1").unwrap();
50 assert_eq!(state.challenge, challenge);
51 }
52}