#[derive(Debug, Clone, PartialEq, Copy, Default)]
pub enum GameOverMenu {
#[default]
Restart,
Menu,
Quit,
}
impl GameOverMenu {
#[must_use]
pub fn next(self) -> Self {
match self {
Self::Restart => Self::Menu,
Self::Menu => Self::Quit,
Self::Quit => Self::Restart,
}
}
#[must_use]
pub fn previous(self) -> Self {
match self {
Self::Restart => Self::Quit,
Self::Menu => Self::Restart,
Self::Quit => Self::Menu,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum GameStatus {
Paused, GameOver(GameOverMenu), ByeBye, Playing, Restarting, Menu, }
#[derive(Clone, Debug, PartialEq)]
pub struct GameState {
pub life: u16, pub score: u32, pub status: GameStatus, pub rank: Option<usize>, life_ini: u16, }
impl GameState {
#[must_use]
pub fn new(life: u16) -> Self {
Self {
life,
score: 0,
status: GameStatus::Playing,
rank: None,
life_ini: life,
}
}
pub fn reset(&mut self) {
self.score = 0;
self.status = GameStatus::Playing;
self.rank = None;
self.life = self.life_ini;
}
}