Create an HTML document containing an empty document division, plus a button below the division. Script the button to call a function named play() when it's clicked; link the JavaScript file into which you will write the  play() function, to your document. In your JavaScript file create a constructor for an object type named RPGActor; write code in the constructor so that it builds an instance of RPGActor containing: A property life, which represents the amount of life the actor object has; a property hitpoints, which represents how much damage the actor does when it attacks; a property alive, which is always set to true when the object is created; a method named attack(enemy), which takes an RPGActor object as its argument. The attack() method must do the following: Generate a random number from 0 to 2, which is used to decide if the attack misses (is blocked); if the number is greater than zero then the attack succeeds. If the attack succeeds, the hit points of the attacking actor must be subtracted from the life points of the enemy; your code must take into account the fact that the enemy might have fewer than the attacker's hit points in life remaining (an actor cannot have negative life points). If the enemy has zero life points remaining after the attack, it's alive property must be set to false. Write the play() function that is called by the button onclick event handler. This function must: Create two RPGActor objects and assign a random number from 10 to 20 as the life for each object, calculated anew for each object (so each object probably has a different amount of life); acquire the document division element; attack each of the two actors alternately i.e., actor1 must attack actor 2, then actor2 must attack actor1, until one of them has no life left, at which point the fight ends and the winner is the actor that still has life. After each attack, report in the document division, on the current status of each actor i.e., how much life does each actor have remaining? This must be a continuous record until the fight is over.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 1E: Create an application class named LetterDemo that instantiates objects of two classes named Letter...
icon
Related questions
Question

Create an HTML document containing an empty document division, plus a button below the division. Script the button to call a function named play() when it's clicked; link the JavaScript file into which you will write the  play() function, to your document.

In your JavaScript file create a constructor for an object type named RPGActor; write code in the constructor so that it builds an instance of RPGActor containing:

  • A property life, which represents the amount of life the actor object has;
  • a property hitpoints, which represents how much damage the actor does when it attacks;
  • a property alive, which is always set to true when the object is created;
  • a method named attack(enemy), which takes an RPGActor object as its argument.

The attack() method must do the following:

  • Generate a random number from 0 to 2, which is used to decide if the attack misses (is blocked); if the number is greater than zero then the attack succeeds.
  • If the attack succeeds, the hit points of the attacking actor must be subtracted from the life points of the enemy; your code must take into account the fact that the enemy might have fewer than the attacker's hit points in life remaining (an actor cannot have negative life points).
  • If the enemy has zero life points remaining after the attack, it's alive property must be set to false.

Write the play() function that is called by the button onclick event handler. This function must:

  • Create two RPGActor objects and assign a random number from 10 to 20 as the life for each object, calculated anew for each object (so each object probably has a different amount of life);
  • acquire the document division element;
  • attack each of the two actors alternately i.e., actor1 must attack actor 2, then actor2 must attack actor1, until one of them has no life left, at which point the fight ends and the winner is the actor that still has life. After each attack, report in the document division, on the current status of each actor i.e., how much life does each actor have remaining? This must be a continuous record until the fight is over.
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage