-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMouse.py
52 lines (40 loc) · 1.15 KB
/
Mouse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import API
from Direction import Direction
class Mouse:
def __init__(self, x, y, d):
self.x = x
self.y = y
self.d = d
self.streak = 1
def getPosition(self):
return (self.x, self.y)
def getDirection(self):
return self.d
def getDirectionTo(self,position):
if position[0] == (self.x)-1:
return Direction.EAST
elif position[0] == (self.x)+1:
return Direction.WEST
elif position[1] == (self.y)-1:
return Direction.SOUTH
elif position[1] == (self.y)+1:
return Direction.NORTH
def turnLeft(self):
API.turnLeft()
self.d = self.d.turnLeft()
def turnRight(self):
API.turnRight()
self.d = self.d.turnRight()
def turnAround(self):
self.turnRight()
self.turnRight()
def moveForward(self):
API.moveForward()
if self.d == Direction.NORTH:
self.y += 1
if self.d == Direction.EAST:
self.x += 1
if self.d == Direction.SOUTH:
self.y -= 1
if self.d == Direction.WEST:
self.x -= 1