basic display of goban works, playing not yet possible. skeleton for game deletion inserted.

This commit is contained in:
phear 2005-09-12 17:30:02 +00:00
parent 298faf0a92
commit ece81b8695
6 changed files with 72 additions and 14 deletions

15
deletegame.py Normal file
View 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.
"""

View file

@ -19,9 +19,9 @@ def display_game_creation_form(req,sessionid,username):
<p>Player One (Black): %s </p> <p>Player One (Black): %s </p>
<p>Player Two (White): %s </p> <p>Player Two (White): %s </p>
<p>Goban Size: %s fields </p> <p>Goban Size: %s fields </p>
<input type="hidden" name="sessionid" value="%s"><p> <input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="username" value="%s"><p> <input type="hidden" name="username" value="%s">
<input type="submit" name="create" value="create game"></p> <input type="submit" name="create" value="create game">
</form> </form>
""" % (p1data,p2data,gobansize,sessionid,username) """ % (p1data,p2data,gobansize,sessionid,username)
@ -49,7 +49,7 @@ def process_creation_form(req,form):
if gameslot != "": if gameslot != "":
psql.set_game_slot(player,gameslot,gamename) psql.set_game_slot(player,gameslot,gamename)
#TODO:game created, now display game overview form #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. else:#should not happen: no free game slot.
#print error msg #print error msg
req.write("Error: No free game slots for player "+player+"!") req.write("Error: No free game slots for player "+player+"!")

View file

@ -1,8 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
"""
the main file for WebGo.
"""
import sys,string import sys,string
import cgi import cgi
import pickle 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. gets: dictionary containing the layout of the used goban.
returns: string containing the HTML code for a clickable goban. returns: string containing the HTML code for a clickable goban.
@ -27,6 +25,11 @@ def display_goban(goban):
data += '<form method="post">' 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: try:
size = goban["size"] size = goban["size"]
except: except:
@ -85,7 +88,7 @@ def display_goban(goban):
data += hoshifield data += hoshifield
else: else:
data += defaultfield data += defaultfield
data += '</form>' data += '\n</form>'
return data 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. # Print the required header that tells the browser how to render the text.
#(currently done by error logger) #(currently done by error logger)
#print "Content-Type: text/plain\n\n" #print "Content-Type: text/plain\n\n"
@ -142,7 +145,7 @@ def main():
data = helper.header() data = helper.header()
#read goban table from database #read goban table from database
tmplist = psql.read_table("test") tmplist = psql.read_table(gamename)
#make a dictionary out of the list #make a dictionary out of the list
goban = psql.fetchall_list_to_goban_dict(tmplist) goban = psql.fetchall_list_to_goban_dict(tmplist)
#print goban #print goban

View file

@ -55,7 +55,7 @@ def game_overview_form(req,user,sessionid):
tmp += '<input type="radio" name="game" value="%s"> %s<br>\n' % (item,item) tmp += '<input type="radio" name="game" value="%s"> %s<br>\n' % (item,item)
#later write partners name and whether its our turn or not #later write partners name and whether its our turn or not
#data += "Your partner: %s." #data += "Your partner: %s."
counter -= 1 counter -= 1
if tmp == "": #no current games if tmp == "": #no current games
data += "You don't have any running games.\n" data += "You don't have any running games.\n"
else: else:
@ -89,8 +89,8 @@ def login_form():
""" """
print welcome message and html form. print welcome message and html form.
""" """
data = helper.header() + """
data = helper.header() + """
<form method="post"> <form method="post">
<p>Name:<br> <p>Name:<br>
<input name="name" size="40"></p> <input name="name" size="40"></p>
@ -110,6 +110,7 @@ def login_form():
def main(req,form): def main(req,form):
req.write((str(form.keys())+"<hr>"))
if "sessionid" not in form.keys(): if "sessionid" not in form.keys():
req.write(login_form()) req.write(login_form())
elif ("create" in form.keys()) and ("username" in form.keys()): elif ("create" in form.keys()) and ("username" in form.keys()):

12
main.py
View file

@ -7,7 +7,7 @@ modified a little
from mod_python import * from mod_python import *
import sys, traceback import sys, traceback,string
import init_webgo import init_webgo
DEBUG = 1 DEBUG = 1
@ -26,9 +26,19 @@ def handler(req):
#load form, then delegate request #load form, then delegate request
form = util.FieldStorage(req) form = util.FieldStorage(req)
foundx = False
for item in form.keys():
if string.find(item,").x") > 0:
foundx = True
if "create" in form.keys(): if "create" in form.keys():
gamecreation = apache.import_module("gamecreation") gamecreation = apache.import_module("gamecreation")
gamecreation.main(req,form) 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: else:
#call login.py #call login.py
login = apache.import_module("login") login = apache.import_module("login")

29
playgame.py Normal file
View 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)