javascript robot
Posted
by sarah
on Stack Overflow
See other posts from Stack Overflow
or by sarah
Published on 2010-04-15T11:47:18Z
Indexed on
2010/04/15
11:53 UTC
Read the original article
Hit count: 320
hey guys! I need help making this robot game in javascript (notepad++)
please HELP! I'm really confused by the functions
<html>
<head><title>Robot Invasion 2199</title></head>
<body style="text-align:center" onload="newGame();">
<h2>Robot Invasion 2199</h2>
<div style="text-align:center; background:white; margin-right: auto; margin-left:auto;">
<div style="">
<div style="width: auto; border:solid thin red; text-align:center; margin:10px auto 10px auto; padding:1ex 0ex;font-family: monospace" id="scene"></pre>
</div>
<div><span id="status"></span></div>
<form style="text-align:center">
PUT THE CONTROL PANEL HERE!!!
</form>
</div>
<script type="text/javascript">
// GENERAL SUGGESTIONS ABOUT WRITING THIS PROGRAM:
// You should test your program before you've finished writing all of the
// functions. The newGame, startLevel, and update functions should be your
// first priority since they're all involved in displaying the initial state
// of the game board.
//
// Next, work on putting together the control panel for the game so that you
// can begin to interact with it. Your next goal should be to get the move
// function working so that everything else can be testable. Note that all nine
// of the movement buttons (including the pass button) should call the move
// function when they are clicked, just with different parameters.
//
// All the remaining functions can be completed in pretty much any order, and
// you'll see the game gradually improve as you write the functions.
//
// Just remember to keep your cool when writing this program. There are a
// bunch of functions to write, but as long as you stay focused on the function
// you're writing, each individual part is not that hard.
// These variables specify the number of rows and columns in the game board.
// Use these variables instead of hard coding the number of rows and columns
// in your loops, etc.
// i.e. Write:
// for(i = 0; i < NUM_ROWS; i++) ...
// not:
// for(i = 0; i < 15; i++) ...
var NUM_ROWS = 15;
var NUM_COLS = 25;
// Scene is arguably the most important variable in this whole program. It
// should be set up as a two-dimensional array (with NUM_ROWS rows and
// NUM_COLS columns). This represents the game board, with the scene[i][j]
// representing what's in row i, column j. In particular, the entries should
// be:
//
// "." for empty space
// "R" for a robot
// "S" for a scrap pile
// "H" for the hero
var scene;
// These variables represent the row and column of the hero's location,
// respectively. These are more of a conveniece so you don't have to search
// for the "H" in the scene array when you need to know where the hero is.
var heroRow;
var heroCol;
// These variables keep track of various aspects of the gameplay.
// score is just the number of robots destroyed.
// screwdrivers is the number of sonic screwdriver charges left.
// fastTeleports is the number of fast teleports remaining.
// level is the current level number.
// Be sure to reset all of these when a new game starts, and update them at the
// appropriate times.
var score;
var screwdrivers;
var fastTeleports;
var level;
// This function should use a sonic screwdriver if there are still charges
// left. The sonic screwdriver turns any robot that is in one of the eight
// squares immediately adjacent to the hero into scrap. If there are no charges
// left, then this function should instead pop up a dialog box with the message
// "Out of sonic screwdrivers!". As with any function that alters the game's
// state, this function should call the update function when it has finished.
//
// Your "Sonic Screwdriver" button should call this function directly.
function screwdriver()
{
// WRITE THIS FUNCTION
}
// This function should move the hero to a randomly selected location if there
// are still fast teleports left. This function MUST NOT move the hero on to
// a square that is already occupied by a robot or a scrap pile, although it
// can move the hero next to a robot. The number of fast teleports should also
// be decreased by one. If there are no fast teleports left, this function
// should just pop up a message box saying so. As with any function that alters
// the game's state, this function should call the update function when it has
// finished.
//
// HINT: Have a loop that keeps trying random spots until a valid one is found.
// HINT: Use the validPosition function to tell if a spot is valid
//
// Your "Fast Teleport" button s
© Stack Overflow or respective owner