Project: Build a Dice Battle Game
Now it’s time to bring your Java skills to life. Use everything you’ve learned to build a fun and functional project—your dice battle game!
Goal
You’ll aim to:
Design and build a complete console app.
Use input, logic, methods, and objects.
Optionally include arrays and randomness.
Your task is to create a simple battle game where the player and the enemy roll dice to fight each other. The higher roll causes the other side to lose 1 HP each round. The battle continues until one of them reaches 0 HP.
Requirements
Initialize health points:
Both player and enemy start with 10 HP.
Roll the dice each round:
Use
Randomto simulate dice rolls for the player and the enemy.Dice rolls must range from 1 to 6.
Compare rolls:
If the player’s roll is higher, the enemy’s HP decreases by 1.
If the enemy’s roll is higher, player HP decreases by 1.
If the rolls are equal, it’s a tie—no HP changes.
Display round info:
Show both dice rolls and current HP for players and enemies after each round.
Game loop:
Keep the game running while the player and enemy HP exceed 0.
Wait for the user to press Enter before each round (use
Scannerfor input).
End result:
When one side’s HP reaches 0, print a victory or defeat message.
Bonus
Add a feature to track the number of rounds played.
Add different attack damage for each roll (e.g., subtract roll difference from HP).
Customize the enemy name or player name.
You did it!
Congratulations! You’ve built a full interactive game using your Java skills.
Project: Build a Dice Battle Game
Now it’s time to bring your Java skills to life. Use everything you’ve learned to build a fun and functional project—your dice battle game!
Goal
You’ll aim to:
Design and build a complete console app.
Use input, logic, methods, and objects.
Optionally include arrays and randomness.
Your task is to create a simple battle game where the player and the enemy roll dice to fight each other. The higher roll causes the other side to lose 1 HP each round. The battle continues until one of them reaches 0 HP.
Requirements
Initialize health points:
Both player and enemy start with 10 HP.
Roll the dice each round:
Use
Randomto simulate dice rolls for the player and the enemy.Dice rolls must range from 1 to 6.
Compare rolls:
If the player’s roll is higher, the enemy’s HP decreases by 1.
If the enemy’s roll is higher, player HP decreases by 1.
If the rolls are equal, it’s a tie—no HP changes.
Display round info:
Show both dice rolls and current HP for players and enemies after each round.
Game loop:
Keep the game running while the player and enemy HP exceed 0.
Wait for the user to press Enter before each round (use
Scannerfor input).
End result:
When one side’s HP reaches 0, print a victory or defeat message.
Bonus
Add a feature to track the number of rounds played.
Add different attack damage for each roll (e.g., subtract roll difference from HP).
Customize the enemy name or player name.
You did it!
Congratulations! You’ve built a full interactive game using your Java skills.
import java.util.Random;
import java.util.Scanner;
public class DiceBattle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Random rand = new Random();
// Add your code here
}
}