Advertisement
Doob

PCards

Apr 16th, 2015
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | None | 0 0
  1. tPlayers = {[1] = 'board'}
  2. -- tPlayers[playerID] = string
  3.  
  4. tCards = {}
  5. -- tCards[playerID][cardID] = (2/3/4/5/6/7/8/9/T/J/Q/K + d/s/h/c)
  6. -- example: tCards[4][2] = 'Jc'
  7.  
  8. tStatus = {}
  9. -- tStatus[playerID][cardID] = boolean
  10. -- example: tCards[4][2] = 0
  11.  
  12. tMoney = {}
  13. -- tMoney[playerID] = number
  14.  
  15. local tH = {
  16. '2d', '3d', '4d', '5d', '6d', '7d', '8d', '9d', 'Td', 'Jd', 'Qd', 'Kd', 'Ad', -- diamonds
  17. '2s', '3s', '4s', '5s', '6s', '7s', '8s', '9s', 'Ts', 'Js', 'Qs', 'Ks', 'As', -- spades
  18. '2h', '3h', '4h', '5h', '6h', '7h', '8h', '9h', 'Th', 'Jh', 'Qh', 'Kh', 'Ah', -- hearts
  19. '2c', '3c', '4c', '5c', '6c', '7c', '8c', '9c', 'Tc', 'Jc', 'Qc', 'Kc', 'Ac'} -- clubs
  20.  
  21. for i = 0, 13 do
  22.   tCards[i] = {0, 0, 0, 0, 0}
  23.   tStatus[i] = {0, 0, 0, 0, 0}
  24.   tMoney[i]=0
  25. end
  26.  
  27. function shuffle()
  28.   trs = math.random(1, 13)
  29.   for i = 0, trs do
  30.   i = 53
  31.     while i > 1 do
  32.       i = i - 1
  33.       j = math.random(1, i)
  34.       tH[j], tH[i] = tH[i], tH[j]
  35.     end
  36.   end
  37.   return tH
  38. end
  39.  
  40. local function addPlayer() -- dealer
  41.   id, msg = rednet.receive()
  42.   msg = textutils.unserialize(msg)
  43.   if msg[1] == 'add' then
  44.     tPlayers[#tPlayers+1] = msg[2]
  45.   end
  46. end
  47.  
  48. local function resetCards() -- dealer
  49.   for i = 0, 13 do
  50.     tCards[i] = {0, 0, 0, 0, 0}
  51.     tStatus[i] = {0, 0, 0, 0, 0}
  52.   end
  53. end
  54.  
  55. local function addMoney(plid, amount) -- dealer
  56.   tMoney[plid] = amount
  57. end
  58.  
  59. local function ShowHideC(plid, crdid, st) -- playerID, cardID, status \\ dealer, player
  60.   tStatus[plid][crdid] = st
  61. end
  62.  
  63. local function cardTransfer(plid, tgid, crdid) -- dealer, player
  64.   tgCid = #tCards[tgid]+1
  65.   tCards[tgid][tgCid] = tCards[plid][crdid]
  66.   ShowHideC(tgid, tgCid, tStatus[plid][crdid])
  67. end
  68.  
  69. local function moneyTransfer(plid, tgid, amount) -- dealer, player
  70.   tMoney[tgid] = tMoney[tgid]+amount
  71.   tMoney[plid] = tMoney[plid]-amount
  72. end
  73.  
  74. local function executeCMD(command, v1, v2, v3)
  75.   if command == 'shuffle' then shuffle()
  76.     elseif command == 'addPlayer' then addPlayer()
  77.     elseif command == 'addMoney' then addMoney(v1, v2)
  78.     elseif command == 'cardTransfer' then cardTransfer(v1, v2, v3)
  79.     elseif command == 'showCards' then ShowHideC(v1, v2, v3)
  80.   end
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement