aboutsummaryrefslogtreecommitdiff
path: root/src/tetris
diff options
context:
space:
mode:
authorcurly <curlybryce@protonmail.com>2022-08-19 14:45:00 -0600
committercurly <curlybryce@protonmail.com>2022-08-19 14:45:00 -0600
commit5d8e223d26f272323c554b61df0f5575060a30ac (patch)
tree6991c550c1c3e931d240a54797c65178e73ec000 /src/tetris
parentf0d5ddacfc97f0e88e3a7c445f890a76fabe47c7 (diff)
downloadtetris-master.tar.gz
tetris-master.tar.bz2
tetris-master.zip
input refactorHEADmaster
Diffstat (limited to 'src/tetris')
-rw-r--r--src/tetris/piece.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/tetris/piece.rs b/src/tetris/piece.rs
index 19e8e6c..fc7d1c7 100644
--- a/src/tetris/piece.rs
+++ b/src/tetris/piece.rs
@@ -198,16 +198,20 @@ impl Piece {
for pos in self.get_bits_pos() {
let new_pos = pos + dir.get();
- // Detect blocks and kill only if Dir is down
- if grid.get_grid_pos(new_pos) == 1 && *dir == Dir::Down {
- self.kill();
- return Err(())
- } else if grid.get_grid_pos(new_pos) == 1 {
- return Err(())
- } else if new_pos.0 > 19 { // Detect bottom and kill
- self.kill();
- return Err(())
- } else if new_pos.1 > 9 || new_pos.1 < 0 { // Detect sides
+ if self.is_alive() {
+ // Detect blocks and kill only if Dir is down
+ if grid.get_grid_pos(new_pos) == 1 && *dir == Dir::Down {
+ self.kill();
+ return Err(())
+ } else if grid.get_grid_pos(new_pos) == 1 {
+ return Err(())
+ } else if new_pos.0 > 19 { // Detect bottom and kill
+ self.kill();
+ return Err(())
+ } else if new_pos.1 > 9 || new_pos.1 < 0 { // Detect sides
+ return Err(())
+ }
+ } else {
return Err(())
}
}
@@ -315,15 +319,12 @@ impl Piece {
self.alive = false
}
- // Return false if the piece cannot move
pub fn r#move(&mut self, dir: Dir, grid: &Tetris) {
// If a hit is detected, don't move
// Otherwise move
- if self.is_alive() {
- match self.hit_detect(&dir, &grid) {
- Ok(_) => self.apply_dir(&dir),
- Err(_) => (),
- }
+ match self.hit_detect(&dir, &grid) {
+ Ok(_) => self.apply_dir(&dir),
+ Err(_) => (),
}
}
} \ No newline at end of file