Here, we will show you how to create a Mouse and eventually get it to run on the Maze. But
making it intelligent, we will leave that to you. Here, we assume that you have a proper
Java JDK installed and properly configured, and that you have downloaded the No-Source set
of Mouse Run. You should unzip the set to a location that is convenient.
If you have properly followed the following steps, you would have succeeded in creating a Mouse.
1. Open up a Text Editor of your choice and enter the following codes in:
package mouserun.mouse;
import mouserun.game.Mouse;
import mouserun.game.Grid;
import mouserun.game.Cheese;
You would notice that all implementation of the Mouse has to be in the package called
mouserun.mouse. This will ensure that the game host
will be able to detect the Mouse when it is compiled and executed later on. You will also need
to import those three classes. You'll find out why later on.
2. Continue adding codes like the following:
package mouserun.mouse;
import mouserun.game.Mouse;
import mouserun.game.Grid;
import mouserun.game.Cheese;
public class FooMouse extends Mouse
{
}
Not only that all Mouse implementations must be in the same package, they too have to
extend from the
Mouse class. If you have checked
the documentation of the Mouse class, you would realize that it is an
abstract class and that you will need to implement
all abstract methods.
3. By checking the documentation, you will know that you will need to
implement those methods like the following:
package mouserun.mouse;
import mouserun.game.Mouse;
import mouserun.game.Grid;
import mouserun.game.Cheese;
public class FooMouse extends Mouse
{
public FooMouse()
{
super("FooMouse");
}
public int move(Grid currentGrid, Cheese cheese)
{
}
public void newCheese()
{
}
public void respawned()
{
}
}
If you have saved this file and compile it, it will already create a Mouse for you. You will
see the mouse on the game interface. But it does not do anything. The mouse is dumber than ever.
But before we move on, lets just see what we have done so far. We have created a constructor
for the Mouse which has to be
public.
super("FooMouse"); will give the name of the Mouse
as FooMouse and appear under the Mouse in the game interface.
public int move(Grid currentGrid, Cheese cheese) is
probably the most important method in your Mouse class. When the game host has detected that
your Mouse has reach a grid, it will need to provide a decision on what to do next.
currentGrid is the current grid that the Mouse is on and
cheese is the cheese that is being sought for. With information
given by the two objects, your mouse need to make the decision.
public void newCheese() is called when a cheese has been consumed.
If you do not wish to do anything, so let it be. This method is normally utilized for cleaning up.
public void respawned() is called when your Mouse has hit a bomb
that is not planted by it and has to be relocated to a new location. If you do not wish to do anything,
so let it be. This method is normally utilized for recalibration or resetting strategy.
Let's see now what you can do in the
move() method.
To move Up, do the following:
public int move(Grid currentGrid, Cheese cheese)
{
return Mouse.UP;
}
To move Down, do the following:
public int move(Grid currentGrid, Cheese cheese)
{
return Mouse.DOWN;
}
To move Left, do the following:
public int move(Grid currentGrid, Cheese cheese)
{
return Mouse.LEFT;
}
To move Right, do the following:
public int move(Grid currentGrid, Cheese cheese)
{
return Mouse.RIGHT;
}
To plant a Bomb, do the following:
public int move(Grid currentGrid, Cheese cheese)
{
return Mouse.BOMB;
}
4. Once when you think you are ready to compile your codes and let the game execute, save
your java file as
FooMouse.java to the directory
of the MouseRun folder you have unzipped. The java file should be in the same directory
as the
launcher.bat (on Windows) or
launcher.sh (on OS X) file.
5. Execute
launcher.bat file and see your mouse
doing things that is based on the logic you have given it.
On OS X however, please open the
Terminal and enter
the following:
bash launcher.sh
6. You can always test out with the TestMouse bundled with the set. But let us warn you,
that mouse is seriously insanely stupid. But oh well...