-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.e
executable file
·173 lines (147 loc) · 3.96 KB
/
game.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
class
GAME
inherit
MONOPOLY_OBJECT
create
make
feature {NONE} -- Initialization
make
-- Create a game
local
n, i: INTEGER
p: PLAYER
first: BOOLEAN
do
first := True
n := Monopoly_view.request_bounded_value ("Enter number of player between between " + Min_player_count.out + " and " + Max_player_count.out + " :", Min_player_count, Max_player_count)
create board
create die_1.make_with_model
create die_2.make_with_model
create players.make (0)
from
i := 1
until
i > n
loop
create p.make (Monopoly_view.request_text ("Player " + i.out + " choose your name"), start_money, create {TOKEN}.make_with_color (colors.item (i).color, colors.item (i).relative_x, colors.item (i).relative_y), colors.item (i).color, board)
p.set_position (1)
players.extend (p)
if first then
current_player := p
first := False
end
i := i + 1
end
end
feature -- Basic operations
play
-- Start a game.
do
players.start
players.item.info_view.roll_dice_button.show
players.item.info_view.roll_dice_button.select_actions.extend (agent play_first_round)
end
play_first_round
-- Initialize the first round
do
players.start
Monopoly_view.board_view.extend (Monopoly_view.dice_container)
players.item.play (die_1, die_2, 1)
end
end_game
-- Finish the game when there's no more player
local
i: INTEGER
do
if winner /= Void then
winner.info_view.remove
if winner.token /= Void and then Monopoly_view.board_view.has (winner.token.view) then
Monopoly_view.remove_token (winner.token.view)
end
end
across
players as p
loop
p.item.info_view.remove
end
players.wipe_out
from
i := 1
until
i > board.squares.count
loop
if attached {PROPERTY_SQUARE} board.squares.item (i) as p then
p.remove_owner
end
i := i + 1
end
end
restart_game
-- Erase the current game and restart a new one
local
n, i: INTEGER
p: PLAYER
do
n := Monopoly_view.request_bounded_value ("Enter number of player between between " + Min_player_count.out + " and " + Max_player_count.out + " :", Min_player_count, Max_player_count)
from
i := 1
until
i > n
loop
create p.make (Monopoly_view.request_text ("Player " + i.out + " choose your name"), start_money, create {TOKEN}.make_with_color (colors.item (i).color, colors.item (i).relative_x, colors.item (i).relative_y), colors.item (i).color, board)
p.set_position (1)
players.extend (p)
i := i + 1
end
play
end
set_current_player (p: PLAYER)
-- Set the current player as `p'
require
p /= Void
do
current_player := p
ensure
current_player = p
end
set_winner (w: PLAYER)
-- Set the winnr of the game
require
winner_exist: w /= Void
do
winner := w
ensure
winner_set: winner = w
end
feature -- Constants
Min_player_count: INTEGER = 2
-- Minimum number of players.
Max_player_count: INTEGER = 6
-- Maximum number of players.
Start_money: INTEGER = 1500
-- The money each player have at the beginning of the game
colors: ARRAY [TUPLE [color: EV_COLOR; relative_x: INTEGER; relative_y: INTEGER]]
-- Colors for the tokens
once
create Result.make_empty
Result.force ([create {EV_COLOR}.make_with_rgb (1, 0, 0), -25, 15], 1)
Result.force ([create {EV_COLOR}.make_with_rgb (0, 1, 0), 25, 15], 2)
Result.force ([create {EV_COLOR}.make_with_rgb (0, 0, 1), -25, -15], 3)
Result.force ([create {EV_COLOR}.make_with_rgb (1, 0, 1), 25, -15], 4)
Result.force ([create {EV_COLOR}.make_with_rgb (0, 0, 0), 0, 15], 5)
Result.force ([create {EV_COLOR}.make_with_rgb (1, 1, 0), 0, -15], 6)
end
feature -- Access
players: ARRAYED_LIST [PLAYER]
-- Container for players.
current_player: PLAYER
-- Payer currently playing
board: MONOPOLY_BOARD
-- Board of the game
die_1: DIE
-- The first die.
die_2: DIE
-- The second die.
winner: PLAYER
-- The winner (Void if the game if not over yet).
end