Skip to content

Commit 6ce13e7

Browse files
committed
added God mode
1 parent 845b604 commit 6ce13e7

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/main.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ enum DeathCause {
3838
Fuel,
3939
}
4040

41+
#[derive(PartialEq, Eq)]
42+
enum GameMode {
43+
Normal,
44+
God,
45+
}
46+
4147
struct Location {
4248
c: u16,
4349
l: u16,
@@ -125,6 +131,7 @@ struct World {
125131
gas: u16,
126132
score: u16,
127133
death_cause: DeathCause,
134+
game_mode: GameMode,
128135
}
129136

130137
impl World {
@@ -144,6 +151,7 @@ impl World {
144151
score: 0,
145152
gas: 1700,
146153
death_cause: DeathCause::None,
154+
game_mode: GameMode::Normal,
147155
}
148156
}
149157
}
@@ -164,6 +172,10 @@ fn draw(mut sc: &Stdout, world: &mut World) -> std::io::Result<()> {
164172
.queue(MoveTo(2, 3))?
165173
.queue(Print(format!(" Fuel: {} ", world.gas / 100)))?;
166174

175+
if world.game_mode == GameMode::God {
176+
draw_god_mode(sc);
177+
}
178+
167179
// draw fuel
168180
for index in (0..world.fuel.len()).rev() {
169181
match world.fuel[index].status {
@@ -418,11 +430,16 @@ fn pause_screen(mut sc: &Stdout , world: &World) {
418430
let _ = sc.flush();
419431
}
420432

433+
fn draw_god_mode(mut sc: &Stdout) {
434+
let msg: &str = " GOD MODE: ON ";
435+
let _ = sc.queue(MoveTo(2, 4));
436+
let _ = sc.queue(Print(msg));
437+
}
438+
421439
fn goodbye_screen(mut sc: &Stdout, world: &World) {
422440
let goodbye_msg1: &str = " ██████╗ ██████╗ ██████╗ ██████╗ ██████╗ █████╗ ███╗ ███╗███████╗██╗\n\r██╔════╝ ██╔═══██╗██╔═══██╗██╔══██╗ ██╔════╝ ██╔══██╗████╗ ████║██╔════╝██║\n\r██║ ███╗██║ ██║██║ ██║██║ ██║ ██║ ███╗███████║██╔████╔██║█████╗ ██║\n\r██║ ██║██║ ██║██║ ██║██║ ██║ ██║ ██║██╔══██║██║╚██╔╝██║██╔══╝ ╚═╝\n\r╚██████╔╝╚██████╔╝╚██████╔╝██████╔╝ ╚██████╔╝██║ ██║██║ ╚═╝ ██║███████╗██╗\n\r ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝\n";
423441
let goodbye_msg2: &str = "████████╗██╗ ██╗ █████╗ ███╗ ██╗██╗ ██╗███████╗\n\r╚══██╔══╝██║ ██║██╔══██╗████╗ ██║██║ ██╔╝██╔════╝\n\r ██║ ███████║███████║██╔██╗ ██║█████╔╝ ███████╗\n\r ██║ ██╔══██║██╔══██║██║╚██╗██║██╔═██╗ ╚════██║\n\r ██║ ██║ ██║██║ ██║██║ ╚████║██║ ██╗███████║██╗\n\r ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝╚══════╝╚═╝\n";
424442
let _ = sc.queue(Clear(crossterm::terminal::ClearType::All));
425-
426443
let _ = sc.queue(MoveTo(0, 2));
427444
let _ = sc.queue(Print(goodbye_msg1));
428445
let _ = sc.queue(MoveTo(0, 10));
@@ -507,6 +524,13 @@ fn handle_pressed_keys(world: &mut World) {
507524
// I'm reading from keyboard into event
508525
match event.code {
509526
KeyCode::Char('q') => world.status = PlayerStatus::Quit,
527+
KeyCode::Char('g') => {
528+
if world.game_mode == GameMode::Normal {
529+
world.game_mode = GameMode::God;
530+
} else if world.game_mode == GameMode::God {
531+
world.game_mode = GameMode::Normal;
532+
}
533+
}
510534
KeyCode::Char('w') => {
511535
if world.status == PlayerStatus::Alive && world.player_location.l > 1 {
512536
world.player_location.l -= 1
@@ -598,6 +622,14 @@ fn main() -> std::io::Result<()> {
598622
handle_pressed_keys(&mut world);
599623
if world.status != PlayerStatus::Paused {
600624
physics(&mut world);
625+
match world.game_mode {
626+
GameMode::God => {
627+
if world.status != PlayerStatus::Quit {
628+
world.status = PlayerStatus::Alive;
629+
}
630+
}
631+
GameMode::Normal => {}
632+
}
601633
draw(&sc, &mut world)?;
602634
} else {
603635
pause_screen(&sc, &world);

0 commit comments

Comments
 (0)