1. Homepage
  2. Programming
  3. COMP284 Scripting Languages Assignment 2: JavaScript

COMP284 Scripting Languages Assignment 2: JavaScript

Engage in a Conversation
LiverpoolCOMP284Scripting LanguagesJavaScript

COMP284 Scripting Languages (2023-24) -- Assignment 2: JavaScript
CourseNana.COM


CourseNana.COM

Requirements CourseNana.COM

The JavaScript program implements a simple game that consists of three stages, setup, play and end. During the play stage the game proceeds in rounds. The game is played on a grid with 10 x 10 cells. It involves a spaceship that is controlled by the user, a couple of roboc spaceships that are controlled by the computer (that is, your program), asteroids, and (inially inacve) mines. The user and your program are the two players of the game. All spaceships can move around on the grid and the roboc spaceships hunt the user's spaceship; the user's spaceship tries to avoid geng caught while trying to acvate all the mines on the grid, possibly destroying some or all the roboc spaceships in the process. CourseNana.COM

The game always starts in the setup stage. During that stage the user is shown the grid and can place four different types of objects on the cells of the grid: CourseNana.COM

by clicking on a cell and typing the leer "a", an asteroid is placed on a cell;
by clicking on a cell and typing the leer "m", a
mine is placed on a cell;
by clicking on a cell and typing the leer "r", a
roboc spaceship is placed on a cell; by clicking on a cell and typing the leer "u", the user's spaceship is placed on a cell. CourseNana.COM

There is no limit on the number of asteroids, mines, and roboc spaceships, but there is obviously only one user's spaceship. No grid cell can inially contain more than one object. If the user types a character that is not among "a", "m", "r" and "u", an error message should be shown. CourseNana.COM

In addion to the grid, there must be a buon that allows the user to end the setup stage of the game. If the user tries to end the setup stage of the game without placing the user's spaceship, then an error message should be shown and the user remains in the setup stage. Otherwise the game connues with the play stage.
CourseNana.COM

At the start and during the play stage, the user is again shown the grid, inially with all the objects that have been placed on the grid during the setup stage, plus addional status informaon: The number of the round currently played, the number of inacve mines on the grid, and the number of roboc spaceships on the grid. In addion, there must be buon that allows the user to end CourseNana.COM

the play stage at any me. CourseNana.COM

While in the play stage, the game proceeds in rounds, each round starts with the user's turn followed by the computer's turn. At the start of a round, the number of the round currently played is increased by one (the first round has the number 1), and the status informaon shown to the user is updated. CourseNana.COM

During his/her turn, the user can aempt to move his/her spaceship horizontally or vercally on the grid by typing one of four leers: CourseNana.COM

"a" aempts to move the user's spaceship one grid cell to the le, "d" aempts to move the user's spaceship one grid cell to the right, "w" aempts to move the user's spaceship one grid cell up,
"s" aempts to move the user's spaceship one grid cell down.
CourseNana.COM

If the user types any other character, then an error message should be shown, the user's turn does not end, and the user has the possibility to type another character. If the aempted move would result in the user's spaceship ending up outside the grid or on a cell occupied by an asteroid, then the aempt to move fails, the user's spaceship does not move, an error message should be shown, the user's turn does not end, and the user has the possibility to type another character. Otherwise, the aempted move is successful and the user's spaceship changes cells: CourseNana.COM

If the cell to which the spaceship has moved was previously empty, then nothing special happens and the user's turn is over.
If the user's spaceship ends up on a grid cell that contains an inacve mine, then the mine
is
acvated, the number of inacve mines shown in the status informaon is reduced by one. The mine remains acvated (and in place) for the remainder of the game. If a roboc spaceship is on a cell surrounding an acvated mine, it is immediately destroyed and the number of roboc spaceships shown in the status informaon is changed accordingly. The user's turn is then over. CourseNana.COM

If the user's spaceship ends up on a grid cell that contains an acvated mine, then nothing special happens. The user's spaceship and the mine simply coexist on the cell. The user's turn is over.
If the user's spaceship ends up on a grid cell that contains a roboc spaceship, then the user's spaceship is destroyed, and the game proceeds to the
end stage. CourseNana.COM

During the computer's turn your program aempts to move each of the roboc spaceships in an order that allows each to move if at all possible. Unlike the user's spaceship, the roboc spaceships CourseNana.COM

are not only able to move horizontally and vercally but also diagonally. Just like the user's spaceship, each roboc spaceship only moves at most one cell in a turn.
CourseNana.COM

If the user's spaceship is on a grid cell immediately surrounding a roboc spaceship, then that roboc spaceship must move to the cell occupied by the user's spaceship. If the user's spaceship is on a cell surrounding an acvated mine, then both the roboc spaceship and the user's spaceship are destroyed. Otherwise only the user's spaceship is destroyed. The status informaon is updated accordingly and the game proceeds to the end stage.
If the user's spaceship is not on a grid cell immediately surrounding a roboc spaceship, but one or more of those grid cells contains an inacve mine, then the roboc spaceship must move to one of those mines, the mine is removed from the grid, the number of inacve mines shown in the
status informaon is reduced by one.
If none of the surrounding grid cells contains the user's spaceship nor an inacve mine, then a roboc spaceship can move to an arbitrary surrounding cell provided that this move does not take it to a grid cell that is outside the grid or occupied by an asteroid or by another roboc spaceship.
If a roboc spaceship were to move onto a cell surrounding an acvated mine, then the roboc spaceship is destroyed and the number of roboc spaceships shown in the
status informaon is reduced by one.
A roboc spaceship is not allowed to stand sll if it can move. However, if a roboc spaceship cannot move at all, then the computer should simply proceed to the next roboc spaceship.
CourseNana.COM

Once an aempt has been made to move each of the roboc spaceships, the computer's turn and the current round ends, and the status informaon is updated. CourseNana.COM

The play stage ends if one of the following condions becomes true: CourseNana.COM

the user ends the play stage (by pressing the buon provided for that);
the user's spaceship is destroyed;
at the end of a turn there are no roboc spaceships le on the grid;
at the end of a turn there are no inacve mines le on the grid;
neither the user's spaceship nor any of the roboc spaceships is able to move.
CourseNana.COM

Once the play stage has ended, the game is in the end stage. In the end stage the program determines the outcome of the game. The outcome is a win for the user if there are no roboc spaceships le on the grid but the user's spaceship has survived; the outcome is a win for the computer if the user's spaceship has been destroyed and at least one roboc spaceship has survived; otherwise, the outcome is a draw. The program should display a message indicang the outcome of the game and then stop. During the end stage the program should not react to any user input or acons. CourseNana.COM

Addional Requirements and Comments: CourseNana.COM

The bulk of your JavaScript code should be in a JavaScript library called game.js . Before subming your soluon, you should create a copy of game.js named game.pretty.js in a directory other than your public_html directory, say, your home directory. Then make the file CourseNana.COM

game.js indecipherable for humans using the command    uglifyjs-3 $HOME/game.pretty.js --mangle --compress > $HOME/public_html/game.js
CourseNana.COM

Make sure that aer performing this operaon your game sll works. Also make sure that game.pretty.js can only be read by yourself and is not in your public_html directory. CourseNana.COM

It is possible that during the setup stage the user does not place any mines on the grid. On entering the play stage your program should recognise that, immediately proceed to
the
end stage, and declare the outcome of the game.
It is also possible that during the
setup stage the user does not place any roboc spaceships on the grid. On entering the play stage your program should recognise that, immediately proceed to the end stage, and declare the outcome of the game. CourseNana.COM

It should be possible for the user to see whether a mine is inacve or has been acvated. Whether the cells surrounding an acvated mine are visually disnct is up to you.
You should carefully analyse in which situaons the user's spaceship and the roboc spaceships might not be able to move in order to correctly end the
play stage in such situaons.
Ideally your program would move the roboc spaceships in such a way that they increase their chances of destroying the user's spaceship. This could be done by each roboc spaceship trying to decrease the distance to the user's spaceship with each move. But you could also implement a strategy by which the roboc killer spaceships try to `encircle' the user's spaceship in order to increase their chances. They could also `guard' one specific inacve mine, knowing that the user must eventually try to acvate it.
Also, be aware that the requirement that a roboc spaceship must move if it can, means that it might have to move onto a cell surrounding an acvated mine and be destroyed. But if alternave moves exist, then they should be preferred.
JavaScript engines differ from browser to browser. You should make sure that your system works in all commonly used browsers (e.g., Google Chrome, Microso Edge, Mozilla Firefox) and on all commonly used plaorms (e.g., Linux derivaves and Microso Windows).
Your JavaScript program should only depend on your own code.
The use of JavaScript libraries/frameworks, This includes poinng out which parts of your code have been developed with the help of on-line sources or textbooks and references for these sources. You must also provide references for any language constructs or funcons that you have used that were not covered in the lectures. CourseNana.COM

A program that deals sasfactorily with these addional requirements and comments, in addion to providing the basic funconality required, will receive higher marks. CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Liverpool代写,COMP284代写,Scripting Languages代写,JavaScript代写,Liverpool代编,COMP284代编,Scripting Languages代编,JavaScript代编,Liverpool代考,COMP284代考,Scripting Languages代考,JavaScript代考,Liverpoolhelp,COMP284help,Scripting Languageshelp,JavaScripthelp,Liverpool作业代写,COMP284作业代写,Scripting Languages作业代写,JavaScript作业代写,Liverpool编程代写,COMP284编程代写,Scripting Languages编程代写,JavaScript编程代写,Liverpoolprogramming help,COMP284programming help,Scripting Languagesprogramming help,JavaScriptprogramming help,Liverpoolassignment help,COMP284assignment help,Scripting Languagesassignment help,JavaScriptassignment help,Liverpoolsolution,COMP284solution,Scripting Languagessolution,JavaScriptsolution,