Permalink
Browse files

added in transactional based timing in cities. fixed player drug problem

  • Loading branch information...
1 parent 96ad9f8 commit e27f13e1241e2a7be43dc06a03224782de3e3aaa @jwoertink committed Jun 2, 2012
Showing with 106 additions and 45 deletions.
  1. +4 −1 lib/city.rb
  2. +86 −18 lib/game.rb
  3. +5 −23 lib/player.rb
  4. +1 −1 lib/utilities.rb
  5. +10 −2 text.yml
View
@@ -1,11 +1,13 @@
class City
- attr_accessor :name, :drugs
+ include Utilities
+ attr_accessor :name, :drugs, :transactions
LOCATIONS = ["Las Vegas", "New York", "Miami", "Amsterdam", "Frankfurt", "El-Jazier"]
def initialize(options = {})
@name = options[:name] ||= LOCATIONS.sort_by { rand }.first
gather_drugs
+ @transactions = 0
end
def gather_drugs
@@ -18,4 +20,5 @@ def market_price_for_drug
rand(500) + 10
end
+
end
View
@@ -17,24 +17,54 @@ def days_remaining
@days - @current_day
end
- #Maybe this should be moved?
- def select_menu(menu_option)
- case menu_option.to_i
- when 1
- buyers_menu
- when 2
- sellers_menu
+ def awareness_level_warning
+ level = case @current_location.transactions
when 3
- airport_menu
+ echo(game_text(:awareness_notice, {:city => @current_location.name}), :yellow, 0)
+ 0 # no chance of getting caught
when 4
- bank_menu
+ echo(game_text(:high_awareness_notice), :yellow, 0)
+ (rand(100) + 30) # 40% chance of being safe
when 5
- check_stats_menu
+ echo(game_text(:high_awareness_notice), :yellow, 0)
+ (rand(100) + 40) # 30% chance of being safe
+ when 6
+ echo(game_text(:high_awareness_notice), :yellow, 0)
+ (rand(100) + 50) # 20% chance of being safe
+ when 7
+ echo(game_text(:high_awareness_notice), :yellow, 0)
+ (rand(100) + 60) # 10% chance of being safe
+ else
+ 0
+ end
+
+ return level
+ end
+
+ #Maybe this should be moved?
+ def select_menu(menu_option)
+ level = awareness_level_warning
+
+ if level > 70
+ battle_agent_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 }
- select_menu(menu_option)
+ case menu_option.to_i
+ when 1
+ buyers_menu
+ when 2
+ sellers_menu
+ when 3
+ airport_menu
+ when 4
+ bank_menu
+ when 5
+ check_stats_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 }
+ select_menu(menu_option)
+ end
end
end
@@ -50,13 +80,14 @@ def buyers_menu
end
loop do
menu_option = ask("Select your option: ", Integer) { |q| q.in = available_options.map(&:to_i) }
- drug = drugs[menu_option.to_i - 1]
+ 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)
@@ -86,6 +117,7 @@ def sellers_menu
increase = drugs[menu_option.to_i - 1].price * amount.to_i
@player.wallet += increase
echo("You made $#{increase}", :cyan)
+ @current_location.transactions += 1
break
else
echo("You can't sell more then #{drug.quantity} of #{drug.name}.", :red, 0)
@@ -95,6 +127,7 @@ def sellers_menu
end
def airport_menu
+ echo(echo_ascii(game_text(:airport_title)), :purple, 0)
city_options = ""
available_options = []
City::LOCATIONS.each_with_index do |city, select_number|
@@ -110,7 +143,11 @@ def airport_menu
break
end
- @player.end_turn!
+ if @player.encounter_agent?
+ battle_agent_menu
+ else
+ @player.end_turn!
+ end
end
def bank_menu
@@ -171,18 +208,49 @@ def check_stats_menu
echo(@player.stats << str, :cyan)
end
+ def battle_agent_menu
+ agent = Agent.new
+ echo("#{@player.name}, there is an agent chasing you!", :yellow)
+ loop do
+ choice = ask("Will you [F]ight or [R]un?")
+ case choice.downcase
+ when 'f'
+ result = @player.fight(agent)
+ if result
+ @bonus_amount = 100000
+ echo(game_text(:killed_agent, {:name => @player.name, :bonus_amount => @bonus_amount}), :green)
+ @player.wallet += @bonus_amount
+ else
+ echo("You have been captured.", :red)
+
+ end
+ break
+ when 'r'
+ result = @player.run_from(agent)
+ if result
+ echo("You escaped this time, but be on the look out", :green)
+ else
+ echo("You have been captured.", :red)
+ end
+ break
+ else
+ echo("You must select F or R", :red, 0)
+ end
+ end
+ end
+
#Main game loop
def start!
echo(game_text(:welcome, {:name => @player.name, :amount => @player.wallet, :drug => @player.drugs.keys.first}), :green)
echo(game_text(:dealer_introduction), :green)
- echo("You have #{days_remaining} Days Remaining", :yellow, 1)
+ echo("You have #{days_remaining} Days Remaining", :yellow)
while days_remaining > 0
@player.start_turn!
loop do
echo(game_text(:main_menu), :blue, 0)
menu_option = ask("Select your option:")
select_menu(menu_option)
- break if @player.end_of_turn?
+ break if @player.end_of_turn? or @player.captured?
end
break if game_over? or @player.captured?
@current_day += 1
View
@@ -1,7 +1,7 @@
class Player
include Utilities
- attr_accessor :name, :drugs, :wallet, :days_remaining, :bank_account, :end_of_turn, :speed, :accuracy, :evasion, :endurance
+ attr_accessor :name, :drugs, :wallet, :days_remaining, :bank_account, :end_of_turn, :speed, :accuracy, :evasion, :endurance, :transactions
def initialize(defaults = {})
@name = defaults[:name].capitalize
@@ -56,8 +56,9 @@ def can_sell_drug?(drug)
def add_to_drugs(drugs_to_add)
drugs_to_add.each_pair do |drug, amount|
+ drug = drug.to_sym
if @drugs.has_key?(drug)
- @drugs[drug] += drugs_to_add[drug]
+ @drugs[drug] += amount
else
@drugs.update({drug => amount})
end
@@ -81,12 +82,11 @@ def fight(agent)
result = defending > agent.attacking
else
result = attacking > agent.defending
- # need to add bonus for killing an agent
end
@free = result
end
- def run(agent)
+ def run_from(agent)
if running > agent.running
# You run faster than the agent
result = true
@@ -102,7 +102,6 @@ def start_turn!
def end_turn!
bank_account.add_daily_interest
- battle_agent if encounter_agent?
@end_of_turn = true
end
@@ -114,25 +113,8 @@ def encounter_agent?
Agent.near_by?
end
- # This belongs in the game
def battle_agent
- agent = Agent.new
- echo("#{name}, there is an agent chasing you!", :green)
- choice = ask("Will you [F]ight or [R]un?")
- case choice.downcase
- when 'f'
- result = fight(agent)
- when 'r'
- result = run(agent)
- else
- echo("You must select F or R", :red)
- battle_agent
- end
- if result
- echo("You escaped this time, but be on the look out", :green)
- else
- echo("You have been captured.", :red)
- end
+
end
end
View
@@ -35,7 +35,7 @@ def color(text, kolor = :white)
"#{TEXT[kolor]}#{text}#{TEXT[:reset]}"
end
- def echo(message, colour = :white, wait_time = 2)
+ def echo(message, colour = :white, wait_time = 1)
#const = ::HighLine.const_get(colour.to_s.upcase)
#say(%{<%= color("#{message}", "#{const}") %>})
puts color(message, colour)
View
@@ -25,7 +25,7 @@ game:
4. Take money from savings.\n
5. Leave"
airport_title:
- "AIRPORT"
+ "> AIRPORT <"
airport_menu:
"You are currently in %{current_city}.\nWhich City would you like to fly to?\n%{city_options}"
sellers_title:
@@ -35,4 +35,12 @@ game:
buyers_title:
"BUY DRUGS"
buyers_menu:
- "Which of these drugs would you like to buy?"
+ "Which of these drugs would you like to buy?"
+ battle_title:
+ "Agent Battle"
+ killed_agent:
+ "Congrats, %{name}! You have killed a DEA agent. You have earned a bonus of $%{bonus_amount}. Be on the lookout, you're wanted internationally now.\n\n"
+ awareness_notice:
+ "People are starting to notice you. If you stay in %{city} for too long, agents may catch on.\n\n"
+ high_awareness_notice:
+ "You have been spotted by a few people. Agents have been alerted of your location.\n You should fly to a new city before you're caught!\n\n"

0 comments on commit e27f13e

Please sign in to comment.