How to utilize javascript to persist and manipulate data

Assignment Help Computer Engineering
Reference no: EM131859211

Assignment: Battleship

You will be implementing the game of Battleship to be played with the web browser. This assignment is to demonstrate an understanding of how to utilize Javascript to collect, persist, and manipulate data, and to respond to user interactions to dynamically change the DOM.

• For this version, you will assume that only one user is viewing the page that presents your game at a time (e.g., the two players are using a laptop that they pass back and forth between turns).
• Wikipedia's Battleship entry lays out the rules.
• Your game will be built on a 10x10 grids, with rows labeled 1-10 and columns labeled A-J.
• We will assume that players will place 3 game pieces
• an aircraft carrier (5 spaces long)
• a battleship (4 spaces long)
• a submarine (3 spaces long).
• These pieces can be placed either horizontally or vertically, and cannot overlap.

Specifications

These are the base requirements for making the page work. You can enhance. You cannot use external libraries like jQuery for this project.

• When the page is loaded, your game should begin by asking the first player for her name (for example, lets assume that the first player is Alice), and a string representing her ship placements.

• Your game should be flexible in accepting the syntax of a ship placement string. Specifically, it should accept strings of the following forms as equivalent, with each resulting in an aircraft carrier placed on A1, A2, A3, A4, A5; a battleship at B6, C6, D6, E6; and a submarine at H3, I3, J3:

• A:A1-A5;B:B6-E6; S:H3-J3

• A(A1-A5); B(B6-E6); S(H3-J3);

• B(B6-E6);S(H3-J3);A(A1-A5)

• Use a regex function to validate the strings.

• After gathering the first player's name and ship placement, your game should prompt the second player for their name and ship placement (for example, lets assume the second player is Bob).

• With this starting info in hand, your game should begin the first player's turn

• At the start of a turn, your game should pop up an alert indicating whose turn it is (e.g., "Click OK to begin Alice's turn").

• After the prompt is dismissed, your game should render 2 10x10 grids, one at the top of the window, and the other just below it, closer to the bottom of the browser window.

• Both grids should have a light blue background.

• The top grid should represent the current players target (i.e., the grid where the other player's ships reside), while the bottom represents the current player's ship deployment.

• At the start of the first player's first turn, the top grid will be completely empty, and the bottom grid will show only the location of the first player's ships

• On the bottom grid, each space occupied by part of an aircraft carrier should contain an "A", each space occupied by part of a battleship should contain a "B", each space occupied by part of a submarine should contain an "S".

• The player is then free to click a space into top grid to "fire" at.

• Clicks on the lower grid should have no effect.

• The game should pop up an alert to inform the player whether the shot was a hit or a miss.

• If the player clicks on a space where no part of any of the other player's ships was placed, the shot is a miss, and the space should be colored white.

• If some part of one of the other player's ships was placed in the clicked space, the shot is a hit, and the space should be colored red.

• If this hit represents the final portion of a ship (i.e., the 5th hit on an aircraft carrier, the 4th hit on a battleship, or the 3rd hit on a submarine), the player should be alerted as to which of the other player's ships they have sunk.

• After the player has clicked on their target space and the hit or miss has been reported, the player's turn is ended and the other player's turn should begin with a popup (e.g., "Click to begin Bob's turn").

• Note: that this will require blanking the page before the alert is created to prevent Bob from seeing Alice's ship placement (and vice-versa), and will require a rearranging of the page after the alert is dismissed so that Bob's target grid appears at the top of the page, and his ship placement appears on the bottom.

• At any point in time, the current player's top grid should display all the hits(red spaces) and misses (white spaces) that they have fired, while the bottom grid shows all of the hits and misses their opponents have fired along with their ship placements.

• The game continues until all of one player's ships have been sunk, at which point the other player wins the game.

• Once a winner has been established, your game should compute the winner's score

• Score is computed as: 24 - (2 points for each hit against them)

• 10 points for sinking the opponent's aircraft carrier

• 8 points for sinking the opponent's battleship

• 6 points for sinking the opponent's submarine

• If Alice won the game while Bob was able to sink her submarine and land a single hit on her battle ship, but did not hit her aircraft carrier at all, Alice score would be 16

• 24 - (2 * 4)

• Your game should keep track of the names and scores of the 10 highest scores in local storage.

• If 10 players have all achieved the max score (24), no further updates to local storage are required.

Reference no: EM131859211

Questions Cloud

Write a program that prompts the user to input the lengths : Write a program that prompts the user to input the lengths and widths of the door, each window, the bookshelf, and the length, width, and height of the room.
Describe several problems confronting women : Describe several problems confronting women and minorities in attempting to integrate into the police work environment.
Do we have to use different ones for each type of process : Can one control chart work for both of these processes, or do we have to use different ones for each type of process?
How should roles be selected for the emergency : How should roles be selected for the Emergency Operations Center (EOC)? Is seniority is less important than experience? Give examples?
How to utilize javascript to persist and manipulate data : Demonstrate an understanding of how to utilize Javascript to collect, persist and manipulate data and to respond to user interactions to dynamically change DOM.
Should organizations seek to reduce or control conflict : Many people view conflict as universally negative. Do you agree with this statement? Should organizations seek to reduce OR control conflict? Give an example.
Reasons and steps required for federal involvement : What are the reasons and steps required for federal involvement in a terrorism critical incident and a natural disaster critical incident?
What should sme do to resolve disputes : Should business should pay attention to IP, or what benefits your medium-sized enterprise could possibly draw from its use.
Do those perceptions differ from the reality : Do those perceptions differ from the reality? Are convicts being corrected?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Write an program to do lagrangian interpolation

Write an N2 program to do lagrangian interpolation. Can x55 be computed with fewer than nine multiplications? If so, say which ones: if not, say why not.

  Organization to consolidate servers

Utilizing any organizational model from your experience and or research, describe the pros and cons of this organization in order to consolidate the servers and to relocate the primary data centers.

  What control mechanisms at your organization

What control mechanisms at your organization are (or should be) the most useful or important for the success of DHL?

  What problems are you possible to encounter

make two algorithms (one iterative and one recursive) to print the daily salary of a worker who, each day, is paid twice the previous day's salary (starting with one penny for the first day's work) for a 30 day period.

  Draw the timing diagram to show the given sequence

Design a synchronous counter to count in the sequence 0000-0101-1100-1001-1110-1111-0000, using T flip-flops. Draw the timing diagram to show this sequence.

  Create the logic for an application that contains an array

Create the logic for an application that contains an array of 10 multiple-choice questions related to your favorite hobby.

  Find sql statements and screenshots of the result

Any other information you would like to retrieve from the database.

  Design a bcd to seven-segment decoder

Design a BCD-to-7-segment decoder circuit whose input consists of the four-bit BCD. The circuit should produce 7 outputs, each of which is connected.

  Create a application that can be used to change form color

Create a Windows application that can be used to change the form color. Your form background color should initially be blue.

  Implementing a streamlined information assurance program

It could be in the field of securing a wireless network, implementing a streamlined information assurance program, generic security design for a business, personal information privacy protection, etc.

  Explain the risk management practices you could use

Clearly identifying the major and minor causal factors. Identify and explain the risk management practices you could use to mitigate them and evaluate the applicability of these techniques.

  Soda vending machine design

Soda Vending Machine Design,    A state diagram showing the implementation of your design. Clearly show all the states and the conditions on which transitions occur.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd