-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabout_extra_credit_second.rb
332 lines (310 loc) · 7.1 KB
/
about_extra_credit_second.rb
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
class Score
attr :result
def calc(dice)
#asegurando que tirada tenga algun valor
if dice.length == 0
return 0
end
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
@result = 0
#mirando las tiradas
dice.each do |value|
if value == 1
one += 1
end
if value == 2
two += 1
end
if value == 3
three += 1
end
if value == 4
four += 1
end
if value == 5
five += 1
end
if value == 6
six += 1
end
end
#generando resultado
if one == 1
@result += 100
end
if one == 2
@result += 200
end
if one == 3
@result += 1000
end
if one == 4
@result += 1100
end
if one == 5
@result += 1200
end
if two == 3
@result += 200
end
if three == 3
@result += 300
end
if four == 3
@result += 400
end
if five == 1
@result += 50
end
if five == 2
@result += 100
end
if five == 3
@result += 500
end
if five == 4
@result += 550
end
if five == 5
@result += 600
end
if six == 3
@result += 600
end
# respuesta
@result
end
end
p "Welcome to GREED game"
p "How many players"
numberplayers = gets.chomp
while (numberplayers.to_i >= 6) || (numberplayers.to_i <= 1) do
p "I need a number between 2 and 5, please"
numberplayers = gets.chomp
end
player1name = ""
while player1name == "" do
p "Input player 1 name :"
player1name = gets.chomp
end
player2name = ""
while player2name == "" do
p "Input player 2 name :"
player2name = gets.chomp
end
if numberplayers.to_i >= 3
player3name = ""
while player3name == "" do
p "Input player 3 name :"
player3name = gets.chomp
end
end
if numberplayers.to_i >= 4
player4name = ""
while player4name == "" do
p "Input player 4 name :"
player4name = gets.chomp
end
end
if numberplayers.to_i == 5
player5name = ""
while player5name == "" do
p "Input player 5 name :"
player5name = gets.chomp
end
end
bestscore = 0
score = []
score1 = Score.new
score2 = Score.new
score3 = Score.new
socre4 = Score.new
score5 = Score.new
score1total = 0
score2total = 0
score3total = 0
score4total = 0
score5total = 0
p "ROLL THE DICE"
while bestscore <= 3000 do
p "Player 1 turn:"
p "Input 1º roll from player 1"
score[0] = gets.chomp
p "Input 2º roll from player 1"
score[1] = gets.chomp
p "Input 3º roll from player 1"
score[2] = gets.chomp
p "Input 4º roll from player 1"
score[3] = gets.chomp
p "Input 5º roll from player 1"
score[4] = gets.chomp
score1total = score1total + score1.calc(score.map(&:to_i))
p "Player 2 turn:"
p "Input 1º roll from player 2"
score[0] = gets.chomp
p "Input 2º roll from player 2"
score[1] = gets.chomp
p "Input 3º roll from player 2"
score[2] = gets.chomp
p "Input 4º roll from player 2"
score[3] = gets.chomp
p "Input 5º roll from player 2"
score[4] = gets.chomp
score2total = score2total + score2.calc(score.map(&:to_i))
if (numberplayers.to_i >= 3)
p "Player 3 turn:"
p "Input 1º roll from player 3"
score[0] = gets.chomp
p "Input 2º roll from player 3"
score[1] = gets.chomp
p "Input 3º roll from player 3"
score[2] = gets.chomp
p "Input 4º roll from player 3"
score[3] = gets.chomp
p "Input 5º roll from player 3"
score[4] = gets.chomp
score3total = score3total + score3.calc(score.map(&:to_i))
end
if (numberplayers.to_i >= 4)
p "Player 4 turn:"
p "Input 1º roll from player 4"
score[0] = gets.chomp
p "Input 2º roll from player 4"
score[1] = gets.chomp
p "Input 3º roll from player 4"
score[2] = gets.chomp
p "Input 4º roll from player 4"
score[3] = gets.chomp
p "Input 5º roll from player 4"
score[4] = gets.chomp
score4total = score4total + score4.calc(score.map(&:to_i))
end
if (numberplayers.to_i == 5)
p "Player 5 turn:"
p "Input 1º roll from player 5"
score[0] = gets.chomp
p "Input 2º roll from player 5"
score[1] = gets.chomp
p "Input 3º roll from player 5"
score[2] = gets.chomp
p "Input 4º roll from player 5"
score[3] = gets.chomp
p "Input 5º roll from player 5"
score[4] = gets.chomp
score5total = score5total + score5.calc(score.map(&:to_i))
end
bestscore = [score1total, score2total, score3total, score4total, score5total].max
if bestscore >= 3000
if bestscore != score1total
p "Player 1 turn:"
p "Input 1º roll from player 1"
score[0] = gets.chomp
p "Input 2º roll from player 1"
score[1] = gets.chomp
p "Input 3º roll from player 1"
score[2] = gets.chomp
p "Input 4º roll from player 1"
score[3] = gets.chomp
p "Input 5º roll from player 1"
score[4] = gets.chomp
score1total = score1total + score1.calc(score.map(&:to_i))
end
if bestscore != score2total
p "Player 2 turn:"
p "Input 1º roll from player 2"
score[0] = gets.chomp
p "Input 2º roll from player 2"
score[1] = gets.chomp
p "Input 3º roll from player 2"
score[2] = gets.chomp
p "Input 4º roll from player 2"
score[3] = gets.chomp
p "Input 5º roll from player 2"
score[4] = gets.chomp
score2total = score2total + score2.calc(score.map(&:to_i))
end
if (numberplayers.to_i >= 3)
if bestscore != score3total
p "Player 3 turn:"
p "Input 1º roll from player 3"
score[0] = gets.chomp
p "Input 2º roll from player 3"
score[1] = gets.chomp
p "Input 3º roll from player 3"
score[2] = gets.chomp
p "Input 4º roll from player 3"
score[3] = gets.chomp
p "Input 5º roll from player 3"
score[4] = gets.chomp
score3total = score3total + score3.calc(score.map(&:to_i))
end
end
if (numberplayers.to_i >= 4)
if bestscore != score3total
p "Player 4 turn:"
p "Input 1º roll from player 4"
score[0] = gets.chomp
p "Input 2º roll from player 4"
score[1] = gets.chomp
p "Input 3º roll from player 4"
score[2] = gets.chomp
p "Input 4º roll from player 4"
score[3] = gets.chomp
p "Input 5º roll from player 4"
score[4] = gets.chomp
score4total = score4total + score4.calc(score.map(&:to_i))
end
end
if (numberplayers.to_i == 5)
if bestscore != score3total
p "Player 5 turn:"
p "Input 1º roll from player 5"
score[0] = gets.chomp
p "Input 2º roll from player 5"
score[1] = gets.chomp
p "Input 3º roll from player 5"
score[2] = gets.chomp
p "Input 4º roll from player 5"
score[3] = gets.chomp
p "Input 5º roll from player 5"
score[4] = gets.chomp
score5total = score5total + score5.calc(score.map(&:to_i))
end
end
bestscore = [score1total, score2total, score3total, score4total, score5total].max
end
p "SCORES:"
p "Player 1: #{score1total}"
p "Player 2: #{score2total}"
if (numberplayers.to_i >= 3)
p "Player 3: #{score3total}"
end
if (numberplayers.to_i >= 4)
p "Player 4: #{score4total}"
end
if (numberplayers.to_i >= 5)
p "Player 5: #{score5total}"
end
if bestscore >= 3000
if bestscore == score1total
p "Player 1 Wins!!!!"
end
if bestscore == score2total
p "Player 2 Wins!!!!"
end
if bestscore == score3total
p "Player 3 Wins!!!!"
end
if bestscore == score4total
p "Player 4 Wins!!!!"
end
if bestscore == score5total
p "Player 5 Wins!!!!"
end
end
end