reorder key handling
This commit is contained in:
parent
d6f4fdaa5b
commit
a0635de65a
|
@ -23,8 +23,8 @@ pub struct Chest {
|
|||
|
||||
impl Chest {
|
||||
pub fn new(position: Position) -> Self {
|
||||
let min_gold = 10 * (position.get_level()+1);
|
||||
let max_gold = min_gold + 10*position.get_level();
|
||||
let min_gold = 10 * (position.get_level() + 1);
|
||||
let max_gold = min_gold + 10 * position.get_level();
|
||||
Self {
|
||||
position,
|
||||
gold: rand::thread_rng().gen_range(min_gold..=max_gold),
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -146,16 +146,19 @@ fn main() -> Result<()> {
|
|||
})?;
|
||||
if event::poll(std::time::Duration::from_millis(FRAME_LENGTH))? {
|
||||
if let event::Event::Key(key) = event::read()? {
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('v') {
|
||||
if key.kind == KeyEventKind::Press {
|
||||
match key.code {
|
||||
KeyCode::Char('v') => {
|
||||
game.messages.insert(
|
||||
0,
|
||||
format!("You are playing version '{}'.", env!("GIT_HASH")).to_string(),
|
||||
format!("You are playing version '{}'.", env!("GIT_HASH"))
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('q') {
|
||||
KeyCode::Char('q') => {
|
||||
break;
|
||||
}
|
||||
if key.kind == KeyEventKind::Press {
|
||||
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),
|
||||
|
@ -169,6 +172,9 @@ fn main() -> Result<()> {
|
|||
}
|
||||
game.player_collects_artifact();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
game.update_level(ticks);
|
||||
|
|
Loading…
Reference in New Issue