Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local deck = {
- [1] = {"A", "diamonds"},
- [2] = {"2", "diamonds"},
- [3] = {"3", "diamonds"},
- [4] = {"4", "diamonds"},
- [5] = {"5", "diamonds"},
- [6] = {"6", "diamonds"},
- [7] = {"7", "diamonds"},
- [8] = {"8", "diamonds"},
- [9] = {"9", "diamonds"},
- [10] = {"10", "diamonds"},
- [11] = {"J", "diamonds"},
- [12] = {"Q", "diamonds"},
- [13] = {"K", "diamonds"},
- [14] = {"A", "hearts"},
- [15] = {"2", "hearts"},
- [16] = {"3", "hearts"},
- [17] = {"4", "hearts"},
- [18] = {"5", "hearts"},
- [19] = {"6", "hearts"},
- [20] = {"7", "hearts"},
- [21] = {"8", "hearts"},
- [22] = {"9", "hearts"},
- [23] = {"10", "hearts"},
- [24] = {"J", "hearts"},
- [25] = {"Q", "hearts"},
- [26] = {"K", "hearts"},
- [27] = {"A", "clubs"},
- [28] = {"2", "clubs"},
- [29] = {"3", "clubs"},
- [30] = {"4", "clubs"},
- [31] = {"5", "clubs"},
- [32] = {"6", "clubs"},
- [33] = {"7", "clubs"},
- [34] = {"8", "clubs"},
- [35] = {"9", "clubs"},
- [36] = {"10", "clubs"},
- [37] = {"J", "clubs"},
- [38] = {"Q", "clubs"},
- [39] = {"K", "clubs"},
- [40] = {"A", "spades"},
- [41] = {"2", "spades"},
- [42] = {"3", "spades"},
- [43] = {"4", "spades"},
- [44] = {"5", "spades"},
- [45] = {"6", "spades"},
- [46] = {"7", "spades"},
- [47] = {"8", "spades"},
- [48] = {"9", "spades"},
- [49] = {"10", "spades"},
- [50] = {"J", "spades"},
- [51] = {"Q", "spades"},
- [52] = {"K", "spades"}
- }
- local cardBack = {{2^14, 1, 2^14}, {1, 2^14, 1}, {2^14, 1, 2^14}}
- local function draw(string, xPos, yPos, txtcol, bakcol)
- local string = string or ""
- local txtcol = txtcol or colors.white
- local bakcol = bakcol or colors.black
- term.setCursorPos(xPos, yPos)
- term.setBackgroundColor(bakcol)
- term.setTextColor(txtcol)
- term.write(string)
- end
- local card = {
- ["draw"] = function(cardInfo, xPos, yPos)
- paintutils.drawFilledBox(xPos, yPos, xPos + 2, yPos + 2, colors.white)
- draw(cardInfo[1], xPos, yPos, colors.black, colors.white)
- draw(cardInfo[1], xPos + (3 - #cardInfo[1]), yPos + 2, colors.black, colors.white)
- if cardInfo[2] == "diamonds" then
- draw("D", xPos + 2, yPos, colors.white, colors.red)
- draw("D", xPos, yPos + 2, colors.white, colors.red)
- elseif cardInfo[2] == "hearts" then
- draw("H", xPos + 2, yPos, colors.white, colors.red)
- draw("H", xPos, yPos + 2, colors.white, colors.red)
- elseif cardInfo[2] == "clubs" then
- draw("C", xPos + 2, yPos, colors.white, colors.black)
- draw("C", xPos, yPos + 2, colors.white, colors.black)
- elseif cardInfo[2] == "spades" then
- draw("S", xPos + 2, yPos, colors.white, colors.black)
- draw("S", xPos, yPos + 2, colors.white, colors.black)
- end
- end,
- ["back"] = function(xPos, yPos)
- paintutils.drawImage(cardBack, xPos, yPos)
- end
- }
- local function shuffleDeck()
- local tempdeck = deck
- local finaldeck = {}
- while #tempdeck > 0 do
- finaldeck[#finaldeck + 1] = table.remove(tempdeck, math.random(1, #tempdeck))
- end
- return finaldeck
- end
- local shuffled = shuffleDeck()
- term.setBackgroundColor(colors.green)
- term.clear()
- card.back(11, 7)
- local place = 1
- repeat
- os.pullEvent("mouse_click")
- card.draw(shuffled[place], 16, 7)
- place = place + 1
- if place == 3 then card.back(21, 7) end
- if place == 52 then paintutils.drawFilledBox(11, 7, 13, 9, colors.green) end
- until place > 52
- os.pullEvent("mouse_click")
- paintutils.drawFilledBox(16, 7, 18, 9, colors.green)
- term.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement