basic display of goban works, playing not yet possible. skeleton for game deletion inserted.
This commit is contained in:
parent
298faf0a92
commit
ece81b8695
6 changed files with 72 additions and 14 deletions
15
deletegame.py
Normal file
15
deletegame.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import psql
|
||||
|
||||
def delete_game(gamename,username):
|
||||
"""
|
||||
get name of game and name of user.
|
||||
remove game from game slot of user.
|
||||
"""
|
||||
|
||||
|
||||
def main(gamename,req,form):
|
||||
"""
|
||||
get the name of a game,request,util.FieldStorage.
|
||||
manage the removal of game from game slots of players and
|
||||
delete game from database.
|
||||
"""
|
|
@ -19,9 +19,9 @@ def display_game_creation_form(req,sessionid,username):
|
|||
<p>Player One (Black): %s </p>
|
||||
<p>Player Two (White): %s </p>
|
||||
<p>Goban Size: %s fields </p>
|
||||
<input type="hidden" name="sessionid" value="%s"><p>
|
||||
<input type="hidden" name="username" value="%s"><p>
|
||||
<input type="submit" name="create" value="create game"></p>
|
||||
<input type="hidden" name="sessionid" value="%s">
|
||||
<input type="hidden" name="username" value="%s">
|
||||
<input type="submit" name="create" value="create game">
|
||||
</form>
|
||||
""" % (p1data,p2data,gobansize,sessionid,username)
|
||||
|
||||
|
@ -49,7 +49,7 @@ def process_creation_form(req,form):
|
|||
if gameslot != "":
|
||||
psql.set_game_slot(player,gameslot,gamename)
|
||||
#TODO:game created, now display game overview form
|
||||
game_overview_form(req,username,form["sessionid"])
|
||||
login.game_overview_form(req,username,form["sessionid"])
|
||||
else:#should not happen: no free game slot.
|
||||
#print error msg
|
||||
req.write("Error: No free game slots for player "+player+"!")
|
||||
|
|
17
goban.py
17
goban.py
|
@ -1,8 +1,6 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
the main file for WebGo.
|
||||
"""
|
||||
|
||||
import sys,string
|
||||
import cgi
|
||||
import pickle
|
||||
|
@ -14,7 +12,7 @@ picklefile = "goban.pickledump"
|
|||
|
||||
|
||||
|
||||
def display_goban(goban):
|
||||
def display_goban(goban,req,form):
|
||||
"""
|
||||
gets: dictionary containing the layout of the used goban.
|
||||
returns: string containing the HTML code for a clickable goban.
|
||||
|
@ -27,6 +25,11 @@ def display_goban(goban):
|
|||
|
||||
|
||||
data += '<form method="post">'
|
||||
data += """<input type="hidden" name="sessionid" value="%s">
|
||||
<input type="hidden" name="username" value="%s">
|
||||
<input type="hidden" name="game" value="%s">
|
||||
""" % (form["sessionid"],form["username"],form["game"])
|
||||
|
||||
try:
|
||||
size = goban["size"]
|
||||
except:
|
||||
|
@ -85,7 +88,7 @@ def display_goban(goban):
|
|||
data += hoshifield
|
||||
else:
|
||||
data += defaultfield
|
||||
data += '</form>'
|
||||
data += '\n</form>'
|
||||
return data
|
||||
|
||||
|
||||
|
@ -133,7 +136,7 @@ def set_stone(goban, position):
|
|||
|
||||
###############################################################################
|
||||
|
||||
def main():
|
||||
def main(gamename):
|
||||
# Print the required header that tells the browser how to render the text.
|
||||
#(currently done by error logger)
|
||||
#print "Content-Type: text/plain\n\n"
|
||||
|
@ -142,7 +145,7 @@ def main():
|
|||
data = helper.header()
|
||||
|
||||
#read goban table from database
|
||||
tmplist = psql.read_table("test")
|
||||
tmplist = psql.read_table(gamename)
|
||||
#make a dictionary out of the list
|
||||
goban = psql.fetchall_list_to_goban_dict(tmplist)
|
||||
#print goban
|
||||
|
|
5
login.py
5
login.py
|
@ -55,7 +55,7 @@ def game_overview_form(req,user,sessionid):
|
|||
tmp += '<input type="radio" name="game" value="%s"> %s<br>\n' % (item,item)
|
||||
#later write partners name and whether its our turn or not
|
||||
#data += "Your partner: %s."
|
||||
counter -= 1
|
||||
counter -= 1
|
||||
if tmp == "": #no current games
|
||||
data += "You don't have any running games.\n"
|
||||
else:
|
||||
|
@ -89,8 +89,8 @@ def login_form():
|
|||
"""
|
||||
print welcome message and html form.
|
||||
"""
|
||||
data = helper.header() + """
|
||||
|
||||
data = helper.header() + """
|
||||
<form method="post">
|
||||
<p>Name:<br>
|
||||
<input name="name" size="40"></p>
|
||||
|
@ -110,6 +110,7 @@ def login_form():
|
|||
|
||||
|
||||
def main(req,form):
|
||||
req.write((str(form.keys())+"<hr>"))
|
||||
if "sessionid" not in form.keys():
|
||||
req.write(login_form())
|
||||
elif ("create" in form.keys()) and ("username" in form.keys()):
|
||||
|
|
12
main.py
12
main.py
|
@ -7,7 +7,7 @@ modified a little
|
|||
|
||||
from mod_python import *
|
||||
|
||||
import sys, traceback
|
||||
import sys, traceback,string
|
||||
import init_webgo
|
||||
|
||||
DEBUG = 1
|
||||
|
@ -26,9 +26,19 @@ def handler(req):
|
|||
|
||||
#load form, then delegate request
|
||||
form = util.FieldStorage(req)
|
||||
foundx = False
|
||||
for item in form.keys():
|
||||
if string.find(item,").x") > 0:
|
||||
foundx = True
|
||||
if "create" in form.keys():
|
||||
gamecreation = apache.import_module("gamecreation")
|
||||
gamecreation.main(req,form)
|
||||
elif "delete" in form.keys():
|
||||
deletegame = apache.import_module("deletegame")
|
||||
deletegame.main(req,form)
|
||||
elif ("play" in form.keys()) or foundx:
|
||||
playgame = apache.import_module("playgame")
|
||||
playgame.main(req,form)
|
||||
else:
|
||||
#call login.py
|
||||
login = apache.import_module("login")
|
||||
|
|
29
playgame.py
Normal file
29
playgame.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import goban,helper,psql
|
||||
|
||||
def main(req,form):
|
||||
"""
|
||||
display selected goban and manage user input.
|
||||
"""
|
||||
req.write(str(form.keys())+"<hr>")
|
||||
|
||||
gamename = form["game"]
|
||||
#do stuff
|
||||
data = helper.header()
|
||||
|
||||
#read goban table from database
|
||||
tmplist = psql.read_table(gamename)
|
||||
#make a dictionary out of the list
|
||||
gobandict = psql.fetchall_list_to_goban_dict(tmplist)
|
||||
#print goban
|
||||
#data += "<p> Turn number: %s, %s Player's Move.</p>" % (gobandict["turn_number"],("White","Black")[gobandict["turn_number"] % 2]) #eleet ;>
|
||||
|
||||
#check whether its our turn
|
||||
#if yes: print 'your move' and display goban and process move
|
||||
#if not: print '...s move' and display goban.
|
||||
|
||||
|
||||
|
||||
data += goban.display_goban(gobandict,req,form)
|
||||
data += helper.footer()
|
||||
req.write(data)
|
||||
|
Loading…
Reference in a new issue