Game Instructions and Coding Tips


Game Instructions

Game Overview

Welcome to Battle Tanks!

In this game you will code a Battle Tank, and then your tank will compete against other tanks. The last tank standing wins!

You can enter your name and choose your bot color. You will write your code in the text boxes under each event name. Once you've written your code, you can test it by clicking the Play button. If your code has any errors, a message will appear in the text box on the bottom of the right side of the screen. It will give you an error message telling you which event and which line it found the error in. Once your code is free of errors, click play again, and it will run the game.

You start with 3 health. When you're playing by yourself, the game will auto generate bots for you to play against. Win by being the last bot standing.

Once you're happy with your Battle Tank, you can click the Export button. This will generate a file with your code. Do not edit this file. Your instructor will have given you a link to Dropbox. Go to the given link and upload your file.

When everyone is ready, the teacher will start the game with everyone's submitted Battle Tanks, and you'll get to see your tank compete against your friend's tanks.

Function List

This game has two types of functions: regular functions and boolean functions.
Regular functions are used to take actions. Boolean functions are used in if statements.

Regular Functions:
TurnRight(): Turns your Battle Tank to face 90° to the right.
TurnLeft(): Turns your Battle Tank to face 90° to the left.
Move(): Moves your Battle Tank one space forward.
Shoot(): Make your Battle Tank shoot a cannon forward.

Boolean Functions (only used as the condition in an if statement):
isHealthGreaterThan(integer): Returns true if your health is greater than the given integer. Else, it returns false.
isHealthLessThan(integer): Returns true if your health is less than the given integer. Else, it returns false.
isHealthEqualTo(integer): Returns true if your health is equal to the given integer. Else, it returns false.
isPlayersGreaterThan(integer): Returns true if the total number of players is greater than the given integer. Else, it returns false.
isPlayersLessThan(integer): Returns true if the total number of players is less than the given integer. Else, it returns false.
isPlayersEqualTo(integer): Returns true if the total number of players is equal to the given integer. Else, it returns false.

Note: An integer is a number without a decimal or fraction. It can be positive, negative, or zero. Most integers used in this game will be positive numbers above 0.
 Examples of integers are: -1, 0, 1, 2, 3.

Event Descriptions

This game has four events: main, hit, collision, and detect.

main is the default event. It will run while none of the other events are triggered.
hit runs when your Battle Tank is hit by another Battle Tank.
collision runs when your Battle Tank runs into a wall.
detect runs when your Battle Tank senses another Battle Tank infront of it.

Whenever any of the events are triggered, your event code will run. When the event code is done running, your Battle Tank will run your main code again.
If multiple events are called within the same turn, collision is prioritized. Else, if will depend on the most recently called event.

Game Syntax

This game uses function calls, if statements, and for loops.

Function Calls
-See the Function List section for the list of this game's functions as well as what they do.
-See the Function Calls section to see how to write a function call.

If Statements
-See the If Statements section to see how to write an if statement.
-For this game, you will use the boolean functions as the condition for the if statements. Boolean functions return true or false. If true is returne, your inner code will execute, elsewise it will be skipped.
-For this game, you can have multiple things in the inner code of the if statment, but we do not allow another if statement or a for loop within the inner code.
Example of a valid if statment in this game:
(isHealthLessThan(2))
 {
  Move()
  TurnRight()
  Shoot()
 }

This code will check if your health is less than 2. If it is less than 2, then your Battle Tank will move forward one, turn right, and shoot.

For Loops
-See the For Loop section to see how to write a for loop.
-This game restricts the integer size to 10, so your for loop can run at most 10 times in a row.
Example fo a valid for loop in this game:
for(2)
 {
  Move()
  TurnRight()
  Shoot()
 }

This code will execute as follows:
Move()
TurnRight()
Shoot()
Move()
TurnRight()
Shoot()


Some extra notes on this game's syntax:
-Most white space (things like spaces and tabs) are ignored, so you do not need to indent your code.
-New lines (what happens when you type the Enter key) are important.
for(2) {Move()}
 and
for(2)
{
Move()
}
 are not the same. The first one will not run in this game. The second one is formatted correctly.
-This game does not use semicolons at the end of everyline.


Coding Tips

Function Calls

A function call means you're using a pre-built function. All you have to do is type in the functions name, opening parenthesis, function parameters, and closing parenthesis.
This is what a function call looks like:
functionName(parameter1, parameter2)
It is important that you spell the function name correctly and use the correct capitalization. The following functions will all be considered different functions:
functionName()
 FunctionName()
 functonName()

Function parameters are things you give to the function. If you had a function that adds two numbers, it's parameters could be the two numbers you want to add. Look at the function definitions to see what parameters (if any) the function takes.
To see the function definitions for this game's functions, refer the to Function List section on this page.

If Statements

An if statement is a conditional statement. That means, if a condition is met, then the code will run.
This is what an if statment looks like:
if(condition)
 {
  *write your inner code here*
 }

The condition should be a boolean value. That means the value will be either true or false. An example of a condition could be 1=0. This is false, so the inner code would not execute.
Note: you can have multiple things in the inner code part of an if statement.

For Loops

For loops repeat their inner code a set amount of times.
This is what a for loop looks like:
for(integer)
 {
  *write your inner code here*
 }

The integer should be written in number form, not spelled out. Whatever integer is given, that's how many time the inner code will execute.
For example:
for(5)
 {
  Move()
 }

This for loop would run the Move() function 5 times in a row.
Note: you can have multiple things in the inner code part of the for loop.

Common Mistakes

Here are some common coding mistakes to try to avoid:
-Misspelling a function name
-Incorrect capitalization in a function name
-Forgetting parentheses
-Forgetting curly brackets
-Using the wrong type of brackets: (), {}, [], <>


Good luck and let the best Battle Tank win!