Advertisement
Guest User

war

a guest
Jul 7th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. local screenx, screeny = term.getSize()
  2. local cards = 15
  3. local tcards = 15
  4. local tArgs = {...}
  5. if #tArgs ~= 3 then
  6. print("Usage: "..shell.getRunningProgram().." <warcards> <warsoundside> <normalsoundside>. Please insure both sound sides are top, bottom, left, right, back, or front.")
  7. else
  8. local s1 = tArgs[3]
  9. local s2 = tArgs[2]
  10. local function genericSound()
  11. redstone.setOutput(s1, true)
  12. sleep(0.1)
  13. redstone.setOutput(s1, false)
  14. end
  15. local function warSound()
  16. redstone.setOutput(s2, true)
  17. sleep(0.1)
  18. redstone.setOutput(s2, false)
  19. end
  20. term.clear()
  21. term.setCursorPos(1, 1)
  22. local warcards = tArgs[1]
  23. while true do
  24. term.clear()
  25. term.setBackgroundColor(colors.black)
  26. if cards < 1 then
  27. term.setCursorPos(1,1)
  28. print("You lost War!")
  29. genericSound()
  30. break
  31. elseif tcards < 1 then
  32. term.setCursorPos(1,1)
  33. print("You beat War!")
  34. warSound()
  35. break
  36. end
  37. term.setCursorPos(35,1)
  38. print("Your cards: "..cards.."")
  39. term.setCursorPos(35,2)
  40. print("Their cards: "..tcards.."")
  41. term.setCursorPos(1,1)
  42. yourcard = math.random(1,11)
  43. theircard = math.random(1,11)
  44. print("3")
  45. sleep(1)
  46. print("2")
  47. sleep(1)
  48. print("1")
  49. sleep(1)
  50. print("Go!")
  51. if yourcard == 11 and theircard == 11 then
  52. print("You have Ace. They have Ace.")
  53. elseif yourcard ~= 11 and theircard ~= 11 then
  54. print("You have "..yourcard..". They have "..theircard.."")
  55. elseif yourcard == 11 then
  56. print("You have Ace. They have "..theircard.."")
  57. elseif theircard == 11 then
  58. print("You have "..yourcard..". They have Ace.")
  59. end
  60. if yourcard > theircard then
  61. cards = cards + 1
  62. tcards = tcards - 1
  63. print("You win!")
  64. genericSound()
  65. paintutils.drawPixel(screenx/2,screeny/2,colors.white)
  66. term.setBackgroundColor(colors.black)
  67. event, button, x, y = os.pullEvent("mouse_click")
  68. if x == screenx/2 and y == screeny/2 then
  69. term.setBackgroundColor(colors.black)
  70. paintutils.drawPixel(screenx/2,screeny/2, colors.black)
  71. term.setbackgroundColor(colors.black)
  72. end
  73. elseif theircard > yourcard then
  74. cards = cards - 1
  75. tcards = tcards + 1
  76. print("They win!")
  77. genericSound()
  78. paintutils.drawPixel(screenx/2,screeny/2,colors.white)
  79. term.setBackgroundColor(colors.black)
  80. event, button, x, y = os.pullEvent("mouse_click")
  81. if x == screenx/2 and y == screeny/2 then
  82. term.setBackgroundColor(colors.black)
  83. paintutils.drawPixel(screenx/2,screeny/2,colors.black)
  84. term.setBackgroundColor(colors.black)
  85. end
  86. elseif theircard == yourcard then
  87. function war(times)
  88. times = times or 1
  89. print("War!")
  90. sleep(0.1)
  91. warSound()
  92. wyourcard = math.random(1,11)
  93. wtheircard = math.random(1,11)
  94. if wyourcard == 11 and wtheircard == 11 then
  95. print("You have Ace. They have Ace.")
  96. elseif wyourcard ~= 11 and wtheircard ~= 11 then
  97. print("You have "..wyourcard..". They have "..wtheircard.."")
  98. elseif wyourcard == 11 then
  99. print("You have Ace. They have "..wtheircard.."")
  100. elseif wtheircard == 11 then
  101. print("You have "..wyourcard..". They have Ace.")
  102. end
  103. if wyourcard > wtheircard then
  104. tcards = tcards - 3+1*times
  105. cards = cards + 3+1*times
  106. print("You win!")
  107. paintutils.drawPixel(screenx/2,screeny/2,colors.white)
  108. term.setBackgroundColor(colors.black)
  109. event, button, x, y = os.pullEvent("mouse_click")
  110. if x == screenx/2 and y == screeny/2 then
  111. term.setBackgroundColor(colors.black)
  112. paintutils.drawPixel(screenx/2,screeny/2,colors.black)
  113. term.setBackgroundColor(colors.black)
  114. end
  115. elseif wtheircard > wyourcard then
  116. tcards = tcards + 3 + 1 * times
  117. cards = cards - 3 + 1 * times
  118. print("They win!")
  119. paintutils.drawPixel(screenx/2,screeny/2,colors.white)
  120. term.setBackgroundColor(colors.black)
  121. event, button, x, y= os.pullEvent("mouse_click")
  122. if x == screenx/2 and y == screeny/2 then
  123. term.setBackgroundColor(colors.black)
  124. paintutils.drawPixel(screenx/2,screeny/2,colors.black)
  125. term.setBackgroundColor(colors.black)
  126. end
  127. elseif wtheircard == wyourcard then
  128. war(times+1)
  129. end
  130. end
  131. war()
  132. end
  133. end
  134. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement