Press Space to restart

This commit is contained in:
Coeuvre 2014-05-22 00:07:36 +08:00
parent c5a8c6d900
commit 6cc38951d8
2 changed files with 8 additions and 4 deletions

View file

@ -26,8 +26,6 @@ impl Game for App {
}
fn load(&mut self, _asset_store: &mut AssetStore) {
self.board.generate_tile();
self.board.generate_tile();
}
fn key_press(
@ -47,6 +45,9 @@ impl Game for App {
if key == keyboard::Down {
self.board.merge_from_top_to_bottom();
}
if key == keyboard::Space {
self.board = Board::new();
}
}
fn key_release(

View file

@ -18,11 +18,14 @@ pub struct Board {
impl Board {
pub fn new() -> Board {
Board {
let mut board = Board {
tiles: Vec::<Tile>::new(),
score: 0,
highest_score: 0,
}
};
board.generate_tile();
board.generate_tile();
board
}
pub fn generate_tile(&mut self) {