Проектная работа - WIP
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user