diff options
author | curly <curlybryce@protonmail.com> | 2022-08-15 15:49:56 -0600 |
---|---|---|
committer | curly <curlybryce@protonmail.com> | 2022-08-15 15:49:56 -0600 |
commit | 462c1f8bf195a1e30b6c05be7a0ec60ee89d230c (patch) | |
tree | 6965d94cfaabecef461597cf8de4b30cc225cfdc /src/tetris.rs | |
parent | 008c2b23c78f8969c9741e537326c13b98c27b58 (diff) | |
download | tetris-462c1f8bf195a1e30b6c05be7a0ec60ee89d230c.tar.gz tetris-462c1f8bf195a1e30b6c05be7a0ec60ee89d230c.tar.bz2 tetris-462c1f8bf195a1e30b6c05be7a0ec60ee89d230c.zip |
half working
Diffstat (limited to 'src/tetris.rs')
-rw-r--r-- | src/tetris.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/tetris.rs b/src/tetris.rs index 9f9cda8..aa9b883 100644 --- a/src/tetris.rs +++ b/src/tetris.rs @@ -1,6 +1,4 @@ -mod piece; - -use piece::Piece; +pub mod piece; #[derive(Debug)] pub struct Tetris { @@ -18,11 +16,23 @@ impl Tetris { &self.grid } - // Set the grid, given a piece - pub fn set_grid(&mut self, piece: Piece) {} + // Set the grid at a Pos + pub fn set_grid(&mut self, pos: piece::Pos, value: i8) { + if self.get_grid_pos(pos) != value { + self.grid[pos.0 as usize][pos.1 as usize] = value + } + } // Check each row of the grid // If one is full, remove it and drop // the rest of the grid down pub fn check_lines() {} + + pub fn get_grid_pos(&self, pos: piece::Pos) -> i8 { + match self.grid.get(pos.0 as usize) { + None => return 0, + _ => return *self.grid.get(pos.0 as usize).unwrap() + .get(pos.1 as usize).unwrap_or(&0) + } + } }
\ No newline at end of file |