rbstar 1.0.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.
- checksums.yaml +7 -0
- data/README.md +3 -0
- data/bin/rbstar +87 -0
- data/lib/rbstar.rb +118 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aef457553174b349c2807ef8d8b5dd9ccb276e5fdea50b6905b7cf44acb6a53c
|
4
|
+
data.tar.gz: abd66c50515ca381e5e8338be9efada823cd001f314ebeaa0427f17bca93a1a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1c0ba42fa4292b5bf5e8bd3c5c62856701ec02ecf899f36e78efae0836e8d7050e7e47a8b3452635c289c3d601bbde8dedea648ff75a96de02e075afdddcab8
|
7
|
+
data.tar.gz: 14fcbc76b4009fb16603aba7c45adc4adab57324aaa4f2651998fea17bf38cc0367bb424a79a13c23a7eb03166b34267fdb3f87517db59a610861d99f80c9952
|
data/README.md
ADDED
data/bin/rbstar
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'curses'
|
5
|
+
|
6
|
+
require 'rbstar'
|
7
|
+
|
8
|
+
def display_curses( field,
|
9
|
+
theme = { '@' => { text: '()' },
|
10
|
+
'H' => { text: '[]' },
|
11
|
+
'#' => { text: '##' },
|
12
|
+
'x' => { text: '<>' },
|
13
|
+
' ' => { text: ' ' } } )
|
14
|
+
Curses.setpos 0, 0
|
15
|
+
Curses.addstr "Level #{field.level}, #{field.count_gifts} gems left, #{theme[ field.whats_moving ][:text]} moving"
|
16
|
+
|
17
|
+
RbStar::LEVEL_HEIGHT.times do |y|
|
18
|
+
Curses.setpos y + 2, 0
|
19
|
+
|
20
|
+
RbStar::LEVEL_WIDTH.times do |x|
|
21
|
+
cell = field.get_cell( x, y )
|
22
|
+
|
23
|
+
Curses.attrset( Curses::A_BOLD ) if cell == field.whats_moving
|
24
|
+
|
25
|
+
Curses.addstr theme[ cell ][:text]
|
26
|
+
|
27
|
+
Curses.attrset( Curses::A_NORMAL )
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Curses.refresh
|
32
|
+
end
|
33
|
+
|
34
|
+
def ncurses_main( level )
|
35
|
+
field = RbStar::Board.new( level )
|
36
|
+
finished = false
|
37
|
+
|
38
|
+
Curses.init_screen
|
39
|
+
Curses.cbreak
|
40
|
+
Curses.noecho
|
41
|
+
Curses.stdscr.keypad = true
|
42
|
+
|
43
|
+
at_exit do
|
44
|
+
Curses.close_screen
|
45
|
+
end
|
46
|
+
|
47
|
+
display_curses( field )
|
48
|
+
|
49
|
+
loop do
|
50
|
+
ch = Curses.getch
|
51
|
+
|
52
|
+
begin
|
53
|
+
case ch
|
54
|
+
when '2', Curses::KEY_DOWN
|
55
|
+
field.move( :down )
|
56
|
+
when '4', Curses::KEY_LEFT
|
57
|
+
field.move( :left )
|
58
|
+
when '6', Curses::KEY_RIGHT
|
59
|
+
field.move( :right )
|
60
|
+
when '8', Curses::KEY_UP
|
61
|
+
field.move( :up )
|
62
|
+
when ' '
|
63
|
+
field.switch_moving
|
64
|
+
when 'n'
|
65
|
+
# finished = true
|
66
|
+
field.next_level
|
67
|
+
when 'p'
|
68
|
+
# finished = true
|
69
|
+
field.prev_level
|
70
|
+
when 'q'
|
71
|
+
break
|
72
|
+
end
|
73
|
+
rescue Curses::RequestDeniedError
|
74
|
+
'prout'
|
75
|
+
end
|
76
|
+
|
77
|
+
finished = field.success?
|
78
|
+
|
79
|
+
field.next_level if finished
|
80
|
+
|
81
|
+
display_curses( field )
|
82
|
+
end
|
83
|
+
|
84
|
+
exit!
|
85
|
+
end
|
86
|
+
|
87
|
+
ncurses_main( 0 )
|
data/lib/rbstar.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RbStar
|
4
|
+
VERSION = '1.0.0'
|
5
|
+
|
6
|
+
LEVEL_HEIGHT = 9
|
7
|
+
LEVEL_WIDTH = 16
|
8
|
+
|
9
|
+
class Board
|
10
|
+
attr_reader :board,
|
11
|
+
:level,
|
12
|
+
:whats_moving
|
13
|
+
|
14
|
+
def initialize( level = 0 )
|
15
|
+
@levels = [
|
16
|
+
'#################@## x#H## x #### ##x ## ## x #### x x x ## x x## x ## ##x x#################',
|
17
|
+
' # # # # # ### x @# #x #x x # # x x # # # x # # #H# x # # # # #xx## # # # # ',
|
18
|
+
'################# x#@## ## ##H## #x x ## x x## x## #x x x# x### ##x #x x x####x ##x #################',
|
19
|
+
'################# #H## # ###x#x x#x#x#x#x## # #x x# # # ####x#x#x x#x#x#x## # ## # #@ #################',
|
20
|
+
' ############## #@ # # # ## #x # x x # ### # # ##x #x# #### # x # ##x# # # # #H## # x# #x# ############## ',
|
21
|
+
' ############ # x #x x# # x # ## # x ##@ x ### x # ### x # ##H # x ##x #################',
|
22
|
+
'################# # ## ### #x ##x# #x #x # # # # # # ### ## ## # #x# #x# # ## @#x H #x#################',
|
23
|
+
'############### # x## ### #x ## x ## x## # #x ### ## #x# ### # x#x ##xHx# x #@# ### # ###############',
|
24
|
+
' # ########### #x#x # @##x x# x # # # x## x# ## #x #xHx x## x## # #x#x # # # ############ ',
|
25
|
+
' ########### #### x ## H ###x x# x## x #x #x # # # x # x##x#x # x# #@# #x ### ### # # # # ######### # #',
|
26
|
+
'################# # @## #xx xx #### x ## x##x #x#xx ##### ## ## ##x x# x H x###x### # ## ## ########### ',
|
27
|
+
'## ## #### #@#####x ### x### xx x ## ## ##x #x# ## # x ###x ## ## ## ## #H# ## x ## x #################',
|
28
|
+
' ############## # @# x ### # #x x## ## x # ## x #x## # x ### x x #x##H # x # # # ############## ',
|
29
|
+
'#################x#x x#x## x#@ ## ## H x ## x# ## x ## x# # ##x#x x#x#################',
|
30
|
+
' ###### ####### # x# x ## # x # # x ## @# #xx #x # # # # x H# ##x # #x # # x # #x x# ############## ',
|
31
|
+
'################## H#x x x##x @x#x #### ### x #### x#x# ##xx x#x ### x ####x ###x# # #################',
|
32
|
+
'################# x# #@ ## # x#xx#x # ## #x##x# x ## x# x# ## x#x x# ## # # ##x# # ## x #x H #################',
|
33
|
+
'################# x x H# ## #x#x #x ## #x# #x ## x # x#x ## #x# # x# ## x#x # x # ##x#@ # # #################',
|
34
|
+
'#################x ## ##x## # # #x ## x# x## x ## # #x ## # x# ## ## x# ##x #H## x# #x ##@#################',
|
35
|
+
'################# x#x ###x x# ##x ### # # x # # ## H # ## # @x## # # x # # ### x## #x x### x#x #################',
|
36
|
+
'################# ### x ### # # ### ##x x ## x x x ### # ###x ## x x @ H x xx################# ',
|
37
|
+
'#################x# #x# #x # ## # ##x # #x x ### #x x #### x # ###x ## #@#H x ################# ',
|
38
|
+
' ############## # # #x# #x # ## x # ### # x #x ## #x # xx x ###x # ## x ## #@#H x # ############## ',
|
39
|
+
'################# # ### ##x x ##x### #x x# #### xx x# ## ## #x x # ## ## ## @#H###xx################# ',
|
40
|
+
'################# # ## x ##x x ## #x x ## ## x ## #x ## #x x# x ## ##x #@ H ################# '
|
41
|
+
]
|
42
|
+
@whats_moving = '@'
|
43
|
+
@distance = 0
|
44
|
+
@level = level
|
45
|
+
@board = ''
|
46
|
+
|
47
|
+
load_level( @level )
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_pos( actor )
|
51
|
+
pos = {}
|
52
|
+
p = @board.index( actor )
|
53
|
+
pos[ 'y' ] = ( p / LEVEL_WIDTH ).floor
|
54
|
+
pos[ 'x' ] = p - ( pos[ 'y' ] * LEVEL_WIDTH )
|
55
|
+
|
56
|
+
pos
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_cell( x, y )
|
60
|
+
@board[ y * LEVEL_WIDTH + x ]
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_cell( x, y, value )
|
64
|
+
@board[ y * LEVEL_WIDTH + x ] = value
|
65
|
+
end
|
66
|
+
|
67
|
+
def move( direction )
|
68
|
+
d = { 'x' => 0, 'y' => 0 }
|
69
|
+
d[ 'x' ] = -1 if direction == :left
|
70
|
+
d[ 'x' ] = 1 if direction == :right
|
71
|
+
d[ 'y' ] = -1 if direction == :up
|
72
|
+
d[ 'y' ] = 1 if direction == :down
|
73
|
+
|
74
|
+
coord = get_pos( @whats_moving )
|
75
|
+
|
76
|
+
while ( coord[ 'y' ] + d[ 'y' ] >= 0 && coord[ 'y' ] + d[ 'y' ] < LEVEL_HEIGHT ) &&
|
77
|
+
( coord[ 'x' ] + d[ 'x' ] >= 0 && coord[ 'x' ] + d[ 'x' ] < LEVEL_WIDTH ) &&
|
78
|
+
( get_cell( coord[ 'x' ] + d[ 'x' ], coord[ 'y' ] + d[ 'y' ] ) == ' ' ) ||
|
79
|
+
( @whats_moving == '@' &&
|
80
|
+
get_cell( coord[ 'x' ] + d[ 'x' ], coord[ 'y' ] + d[ 'y' ] ) == 'x' )
|
81
|
+
|
82
|
+
set_cell( coord[ 'x' ], coord[ 'y' ], ' ' )
|
83
|
+
|
84
|
+
coord[ 'x' ] = coord[ 'x' ] + d[ 'x' ]
|
85
|
+
coord[ 'y' ] = coord[ 'y' ] + d[ 'y' ]
|
86
|
+
|
87
|
+
set_cell( coord[ 'x' ], coord[ 'y' ], @whats_moving )
|
88
|
+
|
89
|
+
@distance += 1
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def load_level( level )
|
94
|
+
@level = level
|
95
|
+
@board = @levels[ @level ].dup
|
96
|
+
end
|
97
|
+
|
98
|
+
def prev_level
|
99
|
+
load_level( @level - 1 ) if @level.positive?
|
100
|
+
end
|
101
|
+
|
102
|
+
def next_level
|
103
|
+
load_level( @level + 1 ) if @level < @levels.length
|
104
|
+
end
|
105
|
+
|
106
|
+
def switch_moving
|
107
|
+
@whats_moving = @whats_moving == '@' ? 'H' : '@'
|
108
|
+
end
|
109
|
+
|
110
|
+
def count_gifts
|
111
|
+
@board.count( 'x' )
|
112
|
+
end
|
113
|
+
|
114
|
+
def success?
|
115
|
+
count_gifts.zero?
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbstar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gwenhael Le Moine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: curses
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.4
|
27
|
+
description: Puzzle game inspired by an old HP 48 called dstar
|
28
|
+
email: gwenhael@le-moine.org
|
29
|
+
executables:
|
30
|
+
- rbstar
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.md
|
34
|
+
files:
|
35
|
+
- README.md
|
36
|
+
- bin/rbstar
|
37
|
+
- lib/rbstar.rb
|
38
|
+
homepage: https://src.le-moine.org/gwh/rbstar
|
39
|
+
licenses:
|
40
|
+
- GPL-3.0
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '3'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.3.7
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Puzzle game
|
61
|
+
test_files: []
|