Guest User

Spades

a guest
May 11th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.51 KB | None | 0 0
  1. local screenW, screenH = term.getSize()
  2. local Cards = {
  3.                 Harts =     {1,2,3,4,5,6,7,8,9,10,11,12,13,14},
  4.                 Spade =     {1,2,3,4,5,6,7,8,9,10,11,12,13,14},
  5.                 Diamond =   {1,2,3,4,5,6,7,8,9,10,11,12,13,14},
  6.                 Clubs =     {1,2,3,4,5,6,7,8,9,10,11,12,13,14},
  7.                 }
  8.                
  9. local Users = { {},
  10.                 {},
  11.                 {},
  12.                 {}
  13.               }
  14.              
  15. local SortedUserType = {}
  16. local SortedUserCard = {}
  17.                
  18. local Buttons = {   {1,5,7},
  19.                     {2,8,10},
  20.                     {3,11,13},
  21.                     {4,14,16},
  22.                     {5,17,19},
  23.                     {6,20,22},
  24.                     {7,23,25},
  25.                     {8,26,28},
  26.                     {9,29,31},
  27.                     {10,32,34},
  28.                     {11,35,37},
  29.                     {12,38,40},
  30.                     {13,41,43},
  31.                     {14,44,46},
  32.                 }
  33.  
  34.  
  35. function pick()
  36.     local CardSort = ""
  37.     local ranSort = math.random(1,4)
  38.     if ranSort == 1 then ranSort = Cards.Harts  CardSort = "Harts"
  39.         elseif ranSort == 2 then ranSort = Cards.Spade  CardSort = "Spade"
  40.         elseif ranSort == 3 then ranSort = Cards.Diamond  CardSort = "Diamond"
  41.         elseif ranSort == 4 then ranSort = Cards.Clubs  CardSort = "Clubs" end
  42.     if #ranSort > 0 then
  43.         local ranCard = ranSort[math.random(1,#ranSort)]
  44.         table.remove(ranSort,ranCard)
  45.         return {CardSort,ranCard}
  46.     end
  47. end
  48.  
  49. function draw(player)
  50. term.clear()
  51. term.setBackgroundColor(colours.red)
  52.     for k = 1,#Buttons do
  53.         if Users[player][k][1] == "Harts" then term.setBackgroundColor(colors.red) CardDrawed = "H"
  54.         elseif Users[player][k][1] == "Spade" then term.setBackgroundColor(colors.gray) CardDrawed = "S"
  55.         elseif Users[player][k][1] == "Diamond" then term.setBackgroundColor(colors.lightGray) CardDrawed = "D"
  56.         elseif Users[player][k][1] == "Clubs" then term.setBackgroundColor(colors.orange) CardDrawed = "C" end
  57.             for y = Buttons[k][2],Buttons[k][3] do
  58.                 for u = 16,18 do
  59.                     term.setCursorPos(y,u)
  60.                     print(" ")
  61.                     term.setCursorPos(Buttons[k][2],u)
  62.                     print("|")
  63.                     term.setCursorPos(Buttons[14][3]+1,u)
  64.                     print("|") 
  65.                     term.setCursorPos(Buttons[k][2]+1,16)
  66.                     print(CardDrawed)
  67.                     term.setCursorPos(Buttons[k][2]+1,17)
  68.                     if Users[player][k][2] == 11 then print( "J" )
  69.                     elseif Users[player][k][2] == 12 then print( "Q" )
  70.                     elseif Users[player][k][2] == 13 then print( "K" )
  71.                     elseif Users[player][k][2] == 14 then print( "A" )
  72.                     else print(Users[player][k][2]) end
  73.                 end
  74.             end
  75.     end
  76.     term.setCursorPos(1,1)
  77. end
  78.  
  79.  
  80. function manage()
  81. for i = 1,4 do
  82.     while #Users[i] < 14 do
  83.         local a = pick()
  84.         local function wob(a,b) return a[1] < b[1] end
  85.             table.sort(Users[i],wob)
  86.             table.insert(Users[i],a)
  87.     end
  88. end
  89. end
  90.  
  91. manage()
  92. draw(1)
Advertisement
Add Comment
Please, Sign In to add comment