
-- FUNCTIONS
function savecredits()
	file = io.open("Settings/credits.lua", "w")
	if file then
		file:write("credits="..credits)
		file:close()
	end
end


function clear_screen()

screen:clear(background)
end


function drawcard(a,x,y,deckimages)
-- screen:print (100,100 ,"decks/small/"..mydeck.."/".. a ..".png",Color.new(0, 255, 0))
-- card1 = Image.load("decks/small/"..mydeck.."/".. a ..".png")
screen:blit(x,y,deckimages[a])
end

function loaddeckimages(size,deck,back)
-- size is "big" or "small"
deckimages ={}

for i=1,52 do
deckimages[i]=Image.load("decks/"..size.."/"..deck.."/"..i..".png")
end
deckimages[0]=Image.load("decks/"..size.."/back/deck".. back ..".png")
return deckimages
end


function drawdeck(x,y,size,deckimages)
	x2=x
	y2=y
	for i=1,size do
	-- i2 = (size- i)+1
	i2 = i
	x2 = x + 2*i2 -2
	y2 = y -2*i2 +2
	drawcard(0,x2,y2,deckimages)
	
	end
	return x2,y2
end

function numtocard(a)
suit=0
value=0
value = 14 - math.floor((a-1) /4)
suit = a % 4
if value==14 then value=1 end
return suit,value
end

function cardtonum(suit,value)
card=0
if (value==1) then value=14 end
value = 14-value
card = value*4 + suit
return card
end

function flushdeck()
startdeck ={}
deck = {}
deck[0]=0
for i=1,52 do
startdeck[i]=i
end
for i=1,52 do
	myval = math.random(1,#startdeck)
	deck[i]=table.remove(startdeck,myval)
end
return deck
end