Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w,h = term.getSize()
- local buffer = {}
- local defcol = colors.white
- local defback = colors.black
- local selcol = defcol
- local selback = defback
- local deck = {}
- local cardPos = {}
- cardPos[1] = {3,2}
- cardPos[2] = {7,2}
- cardPos[3] = {11,2}
- cardPos[4] = {15,2}
- cardPos[5] = {3,12}
- cardPos[6] = {7,12}
- cardPos[7] = {11,12}
- cardPos[8] = {15,12}
- cardPos[9] = {7,7} --center left
- cardPos[10] = {11,7} -- center right
- local p1deck = {20,2}
- local p2deck = {9,17}
- local player1 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}
- local player2 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}
- local cards = {}
- for i=1,13 do
- cards[i] = function(x,y)
- local card = {}
- card.value = i
- card.window = {x,y,x+2,y+2}
- card.graphic = function(x,y)
- x = card.window[1]
- y = card.window[2]
- local len = #tostring(i)
- draw(tostring(i)..string.rep(" ",3-len),x,y,colors.black,colors.white)
- draw(" ",x,y+1,colors.black,colors.white)
- draw(string.rep(" ",3-len)..tostring(i),x,y+2,colors.black,colors.white)
- end
- card.back = function(x,y)
- x = card.window[1]
- y = card.window[2]
- draw(" ",x,y,colors.black,colors.red)
- draw(" ",x+1,y,colors.black,colors.white)
- draw(" ",x+2,y,_,colors.red)
- draw(" ",x,y+1,_,colors.white)
- draw(" ",x+1,y+1,_,colors.red)
- draw(" ",x+2,y+1,_,colors.white)
- for p = 0,2,2 do
- draw(" ",x+p,y+2,_,colors.red)
- end
- draw(" ",x+1,y+2,_,colors.white)
- end
- return card
- end
- end
- --buffer[1][1] = {char "s", int txtcol, int backcol}
- function createBuffer()
- for x=1,w do
- buffer[x] = {}
- for y=1,h do
- buffer[x][y] = nil
- end
- end
- end
- function draw(words,x,y,txt,back)
- txt = txt or defcol
- back = back or defback
- for i = 0,#words-1 do
- if not (x + i > w) then
- buffer[x + i][y] = {words:sub(i+1,i+1),txt,back}
- end
- end
- end
- function drawBuffer(a,b,c,d)
- if not (a and b and c and d) then
- a,b,c,d = 1,1,w,h
- end
- for y = b,d do
- for x = a,c do
- term.setCursorPos(x,y)
- if selcol ~= buffer[x][y][2] then
- selcol = buffer[x][y][2]
- term.setTextColor(selcol)
- end
- if selback ~= buffer[x][y][3] then
- selback = buffer[x][y][3]
- term.setBackgroundColor(selback)
- end
- write(buffer[x][y][1])
- end
- end
- end
- function drawCards(deck)
- for i=1,#deck do
- deck[i].graphic()
- end
- cards[11](p1deck[1],p1deck[2]).back()
- cards[12](p2deck[1],p2deck[2]).back()
- end
- function hitbox(e,cards,x2,y2,func,...)
- if e[3] >= x and e[3] <= x2 and e[4] <= y and e[4] >=y2 then
- local returns = {func(...)}
- if returns then return returns end
- end
- end
- function startup()
- createBuffer()
- for i=1,w do
- for k = 1,h do
- draw(" ",i,k,_,colors.green)
- end
- end
- for i,v in ipairs(cardPos) do
- deck[#deck+1] = cards[i](v[1],v[2])
- end
- drawCards(deck)
- end
- function loop()
- drawBuffer()
- local e = {os.pullEvent()}
- if e[1] == "mouse_click" or "mouse_drag" then
- hitbox(e,cardpos
- end
- startup()
- while true do
- loop()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement