From 4304c6d97fdc031d3e0c3d037b5d77c95cbbe84a Mon Sep 17 00:00:00 2001 From: Alexander Baranov Date: Sat, 6 Jun 2026 09:32:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20-=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake-game/src/domain/position.rs | 2 +- snake-game/src/gameplay.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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();