diff --git a/snake-game/src/domain/position.rs b/snake-game/src/domain/position.rs index 82e5c36..1d63a9e 100644 --- a/snake-game/src/domain/position.rs +++ b/snake-game/src/domain/position.rs @@ -15,7 +15,7 @@ impl Position { Self { x, y } } - pub fn change(&mut self, direction: &Direction) { + pub fn shift(&mut self, direction: &Direction) { match direction { Direction::Up => self.y += 1, Direction::Left => self.x -= 1, diff --git a/snake-game/src/gameplay.rs b/snake-game/src/gameplay.rs index 276e6f9..aad4ed2 100644 --- a/snake-game/src/gameplay.rs +++ b/snake-game/src/gameplay.rs @@ -20,9 +20,10 @@ pub fn head_rotation( new_direction.rotate_left(); if !snake_path.push(dst_pos, new_direction) { trace!("try 1 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); - dst_pos.change(&direction); + dst_pos.shift(&direction); if !snake_path.push(dst_pos, new_direction) { trace!("try 2 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); + return; } } transform.rotation = new_direction.orientation(); @@ -36,9 +37,10 @@ pub fn head_rotation( new_direction.rotate_right(); if !snake_path.push(dst_pos, new_direction) { trace!("try 1 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); - dst_pos.change(&direction); + dst_pos.shift(&direction); if !snake_path.push(dst_pos, new_direction) { trace!("try 2 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); + return; } } transform.rotation = new_direction.orientation();