Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tetris-style Block Puzzle for CC: Tweaked - Simplified Debug Version
- local GRID_SIZE = 6
- local grid = {}
- local score = 0
- local gameOver = false
- local selectedPiece = nil
- local nextPieces = {}
- local PIECE_SHAPES = {
- {{{1, 1}}},
- {{{1, 1}, {1, 1}}},
- {{{1, 1, 1}}},
- }
- local function initGrid()
- for y = 1, GRID_SIZE do
- grid[y] = {}
- for x = 1, GRID_SIZE do
- grid[y][x] = false
- end
- end
- end
- local function generateNextPieces()
- nextPieces = {}
- for i = 1, 3 do
- table.insert(nextPieces, PIECE_SHAPES[math.random(#PIECE_SHAPES)])
- end
- end
- local function drawGrid()
- term.clear()
- term.setCursorPos(1, 1)
- print("=== BLOCK PUZZLE ===")
- print("Score: " .. score)
- print("")
- -- Draw grid
- for y = 1, GRID_SIZE do
- write("|")
- for x = 1, GRID_SIZE do
- if grid[y][x] then
- write("##")
- else
- write(" ")
- end
- end
- print("|")
- end
- print("")
- print("Commands:")
- print("1/2/3 = Select piece")
- print("Click grid = Place piece")
- print("Q = Quit")
- if selectedPiece then
- print("")
- print("SELECTED: Piece " .. selectedPiece)
- end
- end
- local function main()
- initGrid()
- generateNextPieces()
- print("Starting game...")
- os.sleep(1)
- while not gameOver do
- drawGrid()
- local event, param, x, y = os.pullEvent()
- if event == "key" then
- if param == keys.q then
- gameOver = true
- elseif param == keys.one then
- selectedPiece = 1
- elseif param == keys.two then
- selectedPiece = 2
- elseif param == keys.three then
- selectedPiece = 3
- end
- elseif event == "mouse_click" then
- if selectedPiece and nextPieces[selectedPiece] then
- grid[y - 2][math.floor(x / 2)] = true
- end
- elseif event == "terminate" then
- gameOver = true
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Game Over!")
- print("Final Score: " .. score)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment