Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added the bag item. restructured weapons

  • Loading branch information...
commit 100be501531b1930b7a37543fc8c8b7dbe220c8f 1 parent 6274237
@jwoertink authored
View
4 README.rdoc
@@ -44,8 +44,8 @@ You can type ? for help during the game.
* Fill in help menu
* Allow help to be accessed any time
* During battle, HP is not displayed properly
-* Currently no way to purchase new weapons
-* The bag isn't in place to limit the number of drugs you can carry
+* The bag isn't fully in place
+* Item purchases aren't restricted
* The end of game calculation isn't complete
== Upgrades
View
9 bags.yml
@@ -0,0 +1,9 @@
+- size: "Small"
+ quantity: 20
+ cost: 0
+- size: "Medium"
+ quantity: 50
+ cost: 1000
+- size: "Large"
+ quantity: 100
+ cost: 5000
View
3  lib/application.rb
@@ -7,6 +7,7 @@
require 'weapon'
require 'fighter'
require 'player'
+require 'bag'
require 'bank'
require 'agent'
require 'battle'
@@ -17,7 +18,7 @@ module Application
# This just kicks off the application.
def self.run!
- echo(echo_ascii("Dopewars"), :purple, 0)
+ echo(ascii("Dopewars"), :purple, 0)
echo("v#{Utilities::VERSION}", :purple, 0)
key = ask("[S]tart a new game or [Q]uit?")
View
40 lib/bag.rb
@@ -0,0 +1,40 @@
+require 'yaml'
+
+class Bag
+
+ attr_accessor :size, :quantity, :cost, :item_count
+
+ # Returns an array of hashes
+ def self.all
+ YAML::load(File.open(File.expand_path(File.join(File.dirname(__FILE__), '..', "bags.yml"))))
+ end
+
+ def self.find(key)
+ all.collect { |b| b if b["size"].eql?(key) }.compact.first
+ end
+
+ def initialize(options = {})
+ if options[:size]
+ bag = Bag.find(options[:size])
+ else
+ bag = Bag.all.first
+ end
+ bag.each do |k, v|
+ instance_variable_set("@#{k}", v)
+ end
+ @item_count = 0
+ end
+
+ def add(item_quantity)
+ @item_count += item_quantity
+ end
+
+ def remove(item_quantity)
+ @item_count -= item_quantity
+ end
+
+ def full?
+ @item_count >= @quantity
+ end
+
+end
View
2  lib/battle.rb
@@ -15,7 +15,7 @@ def agent
end
def start
- echo(echo_ascii(game_text(:battle_title)), :purple, 0)
+ echo(ascii(game_text(:battle_title)), :purple, 0)
loop do
choice = ask("Will you [F]ight or [R]un?")
case choice.downcase
View
57 lib/game.rb
@@ -62,6 +62,8 @@ def select_menu(menu_option)
check_stats_menu
when '6'
gym_menu
+ when '7'
+ store_menu
when '?'
help_menu
else
@@ -136,7 +138,7 @@ def sellers_menu
end
def airport_menu
- echo(echo_ascii(game_text(:airport_title)), :purple, 0)
+ echo(ascii(game_text(:airport_title)), :purple, 0)
city_options = ""
available_options = []
City::LOCATIONS.each_with_index do |city, select_number|
@@ -167,7 +169,7 @@ def airport_menu
end
def bank_menu
- echo(echo_ascii(game_text(:bank_title)), :purple, 0)
+ echo(ascii(game_text(:bank_title)), :purple, 0)
echo(game_text(:bank_menu), :blue, 0)
menu_option = ask("Select your option:")
loop do
@@ -218,7 +220,7 @@ def bank_menu
end
def check_stats_menu
- echo(echo_ascii(game_text(:stats_title)), :purple, 0)
+ echo(ascii(game_text(:stats_title)), :purple, 0)
str = " Current Location: #{@current_location.name}\n"
str << " Days remaining: #{days_remaining}\n"
echo(@player.stats << str, :cyan)
@@ -228,7 +230,7 @@ def gym_menu
if @player.visited_gym?(@current_location)
echo("You've already worked out today, come back tomorrow.", :red)
else
- echo(echo_ascii(game_text(:gym_title)), :purple, 0)
+ echo(ascii(game_text(:gym_title)), :purple, 0)
echo(game_text(:gym_menu), :blue)
menu_option = ask("Select your option:")
loop do
@@ -247,11 +249,56 @@ def gym_menu
echo("Goodbye.", :green)
break
else
+ help_menu
end
end
end
end
+ def store_menu
+ echo(ascii(game_text(:store_title)), :purple, 0)
+ echo(game_text(:store_main_menu), :blue)
+ menu_option = ask("Select your option:")
+ loop do
+ case menu_option
+ when '1'
+ i = 0
+ items = []
+ available_options = []
+ Weapon.all.each do |weapon|
+ items << weapon["type"]
+ echo("#{i + 1}. #{weapon["type"]} @ $#{weapon["cost"]}", :cyan, 0)
+ available_options << i
+ i += 1
+ end
+ Bag.all.each do |bag|
+ items << bag["size"]
+ echo("#{i + 1}. #{bag["size"]} bag @ $#{bag["cost"]}", :cyan, 0)
+ available_options << i
+ i += 1
+ end
+ loop do
+ menu_option = ask("Select your option: ", Integer) { |q| q.in = available_options.map(&:to_i) }
+ item = items[menu_option - 1]
+ if Weapon.find(item)
+ @player.weapon = Weapon.new(:type => item)
+ @player.wallet -= @player.weapon.cost
+ else
+ @player.bag = Bag.new(:size => item)
+ @player.wallet -= @player.bag.cost
+ end
+ break
+ end
+ break
+ when '2' #leave
+ echo("Goodbye.", :green)
+ break
+ else
+ help_menu
+ end
+ end
+ end
+
def battle_agent_menu
agent = Agent.new
echo("#{@player.name}, there is an agent chasing you!", :yellow)
@@ -260,7 +307,7 @@ def battle_agent_menu
end
def help_menu
- echo(echo_ascii(game_text(:help_menu_title)), :purple, 0)
+ echo(ascii(game_text(:help_menu_title)), :purple, 0)
echo(game_text(:help_menu), :blue)
end
View
3  lib/player.rb
@@ -1,6 +1,6 @@
class Player < Fighter
- attr_accessor :name, :drugs, :wallet, :days_remaining, :bank_account, :end_of_turn, :transactions
+ attr_accessor :name, :drugs, :wallet, :bag, :days_remaining, :bank_account, :end_of_turn, :transactions
def initialize(defaults = {})
@name = defaults[:name].capitalize
@@ -14,6 +14,7 @@ def initialize(defaults = {})
@endurance = ((rand(100) / 2) + Math::PI).ceil
@bank_account = Bank.new
@weapon = Weapon.new
+ @bag = Bag.new
@end_of_turn = false
@free = true
end
View
4 lib/utilities.rb
@@ -26,7 +26,7 @@ module Utilities
:blank => "\e[8m"
}
- def echo_ascii(message)
+ def ascii(message)
@ascii ||= Artii::Base.new
@ascii.asciify(message)
end
@@ -36,8 +36,6 @@ def color(text, kolor = :white)
end
def echo(message, colour = :white, wait_time = 1)
- #const = ::HighLine.const_get(colour.to_s.upcase)
- #say(%{<%= color("#{message}", "#{const}") %>})
puts color(message, colour)
sleep wait_time
end
View
26 lib/weapon.rb
@@ -1,16 +1,32 @@
+require 'yaml'
+
class Weapon
- TYPES = {"Fist" => 1, "Brass Knuckle" => 2, "Knife" => 3, "Gun" => 4}
- attr_accessor :type, :damage
+ attr_accessor :type, :damage, :cost, :level
# Fist deals 1 damage
# Brass Knuckle deals 2 damage
# Knife deals 3 damage
# Gun deals 4 damage
+ def self.find(key)
+ all.collect { |w| w if w["type"].eql?(key) }.compact.first
+ end
+
+ # Returns an array of hashes
+ def self.all
+ YAML::load(File.open(File.expand_path(File.join(File.dirname(__FILE__), '..', "weapons.yml"))))
+ end
+
def initialize(options = {})
- @type = options[:type] || "Fist"
- @damage = TYPES[@type]
+ if options[:type]
+ weapon = Weapon.find(options[:type])
+ else
+ weapon = Weapon.all.first
+ end
+ weapon.each do |k, v|
+ instance_variable_set("@#{k}", v)
+ end
end
-end
+end
View
15 text.yml
@@ -10,14 +10,15 @@ game:
3. Fly to a new city\n
4. Go to the bank.\n
5. Check stats.\n
- 6. Hit the gym."
+ 6. Hit the gym.\n
+ 7. Visit the Store."
bad_selection: "You must choose an available menu option"
help_menu_title:
"? HELP ?"
help_menu:
"Dopewars help\n? - Displays this menu\nWhen given options, they are usually numbers\n"
stats_title:
- "STATS"
+ "* STATS *"
check_stats_menu:
"**********************\n******* STATS ********\n**********************"
bank_title:
@@ -42,11 +43,19 @@ game:
buyers_menu:
"Which of these drugs would you like to buy?"
gym_title:
- "{ GYM }"
+ "i_ GYM _i"
gym_menu:
"Welcome Silver Gloves Gym\nChoose an option.\n
1. Work out\n
2. Leave"
+ store_title:
+ "$ STORE $"
+ store_main_menu:
+ "Welcome to the Bad Mofo's Store.\n
+ 1. Purchase item\n
+ 2. Leave"
+ store_items_menu:
+ ""
player_gained_level:
"Wow! That was an awesome workout. You're now level %{level}.\n%{new_stats}"
battle_title:
View
16 weapons.yml
@@ -0,0 +1,16 @@
+- type: "Fist"
+ damage: 1
+ cost: 0
+ level: 1
+- type: "Brass Knuckle"
+ damage: 2
+ cost: 1000
+ level: 3
+- type: "Knife"
+ damage: 3
+ cost: 5000
+ level: 6
+- type: "Gun"
+ damage: 4
+ cost: 10000
+ level: 12
Please sign in to comment.
Something went wrong with that request. Please try again.