Log In  


based on the tutorial from here https://docs.coronalabs.com/tutorial/data/shuffleTable/index.html

local cardDeck = {"AS","AH","2S","3S","KH","QD","QS","KD","4D","10H"}

math.random(flr(rnd()))

local function shuffleTable(t)
	if (type(t) ~= "table") then
		print("warning")
		return false
	end
	local j
	for i = #t, 2, -1 do
		j = math.random(i)
		t[i], t[j] = t[j], t[i]
	end
	return t
end
cardDeck = shuffleTable(cardDeck)

local currentIndex = 1
local function drawCards(num,deck)
	local cardsDrawn = {}
	for i = currentIndex, num do
		cardsDrawn[#cardsDrawn+1] = deck[i]
	end

	currentIndex = currentIndex + num
	return cardsDrawn
end

local playerHand = drawCards(5,cardDeck)

print(table.concat(playerHand,"\n"))



[Please log in to post a comment]