minesweeper-cl 0.0.3 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af0bc9d27bc14214520ecaa422531778f6ca0ac8
4
- data.tar.gz: d6a78e8abc9bb03129fee1f095279d8d6539ea37
3
+ metadata.gz: 85de14a45adbabf9db52ef0e26a84edb2d1ef8f4
4
+ data.tar.gz: bbdc5313b92f2e82c0fa41110f12b86beb872a9a
5
5
  SHA512:
6
- metadata.gz: 386ea4560612f983a4d413be3210607eb39adf0163808e133db4ade059ef73a2991ca784ced346af748ecfc801c1544bd777ffda648397d1bd09e9bd109b2ff7
7
- data.tar.gz: 51d28d14471273821e73dba73f62f3c84082efd987f967d94f4801938a4c6a8de5a8510470905f4db20cbe8b268b85be2bfecc6bcd0e1a22c82f1c9d5ce2ba52
6
+ metadata.gz: 60a4364bfd95d6f17eef069117938e559eb5bf299857a37a65e591f6048e43a9271cfe860a1a6f2100ca2492f03cbed301651b613736f1e50eb2299ca2c33ccb
7
+ data.tar.gz: 4d5013d5935cef2cc1e5b250cdbaae474ae5ce6bc4c9a52441946174a287427f3eab5d64014f5a615dc0db37e49f006f52ba3f32a1dae8f9e48f19c7ab442ec0
@@ -6,26 +6,34 @@ require 'game_board'
6
6
  puts "Welcome to the game of minesweeper!"
7
7
  puts "-----------------------------------"
8
8
  puts "Please enter the amount of rows that you would like to play with, anything more than 20 will be truncated."
9
- rows = gets.chomp.to_i
9
+ rows = gets.chomp
10
10
 
11
- while !rows.is_a?(Integer) do
11
+ while /^(\d){1,2}\z/.match(rows) == nil do
12
12
  puts "Please enter the amount of rows that you would like to play with, anything more than 20 will be truncated."
13
- rows = gets.chomp.to_i
13
+ rows = gets.chomp
14
14
  end
15
15
 
16
+ # Ternary statement to truncate the rows if value entered is greater than 20
17
+ if rows.to_i > 20 then rows = 20 else rows = rows.to_i end
18
+
16
19
  puts "Please enter the amount of cols that you would like to play with, anything more than 20 will be truncated."
17
- cols = gets.chomp.to_i
20
+ cols = gets.chomp
18
21
 
19
- while !cols.is_a?(Integer) do
22
+ while /^(\d){1,2}\z/.match(cols) == nil do
20
23
  puts "Please enter the amount of cols that you would like to play with, anything more than 20 will be truncated."
21
- cols = gets.chomp.to_i
24
+ cols = gets.chomp
22
25
  end
23
26
 
27
+ # Ternary statement to truncate the cols if value entered is greater than 20
28
+ if cols.to_i > 20 then cols = 20 else cols = cols.to_i end
29
+
24
30
  puts "Please enter the % chance you want for a bomb to occur"
31
+ puts "This number needs to be between 0 and 1"
25
32
  bomb_chance = gets.chomp.to_f
26
33
 
27
- while !bomb_chance.is_a?(Float) do
34
+ while !bomb_chance.is_a?(Float) || bomb_chance > 1.0 || bomb_chance < 0.0 do
28
35
  puts "Please enter the % chance you want for a bomb to occur"
36
+ puts "This number needs to be between 0 and 1"
29
37
  bomb_chance = gets.chomp.to_f
30
38
  end
31
39
 
@@ -6,26 +6,34 @@ require 'game_board'
6
6
  puts "Welcome to the game of minesweeper!"
7
7
  puts "-----------------------------------"
8
8
  puts "Please enter the amount of rows that you would like to play with, anything more than 20 will be truncated."
9
- rows = gets.chomp.to_i
9
+ rows = gets.chomp
10
10
 
11
- while !rows.is_a?(Integer) do
11
+ while /^(\d){1,2}\z/.match(rows) == nil do
12
12
  puts "Please enter the amount of rows that you would like to play with, anything more than 20 will be truncated."
13
- rows = gets.chomp.to_i
13
+ rows = gets.chomp
14
14
  end
15
15
 
16
+ # Ternary statement to truncate the rows if value entered is greater than 20
17
+ if rows.to_i > 20 then rows = 20 else rows = rows.to_i end
18
+
16
19
  puts "Please enter the amount of cols that you would like to play with, anything more than 20 will be truncated."
17
- cols = gets.chomp.to_i
20
+ cols = gets.chomp
18
21
 
19
- while !cols.is_a?(Integer) do
22
+ while /^(\d){1,2}\z/.match(cols) == nil do
20
23
  puts "Please enter the amount of cols that you would like to play with, anything more than 20 will be truncated."
21
- cols = gets.chomp.to_i
24
+ cols = gets.chomp
22
25
  end
23
26
 
27
+ # Ternary statement to truncate the cols if value entered is greater than 20
28
+ if cols.to_i > 20 then cols = 20 else cols = cols.to_i end
29
+
24
30
  puts "Please enter the % chance you want for a bomb to occur"
31
+ puts "This number needs to be between 0 and 1"
25
32
  bomb_chance = gets.chomp.to_f
26
33
 
27
- while !bomb_chance.is_a?(Float) do
34
+ while !bomb_chance.is_a?(Float) || bomb_chance > 1.0 || bomb_chance < 0.0 do
28
35
  puts "Please enter the % chance you want for a bomb to occur"
36
+ puts "This number needs to be between 0 and 1"
29
37
  bomb_chance = gets.chomp.to_f
30
38
  end
31
39
 
@@ -33,25 +33,36 @@ class MinesweeperGame
33
33
  def play_the_game
34
34
  puts "Please put two numbers corresponding to the row and column that you'd like to play in the form"
35
35
  puts "<pf> <row>, <column>"
36
+ puts "Numbers greater than the number of rows or cols will be truncated to the max row/col"
36
37
  puts
37
38
  player_choice = gets.chomp
38
39
 
40
+ if /^(help|h)\z/.match(player_choice) then print_help_message end
41
+
39
42
  # Now match the player response with a regular expression
40
- while /([pf]) (\d), (\d)$/.match(player_choice) == nil
43
+ while /^([pfPF]) (\d){1,2}, (\d){1,2}\z/.match(player_choice) == nil
41
44
  puts "Please put two numbers corresponding to the row and column that you'd like to play in the form"
42
45
  puts "<pf> <row>, <column>"
46
+ puts "Numbers greater than the number of rows or cols will be truncated to the max row/col"
43
47
  puts
44
48
  player_choice = gets.chomp
49
+ if /^(help|h)\z/.match(player_choice) then print_help_message end
45
50
  end
46
- match = /([pf]) (\d), (\d)$/.match(player_choice)
51
+ match = /^([pfPF]) (\d){1,2}, (\d){1,2}\z/.match(player_choice)
52
+ row = match[2].to_i
53
+ col = match[3].to_i
54
+
55
+ if row > @rows then row = @rows end
56
+ if col > @columns then col = @columns end
57
+
47
58
  # A 'p' character indicates that the player wants to "play" the tile.
48
59
  # An 'f' character indicates that the player would like to flag the
49
60
  # tile because they believe there to be a bomb there. Flagged tiles
50
61
  # may still be played after they have been flagged.
51
- if match[1] == 'p'
52
- play_tile(match[2].to_i - 1, match[3].to_i - 1)
53
- elsif match[1] == 'f'
54
- flag_tile(match[2].to_i - 1, match[3].to_i - 1)
62
+ if match[1] == 'p' || match[1] == 'P'
63
+ play_tile(row - 1, col - 1)
64
+ elsif match[1] == 'f' || match[1] == 'F'
65
+ flag_tile(row - 1, col - 1)
55
66
  end
56
67
  puts
57
68
  print_the_board
@@ -93,5 +104,30 @@ class MinesweeperGame
93
104
  @win
94
105
  end
95
106
 
107
+ private
108
+ def print_help_message
109
+ puts """
110
+ This is a command line port of the game of minesweeper. It's supposed to be like
111
+ the minesweeper game that comes standard with most operating systems, but the
112
+ functionality is a little different because it's just command line based. In
113
+ order to make a move you can just put in something like:
114
+
115
+ p 1, 2
116
+
117
+ where the coordinates are number starting at 1, 1 in the upper left corner to
118
+ rows, cols for the number of rows and columns that you put in at the start of the
119
+ game. If you play something like:
120
+
121
+ f 1, 2
122
+
123
+ then that location will be flagged (|>) and marked as played. You can win the
124
+ game while still having marked tiles.
125
+
126
+ Good luck!
127
+ """
128
+ print_the_board
129
+ end
130
+
131
+
96
132
  end
97
133
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minesweeper-cl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - gr1zzly_be4r
@@ -10,7 +10,8 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Minesweeper, ported to the command line
13
+ description: Minesweeper, ported to the command line. Please report any issues to
14
+ the repo on github and star if you like it!
14
15
  email:
15
16
  executables:
16
17
  - minesweeper
@@ -22,7 +23,7 @@ files:
22
23
  - "./lib/minesweeper.rb"
23
24
  - "./lib/minesweeper_game.rb"
24
25
  - bin/minesweeper
25
- homepage:
26
+ homepage: https://github.com/gr1zzly-be4r/ruby-minesweeper-cli
26
27
  licenses:
27
28
  - MIT
28
29
  metadata: {}