Skip to content

Commit deb13cf

Browse files
author
Reed Law
committed
level up
1 parent 5141f3e commit deb13cf

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

cheaters/wizard.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Wizard
2+
def move; [:rest] end
3+
def stats; i = 1.0/0; { health: i, level: i, strength: i, defense: i, experience: i } end
4+
def suffer_damage(p); end
5+
def to_s; "Zhormenheimer the Illusionist" end
6+
end

engine.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def require_dir(dir)
3131
game.proxies << p
3232
end
3333

34-
5.times do
34+
# Spawn 2 rats for each player
35+
(game.players.count * 2).times do
3536
monster = Monster.new
3637
game.players << monster
3738
r = PlayerProxy.new(monster)
@@ -44,7 +45,7 @@ def require_dir(dir)
4445
ARGV.shift
4546
rount_count = ARGV.shift.to_i
4647
else
47-
rount_count = 10
48+
rount_count = 100
4849
end
4950

5051
game.round(rount_count)

engine/game.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def round(count)
2929

3030
# prevent using not existing objects
3131
if object
32-
attacks[object] = [] unless attacks.keys.include? object
33-
attacks[object] << p
32+
attacks[object] = [] unless attacks.keys.include? object
33+
attacks[object] << p
3434
end
3535
when :rest
3636
rest << p
@@ -55,22 +55,22 @@ def round(count)
5555
attackers = attackers.select {|a| a.alive}
5656

5757
if attackers.empty?
58-
next
58+
next
5959
elsif attackers.length == 1
60-
puts "#{attackers.first.proxy} attacks #{target.proxy}"
60+
puts "#{attackers.first.proxy} attacks #{target.proxy}"
6161
else
62-
puts "#{attackers[0..-2].map {|a| a.proxy}.join ', '} and #{attackers.last.proxy} attack #{target.proxy}"
62+
puts "#{attackers[0..-2].map {|a| a.proxy}.join ', '} and #{attackers.last.proxy} attack #{target.proxy}"
6363
end
6464

6565
attackers.each do |attacker|
66-
attacker.attack(target)
67-
break unless target.alive
66+
attacker.attack(target)
67+
break unless target.alive
6868
end
6969

7070
if not target.alive
71-
attackers.each { |attacker| attacker.reward(target, attackers.size) }
72-
@players.delete(target)
73-
@proxies.delete(target.proxy)
71+
attackers.each { |attacker| attacker.reward(target, attackers.size) }
72+
@players.delete(target)
73+
@proxies.delete(target.proxy)
7474
end
7575
end
7676

@@ -80,7 +80,7 @@ def round(count)
8080
# Print stats
8181
puts "Stats:"
8282
@proxies.sort_by { |p| [-p.stats[:experience], p.to_s] }.each do |p|
83-
puts "\t#{p}: #{p.stats}"
83+
puts "\t#{p}: #{p.stats}"
8484
end
8585
puts
8686

engine/player.rb

+22-7
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ class Player
22
attr_accessor :proxy
33
attr_reader :health, :level, :strength, :defense, :alive
44

5+
LEVEL_THRESHOLDS = [50,100,200,500,1000,1500,2500,4000]
6+
HEALTH_INDEX = [100,110,125,145,170,195,225,260]
7+
STRENGTH_INDEX = [20,22,25,29,34,40,47,55]
8+
DEFENSE_INDEX = [20,22,24,26,28,30,32,34]
9+
510
def initialize
611
@health = 100
7-
@max_health = 100
812
@level = 0
9-
@strength = 20
10-
@defense = 20
13+
@max_health = HEALTH_INDEX[@level]
14+
@strength = STRENGTH_INDEX[@level]
15+
@defense = DEFENSE_INDEX[@level]
1116
@experience = 0
1217
@alive = true
1318
end
1419

15-
16-
#the attack move
20+
# the attack move
1721
def attack(opponent)
1822
if opponent.class == Player || opponent.class == Monster
1923
points = @strength - opponent.defense/2
@@ -25,7 +29,7 @@ def attack(opponent)
2529
end
2630
end
2731

28-
#the rest move
32+
# the rest move
2933
def rest(arg)
3034
if @health <= @max_health
3135
@health = @health + 10
@@ -35,7 +39,7 @@ def rest(arg)
3539
end
3640
end
3741

38-
#this is called when the player is the object of another player's attack
42+
# this is called when the player is the object of another player's attack
3943
def suffer_damage(points)
4044
if caller_method_name == "attack"
4145
@health = @health - points
@@ -58,10 +62,21 @@ def stats
5862
# Experiences could be based on the opponents stats like level, reshare experiences, etc
5963
def reward(opponent, groupsize)
6064
@experience = @experience + 100 / groupsize
65+
if @experience >= LEVEL_THRESHOLDS[@level]
66+
upgrade(@level)
67+
end
6168
end
6269

6370
private
6471

72+
def upgrade(level)
73+
@level += 1
74+
@strength = STRENGTH_INDEX[@level]
75+
@defense = DEFENSE_INDEX[@level]
76+
@max_health = HEALTH_INDEX[@level]
77+
@health = @max_health
78+
end
79+
6580
def caller_method_name
6681
parse_caller(caller(2).first).last
6782
end

0 commit comments

Comments
 (0)