reorder key handling
This commit is contained in:
parent
d6f4fdaa5b
commit
a0635de65a
|
@ -23,8 +23,8 @@ pub struct Chest {
|
||||||
|
|
||||||
impl Chest {
|
impl Chest {
|
||||||
pub fn new(position: Position) -> Self {
|
pub fn new(position: Position) -> Self {
|
||||||
let min_gold = 10 * (position.get_level()+1);
|
let min_gold = 10 * (position.get_level() + 1);
|
||||||
let max_gold = min_gold + 10*position.get_level();
|
let max_gold = min_gold + 10 * position.get_level();
|
||||||
Self {
|
Self {
|
||||||
position,
|
position,
|
||||||
gold: rand::thread_rng().gen_range(min_gold..=max_gold),
|
gold: rand::thread_rng().gen_range(min_gold..=max_gold),
|
||||||
|
|
46
src/main.rs
46
src/main.rs
|
@ -146,28 +146,34 @@ fn main() -> Result<()> {
|
||||||
})?;
|
})?;
|
||||||
if event::poll(std::time::Duration::from_millis(FRAME_LENGTH))? {
|
if event::poll(std::time::Duration::from_millis(FRAME_LENGTH))? {
|
||||||
if let event::Event::Key(key) = event::read()? {
|
if let event::Event::Key(key) = event::read()? {
|
||||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('v') {
|
|
||||||
game.messages.insert(
|
|
||||||
0,
|
|
||||||
format!("You are playing version '{}'.", env!("GIT_HASH")).to_string(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('q') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if key.kind == KeyEventKind::Press {
|
if key.kind == KeyEventKind::Press {
|
||||||
let new_pos = match key.code {
|
match key.code {
|
||||||
KeyCode::Left => game.move_player(-1, 0),
|
KeyCode::Char('v') => {
|
||||||
KeyCode::Right => game.move_player(1, 0),
|
game.messages.insert(
|
||||||
KeyCode::Up => game.move_player(0, -1),
|
0,
|
||||||
KeyCode::Down => game.move_player(0, 1),
|
format!("You are playing version '{}'.", env!("GIT_HASH"))
|
||||||
_ => (0, 0),
|
.to_string(),
|
||||||
};
|
);
|
||||||
if !game.player_fights_monster() {
|
}
|
||||||
// player attacked monster but did not kill it
|
KeyCode::Char('q') => {
|
||||||
game.move_player(new_pos.0, new_pos.1);
|
break;
|
||||||
|
}
|
||||||
|
KeyCode::Left | KeyCode::Down | KeyCode::Right | KeyCode::Up => {
|
||||||
|
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.player_collects_artifact();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue