roundingGame's Code

Created by: shr

world

Events

When the world starts
Do:
world.my first method


When is clicked on lever
Do:
world.setLevel


When is clicked on StartButton
Do:
world.playGame


When is clicked on ones
Do:
world.checkRound ObjectClicked = ones


When is clicked on tens
Do:
world.checkPlaceValue ObjectClicked = tens


When is clicked on hundreds
Do:
world.checkPlaceValue ObjectClicked = hundreds


When is clicked on thousands
Do:
world.checkPlaceValue ObjectClicked = thousands


When is clicked on ten thousands
Do:
world.checkPlaceValue ObjectClicked = ten thousands


When is clicked on hundred thousands
Do:
world.checkPlaceValue ObjectClicked = hundred thousands


When is clicked on millions
Do:
world.checkPlaceValue ObjectClicked = millions


When is clicked on ten millions
Do:
world.checkPlaceValue ObjectClicked = ten millions


When is clicked on hundred millions
Do:
world.checkPlaceValue ObjectClicked = hundred millions


When is clicked on upArrow
Do:
world.checkRound ObjectClicked = upArrow


When is clicked on dot
Do:
world.checkRound ObjectClicked = dot


When is clicked on end
Do:
world.finishGame


Methods

  world.my first method ( )
    No variables
       camera set point of view to intro
  // Go ahead and play the world
  // choose the level you want to play and click on the start button


  world.setLevel ( )
    No variables
       // sets the display and the world variable to the selected level
  If ( world.Level == 1 )
       Do together
       lever.mount.handle turn forward 0.1 revolutions
  world.Level set value to 2
  LevelText set text to 2
  numberText set text to 100,000
  Else
    If ( world.Level == 2 )
       Do together
       lever.mount.handle turn forward 0.1 revolutions
  world.Level set value to 3
  LevelText set text to 3
  numberText set text to 100,000,000
  Else
    Do together
       lever.mount.handle turn backward 0.2 revolutions
  world.Level set value to 1
  LevelText set text to 1
  numberText set text to 100


  world.playGame ( )
    No variables
       // starts when the button is clicked
  camera set point of view to secondStart
  world.setNumber
  world.setRandomNumber
  If ( husky.isSitting == false )
       world.HuskyEnter
  Else
  Do Nothing
  // set the rounding place for level of play and wait for user event
  If ( world.Level == 1 )
       world.SetRoundPlaceForLevel1
  Else
    If ( world.Level == 2 )
       world.setRoundPlaceForLevel2
  Else
    world.setRoundPlaceForLevel3


  world.setNumber ( )
    No variables
       // set the opacity for the correct digets to be showing or not showing
  Do together
       ones set opacity to 1 (100%) duration = 0 seconds
  tens set opacity to 1 (100%) duration = 0 seconds
  hundreds set opacity to 1 (100%) duration = 0 seconds
  If ( world.Level > 1 )
       Do together
       thousands set opacity to 1 (100%) duration = 0 seconds
  ten thousands set opacity to 1 (100%) duration = 0 seconds
  hundred thousands set opacity to 1 (100%) duration = 0 seconds
  If ( world.Level > 2 )
       Do together
       millions set opacity to 1 (100%) duration = 0 seconds
  ten millions set opacity to 1 (100%) duration = 0 seconds
  hundred millions set opacity to 1 (100%) duration = 0 seconds
  millionsComma set opacity to 1 (100%) duration = 0 seconds
  Else
  Do Nothing
  Else
  Do Nothing
  If ( world.Level <= 2 )
       Do together
       ten millions set opacity to 0 (0%)
  hundred millions set opacity to 0 (0%)
  millions set opacity to 0 (0%)
  millionsComma set opacity to 0 (0%)
  If ( world.Level == 1 )
       Do together
       thousandsComma set opacity to 0 (0%)
  thousands set opacity to 0 (0%)
  ten thousands set opacity to 0 (0%)
  hundred thousands set opacity to 0 (0%)
  Else
  Do Nothing
  Else
  Do Nothing


  world.setRandomNumber ( )
    RandomSize = 1 , size = 10 , Zero = 0
       // Determines the random number and displays each didgit
  If ( world.Level == 1 )
       RandomSize set value to ( random number integerOnly = true minimum = 10 maximum = 1000 )
  Else
    If ( world.Level == 2 )
       RandomSize set value to ( 10 raised to the ( random number minimum = 2 maximum = 6 ) power )
  Else
    RandomSize set value to ( 10 raised to the ( random number minimum = 3 maximum = 9 ) power )
  // select random numbers based on the size
  Loop index from 0 up to (but not including) 11 times incrementing by 1
       If ( RandomSize >= size )
       set item index to ( random number integerOnly = true maximum = 10 ) in world.PlaceValues duration = 0 seconds
  Else
    If ( ( ( RandomSize * 10 ) ) >= size )
       // Make sure first number is not 0 or 9
  set item index to ( random number integerOnly = true maximum = 9 minimum = 1 ) in world.PlaceValues duration = 0 seconds
  Else
    set item index to Zero in world.PlaceValues duration = 0 seconds
  size set value to ( ( size * 10 ) )
  // hide upper numbers
  world.setNumber
  If ( 100000000 > RandomSize )
       hundred millions set opacity to 0 (0%) duration = 0 seconds
  If ( 10000000 > RandomSize )
       ten millions set opacity to 0 (0%) duration = 0 seconds
  If ( 1000000 > RandomSize )
       millions set opacity to 0 (0%) duration = 0 seconds
  millionsComma set opacity to 0 (0%) duration = 0 seconds
  If ( 100000 > RandomSize )
       hundred thousands set opacity to 0 (0%) duration = 0 seconds
  If ( 10000 > RandomSize )
       ten thousands set opacity to 0 (0%) duration = 0 seconds
  If ( 1000 > RandomSize )
       thousands set opacity to 0 (0%) duration = 0 seconds
  If ( 100 > RandomSize )
       hundreds set opacity to 0 (0%) duration = 0 seconds
  Else
  Do Nothing
  Else
  Do Nothing
  Else
  Do Nothing
  Else
  Do Nothing
  Else
  Do Nothing
  Else
  Do Nothing
  Else
  Do Nothing
  world.displayNumbers


  world.SetRoundPlaceForLevel1 ( )
    currentPlace = 11 , place = default string
       // Determines the rounding place for level 1
  // find the size of the random number
  While ( ( item currentPlace from world.PlaceValues ) == 0 )
       decrement currentPlace by 1
  // determine what rounding place should be selected
  If ( currentPlace == 2 )
       If ( choose true 0.5 (50%) of the time )
       world.currentRoundPlace set value to tens
  place set value to ten
  Else
    world.currentRoundPlace set value to hundreds
  place set value to hundred
  Else
    world.currentRoundPlace set value to tens
  place set value to ten
  husky.body-front.neck.head say ( ( Round This number to the nearest joined with place ) joined with . ) duration = 2 seconds
  husky.body-front.neck.head say ( ( Click on the number in the joined with place ) joined with s position. ) duration = 2 seconds


  world.checkPlaceValue ( [Obj] ObjectClicked)
    No variables
       // checks if the user selected the correct didgit
  Do together
       upArrow set opacity to 1 (100%)
  dot set opacity to 1 (100%)
  If ( ObjectClicked == world.currentRoundPlace )
       arrowVehicle move to ObjectClicked
  world.UpOrDown
  Else
    husky.body-front.neck.head say Try again.
  husky.body-front.neck.head say ( ( Remeber, click on the joined with ( world.currentRoundPlace as a string ) ) joined with place. ) duration = 2 seconds


  world.UpOrDown ( )
    No variables
       // Huskey animation for rounding
  Do together
       husky.SitStand
  Do together
       husky move up .005 meters
  husky.body-front.neck.head turn right 0.12 revolutions
  husky.WagTail WagTurnScale = 0.5 WagDurationScale = 1
  husky.body-front.neck.head say Great Job! duration = 2 seconds fontSize = 30
  husky.body-front.neck.head say Now decide if that number should go up or stay. duration = 3 seconds
  Do together
       roundInstructions set isShowing to true
  husky.body-front.neck.head say Click on the black arrow or circle. duration = 3 seconds


  world.checkRound ( [Obj] ObjectClicked)
    valueOfNeighbour = 1 , currentRoundPlaceIndex = 1 , neighbourObject = <None> , placeObject = <None>
       // checks if the rounding up or staying (arrow or dot) the user selected is correct
  If ( world.currentRoundPlace == tens )
       currentRoundPlaceIndex set value to 1
  neighbourObject set value to ones
  placeObject set value to tens
  Else
    If ( world.currentRoundPlace == hundreds )
       currentRoundPlaceIndex set value to 2
  neighbourObject set value to tens
  placeObject set value to hundreds
  Else
    If ( world.currentRoundPlace == thousands )
       currentRoundPlaceIndex set value to 3
  neighbourObject set value to hundreds
  placeObject set value to thousands
  Else
    If ( world.currentRoundPlace == ten thousands )
       currentRoundPlaceIndex set value to 4
  neighbourObject set value to thousands
  placeObject set value to ten thousands
  Else
    If ( world.currentRoundPlace == hundred thousands )
       currentRoundPlaceIndex set value to 5
  neighbourObject set value to ten thousands
  placeObject set value to hundred thousands
  Else
    If ( world.currentRoundPlace == millions )
       currentRoundPlaceIndex set value to 6
  neighbourObject set value to hundred thousands
  placeObject set value to millions
  Else
    If ( world.currentRoundPlace == ten millions )
       currentRoundPlaceIndex set value to 7
  neighbourObject set value to millions
  placeObject set value to ten millions
  Else
    currentRoundPlaceIndex set value to 8
  neighbourObject set value to ten millions
  placeObject set value to hundred millions
  valueOfNeighbour set value to ( item ( ( currentRoundPlaceIndex - 1 ) ) from world.PlaceValues )
  If ( world.canIRound objectClicked = ObjectClicked valueOfNeighbour = valueOfNeighbour )
       world.Round currentRoundPlaceIndex = currentRoundPlaceIndex neighbourPlace = neighbourObject upOrStay = ObjectClicked
  Else
    world.tryAgain currentRoundPlace = currentRoundPlaceIndex Neighbour = neighbourObject objectClicked = ObjectClicked


  world.Round ( [123] currentRoundPlaceIndex, [Obj] neighbourPlace, [Obj] upOrStay)
    newValue = 1 , check9 = 9 , arrayIndex = 11 , savePlaceIndex = 0
       // Rounds the selected number up and displays animation
  Do together
       savePlaceIndex set value to currentRoundPlaceIndex
  husky.Bark BarkSpeed = 2
  If ( ( item ( ( currentRoundPlaceIndex - 1 ) ) from world.PlaceValues ) > 4 )
       // If the number is 9 go to the next place value
  If ( ( item currentRoundPlaceIndex from world.PlaceValues ) == 9 )
       // in case the upper numbers are also 9
  While ( check9 == 9 )
       currentRoundPlaceIndex set value to ( ( currentRoundPlaceIndex + 1 ) )
  check9 set value to ( item currentRoundPlaceIndex from world.PlaceValues )
  Else
  Do Nothing
  // increase the number by one
  set item currentRoundPlaceIndex to ( ( ( item currentRoundPlaceIndex from world.PlaceValues ) + 1 ) ) in world.PlaceValues duration = 0 seconds
  Else
  Do Nothing
  // set the other values to 0
  Loop index from 0 up to (but not including) currentRoundPlaceIndex times incrementing by 1
       set item index to 0 in world.PlaceValues duration = 0 seconds
  // redraw the numbers
  Do together
       Do together
       upArrow set opacity to 0 (0%)
  dot set opacity to 0 (0%)
  score.addPoints
  If ( upOrStay == dot )
       // if the number is not increasing highlight it
  ( item ( ( 11 - currentRoundPlaceIndex ) ) from arrayVisualization.elements ) resize 1.25
  Else
    If ( check9 == 9 )
       // if the number is increasing and if the number at the selected place is not 9 - move it up
  Do together
       ( item ( ( 11 - currentRoundPlaceIndex ) ) from arrayVisualization.elements ) move up 1 meter
  Else
    // if the number was nine we have moved over to the next numbers
  // If you can believe it this loop works - there might be an easier way... but sometimes it take more brain power to come up with it.
  Do together
       Loop index from 0 up to (but not including) ( ( currentRoundPlaceIndex - ( ( savePlaceIndex - 1 ) ) ) ) incrementing by 1
       ( item ( ( 11 - ( ( savePlaceIndex + index ) ) ) ) from arrayVisualization.elements ) move up 1 meter duration = 0.5 seconds
  Do in order
       Loop index from 0 up to (but not including) ( ( savePlaceIndex - 1 ) ) incrementing by 1
       decrement arrayIndex by 1
  Loop savePlaceIndex times time
       ( item arrayIndex from arrayVisualization.elements ) turn forward 0.5 revolutions duration = 0.5 seconds
  increment arrayIndex by 1
  world.displayNumbers
  Do together
       Loop savePlaceIndex times time
       decrement arrayIndex by 1
  ( item arrayIndex from arrayVisualization.elements ) turn forward 0.5 revolutions duration = 0.5 seconds
  If ( upOrStay == dot )
       // if the number is not increasing highlight it
  ( item ( ( 11 - currentRoundPlaceIndex ) ) from arrayVisualization.elements ) resize 0.8
  Else
    If ( check9 == 9 )
       // if the number is increasing and if the number at the selected place is not 9 - move it up
  Do together
       ( item ( ( 11 - currentRoundPlaceIndex ) ) from arrayVisualization.elements ) move down 1 meter duration = 0.5 seconds
  Else
    // if the number was nine we have moved over to the next numbers
  // If you can believe it this loop works - there might be an easier way... but sometimes it take more brain power to come up with it.
  Do together
       Loop index from 0 up to (but not including) ( ( currentRoundPlaceIndex - ( ( savePlaceIndex - 1 ) ) ) ) incrementing by 1
       ( item ( ( 11 - ( ( savePlaceIndex + index ) ) ) ) from arrayVisualization.elements ) move down 1 meter duration = 0.5 seconds
  Do in order
       Do together
       husky.SitStand
  arrowVehicle move to ones duration = 0.5 seconds
  husky.body-front.neck.head turn right 1/8 revolutions duration = 0.5 seconds
  world.playGame


  world.displayNumbers ( )
    No variables
       // updates the numbers in each didgit
  If ( world.Level == 3 )
       hundred millions set text to ( world.MyNumberString ( item 8 from world.PlaceValues ) ) duration = 0.25 seconds
  ten millions set text to ( world.MyNumberString ( item 7 from world.PlaceValues ) ) duration = 0.25 seconds
  millions set text to ( world.MyNumberString ( item 6 from world.PlaceValues ) ) duration = 0.25 seconds
  Else
  Do Nothing
  If ( either ( world.Level == 2 ) or ( world.Level == 3 ) , or both )
       hundred thousands set text to ( world.MyNumberString ( item 5 from world.PlaceValues ) ) duration = 0.25 seconds
  ten thousands set text to ( world.MyNumberString ( item 4 from world.PlaceValues ) ) duration = 0.25 seconds
  thousands set text to ( world.MyNumberString ( item 3 from world.PlaceValues ) ) duration = 0.25 seconds
  Else
  Do Nothing
  hundreds set text to ( world.MyNumberString ( item 2 from world.PlaceValues ) ) duration = 0.25 seconds
  tens set text to ( world.MyNumberString ( item 1 from world.PlaceValues ) ) duration = 0.25 seconds
  ones set text to ( world.MyNumberString ( item 0 from world.PlaceValues ) ) duration = 0.25 seconds


  world.tryAgain ( [123] currentRoundPlace, [Obj] Neighbour, [Obj] objectClicked)
    No variables
       // Animation for when the wrong rounding decision is chosen by the user (arrow or dot)
  husky.SitStand
  husky.body-front.neck.head say I'm sorry, that is not the correct answer.
  Do together
       husky.ScratchEar ScratchDuration = 0.25
  Loop 3 times times
       Neighbour move up 0.5 meters
  Neighbour move down 0.5 meters
  Do in order
       Neighbour say Check me out.
  If ( objectClicked == dot )
       Neighbour say If I am 5 or higher the number should go up. duration = 3 seconds
  Else
    Neighbour say If I am less than 5 the number should stay. duration = 3 seconds
  husky.SitStand


  world.finishGame ( )
    No variables
       // simple conclusion to the game
  Do together
       husky.HeadNod NodDuration = 1 NumNods = 1
  husky.body-front.neck.head say Thanks for playing with me.
  Do together
       end turn left 4 revolutions duration = 2 seconds
  end move to camera duration = 2 seconds
  world set atmosphereColor to (0, 0, 0) duration = 2 seconds
  world set ambientLightColor to (0, 0, 0) duration = 2 seconds
  light set brightness to 0 duration = 2 seconds


  world.setRoundPlaceForLevel2 ( )
    currentPlace = 11 , Place = default string
       // determines the rounding place for level 2
  While ( ( item currentPlace from world.PlaceValues ) == 0 )
       decrement currentPlace by 1
  If ( both ( choose true 0.3 (30%) of the time ) and ( currentPlace >= 5 ) )
       // if the rounding place is in the hundreds
  world.currentRoundPlace set value to hundred thousands
  Place set value to hundred thousand
  Else
    If ( both ( choose true 0.4 (40%) of the time ) and ( currentPlace >= 4 ) )
       world.currentRoundPlace set value to ten thousands
  Place set value to ten thousand
  Else
    If ( both ( choose true 0.5 (50%) of the time ) and ( currentPlace >= 3 ) )
       world.currentRoundPlace set value to thousands
  Place set value to thousand
  Else
    world.currentRoundPlace set value to hundreds
  Place set value to hundred
  husky.body-front.neck.head say ( ( Round This number to the nearest joined with Place ) joined with . ) duration = 2 seconds
  husky.body-front.neck.head say ( ( Click on the number in the joined with Place ) joined with s position. ) duration = 2 seconds


  world.HuskyEnter ( )
    No variables
       // animation for the husky's entry
  If ( world.Level == 1 )
       husky.WalkCycle NumCycles = 3
  Else
    If ( world.Level == 2 )
       husky.WalkCycle NumCycles = 4
  Else
    husky.WalkCycle NumCycles = 5
  husky turn right 0.12 revolutions
  Do together
       husky turn backward 0.12 revolutions
  husky.body-front turn forward 0.12 revolutions
  husky.body-rear.left-thigh.left-leg turn forward 0.12 revolutions
  husky.body-rear.right-thigh.right-leg turn forward 0.12 revolutions
  husky.body-rear.left-thigh.left-leg.left-shin turn backward 0.12 revolutions
  husky.body-rear.right-thigh.right-leg.right-shin turn backward 0.12 revolutions
  husky.body-rear.tail-1.tail-2 turn backward 0.25 revolutions
  Do together
       husky.body-front.left-upper-arm turn backward 0.18 revolutions
  husky.body-front.right-upper-arm turn backward 0.18 revolutions
  Do together
       husky move up 0.35 meters
  husky move forward 1 meter
  Do together
       husky.body-front.left-upper-arm turn forward 0.18 revolutions
  husky.body-front.right-upper-arm turn forward 0.18 revolutions
  Do together
       husky turn forward 0.12 revolutions
  husky.body-front turn backward 0.12 revolutions
  husky.body-rear.left-thigh.left-leg turn backward 0.12 revolutions
  husky.body-rear.right-thigh.right-leg turn backward 0.12 revolutions
  husky.body-rear.left-thigh.left-leg.left-shin turn forward 0.12 revolutions
  husky.body-rear.right-thigh.right-leg.right-shin turn forward 0.12 revolutions
  husky.body-rear.tail-1.tail-2 turn forward 0.25 revolutions
  Do in order
       husky turn left 0.12 revolutions
  husky.body-front.neck.head turn left 0.25 revolutions
  husky.body-front.neck.head say Oh, hello!
  husky.body-front.neck.head say Welcome to Rounding World.
  husky turn left 3/8 revolutions
  husky.SitStand
  husky.body-front.neck.head turn right 0.12 revolutions
  husky.body-front.neck.head say Let's get started.


  world.setRoundPlaceForLevel3 ( )
    currentPlace = 11 , place = default string
       // determines the rounding place for level 3
  While ( ( item currentPlace from world.PlaceValues ) == 0 )
       decrement currentPlace by 1
  If ( both ( choose true 0.3 (30%) of the time ) and ( currentPlace >= 8 ) )
       // if the length of the number is in the hundred millions
  world.currentRoundPlace set value to hundred millions
  place set value to hundred million
  Else
    If ( both ( choose true 0.3 (30%) of the time ) and ( currentPlace >= 7 ) )
       // if the length of the number is in the ten millions
  world.currentRoundPlace set value to ten millions
  place set value to ten million
  Else
    If ( both ( choose true 0.5 (50%) of the time ) and ( currentPlace >= 6 ) )
       // if the length of the number is in the millions
  world.currentRoundPlace set value to millions
  place set value to million
  Else
    If ( both ( choose true 0.3 (30%) of the time ) and ( currentPlace >= 5 ) )
       // if the length of the number is in the hundred thousands
  world.currentRoundPlace set value to hundred thousands
  place set value to hundred thousand
  Else
    If ( both ( choose true 0.3 (30%) of the time ) and ( currentPlace >= 4 ) )
       world.currentRoundPlace set value to ten thousands
  place set value to ten thousand
  Else
    world.currentRoundPlace set value to thousands
  place set value to thousand
  husky.body-front.neck.head say ( ( Round This number to the nearest joined with place ) joined with . ) duration = 2 seconds
  husky.body-front.neck.head say ( ( Click on the number in the joined with place ) joined with s position. ) duration = 2 seconds


Functions

  java.lang.String world.MyNumberString ( [123] PlaceNumber)
    No variables
       If ( PlaceNumber == 0 )
       Return 0
  Else
    If ( PlaceNumber == 1 )
       Return 1
  Else
    If ( PlaceNumber == 2 )
       Return 2
  Else
    If ( PlaceNumber == 3 )
       Return 3
  Else
    If ( PlaceNumber == 4 )
       Return 4
  Else
    If ( PlaceNumber == 5 )
       Return 5
  Else
    If ( PlaceNumber == 6 )
       Return 6
  Else
    If ( PlaceNumber == 7 )
       Return 7
  Else
    If ( PlaceNumber == 8 )
       Return 8
  Else
    If ( PlaceNumber == 9 )
       Return 9
  Else
    Return 0
Return default string


  Boolean world.canIRound ( [Obj] objectClicked, [123] valueOfNeighbour)
    No variables
       If ( either ( both ( valueOfNeighbour > 4 ) and ( objectClicked == upArrow ) ) or ( both ( valueOfNeighbour < 5 ) and ( objectClicked == dot ) ) , or both )
       Return true
  Else
    Return false
Return true


score

Methods

  score.addPoints ( )
    No variables
       increment score.scoreValue by 1 duration = 0 seconds
  score set text to ( Score: joined with ( score.scoreValue as a string ) )
  If ( score.scoreValue == 10 )
       score turn left 5 revolutions duration = 1 second
  score set color to (1, 0, 0)
  Else
  Do Nothing