gambit 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.
Files changed (111) hide show
  1. data/AUTHORS +2 -0
  2. data/CHANGELOG +7 -0
  3. data/COPYING +340 -0
  4. data/INSTALL +23 -0
  5. data/LICENSE +7 -0
  6. data/README +25 -0
  7. data/Rakefile +87 -0
  8. data/TODO +6 -0
  9. data/examples/bird_wars/game.rb +434 -0
  10. data/examples/bird_wars/html/chest.rhtml +37 -0
  11. data/examples/bird_wars/html/combat.rhtml +38 -0
  12. data/examples/bird_wars/html/fight.rhtml +71 -0
  13. data/examples/bird_wars/html/fridge.rhtml +31 -0
  14. data/examples/bird_wars/html/help.rhtml +30 -0
  15. data/examples/bird_wars/html/house.rhtml +36 -0
  16. data/examples/bird_wars/html/images/albatross.jpg +0 -0
  17. data/examples/bird_wars/html/images/alka_seltzer_small.png +0 -0
  18. data/examples/bird_wars/html/images/bazooka_small.png +0 -0
  19. data/examples/bird_wars/html/images/bb_gun_small.png +0 -0
  20. data/examples/bird_wars/html/images/cat_small.png +0 -0
  21. data/examples/bird_wars/html/images/combat.png +0 -0
  22. data/examples/bird_wars/html/images/crossbow_small.png +0 -0
  23. data/examples/bird_wars/html/images/cuckoo.jpg +0 -0
  24. data/examples/bird_wars/html/images/fridge.png +0 -0
  25. data/examples/bird_wars/html/images/gull.jpg +0 -0
  26. data/examples/bird_wars/html/images/house.jpg +0 -0
  27. data/examples/bird_wars/html/images/items.png +0 -0
  28. data/examples/bird_wars/html/images/not_found.png +0 -0
  29. data/examples/bird_wars/html/images/note.jpg +0 -0
  30. data/examples/bird_wars/html/images/oil_small.png +0 -0
  31. data/examples/bird_wars/html/images/one_stone_small.png +0 -0
  32. data/examples/bird_wars/html/images/owl.jpg +0 -0
  33. data/examples/bird_wars/html/images/poisoned_seeds_small.png +0 -0
  34. data/examples/bird_wars/html/images/rice_small.png +0 -0
  35. data/examples/bird_wars/html/images/shotgun_small.png +0 -0
  36. data/examples/bird_wars/html/images/slingshot_small.png +0 -0
  37. data/examples/bird_wars/html/images/soda_rings_small.png +0 -0
  38. data/examples/bird_wars/html/images/spear_small.png +0 -0
  39. data/examples/bird_wars/html/images/stork.jpg +0 -0
  40. data/examples/bird_wars/html/images/weapons.png +0 -0
  41. data/examples/bird_wars/html/images/woodpecker.jpg +0 -0
  42. data/examples/bird_wars/html/images/you.jpg +0 -0
  43. data/examples/bird_wars/html/index.rhtml +13 -0
  44. data/examples/bird_wars/html/weapons.rhtml +35 -0
  45. data/examples/cli/blackjack.rb +86 -0
  46. data/examples/cli/go.rb +93 -0
  47. data/examples/cli/space_trader2/planet_data +12280 -0
  48. data/examples/cli/space_trader2/space_trader2.rb +248 -0
  49. data/examples/cli/space_trader2/world.rb +127 -0
  50. data/examples/cli/spacetrader.rb +262 -0
  51. data/examples/cli/yahtzee.rb +161 -0
  52. data/examples/galactic_courier/Rakefile +9 -0
  53. data/examples/galactic_courier/bin/galactic_courier.rb +44 -0
  54. data/examples/galactic_courier/html/console.rhtml +15 -0
  55. data/examples/galactic_courier/html/images/barren.jpg +0 -0
  56. data/examples/galactic_courier/html/images/industrial.jpg +0 -0
  57. data/examples/galactic_courier/html/images/jungle.jpg +0 -0
  58. data/examples/galactic_courier/html/images/oceanic.jpg +0 -0
  59. data/examples/galactic_courier/html/images/tundra.jpg +0 -0
  60. data/examples/galactic_courier/html/images/volcanic.jpg +0 -0
  61. data/examples/galactic_courier/lib/galaxy.rb +64 -0
  62. data/examples/galactic_courier/lib/planet.rb +30 -0
  63. data/examples/galactic_courier/lib/sector.rb +84 -0
  64. data/examples/galactic_courier/lib/station.rb +18 -0
  65. data/examples/galactic_courier/test/tc_galaxy.rb +24 -0
  66. data/examples/galactic_courier/test/tc_planet.rb +22 -0
  67. data/examples/galactic_courier/test/tc_sector.rb +55 -0
  68. data/examples/galactic_courier/test/ts_all.rb +12 -0
  69. data/examples/gambit_mail/html/compose.rhtml +39 -0
  70. data/examples/gambit_mail/html/index.rhtml +3 -0
  71. data/examples/gambit_mail/html/mailbox.rhtml +47 -0
  72. data/examples/gambit_mail/html/message.rhtml +34 -0
  73. data/examples/gambit_mail/mail.rb +75 -0
  74. data/lib/gambit.rb +10 -0
  75. data/lib/gambit/server.rb +269 -0
  76. data/lib/gambit/server/gambiterror.rb +28 -0
  77. data/lib/gambit/server/game.rb +185 -0
  78. data/lib/gambit/server/game/eventform.rb +174 -0
  79. data/lib/gambit/server/message.rb +85 -0
  80. data/lib/gambit/server/player.rb +40 -0
  81. data/lib/gambit/tools.rb +13 -0
  82. data/lib/gambit/tools/board.rb +275 -0
  83. data/lib/gambit/tools/cards.rb +11 -0
  84. data/lib/gambit/tools/cards/card.rb +158 -0
  85. data/lib/gambit/tools/cards/deck.rb +99 -0
  86. data/lib/gambit/tools/cards/hand.rb +86 -0
  87. data/lib/gambit/tools/cards/pile.rb +107 -0
  88. data/lib/gambit/tools/currency.rb +148 -0
  89. data/lib/gambit/tools/dice.rb +219 -0
  90. data/lib/gambit/tools/movehistory.rb +164 -0
  91. data/lib/gambit/tools/scorecard.rb +333 -0
  92. data/lib/gambit/viewable.rb +71 -0
  93. data/setup.rb +1360 -0
  94. data/test/tc_board.rb +167 -0
  95. data/test/tc_cards.rb +182 -0
  96. data/test/tc_currency.rb +99 -0
  97. data/test/tc_dice.rb +83 -0
  98. data/test/tc_error.rb +34 -0
  99. data/test/tc_event.rb +367 -0
  100. data/test/tc_game.rb +29 -0
  101. data/test/tc_message.rb +35 -0
  102. data/test/tc_movehistory.rb +38 -0
  103. data/test/tc_player.rb +60 -0
  104. data/test/tc_scorecard.rb +112 -0
  105. data/test/tc_views.rb +353 -0
  106. data/test/test_game.rb +19 -0
  107. data/test/test_view.rhtml +2 -0
  108. data/test/ts_all.rb +12 -0
  109. data/test/ts_server.rb +14 -0
  110. data/test/ts_tools.rb +14 -0
  111. metadata +183 -0
@@ -0,0 +1,248 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # space_trader2.rb
3
+ #
4
+ # Created by Gregory Brown on 2005-06-01
5
+ # Copyright 2005 smtose.org. All rights reserved.
6
+
7
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "..", "..", "lib"))
8
+ $:.unshift(File.dirname(__FILE__))
9
+ require "gambit/tools"
10
+ require "gambit/viewable"
11
+ require "world"
12
+ include Gambit::Tools
13
+
14
+ World.generate_galaxy(File.join(File.dirname(__FILE__), "planet_data"))
15
+ World.generate_board(20,20)
16
+
17
+ @solar_system = nil
18
+
19
+ Currency["cash"] = 1
20
+ Currency["lazers"] = 0
21
+ player_holdings = Hash.new(0)
22
+ player_holdings["cash"] = 500
23
+ player_holdings["lazers"] = 2
24
+ @player_health = 100
25
+ @player = Currency.new(player_holdings)
26
+
27
+ def show_galaxy
28
+ puts World.new(nil).view(:galaxy_view)
29
+ end
30
+
31
+ def show_planet(planet_name)
32
+ puts World.galaxy[planet_name].view(:world_view)
33
+ end
34
+
35
+ def select_world()
36
+ if @solar_system.nil?
37
+ select_solar_system()
38
+ else
39
+ puts "Worlds in System #{@solar_system}: "
40
+ puts World.board[@solar_system].join(" | ")
41
+ print "\n> "
42
+ choice = gets.chomp
43
+ choice = World.board[@solar_system].find { |wor| wor =~ /^#{choice}/ }
44
+
45
+ if choice.nil?
46
+ puts "Either you suck with the keyboard or " +
47
+ "that isn't in this system."
48
+ select_world()
49
+ else
50
+ World.set_current_planet(choice)
51
+ end
52
+
53
+ end
54
+ end
55
+
56
+ def select_solar_system()
57
+ print "Enter Solar System Coordinates to Warp: (i.e. e8 b6 etc.)\n"
58
+ show_galaxy
59
+ print "> "
60
+ choice = gets.chomp
61
+ if World.board.valid?(choice)
62
+ @solar_system = choice
63
+ World.set_current_planet(
64
+ World.board[choice][rand(World.board[choice].size)] )
65
+ select_world
66
+ else
67
+ puts "Invalid choice"
68
+ select_solar_system()
69
+ end
70
+ end
71
+
72
+ def random_events( )
73
+ value = 1.d(6).sum
74
+ combat() if value == 2 or value == 4
75
+ police() if value == 3
76
+ end
77
+
78
+ def combat(police = false )
79
+ multiplier = police ? 2 : 1
80
+ pirate_health = 1.d(100).sum * multiplier
81
+ puts "You have been attacked by pirates!"
82
+ puts "your health: #{@player_health} pirate health #{pirate_health}"
83
+ pirate_lazers = Dice.new(1,3).sum * multiplier
84
+ while pirate_health > 0 && @player_health > 0
85
+ print "(a)ttack (f)lee: "
86
+ case gets.chomp.downcase
87
+ when /^a/
88
+ pirate_health -= Dice.new(@player["lazers"],6).sum
89
+ when /^f/
90
+ if Dice.new(1,6).sum % 2 == 0
91
+ @player.withdraw(@player["cash"]/2,"cash")
92
+ puts "You got away but lost half your cash in the process"
93
+ return
94
+ end
95
+ else
96
+ puts "Schwa?"
97
+ end
98
+ @player_health -= Dice.new(pirate_lazers,5).sum if pirate_health > 0
99
+ if @player_health > 0 && pirate_health > 0
100
+ puts "your health: #{@player_health} " +
101
+ "pirate health #{pirate_health}"
102
+ elsif @player_health <= 0
103
+ puts "The pirates gunned the crap out of you!"
104
+ else
105
+ puts "You destroyed the pirate fools!"
106
+ end
107
+ end
108
+ end
109
+
110
+ def police( )
111
+ puts "You have been stopped by the police!"
112
+ puts "You may let them (i)nspect, try to (f)lee, (a)ttack " +
113
+ "or (b)ribe them for 500 cash"
114
+ print "\n> "
115
+ case gets.chomp.downcase
116
+ when /^a/
117
+ puts "The police were really a band of pirates!" +
118
+ "( Not really, but we havent made police fights yet :) )"
119
+ combat(police = true)
120
+
121
+ when /^i/
122
+ if @player.holdings.keys.any? { |item| World.illegal?(item) }
123
+ @player_health = 0
124
+ puts "You've been busted for transporting illegal substances!"
125
+ return
126
+ else
127
+ puts "The police inspect and find nothing unusual"
128
+ end
129
+ when /^f/
130
+ if Dice.new(1,10).sum % 3 == 0
131
+ puts "Good job, you stuck it to the man and got away!"
132
+ return
133
+ else
134
+ puts "You should never run from the police! BUSTED!"
135
+ @player_health = 0
136
+ return
137
+ end
138
+ when /^b/
139
+ if Dice.new(1,10).sum % 9 == 0
140
+ puts "You've come across the one in ten cops " +
141
+ "who can't be bribed. Bummer"
142
+ @player_health = 0
143
+ return
144
+ elsif @player["cash"] < 500
145
+ puts "You don't have enough to bribe the cops. BUSTED!"
146
+ @player_health = 0
147
+ return
148
+ else
149
+ puts "The cop looks the other way once the cash " +
150
+ "is in his hands."
151
+ @player.withdraw(500,"cash")
152
+ return
153
+ end
154
+ else
155
+ puts "Shiggity Schwa?"
156
+ end
157
+ end
158
+
159
+ def show_player_commodities( )
160
+ puts "You have: "
161
+ @player.holdings.each do |key, value|
162
+ puts key.to_s + " [" + value.to_s + "]" if value > 0
163
+ end
164
+ end
165
+
166
+ def make_purchase( )
167
+ print "\n(quantity item): "
168
+ quantity, item = gets.chomp.split(/ /)
169
+ available = World.resources
170
+ item = available.find { |name| name =~ /^#{item}/ }
171
+
172
+ if item.nil?
173
+ puts "Unknown item."
174
+ return
175
+ end
176
+
177
+ cost = World.cash_value(quantity.to_i,item)
178
+
179
+ if ( @player["cash"] >= cost)
180
+ @player.withdraw(cost,"cash")
181
+ World.galaxy[World.get_current_planet].export(quantity.to_i, item)
182
+ @player.deposit(quantity.to_i,item)
183
+ else
184
+ puts "Insufficient funds."
185
+ end
186
+ end
187
+
188
+ def make_sale()
189
+ print "\n(quantity item): "
190
+ quantity, item = gets.chomp.split(/ /)
191
+ available = World.resources
192
+ item = available.find { |name| name =~ /^#{item}/ }
193
+
194
+ if item.nil?
195
+ puts "Unknown item."
196
+ return
197
+ end
198
+
199
+ if @player[item] >= quantity.to_i
200
+ World.galaxy[World.get_current_planet].import(quantity.to_i, item)
201
+ @player.deposit( World.cash_value(quantity.to_i,item),"cash")
202
+ @player.withdraw(quantity.to_i,item)
203
+ else
204
+ puts "You don't have that much, bonehead!"
205
+ end
206
+ end
207
+
208
+ select_solar_system()
209
+ alive =true
210
+ while alive
211
+ show_planet(World.get_current_planet)
212
+ puts "------------------------------------------"
213
+ show_player_commodities()
214
+ puts "\nWelcome to #{World.get_current_planet}!"
215
+ puts "(b)uy (s)ell (h)eal (m)ove (w)arp (q)uit " +
216
+ "Health: #{@player_health}"
217
+ print "\n>"
218
+ case gets.chomp.downcase
219
+ when /^m/
220
+ random_events()
221
+ select_world()
222
+ when /^w/
223
+ if @player["boosters"] > 0
224
+ @player.withdraw(1,"boosters")
225
+ select_solar_system()
226
+ else
227
+ puts "You need a booster to warp!"
228
+ end
229
+ when /^q/
230
+ exit
231
+ when /^b/
232
+ make_purchase()
233
+ when /^s/
234
+ make_sale()
235
+ when /^h/
236
+ if @player["medicine"] > 0
237
+ @player.withdraw(1,"medicine")
238
+ @player_health + 20 < 100 ? @player_health += 20 :
239
+ @player_health = 100
240
+ else
241
+ puts "No medicine to use!"
242
+ end
243
+ else
244
+ puts "DAMN!"
245
+ end
246
+
247
+ alive = false unless @player_health > 0
248
+ end
@@ -0,0 +1,127 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ # world.rb
4
+ #
5
+ # Created by Gregory Brown on 2005-06-01
6
+ # Copyright 2005 smtose.org. All rights reserved.
7
+
8
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "..", "..", "lib"))
9
+ require "gambit/tools"
10
+ require "gambit/viewable"
11
+ include Gambit::Tools
12
+
13
+ class World
14
+ include Gambit::Viewable
15
+ register_view(:world_view, <<-END_WORLD_VIEW.gsub(/^\t/, ""))
16
+ <%= @name %> resources:
17
+ % self.class.resources.each do |resource|
18
+ % if @exchange_rates[resource] > 0
19
+ * <%= resource %>: $<%= @exchange_rates[resource]%> [<%=
20
+ @currency_hold[resource] %> Available]
21
+ % end
22
+ % end
23
+ END_WORLD_VIEW
24
+ register_view(:galaxy_view, <<-END_GALAXY_VIEW.gsub(/^\t/, ""))
25
+ % self.class.board.each_row do |row|
26
+ <%= row.map { |solar_system| solar_system.any? { |planet|
27
+ self.class.galaxy[planet].visited } ? '#' : '-' }.
28
+ join(' ') %>
29
+ % end
30
+ END_GALAXY_VIEW
31
+
32
+ def self.generate_galaxy(filename)
33
+ @@galaxy = Hash.new(0)
34
+ puts "Loading galaxy file, patience my son..."
35
+ File.open(filename) do |file|
36
+ while planet_name = file.gets
37
+ @@galaxy[planet_name.chomp] = World.new(planet_name.chomp)
38
+ end
39
+ end
40
+
41
+ puts "Loaded!"
42
+ end
43
+
44
+ def self.generate_board(xSize, ySize)
45
+ names = @@galaxy.keys
46
+ @@galaxy_board = Board.new(xSize, ySize, [])
47
+ @@galaxy_board.each_location do |loc|
48
+ (2+rand(8)).times do
49
+ planet_name = names[ rand(names.size) ]
50
+ @@galaxy_board[loc] << planet_name
51
+ end
52
+ end
53
+ end
54
+
55
+ def self.illegal?(resource)
56
+ @@illegal_commodities.include?(resource) ? true : false
57
+ end
58
+
59
+ def self.resources
60
+ return @@commodities
61
+ end
62
+
63
+ def self.galaxy
64
+ return @@galaxy
65
+ end
66
+
67
+ def self.board
68
+ return @@galaxy_board
69
+ end
70
+
71
+ def self.set_current_planet(planet)
72
+ @@planet = planet
73
+ @@galaxy[planet].visited = true
74
+ @@galaxy[planet].update_exchange_rates()
75
+ end
76
+
77
+ def self.get_current_planet()
78
+ return @@planet
79
+ end
80
+
81
+ def self.cash_value(quantity, resource)
82
+ return quantity * Currency[resource]
83
+ end
84
+
85
+ @@commodities = %w[ machinery liquor narcotics livestock computers food
86
+ weapons lazers medicine boosters ]
87
+ @@illegal_commodities = %w[ liquor narcotics weapons ]
88
+
89
+ def initialize(name)
90
+ my_commodities = Hash.new(0);
91
+ @exchange_rates = Hash.new(0);
92
+ @name = name
93
+ @@commodities.each do |resource|
94
+ unless (1.d(10).sum % 3 == 0)
95
+ my_commodities[resource] = Dice.new(500).sum
96
+ @exchange_rates[resource] = Dice.new(5,100).sum
97
+ end
98
+ end
99
+
100
+ @exchange_rates["boosters"] = 1000
101
+
102
+ @currency_hold = Currency.new(my_commodities)
103
+
104
+ @visited = false
105
+ end
106
+
107
+ attr_reader :name
108
+ attr_accessor :visited
109
+
110
+ def update_exchange_rates()
111
+ @exchange_rates.each do |resource,rate|
112
+ Currency[resource] = rate
113
+ end
114
+ end
115
+
116
+ def export(quantity, resource)
117
+ @currency_hold.withdraw(quantity, resource)
118
+ end
119
+
120
+ def import(quantity, resource)
121
+ @currency_hold.deposit(quantity, resource)
122
+ end
123
+
124
+ def available?(quantity, resource)
125
+ @currency_hold[resource] >= quantity ? true : false
126
+ end
127
+ end
@@ -0,0 +1,262 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ # spacetrader.rb
4
+ #
5
+ # Created by Gregory Brown on 2005-05-30
6
+ # Copyright 2005 smtose.org. All rights reserved.
7
+
8
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "..", "lib"))
9
+ require "gambit/tools/dice"
10
+ require "gambit/tools/currency"
11
+ include Gambit::Tools
12
+
13
+ Currency[:cash] = 1
14
+ Currency[:lazer] = 0
15
+ player_holdings = Hash.new(0)
16
+ player_holdings[:cash] = 500
17
+ player_holdings[:lazers] = 2
18
+ @player = Currency.new(player_holdings);
19
+ @player_health = 100;
20
+ @world_holdings = Hash.new(0);
21
+ @world_exchange_rates = Hash.new(0);
22
+
23
+ @world_holdings[:mercury] = Currency.new( { :medicine => 50,
24
+ :alien_liquor => 0,
25
+ :machinery => 15 } )
26
+ @world_exchange_rates[:mercury] = { :medicine => Dice.new(5,10).sum,
27
+ :alien_liquor => Dice.new(5, 20).sum,
28
+ :machinery => Dice.new(10,10).sum }
29
+ @world_holdings[:venus] = Currency.new( { :medicine => 0,
30
+ :alien_liquor => 100,
31
+ :machinery => 30 } )
32
+ @world_exchange_rates[:venus] = { :medicine => Dice.new(20,5).sum,
33
+ :alien_liquor => Dice.new(5,10).sum,
34
+ :machinery => Dice.new(8,15).sum }
35
+ @world_holdings[:mars] = Currency.new({:lazers => 20})
36
+ @world_exchange_rates[:mars] = {:lazers => 500}
37
+
38
+ Currency.register_view(:player, <<END_PLAYER)
39
+ % resources = @holdings.keys
40
+ % resources = resources.sort_by { |res| res.to_s }
41
+ % res_width = resources.max { |a, b| a.to_s.length <=>
42
+ % b.to_s.length }.to_s.length
43
+ % amt_width = @holdings.values.max { |a, b| a.to_s.length <=>
44
+ % b.to_s.length }.to_s.length
45
+ % resources.each do |resource|
46
+ <%= "%\#{res_width}s" % resource.to_s.capitalize %> [<%=
47
+ "%\#{amt_width}d" % @holdings[resource] %>]
48
+ % end
49
+ END_PLAYER
50
+ Currency.register_view(:world, <<END_WORLD)
51
+ % resources = @holdings.keys
52
+ % resources = resources.sort_by { |res| res.to_s }
53
+ % res_width = resources.max { |a, b| a.to_s.length <=>
54
+ % b.to_s.length }.to_s.length
55
+ % val_width = resources.map { |r| self.class[r] }.
56
+ % max { |a, b| a.to_s.length <=> b.to_s.length }.
57
+ % to_s.length
58
+ % amt_width = @holdings.values.max { |a, b| a.to_s.length <=>
59
+ % b.to_s.length }.to_s.length
60
+ % resources.each do |resource|
61
+ <%= "%\#{res_width}s" % resource.to_s.capitalize %>: $<%=
62
+ "%\#{val_width}.2f" % self.class[resource] %> [<%=
63
+ "%\#{amt_width}d" % @holdings[resource] %>]
64
+ % end
65
+ END_WORLD
66
+
67
+ def random_events( )
68
+ value = Dice.new(1,6).sum
69
+
70
+ combat() if value == 2 or value == 4
71
+ police() if value == 3
72
+ end
73
+
74
+ def go_to_world( world )
75
+ @world_exchange_rates[world].each do |key,value|
76
+ Currency[key] = value
77
+ end
78
+ end
79
+
80
+ def show_world_commodities( world )
81
+ puts
82
+ puts "#{world.to_s.capitalize} has: "
83
+ puts @world_holdings[world].view(:world)
84
+ end
85
+
86
+ def show_player_commodities( )
87
+ puts "You have: "
88
+ puts @player.view(:player)
89
+ end
90
+
91
+ def select_world( current_world )
92
+ puts "Please select a destination: "
93
+ worlds = @world_holdings.keys.map { |s| s.to_s }
94
+ worlds.each { |world| puts "- #{world}" if world != current_world }
95
+ print "\n> "
96
+
97
+ choice = gets.chomp
98
+ choice = worlds.find { |world| world =~ /^#{choice}/ }
99
+
100
+ if choice.nil?
101
+ puts "Stick to this galaxy, Buck Rogers!"
102
+ select_world(current_world)
103
+ else
104
+ go_to_world(choice.to_sym)
105
+ return choice.to_sym
106
+ end
107
+ end
108
+
109
+ def make_purchase( current_world )
110
+ print "\n(quantity item): "
111
+ quantity, item = gets.chomp.split(/ /)
112
+ available = @world_holdings[current_world].holdings.keys.map { |s| s.to_s }
113
+ item = available.find { |name| name =~ /^#{item}/ }
114
+
115
+ if item.nil?
116
+ puts "Unknown item."
117
+ return
118
+ end
119
+
120
+ if ( @player[:cash] *
121
+ Currency.relative_value(:cash,item.to_sym) >= quantity.to_i )
122
+ @player.withdraw(
123
+ @world_holdings[current_world].withdraw( quantity.to_i,item.to_sym,
124
+ :cash ),
125
+ :cash )
126
+ @player.deposit(quantity.to_i,item.to_sym)
127
+ else
128
+ puts "Insufficient funds."
129
+ end
130
+ end
131
+
132
+ def make_sale( current_world )
133
+ print "\n(quantity item): "
134
+ quantity, item = gets.chomp.split(/ /)
135
+ available = @world_holdings[current_world].holdings.keys.map { |s| s.to_s }
136
+ item = available.find { |name| name =~ /^#{item}/ }
137
+
138
+ if item.nil?
139
+ puts "Unknown item."
140
+ return
141
+ end
142
+
143
+ if @player[item.to_sym] >= quantity.to_i
144
+ @world_holdings[current_world].deposit(quantity.to_i, item.to_sym)
145
+ @player.deposit( @player.withdraw(quantity.to_i,item.to_sym, :cash),
146
+ :cash )
147
+ else
148
+ puts "You don't have that much, bonehead!"
149
+ end
150
+ end
151
+
152
+ def combat( )
153
+ pirate_health = Dice.new(1,100).sum
154
+ puts "You have been attacked by pirates!"
155
+ puts "your health: #{@player_health} pirate health #{pirate_health}"
156
+ pirate_lazers = Dice.new(1,3).sum
157
+ while pirate_health > 0 && @player_health > 0
158
+ print "(a)ttack (f)lee: "
159
+ case gets.chomp.downcase
160
+ when /^a/
161
+ pirate_health -= Dice.new(@player[:lazers],6).sum
162
+ when /^f/
163
+ if Dice.new(1,6).sum % 2 == 0
164
+ @player.withdraw(@player[:cash]/2,:cash)
165
+ puts "You got away but lost half your cash in the process"
166
+ return
167
+ end
168
+ else
169
+ puts "Schwa?"
170
+ end
171
+ @player_health -= Dice.new(pirate_lazers,5).sum if pirate_health > 0
172
+ if @player_health > 0 && pirate_health > 0
173
+ puts "your health: #{@player_health} " +
174
+ "pirate health #{pirate_health}"
175
+ elsif @player_health <= 0
176
+ puts "The pirates gunned the crap out of you!"
177
+ else
178
+ puts "You destroyed the pirate fools!"
179
+ end
180
+ end
181
+ end
182
+
183
+ def police( )
184
+ puts "You have been stopped by the police!"
185
+ puts "You may let them (i)nspect, try to (f)lee, " +
186
+ "or (b)ribe them for 500 cash"
187
+ print "\n> "
188
+ case gets.chomp.downcase
189
+ when /^i/
190
+ if @player[:alien_liquor] > 0
191
+ @player_health = 0
192
+ puts "You've been busted for transporting illegal substances!"
193
+ return
194
+ else
195
+ puts "The police inspect and find nothing unusual"
196
+ end
197
+ when /^f/
198
+ if Dice.new(1,10).sum % 3 == 0
199
+ puts "Good job, you stuck it to the man and got away!"
200
+ return
201
+ else
202
+ puts "You should never run from the police! BUSTED!"
203
+ @player_health = 0
204
+ return
205
+ end
206
+ when /^b/
207
+ if Dice.new(1,10).sum % 9 == 0
208
+ puts "You've come across the one in ten cops " +
209
+ "who can't be bribed. Bummer"
210
+ @player_health = 0
211
+ return
212
+ elsif @player[:cash] < 500
213
+ puts "You don't have enough to bribe the cops. BUSTED!"
214
+ @player_health = 0
215
+ return
216
+ else
217
+ puts "The cop looks the other way once the cash " +
218
+ "is in his hands."
219
+ @player.withdraw(500,:cash)
220
+ return
221
+ end
222
+ else
223
+ puts "Shiggity Schwa?"
224
+ end
225
+ end
226
+
227
+ alive = true
228
+ my_world = select_world(my_world)
229
+ show_world_commodities(my_world)
230
+ show_player_commodities()
231
+ while alive
232
+ puts "\n Welcome to #{my_world}!\n (h)eal (b)uy (s)ell (m)ove (q)uit " +
233
+ "[Health: #{@player_health}]"
234
+ print "\n> "
235
+ case gets.chomp.downcase
236
+ when /^h/
237
+ if @player[:medicine] > 0
238
+ @player.withdraw(1,:medicine)
239
+ @player_health + 20 < 100 ? @player_health += 20 :
240
+ @player_health = 100
241
+ else
242
+ puts "No medicine to use!"
243
+ end
244
+ when /^b/
245
+ make_purchase(my_world)
246
+ when /^s/
247
+ make_sale(my_world)
248
+ when /^m/
249
+ random_events()
250
+ my_world = select_world(my_world) if (@player_health > 0)
251
+ when /^q/
252
+ exit
253
+ else
254
+ puts "WTF MAN!"
255
+ end
256
+ if @player_health <= 0
257
+ alive = false
258
+ else
259
+ show_world_commodities(my_world)
260
+ show_player_commodities()
261
+ end
262
+ end