Advertisement
Alyssa

Battle Test

Sep 13th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. function cse1()
  2. term.setCursorPos(1, 3)
  3. write("[Attack]  Defend")
  4. end
  5. function cse2()
  6. term.setCursorPos(1, 3)
  7. write("Attack  [Defend]")
  8. end
  9. c1t = 0
  10. c2t = 0
  11. c3t = 0
  12. c4t = 0
  13. c5t = 0
  14. c6t = 0
  15. c7t = 0
  16. c8t = 0
  17. c9t = 0
  18. c10t = 0
  19. c11t = 0
  20. c12t = 0
  21. c13t = 0
  22. exp = 1
  23. hp = 25
  24. dmg = 5
  25. while true do
  26. randenemy = math.random(1, 4)
  27. if randenemy == 4 then
  28. enemy = "skeleton"
  29. elseif randenemy == 3 then
  30. enemy = "enemy.name(nil)"
  31. elseif randenemy == 2 then
  32. enemy = "Ninja"
  33. else
  34. if xp <= 10 then
  35. enemy = "Knight"
  36. elseif xp > 10 and xp < 25 then
  37. enemy = "Lion"
  38. elseif xp > 24 and xp < 50 then
  39. enemy = "King"
  40. elseif xp > 49 then
  41. enemy = "Ultimate Boss"
  42. else
  43. print("Error: battle:21 xp value unexpected")
  44. end
  45. end
  46. function takeaction()
  47. tkactdone = 0
  48. while not tkactdone == 1 do
  49. selectaction = 1
  50. event, p1, p2 = os.pullEvent()
  51. if event == "key" then
  52. if p1 == 28 then
  53. action = selectaction
  54. tkactdone = 1
  55. end
  56. if p1 == 203 then
  57. if selectaction == 2 then
  58. selectaction = 1
  59. elseif selectaction == 1 then
  60. selectaction = 2
  61. end
  62. if p1 == 205 then
  63. if selectaction == 2 then
  64. selectaction = 1
  65. elseif selectaction == 1 then
  66. selectaction = 2
  67. end
  68. end
  69. if selectaction == 1 then
  70. cse1()
  71. elseif selectaction == 2 then
  72. cse2()
  73. else
  74. print("Error:battle:71 selected Action Unknown")
  75. end
  76. end
  77. end
  78. end
  79. if enemy == "skeleton" then
  80.  enemyhp = 50
  81.  enemyatt = 5
  82.  enemyxp = 1
  83. elseif enemy == "enemy.name(nil)" then
  84.  enemyhp = 80
  85.  enemyatt = 15
  86.  enemyxp = 5
  87. elseif enemy == "Ninja" then
  88.  enemyhp = 60
  89.  enemyatt = 15
  90.  enemyxp = 3
  91. elseif enemy == "Knight" then
  92.  enemyhp = 50
  93.  enemyatt = 7
  94.  enemyxp = 2
  95. elseif enemy == "Lion" then
  96.  enemyhp = 65
  97.  enemyatt = 10
  98.  enemyxp = 4
  99. elseif enemy == "King" then
  100.  enemyhp = 90
  101.  enemyatt = 20
  102.  enemyxp = 5
  103. elseif enemy == "Ultimate Boss" then
  104.  enemyhp = 125
  105.  enemyatt = 25
  106.  enemyxp = 10
  107. else
  108.  print("Error:battle:105 Enemy Name Does not exist")
  109.  os.reboot()
  110. end
  111.  
  112. while not enemyhp == 0 do
  113.  takeaction()
  114.  attack()
  115.  enemyturn()
  116.  if hp == 0 then
  117.   break
  118.  end
  119. end
  120. if enemyhp == 0 then
  121.  exp = exp + enemyxp
  122.  if xp == 5 then
  123.   if c13t == 0 then
  124.    maxhp = maxhp +5
  125.    dmg = dmg +3
  126.    c13t = 1
  127.   end
  128.  end
  129.  if xp >= 10 then
  130.   if c12t == 0 then
  131.    maxhp = maxhp +5
  132.    dmg = dmg +4
  133.    c12t = 1
  134.   end
  135.  end
  136.  if xp >= 15 then
  137.   if c11t == 0 then
  138.    maxhp = maxhp +5
  139.    dmg = dmg +5
  140.    c11t = 1
  141.   end
  142.  end
  143.  if xp >= 20 then
  144.   if c10t == 0 then
  145.    maxhp = maxhp +5
  146.    dmg = dmg +5
  147.    c10t = 1
  148.   end
  149.  end
  150.  if xp >= 30 then
  151.   if c9t == 0 then
  152.    maxhp = maxhp +15
  153.    dmg = dmg +13
  154.    c9t = 1
  155.   end
  156.  end
  157.  if xp >= 40 then
  158.   if c8t == 0 then
  159.    maxhp = maxhp +20
  160.    dmg = dmg +15
  161.    c8t = 1
  162.   end
  163.  end
  164.  if xp >= 50 then
  165.   if c7t == 0 then
  166.    maxhp = maxhp +20
  167.    dmg = dmg +15
  168.    c7t = 1
  169.   end
  170.  end
  171.  if xp >= 60 then
  172.   if c6t == 0 then
  173.    maxhp = maxhp +5
  174.    dmg = dmg +5
  175.    c6t = 1
  176.   end
  177.  end
  178.  if xp >= 70 then
  179.   if c5t == 0 then
  180.    maxhp = maxhp +5
  181.    dmg = dmg +5
  182.    c5t = 1
  183.   end
  184.  end
  185.  if xp >= 80 then
  186.   if c4t == 0 then
  187.    maxhp = maxhp +5
  188.    dmg = dmg +5
  189.    c4t = 1
  190.   end
  191.  end
  192.  if xp >= 90 then
  193.   if c3t == 0 then
  194.    maxhp = maxhp +5
  195.    dmg = dmg +5
  196.    c3t = 1
  197.   end
  198.  end
  199.  if xp >= 100 then
  200.   if c2t == 0 then
  201.    maxhp = maxhp +10
  202.    dmg = dmg +10
  203.    c2t = 1
  204.   end
  205.  end
  206.  if xp >= 150 then
  207.   if c1t == 0 then
  208.    maxhp = maxhp +75
  209.    dmg = dmg +30
  210.    c1t = 1
  211.   end
  212.  end
  213.  if xp >= 150 then
  214.   print("error:battle:210 XP unexpected value")
  215.   os.reboot()
  216.  end
  217.  end
  218. end
  219. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement