minehunt 1.0.0 → 1.1.0

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -0
  3. data/bin/gosuhunt +134 -0
  4. data/bin/minehunt +14 -6
  5. data/lib/minehunt.rb +1 -1
  6. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 322e0063d5bfff9584242e7394d523f296b09fb63f8ad60eb4171bf7c140276d
4
- data.tar.gz: 8474fcafea89310fe07dc776dc71243d68e16b805249a9f9111c988caba821d3
3
+ metadata.gz: 5b6cc2262a4efc0a78975d9eb6ae56475257ac95341b77dae5061529bf5b2529
4
+ data.tar.gz: f4051ab48addc96711bc88c3f84aa50d320a96678f62be6674a269dd90bae213
5
5
  SHA512:
6
- metadata.gz: 7c93386b2e102cd6df6f3330172e6a408141daeb885d77152ff3afe7581d5090a22d2c0d69c88c42c33d903c217658d98bee488f5954cd4b35579ddd87c2730f
7
- data.tar.gz: 4fda1ac747d01670cc76f5aef87c64e88c2b8940d19d15b6002cb263a54ee83622ba30555def267ff42258fe97f355bbbf2f1064ce3251c03d533ffb7e9f2029
6
+ metadata.gz: c9647d12b11e8140c312aad1b2790684b8aeff3359a17b77213bcbd42de7073837ad7ebd8f2d49b5964b65653397eebd5d1590ca6e1cc3eee32c071f1dee6304
7
+ data.tar.gz: b5aa966df36b583b4bd1af5328e6ee8814af96bc4cf9e0f1feaa770f9c18b6ee67db0d4a370ed6f0c3227397daa01c174b37f2061644c42eea12c306a2e1bdf0
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,134 @@
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
+ super ( ( @sprite_size + 1 ) * @field.width * @scale ) + @scale,
28
+ ( ( @sprite_size + 1 ) * @field.height * @scale ) + @scale + 20
29
+
30
+ self.caption = 'Gosu Hunt'
31
+ end
32
+
33
+ def bits_to_rgbas( bits )
34
+ bits.scan(/.{#{@sprite_size}}/).map do |line|
35
+ line.gsub( '0', "\0\0\0\0" * @scale ).gsub( '1', "\255\255\255\255" * @scale ) * @scale
36
+ end.join
37
+ end
38
+
39
+ def new_level
40
+ @field = MineHunt::Board.new( @number_of_mines )
41
+ @finished = false
42
+ @state = { dead: false, victory: false }
43
+ end
44
+
45
+ def button_up(id)
46
+ if @finished
47
+ case id
48
+ when Gosu::KB_ESCAPE, Gosu::KB_Q
49
+ close
50
+ when Gosu::KB_R
51
+ new_level
52
+ else
53
+ super
54
+ end
55
+ else
56
+ case id
57
+ when Gosu::KB_ESCAPE, Gosu::KB_Q
58
+ close
59
+ when Gosu::KB_R
60
+ new_level
61
+ when Gosu::KB_NUMPAD_1
62
+ @state = @field.move 'down-left'
63
+ when Gosu::KB_NUMPAD_2, Gosu::KB_DOWN
64
+ @state = @field.move 'down'
65
+ when Gosu::KB_NUMPAD_3
66
+ @state = @field.move 'down-right'
67
+ when Gosu::KB_NUMPAD_4, Gosu::KB_LEFT
68
+ @state = @field.move 'left'
69
+ when Gosu::KB_NUMPAD_6, Gosu::KB_RIGHT
70
+ @state = @field.move 'right'
71
+ when Gosu::KB_NUMPAD_7
72
+ @state = @field.move 'up-left'
73
+ when Gosu::KB_NUMPAD_8, Gosu::KB_UP
74
+ @state = @field.move 'up'
75
+ when Gosu::KB_NUMPAD_9
76
+ @state = @field.move 'up-right'
77
+ else
78
+ super
79
+ end
80
+ end
81
+
82
+ @finished = @state[:dead] || @state[:victory]
83
+ end
84
+
85
+ def update; end
86
+
87
+ def draw
88
+ self.caption = if @state[:dead]
89
+ "You blew up!! :(, score: #{@field.score} "
90
+ elsif @state[:victory]
91
+ "You won!! :), score: #{@field.score} "
92
+ else
93
+ "Near #{@field.count_nearby_mines} mines, score: #{@field.score}"
94
+ end
95
+
96
+ @font.draw_text( caption, 0, 0, 0 )
97
+
98
+ @field.height.times do |y|
99
+ @field.width.times do |x|
100
+ ( if [@field.explorer_x, @field.explorer_y] == [x, y]
101
+ @state[:dead] ? @images[:dead_explorer] : @images[:explorer]
102
+ elsif [@field.width, @field.height] == [x + 1, y + 1]
103
+ @images[:door]
104
+ elsif @field.field[[x, y]].open
105
+ @images[:visited_cell]
106
+ elsif @field.field[[x, y]].mine && ( @state[:dead] || @state[:victory] )
107
+ @images[:mine]
108
+ else
109
+ @images[:cell]
110
+ end ).draw ( ( @sprite_size + 1 ) * x * @scale ) + @scale,
111
+ ( ( @sprite_size + 1 ) * y * @scale ) + @scale + 20,
112
+ 0
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ options = { number_of_mines: 20,
119
+ scale: 3 }
120
+ OptionParser.new do |opts|
121
+ opts.banner = 'Usage: gosuhunt <options>'
122
+
123
+ opts.on( '-m', '--mines INT' ) do |nb_mines|
124
+ options[:number_of_mines] = nb_mines.to_i
125
+ end
126
+
127
+ opts.on( '-s', '--scale INT' ) do |scale|
128
+ options[:scale] = scale.to_i
129
+ end
130
+ end
131
+ .parse!
132
+
133
+ GosuHunt.new( options[:number_of_mines], options[:scale] )
134
+ .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.0'
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.0
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-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -28,11 +28,13 @@ 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
@@ -54,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
56
  - !ruby/object:Gem::Version
55
57
  version: '0'
56
58
  requirements: []
57
- rubygems_version: 3.3.7
59
+ rubygems_version: 3.4.6
58
60
  signing_key:
59
61
  specification_version: 4
60
62
  summary: Mine hunting game