Question: The Cupcake Singularity Watch the instructional video in the Canvas assignment pages. Background & Objectives In this assignment, you will write a program to simulate
The Cupcake Singularity
Watch the instructional video in the Canvas assignment pages.
Background & Objectives
In this assignment, you will write a program to simulate a knight's adventures in a fantastical future where cupcakes gained sentience and now malevolent minions roam the land. You will use objectoriented programming concepts, such as classes and objects, as well as conditional statements and loops. The player takes on the role of a knight who must defeat the malevolent cupcake minions that have taken over the world. The knight will earn gold for the Kingdom's war effort.
Instructions
Step Create a CupcakeMinion and a Knight class
Just create the class definition within the respective java file. Then move onto the next step.
Step Create a CupcakeMinion class according to the following UML:
CupcakeMinion
health: int
damage: int
level: int
CupcakeMinionlevel: int:
getLevel: int
getHealth: int
getDamage: int
toString: String
defenddamage: int: void
attackknight: Knight: String
The constructor CupcakeMinionint should perform the following:
take in as input the level and assign it to the level member variable
calculate the health based on the formula: level
calculate the damage to be level random number between and level inclusive, for example a level minion should calculate its damage to be a random number between inclusive
getLevel getHealth getDamage are accessor methods that should each return their respective variable value.
toString will return a String with the minion level and health: Level MINION health:
We'll cover the remaining methods in a future step, stub out the methods defend can be empty and attack can just return an empty string for now
Make sure Tests & earn full points before continuing.
Step Create a Knight class according to the following UML:
Knight
name: String
health: int
damage: int
Knightname: String:
getName: String
getHealth: int
getDamage: int
rest: void
toString: String
defenddamage: int: void
attackminion: CupcakeMinion: String
flee: boolean
The constructor KnightString should perform the following:
take in as input the name of the knight and assign it to the name member variable.
It should also assign the starting health to and damage to a random number between inclusive
Use constant variables appropriately.
getName getHealth getDamage are accessor methods that should each return their respective variable value.
rest should set the health back to
toString will return a String with the knight name and health: KNIGHT Sir Duncan Frostingcrusher health:
We'll cover the remaining methods in a future step, stub out the methods flee can just return false, and attack can return an empty string for now
Make sure Tests & earn full points before continuing.
Step Create a CupcakeSingularity class and the Game Loop
This is where you get to have some fun. In the main method we'll create the knight that continually encounters cupcake minions until either the knight runs out of health or the player chooses to quit. We are going to build this in steps.
Within the CupcakeSingularity class, create the following function:
public static int playGameScanner scanner, Knight knight
This function is meant to create the main play loop. It returns the total gold earned during the game. Just have it return for the moment.
Create a main function, it should:
Create a Scanner object with System.in
Create a Knight object choose a name for your hero do NOT prompt the user to choose their name and welcome the player. Output a message welcoming your knight to the game see below for an example
Create a gold variable
Call our newly created playGame and save the gold returned into our variable
Finally output the gold earned in the game. Compile and run your program, you should have this output or similar:
Welcome to the Cupcake Singularity Sir Duncan Frostingcrusher
You earned gold for the Kingdoms treasury.
Now let's make more progress in the playGame functionality:
Use scanner and a loop prompt the player if they want to continue playing the game
Do NOT prompt the player to continue when encountering the first minion, only prompt after the first encounter.
If the player wants to continue playing, reprompt, otherwise end the loop which will end the playGame function, ie
Do you want to continue the adventure? yn: y
Do you want to continue the adventure? yn: y
Do you want to continue the adventure? yn: n
We are not done with playGame completely, so we will come back to this in a later step.
Step The Encounter Loop
Within the CupcakeSingularity class, create the following function:
public static boolean encounterScanner scanner,
The Cupcake Singularity
Write the defend method. Debit the damage from the health, don't let the health fall below zero.
Write the attack method:
The Knight's
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
