Re: [Tutor] Better flow for this?

2014-02-12 Thread spir

On 02/12/2014 03:06 AM, R. Alan Monroe wrote:

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)


Also explain the logic in plain words. Else, we can only guess.

d
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Better flow for this?

2014-02-12 Thread spir

On 02/12/2014 10:51 AM, spir wrote:

On 02/12/2014 03:06 AM, R. Alan Monroe wrote:

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)


Also explain the logic in plain words. Else, we can only guess.

d


This will also help you and check the design.

d
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Better flow for this?

2014-02-12 Thread R. Alan Monroe
 Also explain the logic in plain words. Else, we can only guess.

Were the comments not enough? 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


Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Better flow for this?

2014-02-12 Thread R. Alan Monroe
 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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Better flow for this?

2014-02-11 Thread R. Alan Monroe
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 breaks
   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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Better flow for this?

2014-02-11 Thread Alan Gauld

On 12/02/14 02:06, R. Alan Monroe wrote:

Based on a very quick look, its 2:36am!!


(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:


You don;t need if playing since the false conditions both break.
So you don;t need the try either...



 for each thing that shoots at you:
 if dead:
 raise deaderror #this in particular seems horrible
 except deaderror: #since you can't nest breaks
playing=false
break


And you don;t need the error, just make playing false and break



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


Again no need to check playing, you keep breaking...


 if dead:
 playing=false
 break


Not sure if you need this or not...



 #phase 4 - you drop bombs if you're over a target, you can't die here
game over, print score
-


HTH,


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor