Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

for reference language is javascript. pls include an html code for this as well and include buttons. you will be using your knowledge of OOP,

for reference language is javascript. pls include an html code for this as well and include buttons.

you will be using your knowledge of OOP, loops, and functions to build a rudimentary space battle game. The game will be programmed for, and played in the Chrome console. You will need to use pop-up prompts to get user input.

Today's task is to build something according to specification. Pretend you have received the specification below for a class project. Planning your program is a challenge unto itself. START SIMPLE. Break the problem down as far as you can and don't move on until the smallest piece works.

Once you've figured out the basics, it's up to you to make the game you want, but remember, your game does not have to be elegant. The only thing that matters is that it works.

SPECIFICATIONS

Build a game of battling alien spaceships using Javascript.

Earth has been attacked by a horde of aliens! You are the captain of the USS Schwarzenegger, on a mission to destroy every last alien ship.

Battle the aliens as you try to destroy them with your lasers.

There are six alien ships. The aliens' weakness is that they are too logical and attack one at a time: they will wait to see the outcome of a battle before deploying another alien ship. Your strength is that you have the initiative and get to attack first. However, you do not have targeting lasers and can only attack the aliens in order. After you have destroyed a ship, you have the option to make a hasty retreat.

A game round would look like this:

You attack the first alien ship

If the ship survives, it attacks you

If you survive, you attack the ship again

If it survives, it attacks you again

Etc.

If you destroy the ship, you have the option to attack the next ship or to retreat

If you retreat, the game is over, perhaps leaving the game open for further developments or options.

You win the game if you destroy all of the aliens.

You lose the game if you are destroyed.

Ship Properties

hull is the same as hitpoints. If hull reaches 0 or less, the ship is destroyed.

firepower is the amount of damage done to the hull of the target with a successful hit.

accuracy is the chance between 0 and 1 that the ship will hit its target.

Every time the ship will attack, calculate the chance that the damage will hit the opposing ship using Math.random()

If the ship's accuracy is 0.8 - then if the number generated from Math.random() is less than or equal to 0.8 then the attack will be successful. If the value is greater than 0.8 then the attack has missed.

Adjust the accuracy based on the specs for each ship

Your spaceship, the USS Schwarzenegger should have the following properties:

hull - 20

firepower - 5

accuracy - .7

The alien ships should each have the following ranged properties determined randomly:

hull - between 3 and 6

firepower - between 2 and 4

accuracy - between .6 and .8

You could be battling six alien ships each with unique values.

Example use of accuracy to determine a hit:

if (Math.random()

console.log('You have been hit!');

}

image text in transcribed

image text in transcribedimage text in transcribed

Example use of accuracy to determine a hit: Where to begin? - Read over the specifications. Make sure you understand them. If you do not understand them, try to clarify them for yourself. - Plan the game. This is an act of simplification. From these programming principles 1. Use pseudo code to get a sketch of your game first. 2. Avoid Creating a YAGNI (You aren't going to need it) - You should not try to add functionality until you need it. 3. Do the simplest thing that could possibly work. Often, beginning something is an act of creative inspiration to find the simplest possible case. The first step is not necessarily a matter of logical deduction. Once you have a few 'clues' you can follow the trail of crumbs to a logical conclusion. Actors and then actions A good rule of thumb is start with the actors and then the actions. What actors do we need? In this case, we need our spaceship and the alien spaceships. An action these ships can take is to attack something. Perhaps a ship object (an actor) could therefore have an attack method (an action). Actors and then actions A good rule of thumb is start with the actors and then the actions. What actors do we need? In this case, we need our spaceship and the alien spaceships. An action these ships can take is to attack something. Perhaps a ship object (an actor) could therefore have an attack method (an action). A repeating action in the game is that these ships attack each other until one of them has been destroyed. This might necessitate a loop or multiple loops. Start simpler than the instructions suggest Keep these five things in mind when planning and coding your game: 1. Begin even simpler than the specifications suggest. In this case, perhaps just start with one alien ship instead of many alien ships, and get the code for one ship working first. 2. Root out any 'gotchas' that you really ought to foresee. In this case, will we really want nested loops - one for a battle, one for iterating over aliens)? How will we exit one loop and then exit the parent loop? Perhaps keeping it to one loop somehow will help us avoid unnecessary difficulties. after it has been destroyed? Better fix that bug before increasing the complexity of the code. 4. When you have a plece of functionality tested and working, commit it. Try not to commit broken code. Unsure of when to commit? Commit when something works. You want to save working code. Code quality and code sharing From the beginning. you will be writing your code for other developers. Having to read and understand another developer's code is common practice. Get used to it now! In the 'real world', you will be in a position where you inherit someone else's code-base and are told to 'fix it' or to add a feature to the code. What does this mean for your coding practices? - Use proper indentationl On the job, your code immediately fails a code review it indentation is not perfect. - Use semantic variable and function names, and use a verb for your function/method names. - What your code does should be self-evident. - If a piece of code is hard to read have a comment above those few lines explaining what they do. Your code should be as coherent to another developer as possible. Bonuses - The aliens send a random number of ships to attack Earth. Think of a reasonable range and implement it. - Scientists have developed a super targeting computer for your lasers. You now are asked which of the aliens you would like to hit with your lasers. - Scientists have improved your ship's shields. They don't work that consistently, and only improve your hit points by a random number each time - Scientists have put missiles on your ship. You only have a limited number of them, but they do a lot of damage. You can say before each battle if you want to use one of your missles. - The aliens have gained emotions and now can attack more than one at a time. - Evil alien scientists have created an alien mega-ship. This mega-ship contains a number of "weapon pods" that each have their own individual hit points. These "weapon-pods" ( objects ) must all be destroyed before you can begin doing damage to the main ship, which also has its own hit points

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions