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

  1. Initialize health points:

    1. Both player and enemy start with 10 HP.

  2. Roll the dice each round:

    1. Use Random to simulate dice rolls for the player and the enemy.

    2. Dice rolls must range from 1 to 6.

  3. Compare rolls:

    1. If the player’s roll is higher, the enemy’s HP decreases by 1.

    2. If the enemy’s roll is higher, player HP decreases by 1.

    3. If the rolls are equal, it’s a tie—no HP changes.

  4. Display round info:

    1. Show both dice rolls and current HP for players and enemies after each round.

  5. Game loop:

    1. Keep the game running while the player and enemy HP exceed 0.

    2. Wait for the user to press Enter before each round (use Scanner for input).

  6. End result:

    1. 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

  1. Initialize health points:

    1. Both player and enemy start with 10 HP.

  2. Roll the dice each round:

    1. Use Random to simulate dice rolls for the player and the enemy.

    2. Dice rolls must range from 1 to 6.

  3. Compare rolls:

    1. If the player’s roll is higher, the enemy’s HP decreases by 1.

    2. If the enemy’s roll is higher, player HP decreases by 1.

    3. If the rolls are equal, it’s a tie—no HP changes.

  4. Display round info:

    1. Show both dice rolls and current HP for players and enemies after each round.

  5. Game loop:

    1. Keep the game running while the player and enemy HP exceed 0.

    2. Wait for the user to press Enter before each round (use Scanner for input).

  6. End result:

    1. 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
    }

}
Dice battle example