gemwarrior 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7e88f25ec32e8547f6300380c1b28db29d70ddd
4
- data.tar.gz: e52a393b60fdac5aae3d74e5e79d66a8d627ebe1
3
+ metadata.gz: 410ff3b3615c76977920cc1352066588ae94b2aa
4
+ data.tar.gz: bb43488f8f1cdf2d5afc060782995a999cc9997f
5
5
  SHA512:
6
- metadata.gz: a655cc40acff93a91e3b17d41f53a35ec9bb46efad7316f9cce1d255150a63233489ceebfb313629cf559745d521e0f7c6ae27ca6e2502d1074d260618ca19a7
7
- data.tar.gz: 59c4e5452954b732e45ab09e69a04267f68ffa187ca514d2e38e5aa56e7d793ff6627cd9cc388296ac719480c03a89315122a5f29dcdbf543ed290adbedda645
6
+ metadata.gz: 62800096ddfafa1ca85ea279cdd266d350868812368ef20732cbb51defc9ec6f866e557aecb3a36508d4fd3dc2c684e48e2684267700320d8f687ec6b225538c
7
+ data.tar.gz: f1e6fc509b3bf9793bbdea8b785d7126ca4e9f51b7d4bbb20d8a12794242586890e2b67d304a0c608199159752d0e31bbc2a2e3dceb26b4f5588546cd5d6bd60
data/bin/gemwarrior CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
- require_relative '../lib/gemwarrior'
4
+
5
5
  require_relative '../lib/gemwarrior/version'
6
+ require_relative '../lib/gemwarrior/game'
6
7
 
7
8
  def parse_options
8
9
  opts.on('-v', '--version', 'Display version number and exit') do
@@ -22,7 +23,7 @@ def print_error(error)
22
23
  end
23
24
 
24
25
  begin
25
- Gemwarrior::Base.new
26
+ Gemwarrior::Game.new
26
27
  rescue => error
27
28
  print_error(error)
28
29
  exit(false)
@@ -5,7 +5,8 @@ module Gemwarrior
5
5
  PROGRAM_NAME = 'Gem Warrior'
6
6
  SPLASH_MESSAGE = 'Welcome to Gem Warrior, where randomized fortune is just as likely as mayhem.'
7
7
  QUIT_MESSAGE = 'Thanks for playing the game. Until next time...'
8
- SEPARATOR = '====================================================='
8
+ RESUME_MESSAGE = 'Back to adventuring!'
9
+ SEPARATOR = '==========================================================='
9
10
  CHANGE_PARAMS = 'Options: name'
10
11
 
11
12
  DANGER_LEVEL = {:none => 0, :low => 15, :moderate => 30, :high => 55, :assured => 100}
@@ -13,11 +14,13 @@ module Gemwarrior
13
14
  module Errors
14
15
  ERROR_COMMAND_INVALID = 'That\'s not something the game yet understands.'
15
16
  ERROR_INVENTORY_EMPTY = '...and find you currently have diddly-squat, which is nothing.'
17
+ ERROR_INVENTORY_REMOVE_INVALID = 'Your inventory does not contain that item, so you can\'t drop it.'
16
18
  ERROR_ITEM_LOC_INVALID = 'You don\'t see that there.'
17
19
  ERROR_ITEM_INVENTORY_INVALID = 'You don\'t possess that.'
18
20
  ERROR_TAKE_PARAM_MISSING = 'You can\'t just take. You gotta choose something.'
19
21
  ERROR_TAKE_ITEM_UNTAKEABLE = 'That would be great if you could take that thing, wouldn\'t it? Well, it\'s not so great for you right now.'
20
22
  ERROR_TAKE_ITEM_INVALID = 'That item doesn\'t exist here.'
23
+ ERROR_DROP_PARAM_MISSING = 'You can\'t just drop indiscriminately. You gotta choose something.'
21
24
  ERROR_GO_DIR_MISSING = 'Just wander aimlessly? A direction would be nice.'
22
25
  ERROR_GO_DIR_INVALID = 'The place in that direction is far, far, FAR too dangerous. You should try a different way.'
23
26
  ERROR_CHANGE_PARAM_MISSING = 'Ch-ch-changes...aren\'t happening because you didn\'t specify what to change.'
@@ -7,41 +7,49 @@ require_relative 'constants'
7
7
 
8
8
  module Gemwarrior
9
9
  class Evaluator
10
+ private
11
+
12
+ def print_separator
13
+ puts SEPARATOR
14
+ end
15
+
16
+ def list_commands
17
+ i = 0
18
+ print_separator
19
+ @commands.each do |cmd|
20
+ puts " #{cmd}, #{@aliases[i]}\n -- #{@descriptions[i]}"
21
+ i = i + 1
22
+ end
23
+ print_separator
24
+ end
25
+
26
+ public
27
+
10
28
  include Errors
11
29
 
12
30
  def initialize(world)
13
31
  @world = world
14
- @commands = %w(character inventory rest look take world monsters go change help quit exit)
15
- @aliases = %w(c i r l t w m g ch h q x)
32
+ @commands = %w(character inventory rest look take drop world monsters go change help quit exit quit! exit!)
33
+ @aliases = %w(c i r l t d w m g ch h q x qq xx)
16
34
  @descriptions = [
17
35
  'Display character information',
18
36
  'Look in your inventory',
19
37
  'Take a load off and regain stamina',
20
38
  'Look around your current location',
39
+ 'Take item',
40
+ 'Drop item',
21
41
  'List all locations in the world',
22
42
  'List all the monsters in the world',
23
- 'Go in a directions',
43
+ 'Go in a direction',
24
44
  'Change something',
25
45
  'This help menu',
26
- 'Quit the game',
27
- 'Exit the game (very different, of course)'
46
+ 'Quit w/ confirmation',
47
+ 'Exit w/ confirmation (very different, of course)',
48
+ 'Quit w/o confirmation',
49
+ 'Exit w/o confirmation (very, very different, of course)'
28
50
  ]
29
51
  end
30
52
 
31
- def print_separator
32
- SEPARATOR
33
- end
34
-
35
- def list_commands
36
- i = 0
37
- print_separator
38
- @commands.each do |cmd|
39
- puts "#{cmd}, #{@aliases[i]} - #{@descriptions[i]}"
40
- i = i + 1
41
- end
42
- print_separator
43
- end
44
-
45
53
  def evaluate(input)
46
54
  if input.nil?
47
55
  return
@@ -57,39 +65,45 @@ module Gemwarrior
57
65
  param = tokens[1]
58
66
 
59
67
  case command
60
- when @commands[0], @aliases[0] # character
68
+ when 'character', 'c'
61
69
  @world.player.check_self
62
- when @commands[1], @aliases[1] # inventory
70
+ when 'inventory', 'i'
63
71
  if param
64
72
  @world.player.inventory.describe_item(param)
65
73
  else
66
74
  @world.player.list_inventory
67
75
  end
68
- when @commands[2], @aliases[2] # rest
76
+ when 'rest', 'r'
69
77
  @world.player.rest
70
- when @commands[3], @aliases[3] # look
78
+ when 'look', 'l'
71
79
  if param
72
80
  @world.player.cur_loc.describe_item(param)
73
81
  else
74
82
  @world.player.cur_loc.describe
75
83
  end
76
- when @commands[4], @aliases[4] # take
77
- unless param.nil?
78
- @world.player.inventory.add_item(@world.player.cur_loc, param)
79
- else
84
+ when 'take', 't'
85
+ if param.nil?
80
86
  ERROR_TAKE_PARAM_MISSING
87
+ else
88
+ @world.player.inventory.add_item(@world.player.cur_loc, param)
81
89
  end
82
- when @commands[5], @aliases[5] # world
90
+ when 'drop', 'd'
91
+ if param.nil?
92
+ ERROR_DROP_PARAM_MISSING
93
+ else
94
+ @world.player.inventory.remove_item(param)
95
+ end
96
+ when 'world', 'world'
83
97
  @world.list_locations
84
- when @commands[6], @aliases[6] # monsters
98
+ when 'monsters', 'm'
85
99
  @world.list_monsters
86
- when @commands[7], @aliases[7] # go
100
+ when 'go', 'g'
87
101
  if param.nil?
88
102
  ERROR_GO_DIR_MISSING
89
103
  else
90
104
  @world.player.go(@world.locations, param)
91
105
  end
92
- when @commands[8], @aliases[8] # change
106
+ when 'change', 'ch'
93
107
  if param.nil?
94
108
  puts ERROR_CHANGE_PARAM_MISSING
95
109
  puts CHANGE_PARAMS
@@ -101,9 +115,18 @@ module Gemwarrior
101
115
  ERROR_CHANGE_PARAM_INVALID
102
116
  end
103
117
  end
104
- when @commands[9], @aliases[9] # help
118
+ when 'help', 'h'
105
119
  list_commands
106
- when @commands[10..11], @aliases[10] # quit/exit
120
+ when 'quit', 'exit', 'q', 'x'
121
+ puts "You sure you want to quit? (y/n): "
122
+ response = gets.chomp
123
+ if (response.downcase.eql?("y") || response.downcase.eql?("yes"))
124
+ puts QUIT_MESSAGE
125
+ exit(0)
126
+ else
127
+ puts RESUME_MESSAGE
128
+ end
129
+ when 'qq', 'xx'
107
130
  puts QUIT_MESSAGE
108
131
  exit(0)
109
132
  else
@@ -50,9 +50,9 @@ module Gemwarrior
50
50
  end
51
51
 
52
52
  def remove_item(item_name)
53
- if inventory.include?(item_name)
54
- @inventory.delete(item_name)
55
- puts "#{item} has been thrown on the ground, but far out of reach, and you're much too lazy to go get it now, so it's as good as gone.\n"
53
+ if @inventory.map(&:name).include?(item_name)
54
+ @inventory.reject! { |item| item.name == item_name }
55
+ puts "The #{item_name} has been thrown on the ground, but far out of reach, and you're much too lazy to go get it now, so it's as good as gone.\n"
56
56
  else
57
57
  puts ERROR_INVENTORY_REMOVE_INVALID
58
58
  end
@@ -2,5 +2,5 @@
2
2
  # Version of Gem Warrior
3
3
 
4
4
  module Gemwarrior
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemwarrior
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Chadwick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-19 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: os
@@ -116,7 +116,6 @@ files:
116
116
  - Rakefile
117
117
  - bin/gemwarrior
118
118
  - gemwarrior.gemspec
119
- - lib/gemwarrior.rb
120
119
  - lib/gemwarrior/constants.rb
121
120
  - lib/gemwarrior/creature.rb
122
121
  - lib/gemwarrior/evaluator.rb
data/lib/gemwarrior.rb DELETED
@@ -1,9 +0,0 @@
1
- # lib/gemwarrior.rb
2
-
3
- require_relative 'gemwarrior/game'
4
-
5
- module Gemwarrior
6
- class Base
7
- Game.new
8
- end
9
- end