diff --git a/Go b/Go new file mode 100755 index 0000000..b68ba69 Binary files /dev/null and b/Go differ diff --git a/game_saves.db b/game_saves.db new file mode 100644 index 0000000..a90b1dd Binary files /dev/null and b/game_saves.db differ diff --git a/public/css/main.css b/public/css/main.css index 8f29cab..ecf9ea8 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -31,7 +31,7 @@ body { .board-cell { display: inline-block; position: relative; - padding: 5.55556%; } + padding: 5.5555555556%; } .board-cell .overlay { position: absolute; box-sizing: border-box; @@ -42,11 +42,11 @@ body { border-radius: 50%; transition: background-color .25s; } .board-cell.small { - padding: 5.55556%; } + padding: 5.5555555556%; } .board-cell.medium { - padding: 3.84615%; } + padding: 3.8461538462%; } .board-cell.large { - padding: 2.63158%; } + padding: 2.6315789474%; } .black-cell .overlay { background-color: black; } diff --git a/src/Go.cr b/src/Go.cr index b526c05..7d42834 100644 --- a/src/Go.cr +++ b/src/Go.cr @@ -13,30 +13,47 @@ GAME_CACHE = {} of String => Go::Game def save_game(db, gameid, game) puts "Saving" puts game.encode - turn, size, board = game.encode + turn, size, white_pass, black_pass, board = game.encode DB.open "sqlite3:./game_saves.db" do |db| - # When using the pg driver, use $1, $2, etc. instead of ? - #db.exec "create table game_saves (gameid integer, turn integer, size integer, board string )" - db.exec "insert into game_saves values (?, ?, ?, ?)", gameid, turn, size, board + # TODO: Table creation function + # Creates table + db.exec "create table game_saves (gameid integer, turn integer, size integer, white_pass string, black_pass string, board string )" + db.exec "insert into game_saves values (?, ?, ?, ?, ?, ?)", gameid, turn.value, size, white_pass, black_pass, board end end def query_game(db, gameid) : Go::Game? + size = Go::Size::Small + white_pass = "" + black_pass = "" + board = "" + turn = "" DB.open "sqlite3:./game_saves.db" do |db| - puts "contacts:" - db.query "select gameid, turn, size, board from game_saves order by gameid desc" do |rs| + puts "Saves:" + db.query "select gameid, turn, size, white_pass, black_pass, board from game_saves where gameid = #{gameid}" do |rs| rs.each do - puts rs.size - #puts "#{rs.read(Int32)} (#{rs.read(Int32)}) (#{rs.read(Int32)}) (#{rs.read(String)})" + id = rs.read(Int32) + + turn = rs.read(Int32) + size = rs.read(Int32) + white_pass = rs.read(String) + black_pass = rs.read(String) + board = rs.read(String) + puts turn end - puts rs - # puts "#{rs.column_name(0)} (#{rs.column_name(1)})" - #rs.each do - #puts "#{rs.read(String)} (#{rs.read(Int32)})" - #end end end + + game = Go::Game.new() + game.size = Go::Size.from_value(size) + game.white_pass = white_pass + game.black_pass = black_pass + # Todo: Parse game board string + # game.board = + game.turn = Go::Color.from_value(turn) + # Todo: Fix return type mismatch + # return game return nil end diff --git a/src/Go/Game.cr b/src/Go/Game.cr index 546bb6f..0f46560 100644 --- a/src/Go/Game.cr +++ b/src/Go/Game.cr @@ -20,6 +20,14 @@ module Go property turn : Color property sockets : Array(HTTP::WebSocket) + def initialize() + @size = Size::Small + @white_pass = "" + @black_pass = "" + @board = Board.new + @turn = Color::Black + @sockets = [] of HTTP::WebSocket + end def initialize(size : Size, @black_pass, @white_pass) @size = size @board = Board.new @@ -133,7 +141,7 @@ module Go end def encode - { @turn.to_s, @size.value, board_string(@board) } + { @turn, @size.value, @white_pass.to_s, @black_pass.to_s, board_string(@board) } end end end