Lab notes for Fri, Mar 13. So from yesterday we have One.py, Two.py, Store.py and main. Also Data.py The code is listed at: http://www.cs.indiana.edu/classes/a348/spr2009/0312.txt We create a Three.py: -bash-3.2$ cat Three.py def show(): print """
This is screen Three.

""" -bash-3.2$ And main needs to be updated: -bash-3.2$ cat main #!/usr/bin/python import One, Data, Two, Store, Three # note Three print "Content-type: text/html\n\n"; if Data.source == "One": if Data.roll: Two.show() else: Store.show() elif Data.source == "Two": # added lines if Data.roll: # Three.show() # else: # Store.show() # else: One.show() -bash-3.2$ If we include all the transitions and screens we have: -bash-3.2$ cat main #!/usr/bin/python import One, Data, Two, Store, Three print "Content-type: text/html\n\n"; if Data.source == "One": if Data.roll: Two.show() else: Store.show() elif Data.source == "Two": if Data.roll: Three.show() else: Store.show() elif Data.source == "Three": Store.show() else: # happens when source is "Store" or isn't at all One.show() -bash-3.2$ Now we need to choose the next step. We're done with the basic transition layout: http://www.cs.indiana.edu/classes/a348/spr2009/diagram.jpg And I choose to implement the maintenance of the history table. #------------------------------------------------------------------------- #!/usr/bin/python import One, Data, Two, Store, Three print "Content-type: text/html\n\n"; if Data.source == "One": if Data.roll: Two.show() else: Store.show() elif Data.source == "Two": if Data.roll: Three.show() else: Store.show() elif Data.source == "Three": Store.show() elif Data.source == "Store": Store.finalize() One.show() else: # happens when source is wrong or doesn't exist at all One.show() #------------------------------------------------------------------------- import Data def show(): print """
This is screen One.

""" % Data.history #------------------------------------------------------------------------- import Data def show(): print """
This is screen Two.

""" % Data.history #------------------------------------------------------------------------- import Data def show(): print """
This is screen Three.

""" % Data.history #------------------------------------------------------------------------- import Data def show(): print """
Store your combination as:

Click to start new game.

""" % (Data.selection(), Data.history) def finalize(): combination = "" # we ignore it for now Data.history += Data.choice + ":" + combination + "," #------------------------------------------------------------------------- import cgi q = cgi.FieldStorage() (source, roll, history, choice) = ("", "", "", "") if (q.has_key("source")): source = q["source"].value if (q.has_key("roll")): roll = q["roll"].value if (q.has_key("history")): history = q["history"].value if (q.has_key("choice")): choice = q["choice"].value def selection(): entries = ("ones", "twos", "threes", "fives", "chance", "yahtzee") result = "" for entry in entries: temp = entry + ":" if temp in history: pass else: result += "