Skip to content

Commit

Permalink
fix o piece
Browse files Browse the repository at this point in the history
  • Loading branch information
ziloka committed Nov 5, 2023
2 parents 0834e9c + f5f6de6 commit 020ae10
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.72.0-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/rust:buster

ENV DEBIAN_FRONTEND noninteractive

Expand Down
2 changes: 1 addition & 1 deletion src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn main() {
debug: &debug,
};
let mut open_settings = false;
let mut game = Game::new();
let mut game = Game::default();

loop {
let block_size_temp = (screen_height() / (game.board.positions.len() as f32 * 1.25))
Expand Down
29 changes: 15 additions & 14 deletions src/core/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use super::{
generator::Generator,
};

pub type POSITIONS = Vec<Vec<Option<(u8, u8, u8)>>>;

#[derive(Clone)]
pub struct Board {
pub game_state: State,
Expand All @@ -19,7 +21,7 @@ pub struct Board {
generator: Generator,
pub preview_pieces: [Tetromino; 7],
// (0, 0) represents the bottom left corner, (WIDTH, HEIGHT) represents the top right corner
pub positions: Vec<Vec<Option<(u8, u8, u8)>>>,
pub positions: POSITIONS,
pub last_action: Option<Action>,
}

Expand All @@ -28,13 +30,13 @@ impl Display for Board {
let mut board_string = String::new();
for row in self.positions.iter() {
for element in row.iter().rev() {
if let Some(_) = element {
board_string.insert_str(0, "x");
if element.is_some() {
board_string.insert(0, 'x');
} else {
board_string.insert_str(0, " ");
board_string.insert(0, ' ');
}
}
board_string.insert_str(0, "\n");
board_string.insert(0, '\n');
}
write!(f, "{}", board_string)
}
Expand All @@ -45,13 +47,13 @@ impl Debug for Board {
let mut board_string = String::new();
for row in self.positions.iter() {
for element in row.iter().rev() {
if let Some(_) = element {
board_string.insert_str(0, "x");
if element.is_some() {
board_string.insert(0, 'x');
} else {
board_string.insert_str(0, " ");
board_string.insert(0, ' ');
}
}
board_string.insert_str(0, "\n");
board_string.insert(0, '\n');
}
write!(f, "{}", board_string)
}
Expand All @@ -70,7 +72,7 @@ impl Board {
generator,
preview_pieces: tetrominos,
// https://stackoverflow.com/a/53930630
positions: positions,
positions,
last_action: None,
};
board.set_next_tetromino_as_active_piece();
Expand Down Expand Up @@ -252,8 +254,7 @@ impl Board {
self.rotate_tetromino_90(!clockwise, false);
return true;
}

return false;
false
}

pub fn rotate_tetromino_180(&mut self, should_offset: bool) -> bool {
Expand Down Expand Up @@ -288,7 +289,7 @@ impl Board {
self.rotate_tetromino_180(false);
return true;
}
return false;
false

// self.rotate_tetromino(clockwise, true)
}
Expand Down Expand Up @@ -431,7 +432,7 @@ impl Board {
}

fn clear_line(&mut self, row_index: usize) {
for y in row_index..self.positions.len() as usize - 1 {
for y in row_index..self.positions.len() - 1 {
self.positions[y] = self.positions[y + 1].clone();
self.positions[y + 1] = vec![None; self.positions[0].len()];
}
Expand Down
37 changes: 19 additions & 18 deletions src/core/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ pub const TETROMINO_TYPES: [Tetromino; 7] = [
];

// https://en.wikipedia.org/wiki/Tetromino
#[derive(Clone, Copy, Debug)]
#[derive(Default, Clone, Copy, Debug)]
pub enum Tetromino {
#[default]
I,
J,
L,
Expand All @@ -115,11 +116,11 @@ pub enum Tetromino {
Z,
}

impl Default for Tetromino {
fn default() -> Self {
Tetromino::I
}
}
// impl Default for Tetromino {
// fn default() -> Self {
// Tetromino::I
// }
// }

impl Tetromino {
// RGB value of color
Expand Down Expand Up @@ -187,28 +188,28 @@ impl Tetromino {
pub fn find_offset_row_90(first: i8, second: i8) -> usize {
if (first, second) == (0, 1) {
// 0->R
return 0;
0
} else if (first, second) == (1, 0) {
// R->0
return 1;
1
} else if (first, second) == (1, 2) {
// R->2
return 2;
2
} else if (first, second) == (2, 1) {
// 2->R
return 3;
3
} else if (first, second) == (2, 3) {
// 2->L
return 4;
4
} else if (first, second) == (3, 2) {
// L->2
return 5;
5
} else if (first, second) == (3, 0) {
// L->0
return 6;
6
} else if (first, second) == (0, 3) {
// 0->L
return 7;
7
} else {
println!("first: {}, second: {}", first, second);
unimplemented!();
Expand Down Expand Up @@ -364,16 +365,16 @@ impl Tetromino {
pub fn find_offset_row_180(first: i8, second: i8) -> usize {
if (first, second) == (0, 2) {
// 0->L (0>>2)
return 0;
0
} else if (first, second) == (1, 3) {
// L->0 (1>>3)
return 1;
1
} else if (first, second) == (2, 0) {
// R->3 (2>>0)
return 2;
2
} else if (first, second) == (3, 1) {
// 3->R (3>>1)
return 3;
3
} else {
println!("first: {}, second: {}", first, second);
unimplemented!();
Expand Down
4 changes: 2 additions & 2 deletions src/drawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use macroquad::{
};

use crate::core::{
board::Board,
board::{Board, POSITIONS},
consts::{vec2, Piece, Tetromino, Vec2, GRAY},
};

Expand Down Expand Up @@ -140,7 +140,7 @@ impl<'a> Drawer<'a> {
});
}

pub fn draw_tetrominos(&self, positions: &Vec<Vec<Option<(u8, u8, u8)>>>) {
pub fn draw_tetrominos(&self, positions: &POSITIONS) {
let block_size = self.block_size.get();
let bottom_left_corner = self.bottom_left_corner.get();
let debug = self.debug.get();
Expand Down
4 changes: 2 additions & 2 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub struct Game {
pub input: Input,
}

impl Game {
pub fn new() -> Self {
impl Default for Game {
fn default() -> Self {
Self {
board: Box::new(Board::new(now() as usize)),
input: Input::default(),
Expand Down
4 changes: 1 addition & 3 deletions web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,5 @@ headers.Strict-Transport-Security = \"max-age=0; includeSubDomains; preload\"" >
if [ "$1" == "online" ]
then
caddy file-server --listen :8080
# cargo install --git https://github.com/static-web-server/static-web-server
# echo "Running application on http://localhost:8080"
# static-web-server --config-file config.toml --log-level "trace" --port 8080 --root .
# caddy file-server --browse --listen :8080
fi

0 comments on commit 020ae10

Please sign in to comment.