more work

master
Edward Shen 2020-03-19 19:47:50 -04:00
parent 31daef03c7
commit e5c32b3855
Signed by: edward
GPG Key ID: 19182661E818369F
3 changed files with 88 additions and 65 deletions

View File

@ -12,7 +12,18 @@ pub struct Game<RS: RotationSystem> {
points: u64, points: u64,
} }
trait PlayerControllable { impl<RS: RotationSystem> Default for Game<RS> {
fn default() -> Self {
Game {
playfield: PlayField::new(),
rotation_system: RS::default(),
level: 0,
points: 0,
}
}
}
trait Controllable {
fn move_left(&mut self); fn move_left(&mut self);
fn move_up(&mut self); fn move_up(&mut self);
fn move_right(&mut self); fn move_right(&mut self);
@ -23,7 +34,7 @@ trait PlayerControllable {
fn hold(&mut self); fn hold(&mut self);
} }
impl<RS: RotationSystem> PlayerControllable for Game<RS> { impl<RS: RotationSystem> Controllable for Game<RS> {
fn move_left(&mut self) {} fn move_left(&mut self) {}
fn move_up(&mut self) {} fn move_up(&mut self) {}
fn move_right(&mut self) {} fn move_right(&mut self) {}

View File

@ -1,3 +1,6 @@
use game::Game;
use srs::SRS;
mod game; mod game;
mod playfield; mod playfield;
mod random; mod random;
@ -15,8 +18,5 @@ pub enum Tetromino {
} }
fn main() { fn main() {
let mut rs = random::RandomSystem::new(); let mut game: Game<SRS> = Game::default();
for _ in 0..1000000 {
rs.get_tetrino();
}
} }

View File

@ -1,7 +1,7 @@
use crate::playfield::{PlayField, Position}; use crate::playfield::{PlayField, Position};
use crate::Tetromino; use crate::Tetromino;
#[derive(Copy)] #[derive(Copy, Clone)]
pub struct Offset { pub struct Offset {
x: i8, x: i8,
y: i8, y: i8,
@ -13,6 +13,8 @@ pub enum RotationDirection {
} }
pub trait RotationSystem { pub trait RotationSystem {
fn default() -> Self;
fn get_rotation_offset( fn get_rotation_offset(
piece: &Tetromino, piece: &Tetromino,
center: &Position, center: &Position,
@ -23,7 +25,17 @@ pub trait RotationSystem {
pub struct SRS {} pub struct SRS {}
impl SRS {
pub fn new() -> Self {
Self {}
}
}
impl RotationSystem for SRS { impl RotationSystem for SRS {
fn default() -> Self {
SRS::new()
}
fn get_rotation_offset( fn get_rotation_offset(
piece: &Tetromino, piece: &Tetromino,
center: &Position, center: &Position,
@ -43,69 +55,69 @@ enum Rotation {
} }
struct OffsetData { struct OffsetData {
O: Vec<Offset>, // O: &[Offset],
R: Vec<Offset>, // R: &[Offset],
U: Vec<Offset>, // U: &[Offset],
L: Vec<Offset>, // L: &[Offset],
} }
impl OffsetData { impl OffsetData {
pub fn apply_right_rotation() {} pub fn apply_right_rotation() {}
} }
const JLSTZOffsetData: OffsetData = OffsetData { // static JLSTZOffsetData: OffsetData = OffsetData {
O: vec![Offset { x: 0, y: 0 }], // O: vec![Offset { x: 0, y: 0 }],
R: vec![ // R: vec![
Offset { x: 0, y: 0 }, // Offset { x: 0, y: 0 },
Offset { x: 1, y: 0 }, // Offset { x: 1, y: 0 },
Offset { x: 1, y: -1 }, // Offset { x: 1, y: -1 },
Offset { x: 0, y: 2 }, // Offset { x: 0, y: 2 },
Offset { x: 1, y: 2 }, // Offset { x: 1, y: 2 },
], // ],
U: vec![Offset { x: 0, y: 0 }], // U: vec![Offset { x: 0, y: 0 }],
L: vec![ // L: vec![
Offset { x: 0, y: 0 }, // Offset { x: 0, y: 0 },
Offset { x: -1, y: 0 }, // Offset { x: -1, y: 0 },
Offset { x: -1, y: -1 }, // Offset { x: -1, y: -1 },
Offset { x: 0, y: 2 }, // Offset { x: 0, y: 2 },
Offset { x: -1, y: 2 }, // Offset { x: -1, y: 2 },
], // ],
}; // };
const IOffsetData: OffsetData = OffsetData { // static IOffsetData: OffsetData = OffsetData {
O: vec![ // O: vec![
Offset { x: 0, y: 0 }, // Offset { x: 0, y: 0 },
Offset { x: -1, y: 0 }, // Offset { x: -1, y: 0 },
Offset { x: 2, y: 0 }, // Offset { x: 2, y: 0 },
Offset { x: -1, y: 0 }, // Offset { x: -1, y: 0 },
Offset { x: 2, y: 0 }, // Offset { x: 2, y: 0 },
], // ],
R: vec![ // R: vec![
Offset { x: -1, y: 0 }, // Offset { x: -1, y: 0 },
Offset { x: 0, y: 0 }, // Offset { x: 0, y: 0 },
Offset { x: 0, y: 0 }, // Offset { x: 0, y: 0 },
Offset { x: 0, y: 1 }, // Offset { x: 0, y: 1 },
Offset { x: 0, y: -2 }, // Offset { x: 0, y: -2 },
], // ],
U: vec![ // U: vec![
Offset { x: -1, y: 1 }, // Offset { x: -1, y: 1 },
Offset { x: 1, y: 1 }, // Offset { x: 1, y: 1 },
Offset { x: -2, y: 1 }, // Offset { x: -2, y: 1 },
Offset { x: 1, y: 0 }, // Offset { x: 1, y: 0 },
Offset { x: -2, y: 0 }, // Offset { x: -2, y: 0 },
], // ],
L: vec![ // L: vec![
Offset { x: 0, y: 1 }, // Offset { x: 0, y: 1 },
Offset { x: 0, y: 1 }, // Offset { x: 0, y: 1 },
Offset { x: 0, y: 1 }, // Offset { x: 0, y: 1 },
Offset { x: 0, y: -1 }, // Offset { x: 0, y: -1 },
Offset { x: 0, y: 2 }, // Offset { x: 0, y: 2 },
], // ],
}; // };
const OOffsetData: OffsetData = OffsetData { // static OOffsetData: OffsetData = OffsetData {
O: vec![Offset { x: 0, y: 0 }], // O: vec![Offset { x: 0, y: 0 }],
R: vec![Offset { x: 0, y: -1 }], // R: vec![Offset { x: 0, y: -1 }],
U: vec![Offset { x: -1, y: -1 }], // U: vec![Offset { x: -1, y: -1 }],
L: vec![Offset { x: -1, y: 0 }], // L: vec![Offset { x: -1, y: 0 }],
}; // };