roguelike 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1dea25c16631fd6fd93b1ce963282001de3c5abb
4
+ data.tar.gz: 25446f9a50f691abf2ea4cbde61956b77707b352
5
+ SHA512:
6
+ metadata.gz: a20737781fc49df384ce5453c2e8e8859f1ed1c247d97e7d9409cacb776e9ed587a79535d74b01b56911df7025d9137ad42d45a7bf6d090cc3170a7381530ddc
7
+ data.tar.gz: e765ed468e71d48045912b741b7a725684740680bfeed67f8ce7b0ccec324c4c5319b2ebad61e309b41dae0d7c9909eca3597d286dc627fc621f8da4cbedf869
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ dev_map.yaml
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'commander'
@@ -0,0 +1,15 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ commander (4.3.4)
5
+ highline (~> 1.7.2)
6
+ highline (1.7.2)
7
+
8
+ PLATFORMS
9
+ ruby
10
+
11
+ DEPENDENCIES
12
+ commander
13
+
14
+ BUNDLED WITH
15
+ 1.10.3
@@ -0,0 +1,79 @@
1
+ [![Gem Version](https://badge.fury.io/rb/roguelike.svg)](http://badge.fury.io/rb/roguelike)
2
+
3
+ # Roguelike
4
+
5
+ A Rogue cloning engine written in Ruby
6
+
7
+ Roguelike is intended to be a full engine capable of running clones of the 1980 game [Rogue](https://en.wikipedia.org/wiki/Rogue_(video_game)). Users will eventually be able to simply provide a series of maps they've created and Roguelike will handle all of the logic of the game. In this way, someone who wants to create their own version of Rogue simply needs to design their dungeons, layout the enemies and treasures, and let Roguelike do the rest.
8
+
9
+ ## Usage
10
+
11
+ Using Roguelike is relatively simple. In order to create your own clone of Rogue, all you need to do is create a YAML file containing all of the necessary information for the game to run.
12
+
13
+ ### map.yaml
14
+
15
+ Your YAML file should contain a list of rooms (or levels) for your game, each with the following information:
16
+
17
+ Data | Description
18
+ -----|-------------
19
+ number | The number of the room, which will determine the order in which the rooms are visited
20
+ initial_x | An integer representing the x coordinate at which the player character should be drawn upon entering the room
21
+ initial_y | An integer representing the y coordinate at which the player character should be drawn upon entering the room
22
+ layout | A visual representation in ASCII characters of the room's layout
23
+
24
+ When drawing the layout, the following characters should be used to represent various parts of the map:
25
+
26
+ Character | What it Represents
27
+ ------------|-------------------
28
+ `|` and `-` | Walls, which the player cannot pass through
29
+ `#` | Doors/stairs, which will lead the player to the next room
30
+
31
+ There will be more characters available to represent other elements, such as enemies, traps, or treasure further in development. The player's character will be rendered as the `@` character based on the coordinates designed in the YAML file.
32
+
33
+ For an example of how your YAML file should be constructed, look at [example_map.yaml](https://github.com/chrisccerami/roguelike/blob/master/map_example.yaml)
34
+
35
+ Once your map is complete, you can start the program using the command:
36
+
37
+ ```shell
38
+ $ roguelike run my_map.yaml
39
+ ```
40
+
41
+ This will read your YAML file and start the game.
42
+
43
+ ## Contributing
44
+
45
+ If you would like to contribute to Roguelike, feel free to create a
46
+ pull request. If you'd like to contact me, you can reach me at
47
+ [chrisccerami@gmail.com](mailto:chrisccerami@gmail.com) or on
48
+ Twitter [@chrisccerami](https://twitter.com/chrisccerami).
49
+
50
+ 1. Fork it ( https://github.com/chrisccerami/roguelike/fork )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Pull Request
55
+
56
+ ## License
57
+
58
+ Copyright (c) 2015 Chris C Cerami
59
+
60
+ MIT License
61
+
62
+ Permission is hereby granted, free of charge, to any person obtaining
63
+ a copy of this software and associated documentation files (the
64
+ "Software"), to deal in the Software without restriction, including
65
+ without limitation the rights to use, copy, modify, merge, publish,
66
+ distribute, sublicense, and/or sell copies of the Software, and to
67
+ permit persons to whom the Software is furnished to do so, subject to
68
+ the following conditions:
69
+
70
+ The above copyright notice and this permission notice shall be
71
+ included in all copies or substantial portions of the Software.
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
74
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
75
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
76
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
77
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
78
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
79
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ require "rspec/core/rake_task"
2
+ require "./lib/roguelike"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :console do
9
+ exec "irb -r ascii_art -I ./lib"
10
+ end
11
+
12
+ task :run do
13
+ Roguelike.run("./map.yaml")
14
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'commander/import'
4
+ require 'roguelike'
5
+ require 'roguelike/version'
6
+
7
+ program :version, Roguelike::VERSION
8
+ program :description, 'A generator for Rogue clones using levels designed in YAML'
9
+ command :run do |c|
10
+ c.syntax = 'roguelike run [options]'
11
+ c.summary = 'Create Rogue clones using levels designed in YAML'
12
+ c.description = "Roguelike will read your game's YAML file, create levels based on your designs, and then handle all of the logic of building and running a customized Rogue clone for you."
13
+ c.example 'Run your new Rogue clone', 'roguelike run my_levels.yaml'
14
+ c.action do |args, options|
15
+ Roguelike.run(args.first)
16
+ end
17
+ end
18
+
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift './lib/roguelike'
2
+
3
+ module Roguelike
4
+ require 'curses'
5
+ require 'ui'
6
+ require 'game'
7
+ require 'map'
8
+ require 'character'
9
+ require 'yaml'
10
+
11
+ def self.run(map_name)
12
+ Game.instance.run(map_name)
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ class Character
2
+ attr_accessor :avatar, :x_pos, :y_pos
3
+ def initialize(avatar, x, y)
4
+ @avatar = avatar
5
+ @x_pos = x
6
+ @y_pos = y
7
+ end
8
+
9
+ def move(x, y)
10
+ if can_move?(x, y)
11
+ UI.instance.clear_position(@x_pos, @y_pos)
12
+ @x_pos = x
13
+ @y_pos = y
14
+ check_target(x, y)
15
+ else
16
+ UI.instance.alert_user
17
+ end
18
+ end
19
+
20
+ def move_up
21
+ move(@x_pos, @y_pos - 1)
22
+ end
23
+
24
+ def move_down
25
+ move(@x_pos, @y_pos + 1)
26
+ end
27
+
28
+ def move_left
29
+ move(@x_pos - 1, @y_pos)
30
+ end
31
+
32
+ def move_right
33
+ move(@x_pos + 1, @y_pos)
34
+ end
35
+
36
+ def can_move?(target_x, target_y)
37
+ !UI.instance.wall?(target_x, target_y)
38
+ end
39
+
40
+ def check_target(x, y)
41
+ if UI.instance.door?(x, y)
42
+ move_through_door
43
+ end
44
+ end
45
+
46
+ def move_through_door
47
+ UI.instance.next_room
48
+ end
49
+ end
@@ -0,0 +1,40 @@
1
+ class Game
2
+ include Singleton
3
+
4
+ attr_reader :ui, :character
5
+ attr_accessor :map, :map_name
6
+ def initialize
7
+ @map
8
+ @ui = UI.instance
9
+ @character = Character.new("@", nil, nil)
10
+ end
11
+
12
+ def run(map_name)
13
+ self.map = Map.new(map_name, 1)
14
+ set_character_position
15
+ ui.write(0, 0, map.layout)
16
+ ui.write(character.x_pos, character.y_pos, character.avatar)
17
+ loop do
18
+ accept_input
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def set_character_position
25
+ character.x_pos = @map.initial_x
26
+ character.y_pos = @map.initial_y
27
+ end
28
+
29
+ def accept_input
30
+ inputs = {
31
+ w: proc { character.move_up },
32
+ a: proc { character.move_left },
33
+ s: proc { character.move_down },
34
+ d: proc { character.move_right },
35
+ q: proc { ui.close }
36
+ }
37
+ inputs[ui.accept_input.to_sym].call
38
+ ui.write(character.x_pos, character.y_pos, character.avatar)
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ class Map
2
+ require 'yaml'
3
+
4
+ attr_reader :file
5
+ attr_accessor :layout, :number, :initial_x, :initial_y
6
+ def initialize(file_name, number)
7
+ @file = YAML.load_file(file_name)
8
+ map = Map.find_map(@file, number)
9
+ @number = number
10
+ @layout = map["layout"]
11
+ @initial_x = map["initial_x"]
12
+ @initial_y = map["initial_y"]
13
+ end
14
+
15
+ def update_map(number)
16
+ map = Map.find_map(self.file, number)
17
+ @number = number
18
+ @layout = map["layout"]
19
+ @initial_x = map["initial_x"]
20
+ @initial_y = map["initial_y"]
21
+ end
22
+
23
+ private
24
+
25
+ def self.find_map(file, n)
26
+ file.select { |map| map["number"] == n }.first
27
+ end
28
+
29
+ end
@@ -0,0 +1,62 @@
1
+ class UI
2
+ include Curses
3
+ require 'singleton'
4
+ include Singleton
5
+
6
+ def initialize
7
+ noecho
8
+ curs_set(0)
9
+ init_screen
10
+ end
11
+
12
+ def close
13
+ close_screen
14
+ exit
15
+ end
16
+
17
+ def write(x, y, string)
18
+ setpos(y, x)
19
+ addstr(string)
20
+ end
21
+
22
+ def accept_input
23
+ inputs = %w(w a s d q)
24
+ loop do
25
+ input = getch
26
+ return input if inputs.include?(input)
27
+ end
28
+ end
29
+
30
+ def clear_position(x, y)
31
+ setpos(y, x)
32
+ delch
33
+ insch(' ')
34
+ end
35
+
36
+ def wall?(x, y)
37
+ setpos(y, x)
38
+ inch.chr == '|' || inch.chr == '-'
39
+ end
40
+
41
+ def door?(x, y)
42
+ setpos(y, x)
43
+ inch.chr =='#'
44
+ end
45
+
46
+ def alert_user
47
+ beep
48
+ flash
49
+ end
50
+
51
+ def load_room(map)
52
+ write(0, 0, map.layout)
53
+ Game.instance.character.move(map.initial_x, map.initial_y)
54
+ end
55
+
56
+ def next_room
57
+ clear
58
+ next_room = Game.instance.map.number + 1
59
+ Game.instance.map.update_map(next_room)
60
+ load_room(Game.instance.map)
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module Roguelike
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,77 @@
1
+ ---
2
+ - number: 1
3
+ initial_x: 1
4
+ initial_y: 2
5
+ layout: >
6
+ ----------------------------------------------
7
+ | | | |
8
+ | | | |
9
+ - - ---- - ------------- - ---------- -
10
+
11
+ | | | | | | | |
12
+
13
+ | | | | | | | |
14
+
15
+ ---------- - ---- ------- ---------- - -
16
+
17
+ | | | | | | | | |
18
+
19
+ | | | | | | | | |
20
+
21
+ - ---- ---- - - ---- ---- ---- ---- -
22
+
23
+ | | | | | | |
24
+
25
+ | # | | | | | |
26
+
27
+ - ------- ---- ---- ---- ---------- ----
28
+
29
+ | | | | | | | | | |
30
+
31
+ | | | | | | | | | |
32
+
33
+ - - - - - ---- - - ---- - - ---- -
34
+
35
+ | | | | | | | | | | |
36
+
37
+ | | | | | | | | | | |
38
+
39
+ - ------- - ---- ---- - ---------- - -
40
+
41
+ | | | | | | |
42
+
43
+ | | | | | | |
44
+
45
+ ------- ------- ---- ------------------- -
46
+
47
+ | | | | | | |
48
+
49
+ | | | | | | |
50
+
51
+ - ------- - - ---------- - ---- - - -
52
+
53
+ | | | | | | | | |
54
+
55
+ | | | | | | | | |
56
+
57
+ ------- ---------- - - - ---- ---- - -
58
+
59
+ | | | | | | |
60
+
61
+ | | | | | | |
62
+
63
+ ----------------------------------------------
64
+
65
+ - number: 2
66
+ initial_x: 1
67
+ initial_y: 1
68
+ layout: >
69
+ --------------------
70
+
71
+ | |
72
+
73
+ | |
74
+
75
+ | # |
76
+
77
+ ---------------------
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'roguelike/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "roguelike"
8
+ spec.version = Roguelike::VERSION
9
+ spec.authors = ["Chris C Cerami"]
10
+ spec.email = ["chrisccerami@gmail.com"]
11
+ spec.date = '2015-07-26'
12
+ spec.summary = "Create Rogue clones using levels designed in YAML"
13
+ spec.description = "Roguelike will read your game's YAML file, create levels based on your designs, and then handle all of the logic of building and running a customized Rogue clone for you."
14
+ spec.homepage = "http://rubygems.org/gems/roguelike"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_path = "lib"
21
+
22
+ spec.required_ruby_version = '~> 2.0'
23
+
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+
26
+ spec.add_runtime_dependency 'commander', '~> 4.3'
27
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roguelike
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Chris C Cerami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: commander
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.3'
41
+ description: Roguelike will read your game's YAML file, create levels based on your
42
+ designs, and then handle all of the logic of building and running a customized Rogue
43
+ clone for you.
44
+ email:
45
+ - chrisccerami@gmail.com
46
+ executables:
47
+ - roguelike
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - README.md
55
+ - Rakefile
56
+ - bin/roguelike
57
+ - lib/roguelike.rb
58
+ - lib/roguelike/character.rb
59
+ - lib/roguelike/game.rb
60
+ - lib/roguelike/map.rb
61
+ - lib/roguelike/ui.rb
62
+ - lib/roguelike/version.rb
63
+ - map_example.yaml
64
+ - roguelike.gemspec
65
+ homepage: http://rubygems.org/gems/roguelike
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '2.0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.5
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Create Rogue clones using levels designed in YAML
89
+ test_files: []