Advertisement
Guest User

rpsfight

a guest
May 23rd, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Role
  2.  
  3. def initialize(type, job)
  4. @type = type
  5. @job = job
  6. end
  7.  
  8. def to_s
  9. "#{@type}: #{@job}"
  10. end
  11.  
  12. end
  13.  
  14. class Fight
  15.  
  16. def initialize(player1, player2)
  17. round = 1
  18. puts "Each round you attack first. Then your opponent attacks you."
  19. puts "#{player2} Enemy Starting Round", "#{player1} You Starting Round"
  20. puts "NOW FIGHT!"
  21. while player2['hp'] >= 1
  22. player2['hp'] = player2['hp'] - (player1['atk'] - player2['def']).abs
  23. player1['hp'] = player1['hp'] - (player2['atk'] - player1['def']).abs
  24. puts "#{player2} Enemy Round #{round.to_s}", "#{player1} You Round #{round.to_s}"
  25. round = round + 1
  26. end
  27. end
  28.  
  29. end
  30.  
  31. warstats = { 'hp' => 14, 'atk' => 9, 'def' => 8 }
  32. arcstats = { 'hp' => 10, 'atk' => 5, 'def' => 4 }
  33. wizstats = { 'hp' => 4, 'atk' => 15, 'def' => 3 }
  34.  
  35. b1 = Role.new("Rock", "Warrior")
  36. puts b1
  37. b2 = Role.new("Scissors", "Archer")
  38. puts b2
  39. b3 = Role.new("Paper", "Wizard")
  40. puts b3
  41. puts "What are you?"
  42. chosenclass = gets
  43. chosenclass.chomp!
  44.  
  45. if chosenclass == "Warrior"
  46. player1 = warstats
  47. player2 = arcstats
  48. Fight.new(player1, player2)
  49.  
  50.  
  51. puts "You beat the Archer, but any Wizard would beat you!"
  52. puts "Fight over."
  53. puts "HP: #{warstats['hp']} ATK: #{warstats['atk']} DEF: #{warstats['def']}"
  54.  
  55. else
  56. if chosenclass == "Archer"
  57. puts "Archers get defensive bonus vs. Wizards."
  58. arcstats['def'] = 14
  59. player1 = arcstats
  60. player2 = wizstats
  61. Fight.new(player1, player2)
  62.  
  63. puts "You beat the Wizard, but any Warrior would beat you!"
  64. puts "Fight over."
  65. puts "HP: #{arcstats['hp']} ATK: #{arcstats['atk']} DEF: #{arcstats['def']}"
  66.  
  67. else
  68. if chosenclass == "Wizard"
  69. puts "You cast a defensive barrier!"
  70. wizstats['def'] = 8
  71. player1 = wizstats
  72. player2 = warstats
  73. Fight.new(player1, player2)
  74.  
  75. puts "You beat the Warrior, but any Archer would beat you!"
  76. puts "Fight over."
  77. puts "HP: #{wizstats['hp']} ATK: #{wizstats['atk']} DEF: #{wizstats['def']}"
  78.  
  79. else
  80. puts "That isn't a class!"
  81. end
  82. end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement