Question: Review the video and write the code in Netbeans (or an IDE of your choice) Ask for the user name at the start of the

  1. Review the video and write the code in Netbeans (or an IDE of your choice)
  2. Ask for the user name at the start of the game. Get the date time the user played the game and the number of minutes he/she played for. Write the metrics to a file
  3. Attach the code to Moodle
  4. Attach screenshot of the execution result

So I did the code for the text based adventure game (as you can see below) I just need to add the game asking for the user name and get the date and time the user played the game, and the number of minutes. Thank you

package tutorials;

import java.util.Random; import java.util.Scanner;

public class Main { public static void main(String[] args) { //System objects Scanner in = new Scanner(System.in); Random rand = new Random(); /// Game variables String[] enemies = { \"Skeleton\", \"Zombie\", \"Warrior\", \"Assassin\" }; int maxEnemyHealth = 75; int enemyAttackDamage =25; // player variables int health = 100; int attackDamage = 50; int numHealthPotions = 3; int healthPotionHealAmount = 30; int healthPotionDropChance = 50; // Percentage boolean running = true; System.out.println(\"Welcome to the Dungeon\"); Game: while(running) { System.out.println(\"---------------------------------\"); int enemyHealth = rand.nextInt(maxEnemyHealth); String enemy = enemies[rand.nextInt(enemies.length)]; System.out.println(\"\\t# \" + enemy + \" has appeared! # \"); while(enemyHealth > 0) { System.out.println(\"\\tYour HP: \" + health); System.out.println(\"\\t\" +enemy + \"#'s HP: \" + enemyHealth); System.out.println(\" \\tWhat would you like to do\"); System.out.println(\"\\t1. Attack\"); System.out.println(\"\\t2. Drink health potion\"); System.out.println(\"\\t3. Run!\"); String input = in.nextLine(); if(input.equals(\"1\")) { int damageDealt = rand.nextInt(attackDamage); int damageTaken = rand.nextInt(enemyAttackDamage); enemyHealth -=damageDealt; health -= damageTaken; System.out.println(\"\\t> You strike the \" + enemy + \" for\" + damageDealt + \" damage.\"); System.out.println(\"\\t> you recieve \" + damageTaken + \"in retaliation!\"); if(health System.out.println(\"\\t> You have taken too much damage, you are too weak to go on!\"); break; } } else if(input.equals(\"2\")) { if(numHealthPotions > 0) { health += healthPotionHealAmount; numHealthPotions--; System.out.println(\"\\t> You drink a health potion, healing yourself for \" + healthPotionHealAmount +\".\" + \" \\t> You now have\" + health + \"HP\" + \" \\t> You have \" + numHealthPotions + \"health potions left. \" ); } else { System.out.println(\"\\t> You have no health potions left! Defeat enemies for a chance to get one! \"); } } else if(input.equals(\"3\")) { System.out.println(\"\\tYou run away from the\" +enemy +\"!\"); continue Game; } else { System.out.println(\"\\tInvalid command!\"); } } if(health System.out.println(\"Well that was a total failure, get the hell out.\"); break; } System.out.println(\"-----------------------------\"); System.out.println(\" # \" + enemy + \"was defeated! # \"); System.out.println(\" # You have \" + health + \"HP left. #\"); if(rand.nextInt(100) numHealthPotions++; System.out.println(\" # The \" + enemy + \" dropped a health potion! # \"); System.out.println(\" # You now have \" + numHealthPotions + \" health potion(s). #\"); } System.out.println(\"-----------------------------\"); System.out.println(\"what would you like to do now?\"); System.out.println(\"1. Continue fighting\"); System.out.println(\"2. Exit dungeon\"); String input = in.nextLine(); while(!input.equals(\"1\") && !input.equals(\"2\")) { System.out.println(\"invalid command!\"); input = in.nextLine(); } if(input.equals(\"1\")) { System.out.println(\"You continue on your adventure!\"); } else if(input.equals(\"2\")) { System.out.println(\"you exit the dungeon, successful from your adventures!\"); break; } } System.out.println(\"#######################\"); System.out.println(\"THANKS FOR PLAYING!!! #\"); System.out.println(\"#######################\"); } }

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!