Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP284 Scripting Languages (2022-23) -- Assignment 2: JavaScript

Your task for this assignment consists of two parts:

1.    Develop a JavaScript program that provides the functionality stated in theRequirements sectionbelow.

2.    Make the JavaScript program that you have created accessible and usable via the URL

https://student.csc.liv.ac.uk/~<your user

name>/game.html


taking care of the requirements set out inSubmission and Setup sectionbelow.

Requirements

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 submarine that is controlled by the user and a couple of robotic killer submarines that are controlled by the computer (that is, your program). The user and your program are the two players of the game. All submarines can move around on the grid, but while the robotic killer submarines are fuelled by nuclear power that never runs out, the user's submarine only has a limited amount of fuel and needs to collect fuel cells to keep going. The robotic killer submarines hunt the user's         submarine; the user's submarine tries to avoid getting caught while also collecting all the   fuel cells on the grid.

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

•     by clicking on a cell and typing a number between 5 and 9, a fuel cell is placed on a grid cell, the number indicates the amount of fuel in the fuel cell;

•     by clicking on a cell and typing the letter "o", an obstacle is placed on a cell;

•     by clicking on a cell and typing the letter "u", the user's submarine is placed on a cell.

•     by clicking on a cell and typing the letter "k", a robotic killer submarine is placed on a cell.

No grid cell can contain more than one object. There is no limit on the number of fuel cells, obstacles and robotic killer submarines, but there is obviously only one user's submarine. If the user types a character that is not among 5 to 9, "o", "u" and "k", an error message should be shown.

The user must at any time be able to end the setup stage of the game via a button. If the user tries to end the setup stage of the game without placing his own submarine, then an error message should be shown and the user remains in the setup stage. Otherwise the game continues with the play stage.

At the start and during the play stage, the user is again shown the grid, initially with all the objects that have been placed on the grid during the setup stage, plus additional status information: The rounds played so far, the number of units of fuel available to the user's submarine, the user's score, the computer's score. Initially, zero rounds have been played,

the user's submarine has 10 units of fuel, the user's and the computer's score are both zero. In addition, at any time there must be the possibility for the user to end the play stage of the game via a button.

While in the play stage, the game proceeds in rounds, each round starting with the user's turn followed by the computer's turn. At the start of a round, the number of rounds played is increased by one, and the information shown to the user is updated.

During his/her turn, if the number of units of fuel of the user's submarine is zero at the start of the turn, then the user's submarine cannot move, a message should be shown  indicating that the submarine is out of fuel and the user's turn then ends.

If the number of units of fuel of the user's submarine is greater than zero at the start of the turn, the user can attempt to move his/her submarine horizontally or vertically on the grid by typing one of four letters:

•     "a" attempts to move the user's submarine one grid cell to the left,

•     "d" attempts to move the user's submarine one grid cell to the right,

•     "w" attempts to move the user's submarine one grid cell up,

•     "s" attempts to move the user's submarine one grid cell down.

If the user types any other character, then an error message should be shown and the user has the possibility to type another character.

If the attempted move would result in the user's submarine ending up outside the grid or on a cell occupied by an obstacle, then an error message should be shown, the attempt to move fails, the user's submarine does not move, the number of units of fuel available to the user's submarine does not change, and the user's turn is not over.

Otherwise, the attempted move is successful, the user's submarine changes cells, and the number of units of fuel available to the user's submarine reduces by one. If the user's submarine ends up on a grid cell that contains a fuel cell, then that fuel cell is removed from the grid, the value V of the fuel cell is added both to the user's score and to the number of units of fuel available to the user's submarine, and the status information is updated. If the user's submarine ends up on a cell occupied by a robotic killer submarine, then the user's submarine is destroyed, and the game proceeds to the end stage.

During the computer's turn your program attempts to move each of the robotic killer submarines in an order that allows each to move if at all possible. Unlike the user's submarine, the robotic killer submarines are not only able to move horizontally and vertically but also diagonally. Just like the user's submarine, each robotic killer submarine only moves at most one cell in a turn.

If the user's submarine is in a grid cell immediately surrounding a robotic killer submarine,  then that robotic killer submarine must move to the cell occupied by the user's submarine, the user's submarine is destroyed, and the game proceeds to the end stage.

If the user's submarine is not in a grid cell immediately surrounding a robotic killer            submarine, but one or more of those grid cells contains a fuel cell, then the robotic killer submarine must move to one of those fuel cells, the fuel cell is removed from the grid    (thereby the computer deprives the user of fuel), the value V of the fuel cell is added to the computer's score, and the status information is updated.

If none of the surrounding grid cells contains the user's submarine nor a fuel cell, then a     robotic killer submarine 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 obstacle or by another robotic killer submarine. A robotic killer submarine is not allowed to stand still if it can move. However, if a robotic killer submarine cannot move at all, then the computer should simply proceed to the next robotic killer submarine. Once an attempt has been        made to move each of the robotic killer submarines, the computer's turn and the current   round ends, and the status information is updated.

The play stage ends if one of the following conditions becomes true

•    the user ends the play stage (by pressing the button provided for that);

•    the user's submarine is destroyed;

•    there are no robotic killer submarines on the grid;

•    there are no fuel cells left on the grid.

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      robotic killer submarines left on the grid or the user's score is higher than the computer's  score; the outcome is a win for the computer if the user's submarine has been destroyed   or the computer's score is higher than the user's score; otherwise, the outcome is a draw. The program should display a message indicating the outcome of the game and then stop.

During the end stage the program should not react to any user input or actions. Additional requirements and comments:

•    The bulk of your JavaScript code should be in a JavaScript library

called  . Before submitting your solution, 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 game.js indecipherable for humans using the command

uglifyjs

 

 

--mangle --compress >

$HOME/public_html/game.js

 

 

Make sure that after performing this operation your game still works. Also

•     It is possible that during the setup stage the user does not place any fuel cells 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 robotic killer submarines 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.

•     Ideally your program would move the robotic killer submarines in such a way   that they increase their chances of destroying the user's submarine. This could be done by each robotic killer submarine trying to decrease the distance to the user's submarine with each move. But you could also implement a strategy by which the robotic killer submarines try to `encircle' the user's submarine in  order to increase their chances. They could also `guard' one specific fuel cell,   knowing that the user must eventually try to collect it.

•    JavaScript engines differ from browser to browser. You should make sure that your system works in all commonly used browsers (e.g., Google Chrome, Mozilla Firefox) and on all commonly used platforms (e.g., Linux derivatives and Microsoft Windows).

•    Your JavaScript program should only depend on your own code. JavaScript libraries/frameworks should not be used.

•    Your code should follow theCOMP284 Coding StandardLinks to an external site.. This includes pointing out which parts of your code have been                  developed with the help of on-line sources or textbooks and references for   these sources.

A script that deals satisfactorily with these additional requirements and comments, in addition to providing the basic functionality required, will receive higher marks

Submission and Setup

Create a single zip-file named COMP284-2.zip containing all relevant files (game.html, game.js, game.pretty.js, any CSS file, and local images, but no directories) and submit it via the departmental submission system                                                                                                       athttps://sam.csc.liv.ac.uk/COMP/Submissions.pl?module=comp284Links to an external site.(COMP284-2: JavaScript).

Make game.html, game.js, and other files (but not game.pretty.js) accessible via the departmental web server so that the game can be played via the URL given at the  beginning of the assignment.

The files submitted must be identical to those set up on the departmental web server. Furthermore, no alterations are allowed to the latter after files have been submitted. If a submitted file and the corresponding file on the departmental web server have different timestamps, then the later timestamp will be used to determine lateness. This applies even if the earlier file is used for marking.

Permissions of the files in your filestore must be such that no other user can view their contents in the filestore.

Deadline

The deadline for this assignment is

Friday, 28 April 2023, 17:00

Earlier submission is possible, but any submission after the deadline attracts the standard  lateness penalties. Please remember that a strict interpretation of `lateness' is applied by   the Department, that is, a submission a minute after the deadline is considered to be a day late. Also remember that late resubmissions are not allowed.

Assessment

This assignment will address the following learning outcomes of the module:

•     Develop computer-based or client-side web-based applications using an appropriate scripting language.

This assignment will contribute 50% to the overall mark of COMP284. Failure on this      assignment may be compensated by higher marks on other assignments for this module.

Marks will be awarded according to the following scheme, assessing the extend to which  the application you have developed by the deadline meets the requirements, has been set up correctly, and submitted correctly:

•    Submission, Setup, Error-freeness: 10

•    Quality of the interface design: 11

•    Correctness and quality of the implementation of the setup stage: 12

•    Correctness and quality of the implementation of the play stage: 45

•    Correctness and quality of detecting the end of the game and of the end stage: 10

•    Code layout, commenting, and quality of code: 12

In more detail, the requirements above translate into about 32 criteria that your system  must satisfy. Marks are given according to the extent to which the system is observed to behave in the expected way and produces correct results, and, to a lesser extent, how well the code is written. Code that has no observable effect will typically receive no marks.

As stated above, the University policy on late submissions applies to this assignment, as do the University policy on coursework submission (available                                                   athttps://www.liverpool.ac.uk/media/livacuk/tqsd/code-of-practice-on-assessment/appendix_Q_cop_assess.pdfLinks to an external site.) and the University policy on academic integrity (available athttp://www.liv.ac.uk/student-administration/student-administration-centre/policies-procedures/academic-integrity/Links to an external site.). You should follow theCOMP284 Lab RulesLinks to an external site.to ensure that you do not breach the latter policy.