RoboHunter is a VB program that enables students to create robots. The
robots can then be added to an arena where they battle for "treasures".
The "program" consists of:
RoboGrid
-
The primary class
-
The world for the robots
-
Has properties and methods for controlling the robots
-
Details about RoboGrid
-
RoboGrid Class - Copy and paste into
a text file. Save as roboGrid.vb.
RoboArena
-
Main program that uses RoboGrid class to control the battles
-
Provides controls for starting and stopping battles
Robots
-
Programmed to do one thing each turn
-
Move forward - M
-
Face a certain direction - N, S, E, W
-
Fire a laser - F
-
Pause - P
-
Must have myRobotDo method
-
Accepts RobotData and iGrid arrays
-
Returns N, S, E, W, M, F, or P
ACTIVITIES
1. Create a program for testing roboGrid.
-
Create the RoboGrid class and add to the project.
-
Add a button to a form and the following code to the onclick event:
Dim rg As New RoboGrid(10,
200, 50, 10, 10, 1, 1)
rg.InitializeGrid(Me)
rg.DisplayGrid()
-
Run your program and test.
-
Experiment with the parameters in the RoboGrid constructor.
-
Examine the code in the roboGrid class in the .vb file.
2. Create a simple robot (see notes above in Details about RoboGrid). Refer
to this sample code.
-
Create a robot class. The name of your class should be fLastBot where "f" is
your first initial and "Last" is your lastname.
-
Create a contructor that accepts an ID. Your robot should have an ID
property. This property will be used to identify your robot.
-
Create a myRobotDo
method that makes your robot move forward one step.
-
Add the class to your program in #1.
-
Add a button to your program in #1 that executes the robot's command each time
the user clicks the button.
3. Continue #2 by experimenting with RoboData and iGrid.
-
Experiment with the roboData() array that is passed into your myRobotDo method
by adding the following code to your myRobotDo method. This code assumes that
you have a robot with an ID = 1. Run your code and notice what is
displayed in the messagebox. Experiment with the other properties of the
roboData array.
msgbox(roboData(1).x)
-
Continue experimenting to determine what iGrid contains. Add the
following statement to your myRobotDo method. Then test your code until
you understand what iGrid() contains.
msgbox(iGrid(2,4))
4. Modify your robot from #3 to randomly choose its command to be either N, S,
E, W, P, M, F.
5. If your robot runs into the wall it will lose its treasures. Modify
your robot from #4 to prevent it from hitting the walls.