From 2d0b49bf84c3409d01508b203cb58dd3ded3a818 Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 13 Jan 2019 21:52:26 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/database/hsqldb.own | 17 +++ examples/database/sqlite.own | 19 +++ examples/game/pipes_online.own | 176 +++++++++++++++++++++++++++ examples/network/github_timeline.own | 8 +- 4 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 examples/database/hsqldb.own create mode 100644 examples/database/sqlite.own create mode 100644 examples/game/pipes_online.own diff --git a/examples/database/hsqldb.own b/examples/database/hsqldb.own new file mode 100644 index 0000000..47fb10a --- /dev/null +++ b/examples/database/hsqldb.own @@ -0,0 +1,17 @@ +use ["std", "jdbc"] + +connection = getConnection("jdbc:hsqldb:file:hsql.db", "", "", "org.hsqldb.jdbcDriver") +statement = connection.createStatement() +statement.executeUpdate("drop table if exists cities") +statement.executeUpdate("CREATE TABLE cities (id IDENTITY, name VARCHAR(32))") +statement.executeUpdate("INSERT INTO cities (name) VALUES('Киев')") +statement.executeUpdate("INSERT INTO cities (name) VALUES('Минск')") +statement.executeUpdate("INSERT INTO cities (name) VALUES('Москва')") + +rs = statement.executeQuery("SELECT id, name FROM cities") +while(rs.next()) { + // read the result set + println "name = " + rs.getString("name") + println "id = " + rs.getInt("id") +} +statement.execute("SHUTDOWN") diff --git a/examples/database/sqlite.own b/examples/database/sqlite.own new file mode 100644 index 0000000..670d818 --- /dev/null +++ b/examples/database/sqlite.own @@ -0,0 +1,19 @@ +use ["std", "jdbc"] + +// Example from https://github.com/xerial/sqlite-jdbc + +connection = getConnection("jdbc:sqlite:sample.db") +statement = connection.createStatement() +statement.setQueryTimeout(30) // set timeout to 30 sec. + +statement.executeUpdate("drop table if exists person") +statement.executeUpdate("create table person (id integer, name string)") +statement.executeUpdate("insert into person values(1, 'leo')") +statement.executeUpdate("insert into person values(2, 'yui')") + +rs = statement.executeQuery("select * from person") +while(rs.next()) { + // read the result set + println "name = " + rs.getString("name") + println "id = " + rs.getInt("id") +} diff --git a/examples/game/pipes_online.own b/examples/game/pipes_online.own new file mode 100644 index 0000000..396744e --- /dev/null +++ b/examples/game/pipes_online.own @@ -0,0 +1,176 @@ +use "std" +use "canvas" +use "socket" + +/// --- 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 = [ + {"index": HORIZONTAL, "next": VERTICAL}, + {"index": VERTICAL, "next": HORIZONTAL}, + {"index": LEFT_TO_DOWN, "next": LEFT_TO_UP}, + {"index": LEFT_TO_UP, "next": RIGHT_TO_UP}, + {"index": RIGHT_TO_UP, "next": RIGHT_TO_DOWN}, + {"index": RIGHT_TO_DOWN, "next": LEFT_TO_DOWN}, + {"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) + } + } +} + + +/// --- PIPES BOARD --- +SIZE = 10 + +// Creating game board +board = newarray(SIZE, SIZE) +boardGhost = newarray(SIZE, SIZE) + +def switchCell(x, y) { + board[x][y] = Cells[board[x][y]].next +} +def setGhostCell(x, y) { + boardGhost[x][y] = Cells[boardGhost[x][y]].next +} + + +/// --- PIPES MAIN --- +translateX = 0 translateY = 0 +isGameFinished = false +isWin = false + +/* frect with translate ability */ +def fillRect(x,y,w,h) { + frect(translateX+x, translateY+y, w, h) +} + +WIDTH = 320 HEIGHT = 320 +WINDOW_WIDTH = WIDTH * 2 +window("Pipes Online", WINDOW_WIDTH, HEIGHT) +cellSize = WIDTH / SIZE + +// cursor +curX = 0 curY = 0 +curGhostX = 0 curGhostY = 0 + +// Initialize client +socket = newSocket("http://localhost:6469") +socket.on("gameStart", def(data) { + data = data[0] + for i=0, i 0) { + curX-- + socket.emit("updateCursor", {"x": curX, "y": curY}) + } else if (key == VK_RIGHT && curX < SIZE - 1) { + curX++ + socket.emit("updateCursor", {"x": curX, "y": curY}) + } else if (key == VK_UP && curY > 0) { + curY-- + socket.emit("updateCursor", {"x": curX, "y": curY}) + } else if (key == VK_DOWN && curY < SIZE - 1) { + curY++ + socket.emit("updateCursor", {"x": curX, "y": curY}) + } else if (key == VK_FIRE) { + switchCell(curX, curY) + socket.emit("switchCell", {"x": curX, "y": curY}) + } + else if (key == 48) run = 0 + } + + // background + color(isGameFinished ? (isWin ? #66FF66 : #FF6666) : #FFFFFF) + frect(0, 0, WIDTH, HEIGHT) + color(isGameFinished ? (!isWin ? #66FF66 : #FF6666) : #DDDDDD) + frect(WIDTH, 0, WIDTH, HEIGHT) + // cursor + color(#4444FF) + frect(curX*cellSize, curY*cellSize, cellSize, cellSize) + color(#4040DD) + frect(WIDTH + curGhostX*cellSize, curGhostY*cellSize, cellSize, cellSize) + for (i=0, i