-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.rb
More file actions
62 lines (44 loc) · 1.13 KB
/
Matrix.rb
File metadata and controls
62 lines (44 loc) · 1.13 KB
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
def matrix(rows)
puts "[?, ?, ?]",
"[?, ?, ?]",
"[?, ?, ?]"
attempt = 1
loop do
puts "select the row between 1, 2, 3"
rowChoice = gets.chomp.to_i - 1 #minus 1 to match index num
puts "select the column 1, 2, or 3"
colChoice = gets.chomp.to_i - 1
row = rows[rowChoice] || "invalid" #assign false if chosen row array index is nil
if row
chosen = rows[rowChoice][colChoice] #assiging the chose row and col
end
if chosen == "invalid" || chosen == nil #if chosen row and col index is nil print invalid
puts "invalid input"
end
if chosen == "Winner"
puts "Winner"
break
elsif chosen == "miss"
puts "Miss"
end
if attempt == 3
puts "That's 3 tries, Game Over!"
break
end
attempt +=1
end
end
sets = [[["miss", "miss", "miss"],
["miss", "miss", "Winner"],
["miss", "miss", "miss"]],
[["Winner", "miss", "miss"],
["miss", "miss", "miss"],
["miss", "miss", "miss"]],
[["miss", "miss", "miss"],
["miss", "Winner", "miss"],
["miss", "miss", "miss"]],
[["miss", "miss", "miss"],
["Winner", "miss", "miss"],
["miss", "miss", "miss"]]]
rows = sets.sample
matrix(rows)