Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- X and Y dimensions of the playfield
- local boardX, boardY = 7, 6
- -- Colors of the different sides
- local pone_col, ptwo_col = colors.black, colors.red
- -- Color of board and board frame
- local board_col, boardframe_col = colors.yellow, colors.blue
- -- Color of background
- local bg_col = colors.cyan
- local scr_x,scr_y = term.getSize()
- local makeNewBoard = function()
- local output = {}
- for a = 1, boardY do
- output[#output+1] = ("0"):rep(boardX)
- end
- return output
- end
- local grid = makeNewBoard()
- local substrrepl = function(str,char,pos)
- return str:sub(1,pos-1)..char:sub(1,1)..str:sub(pos+1)
- end
- local placePiece = function(pos,side)
- grid[1] = substrrepl(grid[1],side,pos)
- end
- local boardGravity = function()
- local hadFallen = false
- for y = 1, boardY-1 do
- for x = 1, boardX do
- if grid[y+1]:sub(x,x) == "0" then
- grid[y+1] = substrrepl(grid[y+1],grid[y]:sub(x,x),x)
- grid[y] = substrrepl(grid[y],"0",x)
- hadFallen = true
- end
- end
- end
- return hadFallen
- end
- local renderBoard = function(row,posX,posY)
- for y = 1, boardX do
- for x = row or 1, row or boardY do
- term.setCursorPos(posX + x, posY + y)
- if grid[y][x] == "0" then
- term.setTextColor(bg_col)
- elseif grid[y][x] == "1" then
- term.setTextColor(pone_col)
- elseif grid[y][x] == "2" then
- term.setTextColor(ptwo_col)
- end
- term.setBackgroundColor(bg_col)
- term.clearLine()
- term.setBackgroundColor(board_col)
- term.write(string.char(7))
- end
- end
- end
Add Comment
Please, Sign In to add comment