fight monsters, collect artifacts
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -27,6 +27,7 @@ mod level_widget;
|
||||
mod level_generator;
|
||||
mod artifacts;
|
||||
mod monster;
|
||||
|
||||
//
|
||||
fn main() -> Result<()> {
|
||||
let mut game = Game::new(Player::new(realname().as_str(), 10));
|
||||
@@ -56,7 +57,7 @@ fn main() -> Result<()> {
|
||||
width: level::LEVEL_WIDTH as u16,
|
||||
height: level::LEVEL_HEIGHT as u16,
|
||||
};
|
||||
frame.render_stateful_widget(LevelWidget{}, map_area, &mut game);
|
||||
frame.render_stateful_widget(LevelWidget {}, map_area, &mut game);
|
||||
|
||||
let stats_area = Rect {
|
||||
x: area.x + 50,
|
||||
@@ -81,17 +82,20 @@ fn main() -> Result<()> {
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('q') {
|
||||
break;
|
||||
}
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Left {
|
||||
game.move_player(-1, 0);
|
||||
}
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Right {
|
||||
game.move_player(1, 0);
|
||||
}
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Up {
|
||||
game.move_player(0, -1);
|
||||
}
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Down {
|
||||
game.move_player(0, 1);
|
||||
if key.kind == KeyEventKind::Press {
|
||||
let new_pos = match key.code {
|
||||
KeyCode::Left => { game.move_player(-1, 0) }
|
||||
KeyCode::Right => { game.move_player(1, 0) }
|
||||
KeyCode::Up => { game.move_player(0, -1) }
|
||||
KeyCode::Down => { game.move_player(0, 1) }
|
||||
_ => { (0, 0) }
|
||||
};
|
||||
if !game.player_fights_monster() {
|
||||
// player attacked monster but did not kill it
|
||||
game.move_player(new_pos.0, new_pos.1);
|
||||
}
|
||||
game.player_collects_artifact();
|
||||
game.update_level();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user