Section 6

Prepare For Application Deployment

What will we need to do if we want our Laser Game to be a stand-alone application written in Squeak? The overall concept is that we will ensure that only our game morph is open on the screen. Since the user has the ability to resize the Squeak World we need to make it look as if the only "window" visible is our game morph regardless of size.

Let's add the capability of making our Laser Game behave as if it's the only morph in the Squeak World. We will do this by first adding a "flag" we can use to tell us when we want to run in Full World. That is, when we will be the only object visible.

Open up a class hierarchy browser on LaserGame. Ensure you have no methods selected. We're going to modify the existing class definition. We will add a new Class Variable named "FullWorld". Save this change in the class definition.

Morph subclass: #LaserGame
     instanceVariableNames: 'grid boardForm activeCellLocation dirty moves'
     classVariableNames: 'FullWorld'
     poolDictionaries: ''
     category: 'Laser-Game-Graphics'

We will write accessing methods for this new class variable. Make it so the default condition is "false". Here are the new class methods for the LaserGame class.

fullWorld: aBoolean
     "LaserGame fullWorld: true"
     FullWorld := aBoolean

I added a comment statement in the method. If we click once inside the double-quotes that define the comment, adjacent to and inside by one of the double-quotes, the code inside the comment will be selected. We could then execute that little snippet of code when we need to set the value to True.

     FullWorld isNil ifTrue: [self fullWorld: false].

Now we make changes to instance methods on LaserGame. Change this method first.

    | targetForFill |
    self class fullWorld
        ifTrue: [
            self color: Color transparent.
            targetForFill := World
        ifFalse: [
            self color: (Color r: 0.369 g: 0.369 b: 0.505).
            targetForFill := self
    targetForFill fillWithRamp: self windowColorRamp oriented: 0.3@0.8

We're checking if the Full World flag is set. If not, we do what we have done before. The temporary variable "targetForFill" is used for the fill statement at then end of the method. When we are not in a Full World situation, that target is the Laser Game morph.

However, when the Full World flag is set, we want to get the entire world and fill it with our color ramp. And if we change our own color to be transparent it looks like we are part of one very large morph now.

This is just one step in getting all this work. But let's see how it works. If you have a LaserGame morph open, close it. First we should just open up a LaserGame morph to ensure it all still looks and works the same. Click on some mirror cells and fire the laser to quickly check it out.

Before we open our LaserGame morph in a full world mode, we should open up a Workspace window and use the following code to launch our morph.

    fullWorld: true;
        position: 20@230;

Index Page Next Page

Copyright © 2007, 2008, 2009, 2010 Stephan B Wessels