Permalink
Browse files

added help menu. fixed playing being too broke to purchase.

  • Loading branch information...
jwoertink committed Jun 3, 2012
1 parent e27f13e commit 2c8e5922250e619f5fbde1cf9772b01b31ba74b4
Showing with 68 additions and 41 deletions.
  1. +4 −7 README.rdoc
  2. +2 −1 lib/agent.rb
  3. +1 −0 lib/application.rb
  4. +44 −33 lib/game.rb
  5. +13 −0 lib/player.rb
  6. +4 −0 text.yml
View
@@ -24,7 +24,7 @@ For windows
You will be walked through during gameplay. Type "S" to start, or "Q" to quit.
Options are normally numbers 1 through 5 or so.
-
+You can type ? for help during the game.
== Installing
@@ -42,9 +42,8 @@ Options are normally numbers 1 through 5 or so.
* All drugs are always available
* Battles with DEA agents are skewed and you're most likely to lose :(
* No way to exit game mid way
-* Drugs stay in your bag after you've sold them all
-* Standardize color scheme
-
+* Fill in help menu
+* Allow help to be accessed any time
== Upgrades
@@ -53,6 +52,4 @@ Options are normally numbers 1 through 5 or so.
* Limit the amount of drugs that can be carried per bag size
* Allow purchasing of weapons, and bags (maybe other items)
* Fluctuating interest rates depending on which city you start in
-* Fight more than 1 agent at a time
-* Large bonus for killing an agent
-* Implement time restraints
+* Fight more than 1 agent at a time
View
@@ -1,6 +1,6 @@
class Agent
- attr_accessor :speed, :accuracy, :evasion, :endurance
+ attr_accessor :speed, :accuracy, :evasion, :endurance, :level
class << self
@@ -13,6 +13,7 @@ def near_by?
# The higher the speed, the better chance the agent has of catching you if you try to run
# The higher the accuracy, the better chance the agent has of shooting you if you try to fight
def initialize
+ @level = 1
@speed = ((rand(100) / 2) + Math::PI).ceil
@endurance = ((rand(100) / 2) + Math::PI).ceil
@evasion = ((rand(100) / 2) + Math::PI).ceil
View
@@ -15,6 +15,7 @@ module Application
# This just kicks off the application.
def self.run!
echo(echo_ascii("Dopewars"), :purple, 0)
+ echo("v#{Utilities::VERSION}", :purple, 0)
key = ask("[S]tart a new game or [Q]uit?")
if key.downcase.eql?('s')
View
@@ -48,65 +48,69 @@ def select_menu(menu_option)
if level > 70
battle_agent_menu
else
- case menu_option.to_i
- when 1
+ case menu_option
+ when '1'
buyers_menu
- when 2
+ when '2'
sellers_menu
- when 3
+ when '3'
airport_menu
- when 4
+ when '4'
bank_menu
- when 5
+ when '5'
check_stats_menu
+ when '?'
+ help_menu
else
echo(game_text(:bad_selection), :red, 0)
echo(game_text(:main_menu), :blue, 0)
- menu_option = ask("Select your option: ", Integer) { |q| q.in = 1..5 }
+ menu_option = ask("Select your option: ") { |q| q.in = ('1'..'5').to_a }
select_menu(menu_option)
end
end
end
def buyers_menu
- echo(game_text(:buyers_menu), :blue, 0)
- available_options = []
- drugs = []
- @current_location.drugs.each_with_index do |drug, select_number|
- drugs << drug
- max_amount = @player.wallet / drug.price
- echo("#{select_number + 1}. #{drug.name} @ $#{drug.price} {#{max_amount}}", :cyan, 0)
- available_options << (select_number + 1)
- end
- loop do
- menu_option = ask("Select your option: ", Integer) { |q| q.in = available_options.map(&:to_i) }
- drug = drugs[menu_option - 1]
- amount = ask("How Many? ", Integer) { |q| q.above = 0 }
- decrease = (drug.price * amount.to_i)
- if @player.can_buy_drug?(drug.price, amount.to_i)
- @player.add_to_drugs({drug.name => amount.to_i})
- @player.wallet -= decrease
- echo("You have $#{@player.wallet} left.", :cyan)
- @current_location.transactions += 1
- break
- else
- echo("You can't buy that many.", :red)
+ if @player.can_afford_drugs?(@current_location.drugs)
+ echo(game_text(:buyers_menu), :blue, 0)
+ available_options = []
+ drugs = []
+ @current_location.drugs.each_with_index do |drug, select_number|
+ drugs << drug
+ max_amount = @player.wallet / drug.price
+ echo("#{select_number + 1}. #{drug.name} @ $#{drug.price} {#{max_amount}}", :cyan, 0)
+ available_options << (select_number + 1)
end
+ loop do
+ menu_option = ask("Select your option: ", Integer) { |q| q.in = available_options.map(&:to_i) }
+ drug = drugs[menu_option - 1]
+ amount = ask("How Many? ", Integer) { |q| q.above = 0 }
+ decrease = (drug.price * amount.to_i)
+ if @player.can_buy_drug?(drug.price, amount.to_i)
+ @player.add_to_drugs({drug.name => amount.to_i})
+ @player.wallet -= decrease
+ echo("You have $#{@player.wallet} left.", :cyan)
+ @current_location.transactions += 1
+ break
+ else
+ echo("You can't buy that many.", :red)
+ end
+ end
+ else
+ echo("You're too broke to purchase. Go to the bank.", :red)
end
end
def sellers_menu
- if @player.drugs.empty?
- echo("You must purchase drugs first", :red, 0)
- else
+ if @player.has_drugs?
echo(game_text(:sellers_menu), :blue, 0)
i = 0
drugs = []
@player.drugs.each_pair do |drug, amount|
dime_bag = Drug.new({name: drug, price: @current_location.market_price_for_drug, quantity: amount})
echo("#{i + 1}. #{dime_bag.name} x #{dime_bag.quantity} @ $#{dime_bag.price}ea", :cyan, 0)
drugs << dime_bag
- i +=1
+ i += 1
end
loop do
menu_option = ask("Select your option: ", Integer) { |q| q.in = 0..i }
@@ -123,6 +127,8 @@ def sellers_menu
echo("You can't sell more then #{drug.quantity} of #{drug.name}.", :red, 0)
end
end
+ else
+ echo("You must purchase drugs first", :red, 0)
end
end
@@ -239,6 +245,11 @@ def battle_agent_menu
end
end
+ def help_menu
+ echo(echo_ascii(game_text(:help_menu_title)), :purple, 0)
+ echo(game_text(:help_menu), :blue)
+ end
+
#Main game loop
def start!
echo(game_text(:welcome, {:name => @player.name, :amount => @player.wallet, :drug => @player.drugs.keys.first}), :green)
View
@@ -54,6 +54,19 @@ def can_sell_drug?(drug)
drug.can_be_sold?
end
+ def has_drugs?
+ !@drugs.empty?
+ end
+
+ # See if the player has enough money to buy drugs from a particular city
+ def can_afford_drugs?(drugs_from_city)
+ num_of_purchasable_drugs = 0
+ drugs_from_city.each do |drug|
+ num_of_purchasable_drugs += 1 unless (@wallet / drug.price).zero?
+ end
+ num_of_purchasable_drugs > 0
+ end
+
def add_to_drugs(drugs_to_add)
drugs_to_add.each_pair do |drug, amount|
drug = drug.to_sym
View
@@ -11,6 +11,10 @@ game:
4. Go to the bank.\n
5. Check stats."
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"
check_stats_menu:

0 comments on commit 2c8e592

Please sign in to comment.