add 3 distinct outcomes for the game

This commit is contained in:
2023-12-21 23:02:06 +01:00
parent 6b6206370b
commit 2a86201c3e
3 changed files with 85 additions and 7 deletions

View File

@@ -11,10 +11,11 @@ use ratatui::{
widgets::Paragraph,
};
use ratatui::prelude::*;
use ratatui::widgets::Block;
use ratatui::widgets::{Block, Borders, BorderType, Wrap};
use ratatui::widgets::block::{Position, Title};
use whoami::realname;
use crate::game::Game;
use crate::game::{Game, GameState};
use crate::level_widget::LevelWidget;
// use crate::level_widget::LevelWidget;
use crate::player::Player;
@@ -96,6 +97,46 @@ fn main() -> Result<()> {
}
game.player_collects_artifact();
game.update_level();
if game.get_game_state() != GameState::RUNNING {
break;
}
}
}
}
}
loop {
let _ = terminal.draw(|frame| {
let mut area = frame.size();
let w = area.width / 2;
let h = area.height / 2;
area.x += w - 20;
area.y += h - 10;
area.width = 40;
area.height = 20;
let block = Block::default()
.title("Game ended")
.title(Title::from("Press `q` to quit!").position(Position::Bottom))
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::White))
.border_type(BorderType::Rounded)
.style(Style::default().bg(Color::Black));
let paragraph = match game.get_game_state() {
GameState::RUNNING => {
Paragraph::new("Quitting is for cowards! You'll better try again!")
}
GameState::LOST => {
Paragraph::new("Sorry, you died in the dungeon. Better luck next time!")
}
GameState::WON => {
Paragraph::new("Congratulation! You mastered your way through the dungeon and won the game.")
}
}.block(block).wrap(Wrap { trim: true });
frame.render_widget(paragraph, area);
});
if event::poll(std::time::Duration::from_millis(16))? {
if let event::Event::Key(key) = event::read()? {
if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('q') {
break;
}
}
}