COMP284 Scripting Languages (2014-15) — Assignment 3: JavaScript

COMP284 Scripting Languages (2014-15) — Assignment 3: JavaScript
Your task for the third and final COMP284 assignment consists of the following parts:
Write a report comparing Perl, PHP, JavaScript and Java:
Identify three language constructs on which Perl, PHP, and JavaScript pairwise differ (excluding the example given below) and present these in tabular form.Example:
Perl PHP JavaScript
The syntax for conditional statements is
if (condition) { } elsif (condition) { } else { }
The syntax for conditional statements is
if (condition) { } elseif (condition) { } else { }
The syntax for conditional statements is
if (condition) { } else if (condition) { } else { }
Describe what differentiates scripting languages like languages Perl, PHP and JavaScript from programming languages like C, C++ and Java.
Your answers should be presented as a short report, at most two pages long. Sources, including the lecture notes, must be referenced. Make sure that you use your own words.
Develop a JavaScript program that provides the functionality stated in the Requirements section below.
Make the JavaScript program that you have created accessible and usable via the URL
http://cgi.csc.liv.ac.uk/~<your user name>/game.html
Write a short report of at most six pages (plus a cover sheet indicating your name, student id, and departmental user name) that covers the design of the most important aspects of your system:
the web page or pages, messages, and how the user interacts with the program during setup and play stage;
how the program performs the various checks described in the Requirements section;
how the moves of the computer’s robot are determined;
how the end of the play stage and the outcome of the game is determined.
The report will typically include sketches or partial screenshots plus pseudo code or code fragments and explanations of these. It is the combination of pseudo code/code and explanation that attracts marks. The report must contain references to all the sources of information that you have used. Sources, including the lecture notes, must be referenced. Make sure that you use your own words.
Part 1 is worth 25% (10/40) of the overall mark for this assignment. Parts 2 to 4 are together worth 75% (30/40) of the overall mark for this assignment.
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, surrounded by a wall, and involves our hero, controlled by the user, and a bunch of evil killer robots, controller by the computer (that is, your program). Our hero hunts for treasure on the grid while the killer robots hunt our hero. The user and your program are the two players of the game.
The game always starts in the setup stage. During that 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 1 and 9, a treasure is placed on a cell, the number indicates the value of the treasure;
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 “h”, the hero is placed on a cell.
by clicking on a cell and typing the letter “k”, the a killer robot is placed on a cell.
There is no limit on the number of treasures, obstacles and killer robots, but there is only one hero. No cell can contain more than one object and once an object has been placed on a cell it cannot be changed. If the user tries to change the object placed on a cell, then an error message should be shown. If the user types a character that is not among 1 to 9, “o”, “h” and “k”, an error message should be shown.In addition to the grid, the user must have a means to end the setup stage of the game, for example, via a button. If the user tries to end the setup stage of the game without placing the hero, 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, plus additional information: The roundsplayed so far and the user’s score. Initially, zero rounds have been played and the user’s score is also zero. In addition, there must be the possibility for the user to end the playstage at any time, for example, 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.
During his/her turn, the user can attempt to move the hero horizontally or vertically on the grid by typing one of four letters:
“a” attempts to move the hero one cell to the left,
“d” attempts to move the hero one cell to the right,
“w” attempts to move the hero one cell up,
“x” attempts to move the hero one cell down.
If the user types any other character, then an error message should be shown. If the attempted move would result in the hero 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 hero does not move, and the user’s turn is over. Otherwise, the attempted move is successful and the hero changes cells. If the hero ends up on a cell occupied by a killer robot, then our hero dies, the game is over and the game proceeds to theend stage. If the hero ends up on a cell that contains a treasure, then that treasure is removed from the grid, the value of the treasure is added to the user’s score. After the hero changed cells and possibly collected a treasure or died, the user’s turn is again over.
During the computer’s turn your program attempts to move each of the killer robots in some order. Unlike the hero, the killer robots are not only able to move horizontally and vertically but also diagonally. Just like the hero, each killer robot only moves at most one cell in a turn. If the hero is in a cell immediately surrounding a killer robot, then that killer robot must move to the cell occupied by the hero; the hero dies, the computer’s turn and the round ends, the number of rounds played is increased by one, and the game moves to the end stage. If the hero is not in a cell immediately surrounding a killer robot, but one or more of those cells contains a treasure, then the killer robot must move to one of those cells and the treasure on that cell is removed (thereby the killer robot deprives our hero of the opportunity to collect that treasure). If none of the surrounding cells contains the hero nor a treasure, then a killer robot can move to an arbitrary surrounding cell provided that this move does not take it to a cell that is off the grid or occupied by an obstacle or by another killer robot. A killer robot is not allowed to stand still if it can move. However, if a killer robot cannot move at all, then the computer should simply proceed to the next killer robot. Once an attempt has been made to move each of the killer robots, the computer’s turn and the current round ends, and the number of rounds played is increased by one.
At the end of each round or at the end of each turn within a round, the statistical information shown by the program must be 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 hero dies;
there are no treasures left on the grid;
neither the hero nor any of the killer robots is able to move.
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 user if the hero is still alive; the outcome is a win for the computer if the hero is dead; 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:
It is possible that during the setup stage the user does not place any treasures on the grid. On entering the play stage your program should recognise that, immediately proceed to the end stage, and declare that the user has won the game.
It is also possible that during the setup stage the user does not place any killer robots on the grid. The game still proceeds as described above, only that nothing happens during the computer’s turn.
You should carefully analyse in which situations the hero and the killer robots might not be able to move in order to correctly end the play stage in such a situation.
Ideally your program would move the killer robots in such a way that they increase their chances of killing the hero. This could be done by each killer robot trying to decrease the distance to the hero with each move. But you could also implement a strategy by which the killer robots try to `encircle’ the hero in order to increase their chances to kill the hero.
Ideally your program would allow the size of the grid to be changed easily (by the maintainer of the system), independently for each dimension.
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, Microsoft Internet Explorer 9 or higher) 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.
Submission
Submit the following files (as separate, individual files; not as part of an archive file) via the departmental submission system athttps://sam.csc.liv.ac.uk/COMP/Submissions.pl (COMP284-3: JavaScript):
a PDF file of your report on the comparison of Perl, PHP, JavaScript and Java;
a PDF file of your report on the design of the JavaScript program;
the HTML/CSS file or files and any auxiliary JavaScript files for the JavaScript program.
Deadline
The deadline for this assignment is
Wednesday, 6 May 2015, 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 on Wednesday, 6 May 2015, 17:01 is considered to be a day late.
Assessment
This assignment will address the following learning outcomes of the module:
compare and contrast languages such as JavaScript, Perl and PHP with other programming languages
produce an outline design for applications written using a scripting language;
rapidly develop simple applications, both computer and web-based, using an appropriate scripting language.
This assignment will contribute 40% to the overall mark of COMP284. Failure on this assignment may be compensated by higher marks on other assignments for this module.
The report on the comparison of Perl, PHP, JavaScript and Java will be marked separately. Comprehensiveness and quality of the report on the comparison of Perl, PHP, JavaScript and Java will determine 25% (10/40) of the mark for this assignment. The remaining 75% (30/40) will be determined by the remaining tasks of this assignment and marks will be awarded according to the following scheme:
Comprehensiveness and quality of the design report for the JavaScript program: 20
The JavaScript program is accessible via the required URL and works without producing error messages: 8
Correctness and quality of the solution to the JavaScript programming task (72 in total):
Quality of the interface design: 7
Correctness and quality of the implementation of the setup stage: 14
Correctness and quality of the implementation of the play stage: 33
Correctness and quality of detecting the end of the game and of the end stage: 8
Formatting, commenting, and quality of code: 10
Penalties:
If one or both reports are not submitted as a PDF files, then 5 marks will be subtracted.
For every additional page that a report exceeds the specified page limit, 5 marks will be subtracted.
If the HTML file and any auxiliary JavaScript files for the JavaScript program are not submitted as separate files, then 5 marks will marks will be subtracted.
No work that achieves the pass mark of 40 or more before the application of these two penalties will be reduced below the pass mark once the two penalties are taken into account. Work that only achieves a mark below 40 before the application of these two penalties will see no reduction.
As stated above the University policy on lateness penalties applies to this practical assignment as does the University policy on academic integrity.
Department of Computer Science, University of Liverpool
Ashton Building, Ashton Street, Liverpool L69 3BX, United Kingdom
+44 (0)151 795 4275
Maintained by Ullrich Hustadt, u.hustadt@liverpool.ac.uk
© University of Liverpool – a member of The Russell Group
Departmental Contacts | University Contacts | Map | Legal | Accessibility