Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Author: Harry Zhang
- * Date: 20/09/17
- * For: Java Programming Class #1
- */
- import java.util.Random;
- import java.util.Scanner;
- public class MainGame {
- public static void main(String[] args) {
- System.out.println("Welcome to Henry's ManPoke game!");
- // Sets computer and player HP
- int yourHP = 100;
- int compHP = 100;
- // Create a Scanner
- Scanner userInput = new Scanner(System.in);
- // Get User information and start game
- System.out.println("What is your name?");
- String name = userInput.nextLine();
- System.out.println("Hello, " + name + ". Would you like to begin?");
- String start = userInput.nextLine();
- // What to do if the user wants to play
- if (start.equals("Yes") || start.equals("yes")) {
- // Game runs in this infinite loop
- while (true) {
- // Prompt user to start their turn
- System.out.println();
- System.out.println("Start turn?");
- String go = userInput.nextLine();
- // If the user plays
- if (go.equals("Yes")) {
- // Generate an attack damage for both the player and the AI
- Random rand = new Random();
- int yourMove = rand.nextInt(50);
- int compMove = rand.nextInt(50);
- // Show the user what both players rolled
- System.out.println("You did " + yourMove + " damage!");
- System.out.println("Computer did " + compMove + " you!");
- // Calculate and Display both players health
- yourHP = yourHP - compMove;
- compHP = compHP - yourMove;
- System.out.println("You have " + yourHP + " health!");
- System.out.println("Computer has " + compHP + " health!");
- // If both players died at the same time
- if (yourHP <= 0 && compHP <= 0) {
- System.out.println("Tie Game!");
- break;
- // If you died before the AI
- } else if (yourHP <= 0) {
- System.out.println("You Lose!");
- break;
- // If the AI died before you
- } else if (compHP <= 0) {
- System.out.println("You Win!");
- break;
- }
- // If the user quits
- } else {
- System.out.println("You Lose!");
- break;
- }
- }
- // What to do if the user does not want to play
- } else {
- System.out.println("Cya!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement