terminal_hero 0.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.
- checksums.yaml +7 -0
- data/bin/terminal_hero +3 -0
- data/lib/terminal_hero.rb +5 -0
- data/lib/terminal_hero/classes/creature.rb +80 -0
- data/lib/terminal_hero/classes/errors/invalid_input_error.rb +12 -0
- data/lib/terminal_hero/classes/errors/no_feature_error.rb +9 -0
- data/lib/terminal_hero/classes/map.rb +247 -0
- data/lib/terminal_hero/classes/monster.rb +84 -0
- data/lib/terminal_hero/classes/player.rb +98 -0
- data/lib/terminal_hero/classes/stat_menu.rb +76 -0
- data/lib/terminal_hero/classes/tile.rb +45 -0
- data/lib/terminal_hero/modules/display_controller.rb +239 -0
- data/lib/terminal_hero/modules/game_controller.rb +311 -0
- data/lib/terminal_hero/modules/game_data.rb +331 -0
- data/lib/terminal_hero/modules/input_handler.rb +29 -0
- data/lib/terminal_hero/modules/utils.rb +38 -0
- metadata +60 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
# A module containing methods for processing and validating input
|
2
|
+
module InputHandler
|
3
|
+
# Given an array of command-line arguments, return the associated action if any,
|
4
|
+
# or else return false
|
5
|
+
def self.process_command_line_args(
|
6
|
+
args,
|
7
|
+
new_game_args: GameData::COMMAND_LINE_ARGUMENTS[:new_game],
|
8
|
+
load_game_args: GameData::COMMAND_LINE_ARGUMENTS[:load_game]
|
9
|
+
)
|
10
|
+
return false unless args.is_a?(Array) && !args.empty?
|
11
|
+
|
12
|
+
args.map(&:downcase)
|
13
|
+
return :new_game if new_game_args.include?(args[0])
|
14
|
+
return [:load_game, args[1]] if load_game_args.include?(args[0]) && args.length > 1
|
15
|
+
return :load_game if load_game_args.include?(args[0])
|
16
|
+
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
|
20
|
+
# Check if a given character name is valid for creating or loading a character
|
21
|
+
def self.character_name_valid?(name)
|
22
|
+
return false unless name.is_a?(String)
|
23
|
+
return false unless (3..15).include?(name.length)
|
24
|
+
return false unless name.match?(/^\w*$/)
|
25
|
+
return false if name.match?(/\s/)
|
26
|
+
|
27
|
+
return true
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
begin
|
2
|
+
require "logger"
|
3
|
+
require "tmpdir"
|
4
|
+
rescue LoadError => e
|
5
|
+
# Display load errors using puts (not calling external methods which may not have been loaded)
|
6
|
+
puts "It appears that a dependency was unable to be loaded: "
|
7
|
+
puts e.message
|
8
|
+
puts "Please try installing dependencies mannually by running the command "\
|
9
|
+
"\"bundle install\" from within the installation directory."
|
10
|
+
puts "If you installed this application as a gem, you could try reinstalling it by "\
|
11
|
+
"running \"gem uninstall terminal_hero\" followed by \"gem install terminal_hero\""
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
# A module containing general utility methods
|
16
|
+
module Utils
|
17
|
+
# Returns a value "collared" within a given range
|
18
|
+
def self.collar(min, val, max)
|
19
|
+
return [[min, val].max, max].min
|
20
|
+
end
|
21
|
+
|
22
|
+
# Clones a hash, then clones each of its values (but not any deeper values)
|
23
|
+
def self.depth_two_clone(hash)
|
24
|
+
clone = hash.dup
|
25
|
+
clone.each { |key, value| clone[key] = value.dup }
|
26
|
+
return clone
|
27
|
+
end
|
28
|
+
|
29
|
+
# Logs an error to a log file in the user's OS's global temp directory and
|
30
|
+
# returns the path to the file for display to the user.
|
31
|
+
def self.log_error(e)
|
32
|
+
temp_directory = Dir.mktmpdir("/terminal-hero-logs")
|
33
|
+
log_file = File.open(File.join(temp_directory, "th-error.log"), "w")
|
34
|
+
logger = Logger.new(log_file)
|
35
|
+
logger.error("An error occurred: #{e.full_message}")
|
36
|
+
return File.path(log_file)
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: terminal_hero
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Kamp
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Terminal Hero is a simple turn-based roleplaying game, created for coursework.
|
14
|
+
Players can navigate an ASCII world map, encounter monsters and fight using a turn-based
|
15
|
+
combat system. There is a leveling system and players can allocate stat points to
|
16
|
+
different combat attributes.
|
17
|
+
email:
|
18
|
+
executables:
|
19
|
+
- terminal_hero
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- bin/terminal_hero
|
24
|
+
- lib/terminal_hero.rb
|
25
|
+
- lib/terminal_hero/classes/creature.rb
|
26
|
+
- lib/terminal_hero/classes/errors/invalid_input_error.rb
|
27
|
+
- lib/terminal_hero/classes/errors/no_feature_error.rb
|
28
|
+
- lib/terminal_hero/classes/map.rb
|
29
|
+
- lib/terminal_hero/classes/monster.rb
|
30
|
+
- lib/terminal_hero/classes/player.rb
|
31
|
+
- lib/terminal_hero/classes/stat_menu.rb
|
32
|
+
- lib/terminal_hero/classes/tile.rb
|
33
|
+
- lib/terminal_hero/modules/display_controller.rb
|
34
|
+
- lib/terminal_hero/modules/game_controller.rb
|
35
|
+
- lib/terminal_hero/modules/game_data.rb
|
36
|
+
- lib/terminal_hero/modules/input_handler.rb
|
37
|
+
- lib/terminal_hero/modules/utils.rb
|
38
|
+
homepage: https://github.com/chris-kamp/terminal-hero
|
39
|
+
licenses: []
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.1.2
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: A simple turn-based roleplaying game, playable in the terminal.
|
60
|
+
test_files: []
|