use std, canvas /// --- PIPES CELL --- CELL_START = 0 HORIZONTAL = 0 VERTICAL = 1 LEFT_TO_DOWN = 2 LEFT_TO_UP = 3 RIGHT_TO_UP = 4 RIGHT_TO_DOWN = 5 CROSS = 6 CELL_LAST = 6 Cells = [ {"support": [1, 1, 0, 0], "index": HORIZONTAL, "next": VERTICAL}, {"support": [0, 0, 1, 1], "index": VERTICAL, "next": HORIZONTAL}, {"support": [1, 0, 0, 1], "index": LEFT_TO_DOWN, "next": LEFT_TO_UP}, {"support": [1, 0, 1, 0], "index": LEFT_TO_UP, "next": RIGHT_TO_UP}, {"support": [0, 1, 1, 0], "index": RIGHT_TO_UP, "next": RIGHT_TO_DOWN}, {"support": [0, 1, 0, 1], "index": RIGHT_TO_DOWN, "next": LEFT_TO_DOWN}, {"support": [1, 1, 1, 1], "index": CROSS, "next": CROSS} ] def draw(v, cellSize) { c2 = cellSize / 2 match v { case HORIZONTAL : fillRect(0, c2 - 2, cellSize, 4) case VERTICAL : fillRect(c2 - 2, 0, 4, cellSize) case LEFT_TO_DOWN : { fillRect(0, c2 - 2, c2, 4) fillRect(c2 - 2, c2 - 2, 4, c2 + 2) } case LEFT_TO_UP : { fillRect(0, c2 - 2, c2, 4) fillRect(c2 - 2, 0, 4, c2 + 2) } case RIGHT_TO_UP : { fillRect(c2 - 2, c2 - 2, c2 + 2, 4) fillRect(c2 - 2, 0, 4, c2 + 2) } case RIGHT_TO_DOWN : { fillRect(c2 - 2, c2 - 2, c2 + 2, 4) fillRect(c2 - 2, c2 - 2, 4, c2 + 2) } case CROSS : { fillRect(c2 - 2, 0, 4, cellSize) fillRect(0, c2 - 2, cellSize, 4) } } } def supportLeft(v) = Cells[v].support[0] def supportRight(v) = Cells[v].support[1] def supportUp(v) = Cells[v].support[2] def supportDown(v) = Cells[v].support[3] /// --- PIPES BOARD --- SIZE = 10 // Creating game board board = newarray(SIZE, SIZE) def createBoard() { for i=0, i 0) && (supportRight(board[curX - 1][curY])) ) { if (isConnected(curX - 1, curY, visited)) return true } if ( supportRight(current) && (curX < SIZE - 1) && (supportLeft(board[curX + 1][curY])) ) { if (isConnected(curX + 1, curY, visited)) return true } if ( supportUp(current) && (curY > 0) && (supportDown(board[curX][curY - 1])) ) { if (isConnected(curX, curY - 1, visited)) return true } if ( supportDown(current) && (curY < SIZE - 1) && (supportUp(board[curX][curY + 1])) ) { if (isConnected(curX, curY + 1, visited)) return true } return false } /// --- PIPES MAIN --- translateX = 0 translateY = 0 /* frect with translate ability */ def fillRect(x,y,w,h) { frect(translateX+x, translateY+y, w, h) } // JAVA ME // showcanvas() // JAVA SE WIDTH = 480 HEIGHT = 480 window("Pipes", WIDTH, HEIGHT) cellSize = WIDTH / SIZE createBoard() // cursor curX = 0 curY = 0 run = 1 while run { //key = gameaction(keypressed()) key = keypressed() if (key == VK_LEFT && curX > 0) curX-- else if (key == VK_RIGHT && curX < SIZE - 1) curX++ else if (key == VK_UP && curY > 0) curY-- else if (key == VK_DOWN && curY < SIZE - 1) curY++ else if key == VK_FIRE switchCell(curX,curY) else if key == 48 run = 0 // background color(isFinished() ? #00FF00 : #FFFFFF) frect(0,0,WIDTH,HEIGHT) // cursor color(#4444FF) frect(curX*cellSize, curY*cellSize, cellSize, cellSize) for (i=0, i