minesweeper-cl 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/minesweeper +12 -33
- data/lib/game_board.rb +1 -0
- data/lib/minesweeper.rb +12 -33
- data/lib/minesweeper_parser.rb +51 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4c480ca41fdede1f0ab25f66f88d2f6b4f023b6
|
4
|
+
data.tar.gz: 17dff4c4323f1f26723b0cb58a48bbb40276f644
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e81ce953573f91a17a9854e2552a5b9018b906b29c50a5b66b71b5ddf58d24f6dfcc5327fb9d5e08808ae4a33c9bff7d8d4da912753c2aea8005be41aac35ee8
|
7
|
+
data.tar.gz: 70b6a22055d4974f1192a877337716e0aaf464c86b4404c9c30adda72a9de425eb473293c28964c7c7e7f06c75852f07afd116cd794ab49907e2383fd5d9d330
|
data/bin/minesweeper
CHANGED
@@ -1,48 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/")
|
2
3
|
require 'game_tile'
|
3
4
|
require 'minesweeper_game'
|
4
5
|
require 'game_board'
|
6
|
+
require 'minesweeper_parser'
|
5
7
|
|
6
8
|
puts "Welcome to the game of minesweeper!"
|
7
|
-
puts "-----------------------------------"
|
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
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
# Make the parser for parsing the data
|
11
|
+
begin
|
12
|
+
options = MinesweeperParser.new.parse!(ARGV)
|
13
|
+
rescue OptionParser::MissingArgument, OptionParser::InvalidArgument
|
14
|
+
help_msg = MinesweeperParser.parse!(["-h"])
|
15
|
+
puts help_msg
|
14
16
|
end
|
15
17
|
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
puts "Please enter the amount of cols that you would like to play with, anything more than 20 will be truncated."
|
20
|
-
cols = gets.chomp
|
21
|
-
|
22
|
-
while /^(\d){1,2}\z/.match(cols) == nil do
|
23
|
-
puts "Please enter the amount of cols that you would like to play with, anything more than 20 will be truncated."
|
24
|
-
cols = gets.chomp
|
25
|
-
end
|
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
|
-
|
30
|
-
puts "Please enter the % chance you want for a bomb to occur"
|
31
|
-
puts "This number needs to be between 0 and 1"
|
32
|
-
bomb_chance = gets.chomp.to_f
|
33
|
-
|
34
|
-
while !bomb_chance.is_a?(Float) || bomb_chance > 1.0 || bomb_chance < 0.0 do
|
35
|
-
puts "Please enter the % chance you want for a bomb to occur"
|
36
|
-
puts "This number needs to be between 0 and 1"
|
37
|
-
bomb_chance = gets.chomp.to_f
|
38
|
-
end
|
39
|
-
|
40
|
-
# Create the board
|
41
|
-
board = GameBoard.new(rows, cols, bomb_chance)
|
18
|
+
# Create the board. We can now use the arguments that have been handled by the arguments
|
19
|
+
# parser class. The arguments have been stored in a hash in an OpenStruct object.
|
20
|
+
board = GameBoard.new(options.rows_cols_chance[:rows], options.rows_cols_chance[:cols], options.rows_cols_chance[:bomb_chance])
|
42
21
|
|
43
22
|
|
44
23
|
# Use the MinesweeperGame class to play the game
|
45
|
-
game = MinesweeperGame.new(board, rows, cols)
|
24
|
+
game = MinesweeperGame.new(board, options.rows_cols_chance[:rows], options.rows_cols_chance[:cols])
|
46
25
|
|
47
26
|
game.print_the_board
|
48
27
|
while !game.game_over? && !game.win? do
|
data/lib/game_board.rb
CHANGED
data/lib/minesweeper.rb
CHANGED
@@ -1,48 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/")
|
2
3
|
require 'game_tile'
|
3
4
|
require 'minesweeper_game'
|
4
5
|
require 'game_board'
|
6
|
+
require 'minesweeper_parser'
|
5
7
|
|
6
8
|
puts "Welcome to the game of minesweeper!"
|
7
|
-
puts "-----------------------------------"
|
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
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
# Make the parser for parsing the data
|
11
|
+
begin
|
12
|
+
options = MinesweeperParser.new.parse!(ARGV)
|
13
|
+
rescue OptionParser::MissingArgument, OptionParser::InvalidArgument
|
14
|
+
help_msg = MinesweeperParser.parse!(["-h"])
|
15
|
+
puts help_msg
|
14
16
|
end
|
15
17
|
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
puts "Please enter the amount of cols that you would like to play with, anything more than 20 will be truncated."
|
20
|
-
cols = gets.chomp
|
21
|
-
|
22
|
-
while /^(\d){1,2}\z/.match(cols) == nil do
|
23
|
-
puts "Please enter the amount of cols that you would like to play with, anything more than 20 will be truncated."
|
24
|
-
cols = gets.chomp
|
25
|
-
end
|
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
|
-
|
30
|
-
puts "Please enter the % chance you want for a bomb to occur"
|
31
|
-
puts "This number needs to be between 0 and 1"
|
32
|
-
bomb_chance = gets.chomp.to_f
|
33
|
-
|
34
|
-
while !bomb_chance.is_a?(Float) || bomb_chance > 1.0 || bomb_chance < 0.0 do
|
35
|
-
puts "Please enter the % chance you want for a bomb to occur"
|
36
|
-
puts "This number needs to be between 0 and 1"
|
37
|
-
bomb_chance = gets.chomp.to_f
|
38
|
-
end
|
39
|
-
|
40
|
-
# Create the board
|
41
|
-
board = GameBoard.new(rows, cols, bomb_chance)
|
18
|
+
# Create the board. We can now use the arguments that have been handled by the arguments
|
19
|
+
# parser class. The arguments have been stored in a hash in an OpenStruct object.
|
20
|
+
board = GameBoard.new(options.rows_cols_chance[:rows], options.rows_cols_chance[:cols], options.rows_cols_chance[:bomb_chance])
|
42
21
|
|
43
22
|
|
44
23
|
# Use the MinesweeperGame class to play the game
|
45
|
-
game = MinesweeperGame.new(board, rows, cols)
|
24
|
+
game = MinesweeperGame.new(board, options.rows_cols_chance[:rows], options.rows_cols_chance[:cols])
|
46
25
|
|
47
26
|
game.print_the_board
|
48
27
|
while !game.game_over? && !game.win? do
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
# Include this line in order to show a help message if there are no args
|
6
|
+
ARGV << "-h" if ARGV.empty?
|
7
|
+
|
8
|
+
class MinesweeperParser
|
9
|
+
def initialize
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse!(args)
|
13
|
+
options = OpenStruct.new
|
14
|
+
options.rows_cols_chance = {}
|
15
|
+
options.inplace = false
|
16
|
+
options.encoding = "utf8"
|
17
|
+
options.transfer_type = :auto
|
18
|
+
options.verbose = false
|
19
|
+
|
20
|
+
# Here is where we make the options parser
|
21
|
+
opt_parser = OptionParser.new do |opts|
|
22
|
+
opts.banner = "Usage: minesweeper [options]"
|
23
|
+
|
24
|
+
opts.on("-r ROWS", "--rows ROWS", Integer, "Specify the number of rows that you'd like your game to have. Truncated at 20.") do |rows|
|
25
|
+
if rows > 20 then rows = 20 elsif rows < 1 then rows = 1 end
|
26
|
+
options.rows_cols_chance[:rows] = rows
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-c COLUMNS", "--columns COLUMNS", Integer, "Specify the number of columns that you'd like your game to have. Truncated at 20.") do |cols|
|
30
|
+
if cols > 20 then cols = 20 elsif cols < 1 then cols = 1 end
|
31
|
+
options.rows_cols_chance[:cols] = cols
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("-f BOMB_CHANCE", "--frequency BOMB_CHANCE", Float, "Specify frequency that bombs will appear on your board. Must be [0, 1].") do |chance|
|
35
|
+
if chance > 1.0 then chance = 1.0 elsif chance < 0.0 then chance = 0.0 end
|
36
|
+
options.rows_cols_chance[:bomb_chance] = chance
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
40
|
+
puts opts
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
opt_parser.parse!(args)
|
48
|
+
options
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minesweeper-cl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gr1zzly_be4r
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Minesweeper, ported to the command line. Please report any issues to
|
14
14
|
the repo on github and star if you like it!
|
@@ -22,6 +22,7 @@ files:
|
|
22
22
|
- "./lib/game_tile.rb"
|
23
23
|
- "./lib/minesweeper.rb"
|
24
24
|
- "./lib/minesweeper_game.rb"
|
25
|
+
- "./lib/minesweeper_parser.rb"
|
25
26
|
- bin/minesweeper
|
26
27
|
homepage: https://github.com/gr1zzly-be4r/ruby-minesweeper-cli
|
27
28
|
licenses:
|