Puzzle Game - Thursday, March 6th, 2008



  1. Be sure to play the game several times. You will see the results of the following code whenever you improve on your best score so far. The lowSoFar variable contains the approximate number of seconds since you started the game.
    playAgain_btn.addEventListener(MouseEvent.CLICK, playAgain);
     
    var sec:Number = s / 4;   // s is the number of quarter seconds since you started the puzzle till you got it solved.
     
    if (sec < lowSoFar) {      // If this condition is true, you have a new fastest time!  
                               //         The sec # of seconds is less than the previous lowSoFar.
     
        lowSoFar = sec;
     
        if (times > 0) {                         // The wow_mc object is a movie clip message of congrats on new best time.
            this.wow_mc.alpha = 100;             // It is invisible because its alpha property is set to 0% normally.
        }
    }
    
  2. How do you do Drag and Drop in Flash CS 3 (using ActionScript 3.0)?
  3. puzzlePiece5.addEventListener("mouseDown", pieceMove);
    puzzlePiece5.addEventListener("mouseUp", pieceMove);
     
    function pieceMove(evt:Event):void {
       if (evt.type == "mouseDown") {
           evt.target.startDrag();
       } else if (evt.type == "mouseUp") {
           evt.target.stopDrag();
    }
    
  4. The timing of your puzzle solving event is done using an instance of the Timer class. The Timer is set to go off every 250 milliseconds. There are 1,000 milliseconds in 1 second.

    The timer has a start() method and a stop() method, just like a real stop watch would.

    var timer:Timer = new Timer(250);       // I tried using 100 instead of 250 but the accuracy was very poor [ with = new Timer(100) ]
                                            //         having the timer try to execute its actions 10 times per second.
     
    timer.addEventListener(TimerEvent.TIMER, countQuarterSeconds);
      
    function countQuarterSeconds(evt:TimerEvent):void {
        s++;                                                  //  s++;    <---- is equivalent to ---->    s = s + 1;
    }
    
  5. Here is how the dragging and the dropping happens, in a simplified version. Note that the e in the letter Alice is puzzlePiece5, and is an instance of a movie clip symbol from the Flash Library.

    1. The pieceMove function is called or invoked whenever the puzzlePiece5 "hears" the mouseDown event or "hears" the mouseUp event.
    2. It is listening for either of those events. It ignores all other events except for mouseUp and MouseDown.
    3. The startDrag() method is executed if it was a mouseDown event that was "heard".
    4. Until the mouseUp occurs, the Flash ActionScript 3.0 statement has enabled the user to drag the puzzlePiece5 movie clip around on the stage.
    5. When the mouseUp event is heard, the stopDrag() method causes the dragged object to be dropped right there at that location on the stage.
  6. What happens after a puzzle piece is dropped? See if you can desribe in English (or your native tongue) exactly what happens when you drop one of the pieces. Most of the thinking involved in developing software uses English or Spanish or German or Farsi or Norwegian or whatever your native tongue language is.

  7. There is a method called hitTestObject() that can tell is one object (movie clip instance) is touching another object (another movie clip instance).
      puzzlePiece5.hitTestObject(puzzlePiece5_square) == true)
      

  8. The game above reminds me of the Missouri Valley Track and Field Championships held last weekend at the UNI-Dome. Its fun to try to focus and practice and improve on your best time in this video game event! From track and field to mouse and monitor... :-)

  1. Superb Jazz Guitarist: Musician Wes Montgomery's birthday is March 6th, which is today.

  2. If you want to hear a beautiful solo in honor of spring, Bumpin on Sunset would be the song.

  3. Think roller blading, bike rides, evening walks, talks or runs, think spring. Think evening picnics. Think beautiful sunsets.