Landing : Athabascau University

assignment 4

Last updated September 1, 2021 - 10:56am by SOBECHI cornella Madueke-Aniemeka

Assignment 4

 

 

making this game. i had no detailed knowledge on the alice in wonderland game so i tried to design my own game. i did not use any estranged method i kept my game simple and straight to the point. using scanner packages and if else statements as the game is a prompt game and requires user input to guarantee the next steps that would be taken.the knowledge i used for this game was from the textbook and then youtube. but youtube only came in handy for when i had an idea and wasn't sure how to piece it together. i did not necessarily gather any code from there. designing this game i thought about how i wanted to make it as interactive as possible. i thought about all those games where the mission starts  in a palace and you are going to encounter various creatures depending on the route you follow, you will be given a weapon to fight them off. so that image was entirely what i based my game upon. at the end depending on your choices you either win or youre dead (you lost.)

 

 THE VARIOUS CLASSES IN MY GAME.

1. MAIN CLASS

the first class was where main class.i basically called out everything i would use in the rest of the program. in there i called the scanner class above.i already imported the java.util pacakge above the code.i created variables to store the players,monsters life, the choices and silver ring that was stored with int. the name and players weapon was stored using string.

  the public static void main as we know is the entry point of any java program. in there i defined a main class of type dublin and then created an instance of it from the main class. in called in two methods of the class the playersetup method and town gate method.

 

2. PLAYER SET UP METHOD

inside the player set up class. i had the players life, the monsters life and the weapon set up in there. i set the player life to 10, monster life to 15 and put a knife as the players weapon.

i used system print to tell the user the amount of lives they have and the weapon they are going to use for the adventure. the game then asks the user to input their name and scans it using scanner. it then goes on to welcome the user by saying lets start the game.

3. Town GATE METHOD.

in this method, I printed out that the player is at the front of the gate and has a guard infront of them. i then provided a list of choices from 1-3. i then stored the user input in a vairable called choice and scanned the users input. using the if else statement if the user chooses.

a. choice 1 :  that’s to talk to the guard. it goes ahead to check if the silver ring is equals to 1. if it is the ending function will then run. else the program will print out a message from the guard to the user that says. hello stranger, your name is __- we can’t let you into town. it then goes ahead and runs the town gate function again

b. choice 2: attack the guard.  one point would be reduced from the players hp. the guard will then tell the player to not be stupid and then hits the user so they receive one damage. the users hp is then printed out to let them know their life has been reduced by a point. then we listen to scanner again and finally the town gate function runs again.

c. if choice 3: leave the crossroad function will run.

d. i put in a last else statement for when the user inputs an invalid option. if that happens the town gate method runs again, and the options are displayed again.

 

4. CROSS ROAD METHOD.

This method is connected to the leave option in the town gate method. i printed out a message letting the user know that they are at a crossroad. i listed out options 1-4 those included the four main cardinal points. the user’s choice is then scanned into the variable called choice that was created earlier. and scanner was used to take the input in.

choice 1 go north

choice 2 go east

choice 3 go south

choice 4 go west

else ( the cross road method will run again)

 

5. THE NORTH METHOD.

I sort of river of life lol. the program tells the user that there is a river, for them to drink and then rest. doing so increases the users hp (life) by 1. the program then tells the user their new hp. the program then asks for an input again if the user’s choice is 1 they go back to the cross road. if not it runs the north function again.

 

6. THE EAST METHOD.

in this function. the programs lets the user know that they walked into a forest and found a lond sword. it then updates the weapon from a knife to a long sword. it then tells the user to go back to the cross road. it waits for the user to press one for that. if 1 is not selected it will run the east function again.

 

7. THE WEST METHOD.

in this block of code. when the user goes west. the program lets the user know that they have encountered a goblin. it gives 2 options. 1. to run and 2. to fight. it uses scanner to get the input of the user.

a. if choice == 1 (FIGHT) it would start the fight function

b. if choice ==2 (RUN) this will take the player back to the crossroad.

c. else the west function runs again.

 

8. THE FIGHT METHOD.

this program runs when the user chooses 1 from the west function. it prints out both the lives of the monster and the player. it then gives option. 1. to attack and 2 . to run.

a. if choice is 1 : the attack function will run

b. if choice is 2 it will take the user back to the crossroad

c. else the fight method will run again.

 

9. THE ATTACKK FUNCTION.

i created a variable called the players damage and set the players damage to 0. i have two weapons so what i did was that if the weapon was a knife a random integer selected between 1 and 5 would be the damage the user gives to the monster but if the weapon is a long sword a random number between 1 and 8 would be selected for the damage. it then tells the user what damage was given to the monster. the monster’s life is then updated by subtracting the player damage from the monster’s life and lets the user know.

if the monsters life is less than one the win function will run.

else if the monsters life is greater than 0 the monster is going to attack the user within the range 0-4 and . i created a variable called the monsters damage and set the monsters damage to 0.the random number generated was saved to the monster damage variable. the players hp is then updated by subtracting the monsters damage from the users life.  the players life is then printed out.

if the players life is less than 1 the dead function will run. else the fight function id called again.

 

10. DEAD METHOD.

This just lets the user know that they are dead. and that the game is over.

 

11. THE WIN METHOD.

lets the user know that they killed the monster, and obtained a silver ring. it then tells the user to go east by inputing 1. the silver ring is set to one in this function. it waits for the users choice. if choice is 1 the cross road function will run else the win method will run again.

12. THE ENDING FUNCTION.

this just prints out congratulatory messages and then the game ends.

 

One of the challenges I faced making this game was. I forgot to call another function within a code. My code was designed in a way that a choice in a method leads to another method. Like how the cross road method is connected to the leave option in the town gate function.  Instead of my calling it by saying crossroad(). I used exit() so It simply did not link when I ran my program the first time. But after going through YouTube text-based games on java. I found out why and went back to properly link my methods. Overall this game was actually pretty fun to make.