-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.e
executable file
·89 lines (73 loc) · 2.14 KB
/
token.e
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
class
TOKEN
inherit
MONOPOLY_OBJECT
create
make_with_color
feature -- Initialization
make_with_color (c: EV_COLOR; x, y: INTEGER)
require
c /= Void
do
create view.make_with_positions (550 + x, 550 + y, 565 + x, 565 + y)
color := c
relative_x := x
relative_y := y
view.set_background_color (color)
Monopoly_view.add_token (view)
ensure
view_exist: view /= Void
color /= Void
end
feature -- Basic operations
move_to_position (position: INTEGER)
-- Move the token to the square at position `p'
require
correct_position: position >= 0
local
x, y: INTEGER
do
if (position - 1) // 5 = 0 then
x := Board_width - get_square_position (position)
y := Board_width - (Square_inner_height / 2).truncated_to_integer
elseif (position - 1) // 5 = 1 then
x := (Square_inner_height / 2).truncated_to_integer
y := Board_width - get_square_position (position - 5)
elseif (position - 1) // 5 = 2 then
x := get_square_position (position - 10)
y := (Square_inner_height / 2).truncated_to_integer
elseif (position - 1) // 5 = 3 then
x := Board_width - (Square_inner_height / 2).truncated_to_integer
y := get_square_position (position - 15)
end
view.set_point_a_position (x + relative_x, y + relative_y)
view.set_point_b_position (x + 15 + relative_x, y + 15 + relative_y)
Monopoly_view.projector.project
end
remove
-- Erase the token from the board
do
Monopoly_view.remove_token (view)
end
feature -- Access
view: EV_MODEL_ELLIPSE
-- Representation on the board view
color: EV_COLOR
-- Color of the token
feature {NONE} -- Implementation
relative_x: INTEGER
-- x position relative to square center
relative_y: INTEGER
-- y position relative to square center
get_square_position (square_number: INTEGER): INTEGER
-- Returns the position of the square in a line
require
square_number >= 0 and square_number <= 5
do
if square_number = 1 then
Result := (Square_height / 2).truncated_to_integer
else
Result := Square_height + Square_width.truncated_to_integer // 2 + ((square_number - 2) * Square_width).truncated_to_integer
end
end
end