aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcurly <curlybryce@protonmail.com>2022-08-15 17:10:34 -0600
committercurly <curlybryce@protonmail.com>2022-08-15 17:10:34 -0600
commit550197e13a9aa00f17b40ddff2d877e52a9f1e9b (patch)
tree525689c17426448826dbed228895050f5c65c8ad /src
parent02515663dd89994dbc987958b19d707a4cd44864 (diff)
downloadtetris-550197e13a9aa00f17b40ddff2d877e52a9f1e9b.tar.gz
tetris-550197e13a9aa00f17b40ddff2d877e52a9f1e9b.tar.bz2
tetris-550197e13a9aa00f17b40ddff2d877e52a9f1e9b.zip
updated TODO and implemented check_lines()
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs1
-rw-r--r--src/tetris.rs26
2 files changed, 26 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 03c67f3..bb9d97d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -25,6 +25,7 @@ impl Game {
let mut tetris = tetris::Tetris::new();
let mut piece = piece::Piece::random(piece::Pos(0,0));
loop {
+ tetris.check_lines();
piece.r#move(piece::Dir::Down, &tetris);
// Check if piece is dead
diff --git a/src/tetris.rs b/src/tetris.rs
index aa9b883..cd88231 100644
--- a/src/tetris.rs
+++ b/src/tetris.rs
@@ -26,7 +26,31 @@ impl Tetris {
// 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 check_lines(&mut self) {
+ // While there are full lines, continue to iterate
+ let mut row = 19;
+ while row > 0 {
+ let mut c = 0;
+ for x in self.grid.get(row as usize).expect("Out of bounds") {
+ if *x == 1 {
+ c += 1;
+ } else {
+ row -= 1;
+ continue
+ }
+ }
+
+ // If the line is full remove it and
+ // move everything down
+ if c == 10 {
+ self.grid.remove(row as usize);
+ self.grid.insert(0, vec![0; 10]);
+ continue;
+ }
+
+ row -= 1;
+ }
+ }
pub fn get_grid_pos(&self, pos: piece::Pos) -> i8 {
match self.grid.get(pos.0 as usize) {