Thursday, July 23, 2009

Redware's Fish-2.0 Game - Shortly Explained

This game consists of 8 sprites (1 shark-sprite, 6 yellow-fish-sprite, 1 red-fish-sprite). But if we look at the script blocks, we just have to focus on two things: the script blocks for the shark-sprite and the other blocks for the yellow and red-fish sprites (see picture below). Note that (1) only the shark-sprite has more than one costume; (2) all yellow-fish sprites and red-fish sprite have similar behaviour (except that in the event "touching shark" red-fish sprite broadcast a different message than its yellow friends).



For original script description, you should refer to Redware's website. Here I just want to shortly explain & summarize the script blocks above.

Shark Sprite:
  • If the green flag is clicked, "score" variable is set to 0; the shark will begin its exploration by following mouse-pointer

  • If the shark receive "sharktouchingyellowfish" message, it will animate 3 times before it looks normal again

  • If the shark receive "sharktouchingredfish" message, the score will be reset to 0 and the shark will take another (sad-looking) costume for a while

Other Fish Sprites:
  • If the green flag is clicked, each sprite will sense if it has been eaten by the shark (i.e. touching shark); if not, it just randomly take a direction and move forward

  • If a fish meets the shark, it broadcasts the "sharktouchingXXfish" message and hides for a while but appears again from a random position at the left or right side; in this case the score is incremented

Monday, July 20, 2009

Netbeans : Project Folder Structure

How does a Netbeans's project folder look like? Let's see a simple (and usual) case. Create a new project [File]-->[New Project] or [Ctrl+Shift+N]. Select [Categories]-->[Java] and [Projects]-->[Java Application]. Configure the next screen / window as displayed below.


After clicking the "Finish" button, add a line to the code editor (HelloWorld class) to print the message (yes, sure, what else .. the "Hello World" .. :-D )
package javaapplication01;

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}

}

Now you can inspect and compare the "Files View" as you try to run / build the program.


Some Notes: The project is created and opened in the IDE. You should see the following components:
  • The Projects window, which contains a tree view of the components of the project, including source files, libraries that your code depends on, and so on

  • The Source Editor window with a file called HelloWorld.java open

  • The Navigator window, which you can use to quickly navigate between elements within the selected class

  • The Tasks window, which lists compilation errors as well other tasks that are marked with keywords such as XXX and TODO

Because of the IDE's Compile on Save feature, you do not have to manually compile your project in order to run it in the IDE. When you save a Java source file, the IDE automatically compiles it.

Once you have written and test run your application, you can use the Clean and Build command to build your application for deployment. When you use the Clean and Build command, the IDE runs a build script that performs the following tasks:
  • Deletes any previously compiled files and other build outputs

  • Recompiles the application and builds a JAR file containing the compiled files

(Another) Note: Netbeans 6.7 ; Official quickstart guide