minehunt 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -0
  3. data/bin/gosuhunt +133 -0
  4. data/bin/minehunt +14 -6
  5. data/lib/minehunt.rb +1 -1
  6. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 322e0063d5bfff9584242e7394d523f296b09fb63f8ad60eb4171bf7c140276d
4
- data.tar.gz: 8474fcafea89310fe07dc776dc71243d68e16b805249a9f9111c988caba821d3
3
+ metadata.gz: 5728888bee611e69d99f58590ab1be63b0df1f691e55bf120adafa9f45880554
4
+ data.tar.gz: d84793188558a0e80d20c15e5ca97c777bddea8d17e4eb5e49b4bccf6bfa67e6
5
5
  SHA512:
6
- metadata.gz: 7c93386b2e102cd6df6f3330172e6a408141daeb885d77152ff3afe7581d5090a22d2c0d69c88c42c33d903c217658d98bee488f5954cd4b35579ddd87c2730f
7
- data.tar.gz: 4fda1ac747d01670cc76f5aef87c64e88c2b8940d19d15b6002cb263a54ee83622ba30555def267ff42258fe97f355bbbf2f1064ce3251c03d533ffb7e9f2029
6
+ metadata.gz: aceb66b35850f9f0b8c7122c9c185a1a76b1af6e2cb2dfb2add66e4419155dfb80ce384f4680990c50d37b70113d83e9d98eb37238055ad9322f51910d1bc5b3
7
+ data.tar.gz: d4eeb15c1dfece0c9c7016fc16e0d120ef25e73862642c78cfc3f152ba7cc955232729eb3efbb05971e69c56f977e4f2228f6860b72c948e33f655cc0241b99a
data/README.md CHANGED
@@ -1 +1,16 @@
1
1
  Implementing HP {48,49,50} minehunt game
2
+
3
+ You start on the top-left corner and your goal is to reach the bottom0right corner without blowing-up a mine.
4
+
5
+ You can move using
6
+
7
+ ← ↓ →
8
+
9
+ or (better) the keypad which moves as
10
+ 7 8 9 ↖ ↑ ↗
11
+ 4 6 ← →
12
+ 1 2 3 ↙ ↓ ↘
13
+
14
+ You can quit at any time using 'q'
15
+
16
+ You can replay at the end using 'r'
data/bin/gosuhunt ADDED
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'gosu'
5
+ require 'optparse'
6
+
7
+ require 'minehunt'
8
+
9
+ class GosuHunt < Gosu::Window
10
+ def initialize( number_of_mines, scale )
11
+ @scale = scale
12
+ @sprite_size = 6
13
+
14
+ @number_of_mines = number_of_mines
15
+ @field = MineHunt::Board.new( @number_of_mines )
16
+ @finished = false
17
+ @state = { dead: false, victory: false }
18
+
19
+ @font = Gosu::Font.new( 20 )
20
+ @images = { explorer: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '000000001100011110011110001100000000' ) ),
21
+ dead_explorer: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '100001010010001100001100010010100001' ) ),
22
+ door: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '010101101010' * ( @sprite_size / 2 ) ) ),
23
+ mine: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '111111110011100001100001110011111111' ) ),
24
+ cell: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '1' * @sprite_size * @sprite_size ) ),
25
+ visited_cell: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '0' * @sprite_size * @sprite_size ) ) }
26
+
27
+ # Creation of the window
28
+ super ( ( @sprite_size + 1 ) * @field.width * @scale ) + @scale,
29
+ ( ( @sprite_size + 1 ) * @field.height * @scale ) + @scale + 20
30
+ end
31
+
32
+ def bits_to_rgbas( bits )
33
+ bits.scan(/.{#{@sprite_size}}/).map do |line|
34
+ line.gsub( '0', "\0\0\0\0" * @scale ).gsub( '1', "\255\255\255\255" * @scale ) * @scale
35
+ end.join
36
+ end
37
+
38
+ def new_level
39
+ @field = MineHunt::Board.new( @number_of_mines )
40
+ @finished = false
41
+ @state = { dead: false, victory: false }
42
+ end
43
+
44
+ def button_up(id)
45
+ if @finished
46
+ case id
47
+ when Gosu::KB_ESCAPE, Gosu::KB_Q
48
+ close
49
+ when Gosu::KB_R
50
+ new_level
51
+ else
52
+ super
53
+ end
54
+ else
55
+ case id
56
+ when Gosu::KB_ESCAPE, Gosu::KB_Q
57
+ close
58
+ when Gosu::KB_R
59
+ new_level
60
+ when Gosu::KB_NUMPAD_1
61
+ @state = @field.move 'down-left'
62
+ when Gosu::KB_NUMPAD_2, Gosu::KB_DOWN
63
+ @state = @field.move 'down'
64
+ when Gosu::KB_NUMPAD_3
65
+ @state = @field.move 'down-right'
66
+ when Gosu::KB_NUMPAD_4, Gosu::KB_LEFT
67
+ @state = @field.move 'left'
68
+ when Gosu::KB_NUMPAD_6, Gosu::KB_RIGHT
69
+ @state = @field.move 'right'
70
+ when Gosu::KB_NUMPAD_7
71
+ @state = @field.move 'up-left'
72
+ when Gosu::KB_NUMPAD_8, Gosu::KB_UP
73
+ @state = @field.move 'up'
74
+ when Gosu::KB_NUMPAD_9
75
+ @state = @field.move 'up-right'
76
+ else
77
+ super
78
+ end
79
+ end
80
+
81
+ @finished = @state[:dead] || @state[:victory]
82
+ end
83
+
84
+ def update; end
85
+
86
+ def draw
87
+ self.caption = if @state[:dead]
88
+ "You blew up!! :(, score: #{@field.score} "
89
+ elsif @state[:victory]
90
+ "You won!! :), score: #{@field.score} "
91
+ else
92
+ "Near #{@field.count_nearby_mines} mines, score: #{@field.score}"
93
+ end
94
+
95
+ @font.draw_text( caption, 0, 0, 0 )
96
+
97
+ @field.height.times do |y|
98
+ @field.width.times do |x|
99
+ ( if [@field.explorer_x, @field.explorer_y] == [x, y]
100
+ @state[:dead] ? @images[:dead_explorer] : @images[:explorer]
101
+ elsif [@field.width, @field.height] == [x + 1, y + 1]
102
+ @images[:door]
103
+ elsif @field.field[[x, y]].open
104
+ @images[:visited_cell]
105
+ elsif @field.field[[x, y]].mine && ( @state[:dead] || @state[:victory] )
106
+ @images[:mine]
107
+ else
108
+ @images[:cell]
109
+ end ).draw ( ( @sprite_size + 1 ) * x * @scale ) + @scale,
110
+ ( ( @sprite_size + 1 ) * y * @scale ) + @scale + 20,
111
+ 0
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ options = { number_of_mines: 20,
118
+ scale: 3 }
119
+ OptionParser.new do |opts|
120
+ opts.banner = 'Usage: gosuhunt <options>'
121
+
122
+ opts.on( '-m', '--mines INT' ) do |nb_mines|
123
+ options[:number_of_mines] = nb_mines.to_i
124
+ end
125
+
126
+ opts.on( '-s', '--scale INT' ) do |scale|
127
+ options[:scale] = scale.to_i
128
+ end
129
+ end
130
+ .parse!
131
+
132
+ GosuHunt.new( options[:number_of_mines], options[:scale] )
133
+ .show
data/bin/minehunt CHANGED
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'curses'
5
+ require 'optparse'
5
6
 
6
7
  require 'minehunt'
7
8
 
@@ -16,11 +17,11 @@ def display_curses( field,
16
17
  Curses.setpos 0, 0
17
18
 
18
19
  if state[:dead]
19
- Curses.addstr "You died! :(, score #{field.score} "
20
+ Curses.addstr "You blew up!!, score: #{field.score} "
20
21
  elsif state[:victory]
21
- Curses.addstr "You won!! :), score #{field.score} "
22
+ Curses.addstr "You won!! :), score: #{field.score} "
22
23
  else
23
- Curses.addstr "#{field.number_of_mines} mines, #{field.count_nearby_mines} nearby, score #{field.score}"
24
+ Curses.addstr "Near #{field.count_nearby_mines} mines, score: #{field.score}"
24
25
  end
25
26
 
26
27
  field.height.times do |y|
@@ -108,7 +109,14 @@ def ncurses_main( number_of_mines )
108
109
  exit!
109
110
  end
110
111
 
111
- number_of_mines = 20
112
- number_of_mines = ARGV.first.to_i if ARGV.length == 1
112
+ options = { number_of_mines: 20 }
113
+ OptionParser.new do |opts|
114
+ opts.banner = 'Usage: minehunt <options>'
113
115
 
114
- ncurses_main( number_of_mines )
116
+ opts.on( '-m', '--mines INT' ) do |nb_mines|
117
+ options[:number_of_mines] = nb_mines.to_i
118
+ end
119
+ end
120
+ .parse!
121
+
122
+ ncurses_main( options[:number_of_mines] )
data/lib/minehunt.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module MineHunt
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.1'
6
6
 
7
7
  class Cell
8
8
  attr_accessor :mine,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minehunt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gwenhael Le Moine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-22 00:00:00.000000000 Z
11
+ date: 2023-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -28,17 +28,20 @@ description: Mine hunting game inspired by the HP 48
28
28
  email: gwenhael@le-moine.org
29
29
  executables:
30
30
  - minehunt
31
+ - gosuhunt
31
32
  extensions: []
32
33
  extra_rdoc_files:
33
34
  - README.md
34
35
  files:
35
36
  - README.md
37
+ - bin/gosuhunt
36
38
  - bin/minehunt
37
39
  - lib/minehunt.rb
38
40
  homepage: https://src.le-moine.org/gwh/myhunt/src/branch/main/ruby
39
41
  licenses:
40
42
  - GPL-3.0
41
- metadata: {}
43
+ metadata:
44
+ rubygems_mfa_required: 'true'
42
45
  post_install_message:
43
46
  rdoc_options: []
44
47
  require_paths:
@@ -54,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
57
  - !ruby/object:Gem::Version
55
58
  version: '0'
56
59
  requirements: []
57
- rubygems_version: 3.3.7
60
+ rubygems_version: 3.4.10
58
61
  signing_key:
59
62
  specification_version: 4
60
63
  summary: Mine hunting game