Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Todo:
- -- 1) Make all text input use arrow selector instead
- -- 2) Allow user to have infinte players. (insert deck into istelf when the amount left in the deck is less than X)
- -- 3) Add "Colorblind" Option
- -- 4) Add normal computer use (dont use term.setBackgroundColor() and make everything in "colorblind" mode)
- term.clear()
- term.setCursorPos(1,1)
- print("Card Games\n\nChoose a game:\n\n1) Uno\n2) Go fish")
- repeat
- game = string.lower(read())
- if type(tonumber(game)) == "number" then
- if game == "1" then
- game = "uno"
- elseif game == "2" then
- game = "go fish"
- end
- end
- until game == "uno" or game == "go fish"
- --Uno
- if game == "uno" then
- deck = {"R0", "R1", "R1", "R2", "R2", "R3", "R3", "R4", "R4", "R5", "R5", "R6", "R6", "R7", "R7", "R8", "R8", "R9", "R9", "RSK", "RSK", "RR", "RR", "RD2", "RD2",
- "Y0", "Y1", "Y1", "Y2", "Y2", "Y3", "Y3", "Y4", "Y4", "Y5", "Y5", "Y6", "Y6", "Y7", "Y7", "Y8", "Y8", "Y9", "Y9", "YSK", "YSK", "YR", "YR", "YD2", "YD2",
- "B0", "B1", "B1", "B2", "B2", "B3", "B3", "B4", "B4", "B5", "B5", "B6", "B6", "B7", "B7", "B8", "B8", "B9", "B9", "BSK", "BSK", "BR", "BR", "BD2", "BD2",
- "G0", "G1", "G1", "G2", "G2", "G3", "G3", "G4", "G4", "G5", "G5", "G6", "G6", "G7", "G7", "G8", "G8", "G9", "G9", "GSK", "GSK", "GR", "GR", "GD2", "GD2",
- "AW", "AW", "AW", "AW", "AD4", "AD4", "AD4", "AD4"}
- --Players VS Robots!
- players = 0
- robots = 0
- print("How many human players? (1-4)")
- repeat
- players = tonumber(read())
- until type(players) == "number" and (players < 5 and players > 0)
- if players < 4 and players > 1 then
- print("How many robots? (0-"..tostring(4 - players)..")")
- repeat
- robots = tonumber(read())
- until type(robots) == "number" and ((robots < 5 - players) and robots > -1)
- end
- if players == 1 then
- print("How many robots? (1-"..tostring(4 - players)..")")
- repeat
- robots = tonumber(read())
- until type(robots) == "number" and ((robots < 5 - players) and robots > 0)
- end
- --Shuffling!
- function shuffle()
- for i = 1, 50 do
- math.randomseed(1000*os.time())
- for j = #deck, 2, -1 do
- k = math.random(i)
- deck[j], deck[k] = deck[k], deck[j]
- end
- end
- end
- shuffle()
- --Dealing!
- play1 = {""}
- play2 = {""}
- play3 = {""}
- play4 = {""}
- robot1 = {""}
- robot2 = {""}
- robot3 = {""}
- function deal(playdeck)
- for i = 1, 7 do
- table.insert(playdeck, table.remove(deck))
- end
- table.remove(playdeck, 1)
- end
- deal(play1)
- if players >= 2 then
- deal(play2)
- end
- if players >= 3 then
- deal(play3)
- end
- if players == 4 then
- deal(play4)
- end
- if robots >= 1 then
- deal(robot1)
- end
- if robots >= 2 then
- deal(robot2)
- end
- if robots == 3 then
- deal(robot3)
- end
- --Gameplay and Visuals!
- discard = {""}
- table.insert(discard, table.remove(deck))
- table.remove(discard, 1)
- player = play1
- playnum = 1
- goneout = 0
- direction = 1
- realPlayNum = 1
- playAction = "Game Started."
- while goneout == 0 do
- shuffle()
- term.clear()
- if playnum > players then
- playtype = true
- else
- playtype = false
- end
- function cardtype(cardspecimen, setback, wilds)
- if cardspecimen ~= "RR" then
- local subcolor = string.sub(cardspecimen, 2)
- color = string.gsub(cardspecimen, subcolor, "")
- card = string.sub(cardspecimen, 2)
- else
- color = "R"
- card = "R"
- end
- cardstype = {color, card}
- if setback then
- if color == "R" then
- term.setBackgroundColor(colors.red)
- elseif color == "B" then
- term.setBackgroundColor(colors.blue)
- elseif color == "Y" then
- term.setBackgroundColor(colors.yellow)
- elseif color == "G" then
- term.setBackgroundColor(colors.green)
- else
- term.setBackgroundColor(colors.white)
- if wilds then
- if color == "A" then
- term.setBackgroundColor(colors.white)
- elseif color == "r" then
- term.setBackgroundColor(colors.red)
- elseif color == "g" then
- term.setBackgroundColor(colors.green)
- elseif color == "b" then
- term.setBackgroundColor(colors.blue)
- else
- term.setBackgroundColor(colors.yellow)
- end
- end
- end
- end
- end
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- print("Player "..playnum)
- cardtype(discard[#discard],false,false)
- color = string.lower(color)
- if color == "a" then
- color = "Any"
- term.setTextColor(colors.white)
- elseif color == "r" then
- color = "Red"
- term.setTextColor(colors.red)
- elseif color == "g" then
- color = "Green"
- term.setTextColor(colors.green)
- elseif color == "b" then
- color = "Blue"
- term.setTextColor(colors.blue)
- elseif color == "y" then
- color = "Yellow"
- term.setTextColor(colors.yellow)
- end
- term.setCursorPos(1,2)
- print("Color: "..color)
- term.setTextColor(colors.white)
- term.setCursorPos(1,4)
- print(playAction)
- cardtype(discard[#discard],true,true)
- term.setTextColor(colors.gray)
- term.setCursorPos(21,2)
- print("+--------+")
- term.setCursorPos(21,3)
- print("| |")
- term.setCursorPos(21,4)
- print("| |")
- term.setCursorPos(21,5)
- print("| |")
- term.setCursorPos(21,6)
- print("| |")
- term.setCursorPos(21,7)
- print("| |")
- term.setCursorPos(21,8)
- print("| |")
- term.setCursorPos(21,9)
- print("| |")
- term.setCursorPos(21,10)
- print("| |")
- term.setCursorPos(21,11)
- print("+--------+")
- term.setCursorPos(33,11)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- print("Arrows: Select Card")
- term.setCursorPos(33,12)
- print("Enter: Discard Card")
- term.setCursorPos(33,13)
- print("Space: Draw Card")
- term.setTextColor(colors.gray)
- for i = 1, #player do
- cardtype(player[i],true,false)
- term.setCursorPos(2*i-1,14)
- print("-+")
- term.setCursorPos(2*i-1,15)
- print(" |")
- term.setCursorPos(2*i-1,16)
- print(" |")
- term.setCursorPos(2*i-1,17)
- print(" |")
- term.setCursorPos(2*i-1,18)
- print(" |")
- for j = 1, string.len(card) do
- term.setCursorPos(2*i-1,14+j)
- print(string.sub(card, j, j))
- end
- end
- function showDiscard(printcards)
- cardtype(discard[#discard],true,true)
- if card == "R" then
- card = "Reverse"
- elseif card == "SK" then
- card = "Skip"
- elseif card == "D2" then
- card = "Draw 2"
- elseif card == "W" then
- card = "Wild"
- elseif card == "D4" then
- card = "Draw 4 W"
- end
- if printcards then
- term.setCursorPos(22,3)
- print(card)
- term.setCursorPos(30 - string.len(card),10)
- print(card)
- end
- end
- showDiscard(true)
- term.setCursorPos(1,19)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write(" ")
- arrow = 1
- local function printarrow()
- term.setCursorPos(2*arrow - 3,19)
- write(" ")
- term.setCursorPos(2*arrow + 1,19)
- write(" ")
- term.setCursorPos(2*arrow - 1,19)
- write("^")
- end
- printarrow()
- local endturn = false
- if not(playtype) then
- while endturn == false do
- event, key = os.pullEvent("key")
- if event == "key" then
- if key == 203 then
- if arrow > 1 then
- arrow = arrow - 1
- printarrow()
- end
- elseif key == 205 then
- if arrow < #player then
- arrow = arrow + 1
- printarrow()
- end
- elseif key == 28 then
- cardtype(player[arrow],false,false)
- playcard = cardstype
- cardtype(discard[#discard],false,false)
- matchcard = cardstype
- if (string.lower(playcard[1]) == string.lower(matchcard[1]) or playcard[2] == matchcard[2]) and (playcard[2] ~= "W" and playcard[2] ~= "D4") then
- table.insert(discard, table.remove(player, arrow))
- endturn = true
- playAction = "Player "..realPlayNum.." discarded \ncard "..playcard[1]..playcard[2]
- elseif playcard[2] == "W" or playcard[2] == "D4" then
- table.remove(player, arrow)
- endturn = true
- term.setCursorPos(1,19)
- write("What color? (Red, Blue, Green, Yellow) ")
- repeat
- inputcolor = string.lower(read())
- until inputcolor == "red" or inputcolor == "blue" or inputcolor == "green" or inputcolor == "yellow"
- if inputcolor == "red" then
- table.insert(discard, "r"..playcard[2])
- elseif inputcolor == "blue" then
- table.insert(discard, "b"..playcard[2])
- elseif inputcolor == "green" then
- table.insert(discard, "g"..playcard[2])
- elseif inputcolor == "yellow" then
- table.insert(discard, "y"..playcard[2])
- end
- playAction = "Player "..realPlayNum.." discarded \na wild."
- elseif matchcard[1] == "A" then
- table.insert(discard, table.remove(player, arrow))
- endturn = true
- playcard = "None"
- matchcard = "None"
- showDiscard(false)
- playAction = "Player "..realPlayNum.." discarded \na wild."
- end
- elseif key == 57 then
- if #player < 25 then
- table.insert(player, table.remove(deck))
- endturn = true
- playcard = "None"
- matchcard = "None"
- end
- playAction = "Player "..realPlayNum.." drew a \ncard."
- end
- end
- end
- end
- --Robots!
- if playtype then
- robot1 = {"AW", "rD4", "GR", "BSK", "YD2", "R9"}
- for i = 1, #player do
- cardtype(player[i],false,false)
- playcard = cardstype
- cardtype(discard[#discard],false,false)
- matchcard = cardstype
- if (string.lower(playcard[1]) == string.lower(matchcard[1]) or playcard[2] == matchcard[2]) and (playcard[2] ~= "W" and playcard[2] ~= "D4") then
- table.insert(discard, table.remove(player, i))
- endturn = true
- playAction = "Robot "..realPlayNum.." discarded \ncard "..playcard[1]..playcard[2]
- elseif playcard[2] == "W" or playcard[2] == "D4" then
- table.remove(player, i)
- endturn = true
- inputcolor = math.random(4)
- if inputcolor == 1 then
- table.insert(discard, "r"..playcard[2])
- elseif inputcolor == 2 then
- table.insert(discard, "b"..playcard[2])
- elseif inputcolor == 3 then
- table.insert(discard, "g"..playcard[2])
- elseif inputcolor == 4 then
- table.insert(discard, "y"..playcard[2])
- end
- playAction = "Robot "..realPlayNum.." discarded \na wild."
- elseif matchcard[1] == "A" then
- table.insert(discard, table.remove(player, i))
- endturn = true
- playcard = "None"
- matchcard = "None"
- playAction = "Robot "..realPlayNum.." discarded \na wild."
- end
- end
- if endturn == false then
- table.insert(player, table.remove(deck))
- playAction = "Robot "..realPlayNum.." drew a \ncard."
- end
- read()
- end
- --Special Cards and Next Player!
- if #player == 0 then
- goneout = 1
- if playtype then
- print("\nRobot "..realPlayNum.." Won!")
- else
- print("\nPlayer "..playnum.." Won!")
- end
- end
- function checkdeck()
- if #deck == 0 then
- for i = 1, #discard do
- table.insert(deck,table.remove(discard))
- shuffle()
- end
- table.insert(discard,table.remove(deck))
- end
- end
- function nextplayer()
- playnum = playnum + direction
- if playnum == 0 then
- playnum = players + robots
- elseif playnum == -1 then
- playnum = players + robots - 1
- end
- if playnum == players + 1 and robots > 0 then
- player = robot1
- elseif playnum == players + 2 and robots > 1 then
- player = robot2
- elseif playnum == players + 3 and robots > 2 then
- player = robot3
- elseif playnum == players + robots + 1 then
- playnum = 1
- elseif playnum == players + robots + 2 then
- playnum = 2
- end
- if playnum == 1 then
- player = play1
- elseif playnum == 2 then
- player = play2
- elseif playnum == 3 then
- player = play3
- elseif playnum == 4 then
- player = play4
- end
- if playnum > players then
- realPlayNum = playnum - players
- else
- realPlayNum = playnum
- end
- end
- if playcard[2] == "R" then
- if players + robots == 2 then
- nextplayer()
- if playtype then
- playAction = "Robot "..realPlayNum.." got \nskipped."
- else
- playAction = "Player "..playnum.." got \nskipped."
- end
- else
- direction = direction * -1
- if playtype then
- playAction = "Robot "..realPlayNum.." reversed \nthe direction."
- else
- playAction = "Player "..playnum.." reversed \nthe direction."
- end
- end
- elseif playcard[2] == "SK" then
- nextplayer()
- if playtype then
- playAction = "Robot "..realPlayNum.." got \nskipped."
- else
- playAction = "Player "..playnum.." got \nskipped."
- end
- end
- if playcard[2] == "D2" then
- nextplayer()
- for i = 1, 2 do
- checkdeck()
- table.insert(player, table.remove(deck))
- end
- if playtype then
- playAction = "Robot "..realPlayNum.." had to \ndraw two cards."
- else
- playAction = "Player "..playnum.." had to \ndraw two cards."
- end
- elseif playcard[2] == "D4" then
- nextplayer()
- for i = 1, 4 do
- checkdeck()
- table.insert(player, table.remove(deck))
- end
- if playtype then
- playAction = "Robot "..realPlayNum.." had to \ndraw four cards."
- else
- playAction = "Player "..playnum.." had to \ndraw four cards."
- end
- end
- checkdeck()
- nextplayer()
- if playnum > players then
- currentPlayer = " Robot"
- else
- currentPlayer = "Player"
- end
- if goneout == 0 then
- term.clear()
- term.setCursorPos(13,7)
- print("+------------------------+")
- term.setCursorPos(13,8)
- print("| |")
- term.setCursorPos(13,9)
- print("| "..currentPlayer.." "..realPlayNum.."'s turn! |")
- term.setCursorPos(13,10)
- print("| |")
- term.setCursorPos(13,11)
- print("+------------------------+")
- term.setCursorPos(13,13)
- os.sleep(2)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement