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 object-oriented 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 1- Create a CupcakeMinion and a Knight class
Just create the class definition within the respective .java file. Then move onto the next step.
Step 2- Create a CupcakeMinion class according to the following UML:
CupcakeMinion
- health: int
- damage: int
- level: int
+ CupcakeMinion(level: int):
+ getLevel(): int
+ getHealth(): int
+ getDamage(): int
+ toString(): String
+ defend(damage: int): void
+ attack(knight: Knight): String
The constructor CupcakeMinion(int) 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: 3* level +3
calculate the damage to be level +(random number between 0 and 2* level) inclusive, for example a level 6 minion should calculate its damage to be a random number between 6-18(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 2 MINION (health: 9)
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 1 & 2 earn full points before continuing.
Step 3- Create a Knight class according to the following UML:
Knight
- name: String
- health: int
- damage: int
+ Knight(name: String):
+ getName(): String
+ getHealth(): int
+ getDamage(): int
+ rest(): void
+ toString(): String
+ defend(damage: int): void
+ attack(minion: CupcakeMinion): String
+ flee(): boolean
The constructor Knight(String) 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 20 and damage to a random number between 5-10(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 20
toString will return a String with the knight name and health: KNIGHT Sir Duncan Frostingcrusher (health: 20)
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 3 & 4 earn full points before continuing.
Step 4- 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 playGame(Scanner 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 0 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 0 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, i.e.
Do you want to continue the adventure? (y/n): y
Do you want to continue the adventure? (y/n): y
Do you want to continue the adventure? (y/n): n
We are not done with playGame completely, so we will come back to this in a later step.
Step 5- The Encounter Loop
Within the CupcakeSingularity class, create the following function:
public static boolean encounter(Scanner 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
The Cupcake Singularity Watch the instructional

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!