"basic multiuser gameplay possible. Milestone m6 reached!
This commit is contained in:
parent
e7e9c72e54
commit
8f5568bcd0
4 changed files with 72 additions and 24 deletions
65
playgame.py
65
playgame.py
|
@ -1,4 +1,39 @@
|
|||
import goban,helper,psql
|
||||
import string
|
||||
|
||||
def is_my_turn(req,form,gobandict):
|
||||
"""
|
||||
gets request and util.FiedStorage form.
|
||||
check wether or not the current this is the players turn.
|
||||
return true or false.
|
||||
"""
|
||||
|
||||
#INFO: player1 is black,player2 is white. black starts the game.
|
||||
me = form["username"]
|
||||
player1 = gobandict["player1"]
|
||||
player2 = gobandict["player2"]
|
||||
|
||||
#get turn_number.
|
||||
turn_number = gobandict["turn_number"]
|
||||
#if turn_number modulo 2 == 0: are we player two?
|
||||
# yes:return True, else return False
|
||||
if turn_number % 2 == 0:
|
||||
if me == player2:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
#else:are we player1?
|
||||
# yes:return True, else return False
|
||||
else:
|
||||
if me == player1:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def main(req,form):
|
||||
"""
|
||||
|
@ -11,25 +46,41 @@ def main(req,form):
|
|||
except:
|
||||
gamename = ""
|
||||
if gamename != "":
|
||||
#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 if user has already clicked onto a field:
|
||||
foundx = False
|
||||
for item in form.keys():
|
||||
if string.find(item,").x") > 0:
|
||||
foundx = True
|
||||
if foundx:
|
||||
if is_my_turn(req,form,gobandict):
|
||||
(gobandict,retstring) = goban.process_form(req,form,gobandict)
|
||||
else:
|
||||
pass
|
||||
|
||||
#do stuff
|
||||
data = helper.header()
|
||||
|
||||
|
||||
data += "Turn number: "+str(gobandict["turn_number"])+". "
|
||||
|
||||
#check whether its our turn
|
||||
#if yes: print 'your move' and display goban and process move
|
||||
#if not: print '...s move' and display goban.
|
||||
if is_my_turn(req,form,gobandict):
|
||||
data += ("Its your turn.<br>")
|
||||
else:
|
||||
data+= ("This is not your turn. Look, but don't touch ;)<br>")
|
||||
|
||||
|
||||
|
||||
#print goban
|
||||
data += goban.display_goban(gobandict,req,form)
|
||||
data += helper.footer()
|
||||
req.write(data)
|
||||
|
||||
else:
|
||||
req.write('Error: You have to select a game to play it!')
|
||||
req.write('Error: You have to select a game to play it!')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue