forked from zakstal/Minesweeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.rb
More file actions
86 lines (69 loc) · 1.53 KB
/
game.rb
File metadata and controls
86 lines (69 loc) · 1.53 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#this is kc's version
require_relative 'board'
class Game
attr_accessor :board #probably shouldn't be accessor
def initialize(board = Board.new)
@board = board
end
def play
puts "MINESWEEPER"
until board.won?
begin
mode_prompt
mode = get_mode
place_prompt
place = get_place
board.click(mode, place)
if board.lost
board.display
lost_prompt
play_again
return
end
rescue RuntimeError
puts "That spot has been clicked already. Enter another spot."
retry
end
end
board.display
won_prompt
play_again
end
def mode_prompt
board.display
puts "Enter r for reveal or f for flag or unflag."
print '≽ '
end
def get_mode
mode = gets.chomp.to_sym
return mode if [:r,:f].include?(mode)
mode_prompt
get_mode
end
def place_prompt
puts "Enter an x, y location."
print '≽ '
end
def get_place
place = gets.chomp.split(',').map(&:strip).map(&:to_i) #use Integer instead
place.reverse!
end
def lost_prompt
puts "You are a good person. This happens to everyone."
puts "Love yourself."
end
def won_prompt
puts "You did great. Because you are great."
end
def play_again
puts "Would you like to play again? Chump?"
print '≽ '
reply = gets.chomp[0].downcase
if reply == 'y'
new_game = Game.new
new_game.play
else
puts "Thanks for playing. Chump. Bye. Whatever."
end
end
end