-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot.py
133 lines (118 loc) · 4.85 KB
/
robot.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/python
# -*- coding: utf-8 -*-
import math
# ******************************************************************************
# ************************************************************************* TODO
# ******************************************************************************
class Robot(object):
"""
Un robot a une _pos et une _color.
"""
# --------------------------------------------------------------------------
# --------------------------------------------------------------------- todo
def __init__(self, board, col=(1,0,0), label="rr"):
"""
Un robot, associé à une Board.
"""
self._label = label
self._board = board
self._color = col
self._pos = None
# --------------------------------------------------------------------------
# --------------------------------------------------------------------- todo
def put(self, pos):
"""
Pose le robot sur Board, màj Cell (_label)
:Param
- `pos`: (x,y)
"""
# Cell doit pas avoir un robot
cell = self._board.get_cell( pos )
if cell._type.startswith( ('r') ) or cell.has_rob():
raise RobotPosError( cell )
# Pose le robot
cell._rob = self
self._pos = cell._pos
# --------------------------------------------------------------------------
# --------------------------------------------------------------------- todo
def remove(self, ):
"""Enlève le robot du Board.
"""
if self._pos != None:
cell = self._board.get_cell( self._pos )
cell._rob = None
self._pos = None
# --------------------------------------------------------------------------
# --------------------------------------------------------------------- todo
def draw(self, cr):
"""
:Param
- `cr`: Cairo context
"""
if self._pos <> None :
cr.set_source_rgb( *self._color )
cr.arc( self._pos[0], self._pos[1], 0.3, 0, math.pi*2 )
cr.fill()
# ******************************************************************************
# ************************************************************************* TODO
# ******************************************************************************
class Target(object):
"""
Une Target a une _pos et une _color.
"""
# --------------------------------------------------------------------------
# --------------------------------------------------------------------- todo
def __init__(self, board, col=(0,0,0), label="ta"):
"""
Une Target, associé à une Board.
"""
self._label = label
self._board = board
self._color = col
self._pos = None
# --------------------------------------------------------------------------
# --------------------------------------------------------------------- todo
def put(self, pos):
"""
Pose la Target sur Board, màj Cell (_label)
:Param
- `pos`: (x,y)
"""
# Pose la target
self._pos = pos
# --------------------------------------------------------------------------
# --------------------------------------------------------------------- todo
def remove(self, ):
"""Enlève la Target du Board.
"""
if self._pos != None:
cell = self._board.get_cell( self._pos )
self._pos = None
# --------------------------------------------------------------------------
# --------------------------------------------------------------------- todo
def draw(self, cr):
"""
:Param
- `cr`: Cairo context
"""
if self._pos <> None :
cr.set_source_rgb( *self._color )
cr.arc( self._pos[0], self._pos[1], 0.4, 0, math.pi*2 )
cr.stroke()
# ******************************************************************************
# ************************************************************************* TODO
# ******************************************************************************
class RobotPosError(Exception):
"""Robot badly placed
"""
# --------------------------------------------------------------------------
# --------------------------------------------------------------------- todo
def __init__(self, cell):
"""Crée le msg erreur
:Param
- `cell`: Cell
"""
Exception.__init__( 'Rob mal placé pos={0}, type={1}, rob={2}'.format( cell._pos, cell._type, cell._rob))
# ******************************************************************************
# ************************************************************************** END
# ******************************************************************************