p.s. the code to add the frames looks like this.
n.b. presumably there'd be a Frame class and the passing in the 
rolls would look more like "frame roll1: roll1" than
"frame at: 1 put: roll1", .... in fact there's no story calling
out the need for this, nor tests; I just wanted to scratch out
the code for a moment to see what it would look like ...

  frames := OrderedCollection new.
  10 timesRepeat: [  | roll1 roll2  open spare strike frame |
    frame := #( 0 0 0 ).
    roll1 := rolls at: frameStart .  
    roll2 := rolls at: frameStart + 1.
    strike := roll1 = 10.
    spare := (roll1 < 10)   and:  (roll1 + roll2 = 10).
    open := roll1 + roll2 < 10.

    frame at: 1 put: roll1. 
    frame at: 2 put: roll2.

    ( strike or: spare ) ifTrue: [ 
      frame at: 3 put: (rolls at: frameStart + 2) ].

    ( strike ) ifTrue: [ frameStart := frameStart + 1 ].
    ( open or: spare ) 
      ifTrue: [ frameStart := frameStart + 2 ].

    frames addLast: frame.
  ].


or with Frame(s)... 


  frames := OrderedCollection new.
  10 timesRepeat: [  | roll1 roll2  open spare strike frame |
    frame := Frame new.
    roll1 := rolls at: frameStart .  
    roll2 := rolls at: frameStart + 1.
    strike := roll1 = 10.
    spare := (roll1 < 10)   and:  (roll1 + roll2 = 10).
    open := roll1 + roll2 < 10.

    frame roll1: roll1. 
    frame roll2: roll2.

    ( strike or: spare ) ifTrue: [ 
      frame roll3: (rolls at: frameStart + 2) ].

    ( strike ) ifTrue: [ frameStart := frameStart + 1 ].
    ( open or: spare ) 
      ifTrue: [ frameStart := frameStart + 2 ].

    frames addLast: frame.
  ].








To Post a message, send it to:   [EMAIL PROTECTED]

To Unsubscribe, send a blank message to: [EMAIL PROTECTED]

ad-free courtesy of objectmentor.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/extremeprogramming/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to