Press Space to restart
This commit is contained in:
parent
c5a8c6d900
commit
6cc38951d8
2 changed files with 8 additions and 4 deletions
|
|
@ -26,8 +26,6 @@ impl Game for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(&mut self, _asset_store: &mut AssetStore) {
|
fn load(&mut self, _asset_store: &mut AssetStore) {
|
||||||
self.board.generate_tile();
|
|
||||||
self.board.generate_tile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key_press(
|
fn key_press(
|
||||||
|
|
@ -47,6 +45,9 @@ impl Game for App {
|
||||||
if key == keyboard::Down {
|
if key == keyboard::Down {
|
||||||
self.board.merge_from_top_to_bottom();
|
self.board.merge_from_top_to_bottom();
|
||||||
}
|
}
|
||||||
|
if key == keyboard::Space {
|
||||||
|
self.board = Board::new();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key_release(
|
fn key_release(
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,14 @@ pub struct Board {
|
||||||
|
|
||||||
impl Board {
|
impl Board {
|
||||||
pub fn new() -> Board {
|
pub fn new() -> Board {
|
||||||
Board {
|
let mut board = Board {
|
||||||
tiles: Vec::<Tile>::new(),
|
tiles: Vec::<Tile>::new(),
|
||||||
score: 0,
|
score: 0,
|
||||||
highest_score: 0,
|
highest_score: 0,
|
||||||
}
|
};
|
||||||
|
board.generate_tile();
|
||||||
|
board.generate_tile();
|
||||||
|
board
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_tile(&mut self) {
|
pub fn generate_tile(&mut self) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue