[Tutor] Better flow for this?

R. Alan Monroe amonroe at columbus.rr.com
Wed Feb 12 03:06:39 CET 2014


I started on an implementation of a solitaire board game simulating a
B52 bombing run ( http://victorypointgames.com/details.php?prodId=119
). It seems like there ought to be a better way to structure this
program flow, but it's escaping me at the moment.

(pseudo code)
-----
playing=True
while playing:
    #phase 1 - fly every turn, you might die
    if dead:
        playing=false
        break
    if you make it home intact:
        playing=false
        break
    #phase 2 - stuff shoots at you every turn, you might die
    if playing:
        try:
            for each thing that shoots at you:
                if dead:
                    raise deaderror #this in particular seems horrible
        except deaderror:         #since you can't nest "break"s
           playing=false
           break
    #phase 3 - may or may not get an event card, with certain cards you might die
    if playing:
        #stuff
        if dead:
            playing=false
            break
    #phase 4 - you drop bombs if you're over a target, you can't die here
game over, print score
-----


Alan



More information about the Tutor mailing list