Permalink
Browse files

working on new battle system. added in new classes, and methods

  • Loading branch information...
1 parent 2c8e592 commit 741d0eea7d25386ccccf5d2462c4495de9761ef9 @jwoertink committed Jun 5, 2012
Showing with 302 additions and 102 deletions.
  1. +1 −25 lib/agent.rb
  2. +107 −0 lib/battle.rb
  3. +6 −1 lib/city.rb
  4. +44 −0 lib/fighter.rb
  5. +49 −36 lib/game.rb
  6. +68 −38 lib/player.rb
  7. +16 −0 lib/weapon.rb
  8. +11 −2 text.yml
View
@@ -1,6 +1,4 @@
-class Agent
-
- attr_accessor :speed, :accuracy, :evasion, :endurance, :level
+class Agent < Fighter
class << self
@@ -10,26 +8,4 @@ def near_by?
end
- # 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
- @accuracy = ((rand(100) / 2) + Math::PI).ceil
- end
-
- def running
- @speed + @endurance
- end
-
- def defending
- @evasion
- end
-
- def attacking
- @accuracy
- end
-
end
View
@@ -0,0 +1,107 @@
+# This class will simulate the battles between the player and agents
+class Battle
+ include Utilities
+
+ attr_accessor :player, :agents
+
+ def initialize(player, agents = [])
+ @player = player
+ @agents = agents
+ @agent = @agents.first # Implementing single 1 on 1 battle for now
+ end
+
+ def agent
+ @agent
+ end
+
+ def start
+ echo(echo_ascii(game_text(:battle_title)), :purple, 0)
+ loop do
+ choice = ask("Will you [F]ight or [R]un?")
+ case choice.downcase
+ when 'f'
+ fight_mode
+ break
+ when 'r'
+ run_away
+ break
+ else
+ echo("You must select F or R", :red, 0)
+ end
+ end
+ end
+
+ def fight_mode
+ if @player.has_drugs?
+ if agree("Do you want to take a drug boost?")
+ # Need a way to select a specific drug
+ boost = @player.drugs.sort_by { rand }.first
+ @boost_amount = 2 # this would allow each drug to react differently
+ @player.remove_from_drugs({boost[0] => 1})
+ echo("You take some #{boost[0]} which boosts your accuracy by #{@boost_amount}", :cyan, 0)
+ end
+ else
+ echo("You have no drugs to take, good luck!", :cyan, 0)
+ end
+
+ # Roll to see who attacks first
+ # if agent attacks first
+ # if player defends, agent misses
+ # if player doesn't defend, agent attacks
+ # player is hit for damage amount of agent's weapon
+ # if player attacks first
+ # agent tries to defend
+ # if agent doesn't defend, player attacks
+ # agent is hit for damage amount of player's weapon
+ #
+ loop do
+ if @player.attack_first?
+ break if attack(@player, agent, @boost_amount)
+ else
+ break if attack(agent, @player)
+ end
+ end
+
+ if agent.dead?
+ @bonus_amount = 10000
+ 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
+ end
+
+ def run_away
+ if @player.has_drugs?
+ if agree("Do you want to take a drug boost?")
+ boost = @player.drugs.sort_by { rand }.first
+ @boost_amount = 2
+ @player.remove_from_drugs({boost[0] => 1})
+ echo("You take some #{boost[0]} which boosts your speed by #{@boost_amount}", :cyan, 0)
+ end
+ else
+ echo("You have no drugs to take, good luck!", :cyan, 0)
+ end
+ result = @player.run_from(agent, @boost_amount)
+ if result
+ echo("You escaped this time, but be on the look out", :green)
+ else
+ echo("You have been captured.", :red)
+ end
+ end
+
+ def attack(opponent1, opponent2, modifiers = nil)
+ damage_amount = opponent1.fight(opponent2, modifiers)
+ if opponent1.is_a?(Player)
+ echo("\nYou hit the agent for #{damage_amount} points.\n")
+ else
+ echo("\nThe agent hits you for #{damage_amount} points.\n")
+ end
+ if opponent2.alive?
+ attack(opponent2, opponent1)
+ else
+ return true
+ end
+ end
+
+end
View
@@ -1,20 +1,25 @@
class City
include Utilities
- attr_accessor :name, :drugs, :transactions
+ attr_accessor :name, :drugs, :transactions, :gym_closed
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
+ @gym_closed = false
end
def gather_drugs
@drugs = []
@drugs += Drug::TYPES.collect { |d| Drug.new({name: d, price: market_price_for_drug, quantity: 0}) }
end
+ def gym_closed?
+ @gym_closed
+ end
+
# currently returns a random number
def market_price_for_drug
rand(500) + 10
View
@@ -0,0 +1,44 @@
+class Fighter
+
+ attr_accessor :speed, :accuracy, :evasion, :endurance, :level, :hp, :weapon
+
+ def initialize
+ @level = 1
+ @speed = ((rand(95) / 2) + Math::PI).floor
+ @endurance = ((rand(95) / 2) + Math::PI).floor
+ @evasion = ((rand(90) / 2) + Math::PI).floor
+ @accuracy = ((rand(90) / 2) + Math::PI).floor
+ @hp = 2
+ @weapon = Weapon.new
+ end
+
+ def running
+ @speed + @endurance
+ end
+
+ def attacking
+ @accuracy
+ end
+
+ def defending
+ @evasion
+ end
+
+ def max_hit_points
+ @level * 2
+ end
+ alias :max_hp :max_hit_points
+
+ def attack_first?
+ rand(10) % 2 == 0
+ end
+
+ def attacks(opponent)
+ 0
+ end
+
+ def dead?
+ @hp <= 0
+ end
+
+end
View
@@ -59,12 +59,14 @@ def select_menu(menu_option)
bank_menu
when '5'
check_stats_menu
+ when '6'
+ gym_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: ") { |q| q.in = ('1'..'5').to_a }
+ menu_option = ask("Select your option: ") { |q| q.in = ('1'..'6').to_a }
select_menu(menu_option)
end
end
@@ -141,18 +143,25 @@ def airport_menu
available_options << (select_number + 1)
city_options += "#{select_number + 1}. #{city}\n"
end
+ available_options << (City::LOCATIONS.length + 1)
+ city_options += "#{City::LOCATIONS.length + 1}. Leave\n"
echo(game_text(:airport_menu, {current_city: @current_location.name ,city_options: city_options}), :blue, 0)
loop do
menu_option = ask("Select your option: ", Integer) { |q| q.in = available_options.map(&:to_i) }
- @current_location = City.new(name: City::LOCATIONS[menu_option.to_i - 1])
- echo("You fly to #{@current_location.name}", :cyan)
- break
- end
-
- if @player.encounter_agent?
- battle_agent_menu
- else
- @player.end_turn!
+ case menu_option
+ when City::LOCATIONS.length + 1
+ echo("Goodbye.", :green)
+ break
+ else
+ @current_location = City.new(name: City::LOCATIONS[menu_option.to_i - 1])
+ echo("You fly to #{@current_location.name}", :cyan)
+ if @player.encounter_agent?
+ battle_agent_menu
+ else
+ @player.end_turn!
+ end
+ break
+ end
end
end
@@ -199,7 +208,7 @@ def bank_menu
break
end
when "5" #leave
- echo("Goodbye.", :blue)
+ echo("Goodbye.", :green)
break
else
menu_option = ask("Please select an available option:")
@@ -214,37 +223,41 @@ 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)
+ 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(game_text(:gym_menu), :blue)
+ menu_option = ask("Select your option:")
+ loop do
+ case menu_option
+ when '1'
+ current_level = @player.level
+ @player.workout!
+ if @player.level > current_level
+ echo(game_text(:player_gained_level, {:level => @player.level, :new_stats => @player.stats(false)}), :green, 0)
+ else
+ echo("You had a good workout, but still need improvement", :cyan)
+ end
+ @current_location.gym_closed = true
+ break
+ when '2' #leave
+ echo("Goodbye.", :green)
+ break
else
- echo("You have been captured.", :red)
end
- break
- else
- echo("You must select F or R", :red, 0)
end
end
end
+ def battle_agent_menu
+ agent = Agent.new
+ echo("#{@player.name}, there is an agent chasing you!", :yellow)
+ current_battle = Battle.new(@player, [agent])
+ current_battle.start
+ end
+
def help_menu
echo(echo_ascii(game_text(:help_menu_title)), :purple, 0)
echo(game_text(:help_menu), :blue)
Oops, something went wrong.

0 comments on commit 741d0ee

Please sign in to comment.