2020-03-19 15:51:43 -07:00
|
|
|
// A game is a self-contained struct that holds everything that an instance of
|
|
|
|
// Tetris needs to run, except for something to tick the time forward.
|
|
|
|
|
|
|
|
use crate::playfield::PlayField;
|
|
|
|
use crate::srs::RotationSystem;
|
|
|
|
use crate::srs::SRS;
|
|
|
|
|
|
|
|
pub struct Game<RS: RotationSystem> {
|
|
|
|
playfield: PlayField,
|
|
|
|
rotation_system: RS,
|
|
|
|
level: u8,
|
|
|
|
points: u64,
|
|
|
|
}
|
|
|
|
|
2020-03-19 16:47:50 -07:00
|
|
|
impl<RS: RotationSystem> Default for Game<RS> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Game {
|
|
|
|
playfield: PlayField::new(),
|
|
|
|
rotation_system: RS::default(),
|
|
|
|
level: 0,
|
|
|
|
points: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Controllable {
|
2020-03-19 15:51:43 -07:00
|
|
|
fn move_left(&mut self);
|
|
|
|
fn move_up(&mut self);
|
|
|
|
fn move_right(&mut self);
|
|
|
|
fn move_down(&mut self);
|
|
|
|
fn rotate_left(&mut self);
|
|
|
|
fn rotate_right(&mut self);
|
|
|
|
fn hard_drop(&mut self);
|
|
|
|
fn hold(&mut self);
|
|
|
|
}
|
|
|
|
|
2020-03-19 16:47:50 -07:00
|
|
|
impl<RS: RotationSystem> Controllable for Game<RS> {
|
2020-03-19 15:51:43 -07:00
|
|
|
fn move_left(&mut self) {}
|
|
|
|
fn move_up(&mut self) {}
|
|
|
|
fn move_right(&mut self) {}
|
|
|
|
fn move_down(&mut self) {}
|
|
|
|
fn rotate_left(&mut self) {}
|
|
|
|
fn rotate_right(&mut self) {}
|
|
|
|
fn hard_drop(&mut self) {}
|
|
|
|
|
|
|
|
fn hold(&mut self) {
|
|
|
|
// if self.can_swap_hold {
|
|
|
|
// match self.hold_piece {
|
|
|
|
// None => {
|
|
|
|
// self.hold_piece = Some(self.active_piece);
|
|
|
|
// self.get_new_piece();
|
|
|
|
// }
|
|
|
|
// Some(piece) => {
|
|
|
|
// self.hold_piece = Some(self.active_piece);
|
|
|
|
// self.active_piece = piece;
|
|
|
|
// self.reset_position();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// self.can_swap_hold = false;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|