good_luck_wizard 0.0.1 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b6d9433bd142292329a04da71e53365da906d1e73d96c7424a91adc2fa3f7b6
4
- data.tar.gz: 4e9c31089c9976fdc8f756b257f349c0a5d238f5e7bef1c6a813a918caa6da8d
3
+ metadata.gz: c0cb37ba935956a080d7e4f02a6f771d50c78396d9929d5424d1f9427f354bc1
4
+ data.tar.gz: 185370ffabbe5b7688304cb97cf8fa1a385e49e9461cff77e8f185763bec3434
5
5
  SHA512:
6
- metadata.gz: ca4eba9034e385f7112ae9837f4029e684874ef11bc0d054d5ca8eb7816c94ba928d02077f634edb5ddb355188d76afc9ddae7aaf2a650097344e7bac55f4fd2
7
- data.tar.gz: d4e3fdd503ddf4d775419b98e756572813c63b02085574605ca7e284754ac79f6a6375129b29acf5441f4d1129536eecc4458546c963228f5b7d34bdc78076c4
6
+ metadata.gz: f03c3bdc66579466bad239ff5f04faaa4cfef2ea547364e083955ee8a43e371d4b33aa3652882088a6906193269f20b8136d496fb8454f11ab94231f2df60551
7
+ data.tar.gz: 1716b9749d7ec53582ab84234cdc9927ac49ec8f8a12b1d741fed7a3f436a89a392b74d5c3bd22b5d0bdd5233d74dafb817532ac4849b33a57c9172102651832
@@ -0,0 +1,27 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ name: Ruby ${{ matrix.ruby }}
14
+ strategy:
15
+ matrix:
16
+ ruby:
17
+ - "3.4.2"
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Run tests
27
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /Gemfile.lock
10
+ /.rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile CHANGED
@@ -4,3 +4,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in good_luck_wizard.gemspec
6
6
  gemspec
7
+
8
+ gem "rake", "~> 13.2"
9
+ gem "rspec", "~> 3.4"
10
+ gem "standard", "~> 1.45"
data/README.md CHANGED
@@ -1,36 +1,26 @@
1
- # Good Luck, Wizard
1
+ **Good Luck, Wizard**. You're going to need it. Especially because this is an
2
+ _extremely_ unfinished game. It's hard to even call it a game at this point. You
3
+ should come back later when there's something worth playing.
2
4
 
3
- ## Installation
5
+ **If you absolutely must try it, you can install it** with `gem install
6
+ good_luck_wizard` and run it with `glw`. This assumes you have a working Ruby
7
+ environment and a new enough version of Ruby.
4
8
 
5
- Assuming you Ruby set up, you can run `gem install good_luck_wizard` to install the game.
9
+ **This project is not seeking contributions,** but bug reports are accepted [on
10
+ GitHub](https://github.com/jarednorman/good_luck_wizard).
6
11
 
7
- ## Usage
8
-
9
- Start the game by running `glw`.
12
+ **This project is intended to be a safe, welcoming space for collaboration.**
13
+ Everyone interacting in the _Good Luck, Wizard_ project’s codebases, issue
14
+ trackers, chat rooms and mailing lists is expected to follow the [code of
15
+ conduct](https://github.com/jarednorman/good_luck_wizard/blob/master/CODE_OF_CONDUCT.md).
10
16
 
11
- ## Development
17
+ ---
12
18
 
13
- After checking out the repo, run `bin/setup` to install dependencies. Then, run
14
- `rake test` to run the tests. You can also run `bin/console` for an interactive
15
- prompt that will allow you to experiment.
19
+ **To run thep roject locally,** checck out the repo and run `bin/setup` to
20
+ install dependencies. The tests are run with `bundle exec rspec`. You can also
21
+ run `bin/console` for an interactive prompt that will allow you to experiment.
16
22
 
17
- To install this gem onto your local machine, run `bundle exec rake install`. To
18
- release a new version, update the version number in `version.rb`, and then run
19
- `bundle exec rake release`, which will create a git tag for the version, push
20
- git commits and tags, and push the `.gem` file to
23
+ To release a new version, update the version number in `version.rb`, and then
24
+ run `bundle exec rake release`, which will create a git tag for the version,
25
+ push git commits and tags, and push the `.gem` file to
21
26
  [rubygems.org](https://rubygems.org).
22
-
23
- ## Contributing
24
-
25
- This project is not seeking code contributions, but bug reports and pull
26
- requests are accepted [on
27
- GitHub](https://github.com/jarednorman/good_luck_wizard). This project is
28
- intended to be a safe, welcoming space for collaboration, and contributors are
29
- expected to adhere to the [Contributor
30
- Covenant](http://contributor-covenant.org) code of conduct.
31
-
32
- ## Code of Conduct
33
-
34
- Everyone interacting in the _Good Luck, Wizard_ project’s codebases, issue trackers,
35
- chat rooms and mailing lists is expected to follow the [code of
36
- conduct](https://github.com/jarednorman/good_luck_wizard/blob/master/CODE_OF_CONDUCT.md).
data/bin/console CHANGED
@@ -3,5 +3,5 @@
3
3
  require "bundler/setup"
4
4
  require "glw"
5
5
 
6
- require "pry"
7
- Pry.start
6
+ require "irb"
7
+ IRB.start(__FILE__)
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = "An unfinished terminal-based roguelike game"
13
13
  spec.description = spec.summary
14
- spec.homepage = "http://github.com/jarednorman/glw"
14
+ spec.homepage = "http://github.com/jarednorman/good_luck_wizard"
15
15
 
16
16
  # Specify which files should be added to the gem when it is released.
17
17
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -22,12 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
+ spec.required_ruby_version = ">= 3.4.0"
26
+
25
27
  spec.add_dependency "curses", "~> 1.4.0"
26
28
  spec.add_dependency "zeitwerk", "~> 2.4"
27
-
28
- spec.add_development_dependency "bundler", "~> 1.17"
29
- spec.add_development_dependency "rake", "~> 10.0"
30
- spec.add_development_dependency "minitest", "~> 5.0"
31
- spec.add_development_dependency "pry"
32
- spec.add_development_dependency "pry-stack_explorer"
33
29
  end
data/lib/glw/game.rb ADDED
@@ -0,0 +1,31 @@
1
+ module GLW
2
+ class Game
3
+ def initialize(term:)
4
+ @map = Map.new
5
+ @term = term
6
+ end
7
+
8
+ def send_key(key)
9
+ case key
10
+ when "q"
11
+ :quit
12
+ when "h"
13
+ @map.send_event :left
14
+ when "l"
15
+ @map.send_event :right
16
+ when "k"
17
+ @map.send_event :up
18
+ when "j"
19
+ @map.send_event :down
20
+ end
21
+ end
22
+
23
+ def render
24
+ map.render(term, width: term.width - 60, height: term.height)
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :term, :map
30
+ end
31
+ end
data/lib/glw/map.rb ADDED
@@ -0,0 +1,71 @@
1
+ module GLW
2
+ class Map
3
+ MAP = <<~TXT
4
+ ############
5
+ #..........# ##########
6
+ #..........############....#...#
7
+ #..............................#
8
+ #.......g..############....#...#
9
+ #..........# #....#...#
10
+ ############ ##########
11
+ TXT
12
+
13
+ def initialize
14
+ @player_x = 3
15
+ @player_y = 3
16
+
17
+ @map = Hash.new(" ")
18
+ MAP.lines.each_with_index do |line, y|
19
+ line.chars.each_with_index do |c, x|
20
+ @map[[x, y]] = c
21
+ end
22
+ end
23
+
24
+ @offset_x = 1
25
+ @offset_y = 1
26
+ end
27
+
28
+ def send_event(e)
29
+ case e
30
+ when :left
31
+ @player_x -= 1 if valid_player_position?(@player_x - 1, @player_y)
32
+ when :right
33
+ @player_x += 1 if valid_player_position?(@player_x + 1, @player_y)
34
+ when :up
35
+ @player_y -= 1 if valid_player_position?(@player_x, @player_y - 1)
36
+ when :down
37
+ @player_y += 1 if valid_player_position?(@player_x, @player_y + 1)
38
+ end
39
+ end
40
+
41
+ def render(term, width:, height:)
42
+ (0..width - 1).each do |x|
43
+ (0..height - 1).each do |y|
44
+
45
+ if [@player_x + @offset_x, @player_y + @offset_y] == [x, y]
46
+ term.set(
47
+ x: x,
48
+ y: y,
49
+ c: "@",
50
+ fg: 220
51
+ )
52
+ else
53
+ term.set(
54
+ x: x,
55
+ y: y,
56
+ c: @map[[x - @offset_x, y - @offset_y]]
57
+ )
58
+ end
59
+ end
60
+ end
61
+
62
+ term.refresh
63
+ end
64
+
65
+ private
66
+
67
+ def valid_player_position?(x, y)
68
+ @map[[x, y]] == "."
69
+ end
70
+ end
71
+ end
data/lib/glw/random.rb ADDED
@@ -0,0 +1,33 @@
1
+ module GLW
2
+ class Random
3
+ MASK64 = (1 << 64) - 1
4
+ MASK32 = (1 << 32) - 1
5
+ CONST = 0x2545F4914F6CDD1D
6
+
7
+ def initialize(seed)
8
+ @state = seed & MASK64
9
+ end
10
+
11
+ def sample(collection)
12
+ collection[integer % collection.length]
13
+ end
14
+
15
+ def integer
16
+ x = state
17
+ x = (x ^ (x >> 12)) & MASK64
18
+ x = (x ^ (x << 25)) & MASK64
19
+ x = (x ^ (x >> 27)) & MASK64
20
+ self.state = x
21
+
22
+ (((x * CONST) & MASK64) >> 32) & MASK32
23
+ end
24
+
25
+ def float
26
+ integer.to_f / (1 << 32)
27
+ end
28
+
29
+ private
30
+
31
+ attr_accessor :state
32
+ end
33
+ end
data/lib/glw/term.rb CHANGED
@@ -6,23 +6,9 @@ module GLW
6
6
  DEFAULT_FG = 255
7
7
  DEFAULT_BG = 16
8
8
 
9
- Cell = Struct.new(:c, :fg, :bg) do
10
- def initialize(*args)
11
- super
12
- @dirty = true
13
- end
14
-
15
- def seen?
16
- !@dirty
17
- end
18
-
19
- def seen!
20
- @dirty = false
21
- end
22
- end
9
+ Cell = Struct.new(:c, :fg, :bg)
23
10
 
24
11
  DEFAULT_CELL = Cell.new(" ", DEFAULT_FG, DEFAULT_BG)
25
- DEFAULT_CELL.seen!
26
12
 
27
13
  class << self
28
14
  def with_term
@@ -43,6 +29,7 @@ module GLW
43
29
  @window = window
44
30
  @tiles = Hash.new { DEFAULT_CELL }
45
31
  @next_tiles = {}
32
+ @colors = TermColors.new
46
33
  end
47
34
 
48
35
  def set(x:, y:, c:, fg: DEFAULT_FG, bg: DEFAULT_BG)
@@ -51,10 +38,26 @@ module GLW
51
38
  @next_tiles[[x, y]] = cell unless @tiles[[x, y]] == cell
52
39
  end
53
40
 
41
+ def width
42
+ Curses.cols
43
+ end
44
+
45
+ def height
46
+ Curses.lines
47
+ end
48
+
49
+ def getch
50
+ window.getch
51
+ end
52
+
54
53
  def refresh
55
54
  @next_tiles.each do |coords, cell|
56
- window.setpos *coords.reverse
57
- window << cell.c
55
+ x, y = *coords
56
+ window.setpos(y, x)
57
+
58
+ window.attron(colors[cell.fg, cell.bg]) do
59
+ window << cell.c
60
+ end
58
61
  end
59
62
 
60
63
  @tiles = @tiles.merge(@next_tiles)
@@ -64,6 +67,6 @@ module GLW
64
67
 
65
68
  private
66
69
 
67
- attr_reader :window
70
+ attr_reader :window, :colors
68
71
  end
69
72
  end
@@ -0,0 +1,22 @@
1
+ module GLW
2
+ class TermColors
3
+ def initialize(curses = Curses)
4
+ index = 1
5
+
6
+ @colors = Hash.new do |hash, key|
7
+ fg, bg = *key
8
+
9
+ curses.init_pair(index, fg, bg)
10
+ hash[key] = curses.color_pair(index)
11
+
12
+ index += 1
13
+
14
+ hash[key]
15
+ end
16
+ end
17
+
18
+ def [](fg, bg)
19
+ @colors[[fg, bg]]
20
+ end
21
+ end
22
+ end
data/lib/glw/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GLW
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/glw.rb CHANGED
@@ -9,30 +9,25 @@ module GLW
9
9
  initialize_zeitwerk
10
10
 
11
11
  GLW::Term.with_term do |t|
12
- t.set(x: 0, y: 0, c: "@")
13
- t.refresh
14
- sleep 1
12
+ g = Game.new(term: t)
15
13
 
16
- t.set(x: 0, y: 0, c: " ")
17
- t.set(x: 1, y: 1, c: "@")
18
- t.refresh
19
- sleep 1
20
-
21
- t.set(x: 1, y: 1, c: " ")
22
- t.set(x: 2, y: 2, c: "@")
23
- t.refresh
24
- sleep 1
14
+ loop do
15
+ g.render
16
+ break if g.send_key(t.getch) == :quit
17
+ end
25
18
  end
26
19
  end
27
20
 
28
- private
29
-
30
21
  def initialize_zeitwerk
22
+ return if @zeitwerk_enabled
23
+
31
24
  Zeitwerk::Loader.new.tap do |loader|
32
25
  loader.inflector.inflect("glw" => "GLW")
33
26
  loader.push_dir(__dir__)
34
27
  loader.setup
35
28
  end
29
+
30
+ @zeitwerk_enabled = true
36
31
  end
37
32
  end
38
33
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: good_luck_wizard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Norman
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2020-12-31 00:00:00.000000000 Z
10
+ date: 2025-03-09 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: curses
@@ -38,76 +37,6 @@ dependencies:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
39
  version: '2.4'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.17'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.17'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '10.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '10.0'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '5.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '5.0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: pry-stack_explorer
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
40
  description: An unfinished terminal-based roguelike game
112
41
  email:
113
42
  - jared@super.gd
@@ -116,8 +45,9 @@ executables:
116
45
  extensions: []
117
46
  extra_rdoc_files: []
118
47
  files:
48
+ - ".github/workflows/main.yml"
119
49
  - ".gitignore"
120
- - ".travis.yml"
50
+ - ".rspec"
121
51
  - CODE_OF_CONDUCT.md
122
52
  - Gemfile
123
53
  - README.md
@@ -127,12 +57,15 @@ files:
127
57
  - exe/glw
128
58
  - good_luck_wizard.gemspec
129
59
  - lib/glw.rb
60
+ - lib/glw/game.rb
61
+ - lib/glw/map.rb
62
+ - lib/glw/random.rb
130
63
  - lib/glw/term.rb
64
+ - lib/glw/term_colors.rb
131
65
  - lib/glw/version.rb
132
- homepage: http://github.com/jarednorman/glw
66
+ homepage: http://github.com/jarednorman/good_luck_wizard
133
67
  licenses: []
134
68
  metadata: {}
135
- post_install_message:
136
69
  rdoc_options: []
137
70
  require_paths:
138
71
  - lib
@@ -140,15 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
73
  requirements:
141
74
  - - ">="
142
75
  - !ruby/object:Gem::Version
143
- version: '0'
76
+ version: 3.4.0
144
77
  required_rubygems_version: !ruby/object:Gem::Requirement
145
78
  requirements:
146
79
  - - ">="
147
80
  - !ruby/object:Gem::Version
148
81
  version: '0'
149
82
  requirements: []
150
- rubygems_version: 3.0.3
151
- signing_key:
83
+ rubygems_version: 3.6.2
152
84
  specification_version: 4
153
85
  summary: An unfinished terminal-based roguelike game
154
86
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.6
7
- before_install: gem install bundler -v 1.17.2