0% found this document useful (0 votes)
13 views1 page

Game

This Java code defines a game where a player battles a monster by blocking attacks. It tracks the player's life, number of blocks, damage from hits, and number of assaults. The player chooses to block high, middle, or low and random chance determines if a block was successful, affecting life. The game ends if life hits 0 or 15 assaults are reached, printing final stats.

Uploaded by

0247isanchez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Game

This Java code defines a game where a player battles a monster by blocking attacks. It tracks the player's life, number of blocks, damage from hits, and number of assaults. The player chooses to block high, middle, or low and random chance determines if a block was successful, affecting life. The game ends if life hits 0 or 15 assaults are reached, printing final stats.

Uploaded by

0247isanchez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;

public class Play {

public static void main(String[] args) {


// TODO Auto-generated method stub
boolean finish = false;

int life,assault,block,blocks,damage,height;

assault = 1;
life = 100;
blocks = 1;
damage = 1;

Scanner entry = new Scanner(System.in);


System.out.println("Welcome to the game\r\n"+"\r\n");

while (finish == false) {


height = (int) (Math.random() * 2);

System.out.println("Assault #"+ assault +"\r\n");


System.out.println("The monster is attacking. PROTEGATE!");
System.out.println("Choose your block (0 for bottom, 1 for
middle, 2 for top): ");
block = entry.nextInt();

if (block != height) {
damage = (int) (Math.random() * 30);
System.out.println("\r\n" + "You didn't block the blow");
System.out.println("- Damage received: " + damage);
life = life - damage;
System.out.println("- Remaining life: " + life + "\r\n" +
"--------------\r\n" + "\r\n");
blocks = 1;
}
else if (block == height) {
System.out.println("\r\n" + "You blocked the blow!");
System.out.println("- Remaining life: " + life + "\r\
n"+"--------------\r\n" + "\r\n");
blocks++;
if (blocks == 3) {
life = life + 5;
blocks = 1;
}
}
if (life <= 0 || assault >= 15) {
finish = true;
}
else {
assault++;
}
}
System.out.println("End of game.");
System.out.println("Remaining life: " + life);
System.out.println("Remaining rounds: " + assault);
}
}

You might also like