[Tutor] Better flow for this?

R. Alan Monroe amonroe at columbus.rr.com
Wed Feb 12 17:20:15 CET 2014


> You keep taking turns until you get home or die. Each turn has 4
> phases.

> while playing:
>     #phase 1 - fly every turn, you might die
>     #phase 2 - stuff shoots at you every turn, you might die
>     #phase 3 - may or may not get an event card, with certain cards you might die
>     #phase 4 - you drop bombs if you're over a target, you can't die here
> game over, print score

Thinking about this this morning, I struck upon this idea, which seems
much cleaner:

------
def phase1():
       #do stuff
       return boolSurvived

def phase2():
       #do stuff
       return boolSurvived

def phase2():
       #do stuff
       return boolSurvived

def phase4():
       #do stuff

while playing:
    #phase 1 - fly every turn, you might die
    playing = phase1()

    #phase 2 - stuff shoots at you every turn, you might die
    if playing:
        playing=phase2()

    #phase 3 - may or may not get an event card, with certain cards you might die
    if playing:
        playing=phase3()

    #phase 4 - you drop bombs if you're over a target, you can't die here
    if playing:
        phase4()

game over, print score
------


Alan




More information about the Tutor mailing list