more work

This commit is contained in:
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,
}
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_up(&mut self);
fn move_right(&mut self);
@ -23,7 +34,7 @@ trait PlayerControllable {
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_up(&mut self) {}
fn move_right(&mut self) {}

View file

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

View file

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