completed move functions
This commit is contained in:
		
							parent
							
								
									80dfe2d69e
								
							
						
					
					
						commit
						f7d86c9991
					
				
							
								
								
									
										10
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/main.rs
									
									
									
									
									
								
							@ -110,7 +110,8 @@ impl Robot {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /// Apply right instruction to the robot.
 | 
					    /// Apply right instruction to the robot.
 | 
				
			||||||
    fn move_right(&mut self) {
 | 
					    fn move_right(&mut self, w: &mut World) {
 | 
				
			||||||
 | 
					        w.map[(self.p.x + (self.p.y * w.x as i32)) as usize] = '.';
 | 
				
			||||||
        match self.o {
 | 
					        match self.o {
 | 
				
			||||||
            Orientation::N => self.p.x += 1,
 | 
					            Orientation::N => self.p.x += 1,
 | 
				
			||||||
            Orientation::S => self.p.x -= 1,
 | 
					            Orientation::S => self.p.x -= 1,
 | 
				
			||||||
@ -119,7 +120,8 @@ impl Robot {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /// Apply left instruction to the robot.
 | 
					    /// Apply left instruction to the robot.
 | 
				
			||||||
    fn move_left(&mut self) {
 | 
					    fn move_left(&mut self, w: &mut World) {
 | 
				
			||||||
 | 
					        w.map[(self.p.x + (self.p.y * w.x as i32)) as usize] = '.';
 | 
				
			||||||
        match self.o {
 | 
					        match self.o {
 | 
				
			||||||
            Orientation::N => self.p.x -= 1,
 | 
					            Orientation::N => self.p.x -= 1,
 | 
				
			||||||
            Orientation::S => self.p.x += 1,
 | 
					            Orientation::S => self.p.x += 1,
 | 
				
			||||||
@ -307,9 +309,9 @@ mod tests {
 | 
				
			|||||||
        w.create();
 | 
					        w.create();
 | 
				
			||||||
        r.move_forward(&mut w);
 | 
					        r.move_forward(&mut w);
 | 
				
			||||||
        assert_eq!(0, r.p.y);
 | 
					        assert_eq!(0, r.p.y);
 | 
				
			||||||
        r.move_right();
 | 
					        r.move_right(&mut w);
 | 
				
			||||||
        assert_eq!(2, r.p.x);
 | 
					        assert_eq!(2, r.p.x);
 | 
				
			||||||
        r.move_left();
 | 
					        r.move_left(&mut w);
 | 
				
			||||||
        assert_eq!(1, r.p.x);
 | 
					        assert_eq!(1, r.p.x);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user