Skip to content

Commit

Permalink
join is working :)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackbenn committed Jan 21, 2019
1 parent 58d9884 commit 878e20f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
4 changes: 3 additions & 1 deletion gengo/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def join():
def game():
game_name = request.args.get('game_name')
board_size = int(request.args.get('board_size'))
action = request.args.get('action')
return render_template('game.html',
game_name=game_name,
board_size=board_size)
board_size=board_size,
action=action)
19 changes: 14 additions & 5 deletions gengo/app/static/js/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ def on_open(evt):
logging.info("Opened connection; creating initial board")
global game_name
global board_size
game_name = document.select('div#rules')[0].attrs['game_name']
board_size = int(document.select('div#rules')[0].attrs['board_size'])
ws.send("new game")
ws.send(game_name)
ws.send(str(board_size))
div_rules = document.select('div#rules')[0]
game_name = div_rules.attrs['game_name']
board_size = int(div_rules.attrs['board_size'])
action = div_rules.attrs['action']
print("action = ", action)
if action == "new":
ws.send("new game")
ws.send(game_name)
ws.send(str(board_size))
elif action == "join":
ws.send("join game")
ws.send(game_name)
else:
logging.error(f"Invalid action {action}")

logging.debug("Binding events to board squares and buttons")
for x in range(board_size):
Expand Down
14 changes: 10 additions & 4 deletions gengo/app/static/js/list_games.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
from browser import document, alert, svg
from browser import websocket
import browser
from browser.html import LI
from browser.html import LI, A
import logging

import json


def on_message(evt):

games = json.loads(evt.data)
game_list = document['games']
for game in games:
li = LI(game)
for game_data in games:
logging.info("Game data:", game_data)
game_name = game_data["game_name"]
board_size = int(game_data["board_size"])
li = LI()
a = A(game_name)
a.attrs["href"] = f"/game?game_name={game_name}&board_size={board_size}&action=join"
li <= a
game_list <= li


Expand Down
2 changes: 1 addition & 1 deletion gengo/app/templates/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="{{url_for('static', filename='js/board.py')}}"
type="text/python"></script>

<div id="rules" game_name={{game_name}} board_size={{board_size}}></div>
<div id="rules" game_name={{game_name}} board_size={{board_size}} action={{action}}></div>
<div style="float:left">
<svg width="750" height="750" id="svg">
<rect x="{{0}}" y="{{0}}"
Expand Down
1 change: 1 addition & 0 deletions gengo/app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ <h1>Start a new game</h1>
<form action="/game" method="get">
Game name:<input type="text" name="game_name"/><br/>
Board Size:<input type="text" name="board_size"/><br/>
<input type="hidden" name="action" value="new"/><br/>
<input type="submit" value="submit"/>

</form>
Expand Down
1 change: 1 addition & 0 deletions gengo/app/templates/join.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
type="text/python"></script>

<h1>Join a game</h1>
<h3>Games to join</h3>
<ul id="games"></ul>

<form action="/game" method="get">
Expand Down
2 changes: 2 additions & 0 deletions gengo/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from ..src.gengo import Board, GridBoard, Rules, Player, Game, InvalidMove

logging.basicConfig(level=logging.DEBUG)

games = {}


Expand Down

0 comments on commit 878e20f

Please sign in to comment.