SHOW:
|
|
- or go back to the newest paste.
| 1 | local screenx, screeny = term.getSize() | |
| 2 | local cards = 15 | |
| 3 | local tcards = 15 | |
| 4 | local tArgs = {...}
| |
| 5 | ||
| 6 | if #tArgs < 2 then | |
| 7 | print("Usage: "..shell.getRunningProgram().." <warcards> <layside> [warsoundside] [normalsoundside]")
| |
| 8 | print("Please insure both sound sides are top, bottom, left, right, back, or front.")
| |
| 9 | print('The lay side is what side to receive redstone input to "lay a card" (options same as sound sides)')
| |
| 10 | else | |
| 11 | ||
| 12 | local s1 = tArgs[4] or "bottom" | |
| 13 | local s2 = tArgs[3] or "bottom" | |
| 14 | local layside = tArgs[2] | |
| 15 | local function genericSound() | |
| 16 | redstone.setOutput(s1, true) | |
| 17 | sleep(0.1) | |
| 18 | redstone.setOutput(s1, false) | |
| 19 | end | |
| 20 | ||
| 21 | local function warSound() | |
| 22 | redstone.setOutput(s2, true) | |
| 23 | sleep(0.1) | |
| 24 | redstone.setOutput(s2, false) | |
| 25 | end | |
| 26 | ||
| 27 | term.clear() | |
| 28 | term.setCursorPos(1, 1) | |
| 29 | local warcards = tArgs[1] | |
| 30 | ||
| 31 | while true do | |
| 32 | term.clear() | |
| 33 | term.setBackgroundColor(colors.black) | |
| 34 | ||
| 35 | if cards < 1 then | |
| 36 | term.setCursorPos(1,1) | |
| 37 | print("You lost War!")
| |
| 38 | genericSound() | |
| 39 | break | |
| 40 | ||
| 41 | elseif tcards < 1 then | |
| 42 | term.setCursorPos(1,1) | |
| 43 | print("You beat War!")
| |
| 44 | warSound() | |
| 45 | break | |
| 46 | end | |
| 47 | ||
| 48 | term.setCursorPos(35,1) | |
| 49 | print("Your cards: "..cards.."")
| |
| 50 | term.setCursorPos(35,2) | |
| 51 | print("Their cards: "..tcards.."")
| |
| 52 | term.setCursorPos(1,1) | |
| 53 | ||
| 54 | local yourcard = math.random(1,11) | |
| 55 | local theircard = math.random(1,11) | |
| 56 | ||
| 57 | print("Lay a card")
| |
| 58 | while not redstone.getInput(layside) do | |
| 59 | end | |
| 60 | ||
| 61 | print("3")
| |
| 62 | sleep(1) | |
| 63 | print("2")
| |
| 64 | sleep(1) | |
| 65 | print("1")
| |
| 66 | sleep(1) | |
| 67 | print("Go!")
| |
| 68 | ||
| 69 | if yourcard == 11 and theircard == 11 then | |
| 70 | print("You have Ace. They have Ace.")
| |
| 71 | elseif yourcard ~= 11 and theircard ~= 11 then | |
| 72 | print("You have "..yourcard..". They have "..theircard.."")
| |
| 73 | elseif yourcard == 11 then | |
| 74 | print("You have Ace. They have "..theircard.."")
| |
| 75 | elseif theircard == 11 then | |
| 76 | print("You have "..yourcard..". They have Ace.")
| |
| 77 | end | |
| 78 | ||
| 79 | if yourcard > theircard then | |
| 80 | cards = cards + 1 | |
| 81 | tcards = tcards - 1 | |
| 82 | print("You win!")
| |
| 83 | genericSound() | |
| 84 | ||
| 85 | paintutils.drawPixel(screenx/2,screeny/2,colors.white) | |
| 86 | term.setBackgroundColor(colors.black) | |
| 87 | event, button, x, y = os.pullEvent("mouse_click")
| |
| 88 | ||
| 89 | if x == screenx/2 and y == screeny/2 then | |
| 90 | term.setBackgroundColor(colors.black) | |
| 91 | paintutils.drawPixel(screenx/2,screeny/2, colors.black) | |
| 92 | term.setbackgroundColor(colors.black) | |
| 93 | end | |
| 94 | ||
| 95 | elseif theircard > yourcard then | |
| 96 | cards = cards - 1 | |
| 97 | tcards = tcards + 1 | |
| 98 | print("They win!")
| |
| 99 | genericSound() | |
| 100 | ||
| 101 | paintutils.drawPixel(screenx/2,screeny/2,colors.white) | |
| 102 | term.setBackgroundColor(colors.black) | |
| 103 | event, button, x, y = os.pullEvent("mouse_click")
| |
| 104 | ||
| 105 | if x == screenx/2 and y == screeny/2 then | |
| 106 | term.setBackgroundColor(colors.black) | |
| 107 | paintutils.drawPixel(screenx/2,screeny/2,colors.black) | |
| 108 | term.setBackgroundColor(colors.black) | |
| 109 | end | |
| 110 | ||
| 111 | elseif theircard == yourcard then | |
| 112 | function war(times) | |
| 113 | local times = times or 1 | |
| 114 | print("War!")
| |
| 115 | sleep(0.1) | |
| 116 | warSound() | |
| 117 | ||
| 118 | print("Lay a card")
| |
| 119 | while not redstone.getInput(layside) do | |
| 120 | end | |
| 121 | ||
| 122 | local wyourcard = math.random(1,11) | |
| 123 | local wtheircard = math.random(1,11) | |
| 124 | ||
| 125 | if wyourcard == 11 and wtheircard == 11 then | |
| 126 | print("You have Ace. They have Ace.")
| |
| 127 | elseif wyourcard ~= 11 and wtheircard ~= 11 then | |
| 128 | print("You have "..wyourcard..". They have "..wtheircard.."")
| |
| 129 | elseif wyourcard == 11 then | |
| 130 | print("You have Ace. They have "..wtheircard.."")
| |
| 131 | elseif wtheircard == 11 then | |
| 132 | print("You have "..wyourcard..". They have Ace.")
| |
| 133 | end | |
| 134 | ||
| 135 | if wyourcard > wtheircard then | |
| 136 | tcards = tcards - 3+1*times | |
| 137 | cards = cards + 3+1*times | |
| 138 | print("You win!")
| |
| 139 | ||
| 140 | paintutils.drawPixel(screenx/2,screeny/2-2,colors.white) | |
| 141 | term.setBackgroundColor(colors.black) | |
| 142 | event, button, x, y = os.pullEvent("mouse_click")
| |
| 143 | if x == screenx/2 and y == screeny/2 then | |
| 144 | term.setBackgroundColor(colors.black) | |
| 145 | paintutils.drawPixel(screenx/2,screeny/2-2,colors.black) | |
| 146 | term.setBackgroundColor(colors.black) | |
| 147 | end | |
| 148 | ||
| 149 | elseif wtheircard > wyourcard then | |
| 150 | tcards = tcards + 3 + 1 * times | |
| 151 | cards = cards - 3 + 1 * times | |
| 152 | print("They win!")
| |
| 153 | ||
| 154 | paintutils.drawPixel(screenx/2,screeny/2-2,colors.white) | |
| 155 | term.setBackgroundColor(colors.black) | |
| 156 | event, button, x, y= os.pullEvent("mouse_click")
| |
| 157 | if x == screenx/2 and y == screeny/2 then | |
| 158 | term.setBackgroundColor(colors.black) | |
| 159 | paintutils.drawPixel(screenx/2,screeny/2-2,colors.black) | |
| 160 | term.setBackgroundColor(colors.black) | |
| 161 | end | |
| 162 | ||
| 163 | elseif wtheircard == wyourcard then | |
| 164 | war(times+1) | |
| 165 | end | |
| 166 | ||
| 167 | end | |
| 168 | war() | |
| 169 | end | |
| 170 | ||
| 171 | end | |
| 172 | ||
| 173 | ||
| 174 | ||
| 175 | ||
| 176 | end |