Posted 11 May 2014 - 03:35 AM
Hello :D/>
i'm currently making a card game and i can't get the program not to draw the same card over and over again
i tried in my pick() function by deleting the used one but it looks like i'm misunderstanding table.remove
this is what i got so far.
i'm currently making a card game and i can't get the program not to draw the same card over and over again
i tried in my pick() function by deleting the used one but it looks like i'm misunderstanding table.remove
this is what i got so far.
Spoiler
pastebin get hxgeifqUspades
local screenW, screenH = term.getSize()
local Cards = {
Harts = {1,2,3,4,5,6,7,8,9,10,11,12,13,14},
Spade = {1,2,3,4,5,6,7,8,9,10,11,12,13,14},
Diamond = {1,2,3,4,5,6,7,8,9,10,11,12,13,14},
Clubs = {1,2,3,4,5,6,7,8,9,10,11,12,13,14},
}
local Users = { {},
{},
{},
{}
}
local Buttons = { {1,5,7},
{2,8,10},
{3,11,13},
{4,14,16},
{5,17,19},
{6,20,22},
{7,23,25},
{8,26,28},
{9,29,31},
{10,32,34},
{11,35,37},
{12,38,40},
{13,41,43},
{14,44,46},
}
function pick()
local CardSort = ""
local ranSort = math.random(1,4)
if ranSort == 1 then ranSort = Cards.Harts CardSort = "Harts"
elseif ranSort == 2 then ranSort = Cards.Spade CardSort = "Spade"
elseif ranSort == 3 then ranSort = Cards.Diamond CardSort = "Diamond"
elseif ranSort == 4 then ranSort = Cards.Clubs CardSort = "Clubs" end
if #ranSort > 0 then
local ranCard = math.random(1,#ranSort)
print(#ranSort)
--sleep(.1)
table.remove(ranSort,ranCard)
return {CardSort,ranCard}
end
end
function draw(player)
term.clear()
term.setBackgroundColor(colours.red)
for k = 1,#Buttons do
if Users[player][k][1] == "Harts" then term.setBackgroundColor(colors.red) CardDrawed = "H"
elseif Users[player][k][1] == "Spade" then term.setBackgroundColor(colors.gray) CardDrawed = "S"
elseif Users[player][k][1] == "Diamond" then term.setBackgroundColor(colors.lightGray) CardDrawed = "D"
elseif Users[player][k][1] == "Clubs" then term.setBackgroundColor(colors.orange) CardDrawed = "C" end
for y = Buttons[k][2],Buttons[k][3] do
for u = 16,18 do
term.setCursorPos(y,u)
print(" ")
term.setCursorPos(Buttons[k][2],u)
print("|")
term.setCursorPos(Buttons[14][3]+1,u)
print("|")
term.setCursorPos(Buttons[k][2]+1,16)
print(CardDrawed)
term.setCursorPos(Buttons[k][2]+1,17)
print(Users[player][k][2])
end
end
end
term.setCursorPos(1,1)
end
function manage()
for i = 1,4 do
while #Users[i] < 14 do
local a = pick()
table.insert(Users[i],a)
end
end
end
manage()
draw(3)