add game class
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class game {
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
private Scanner scanner;
|
||||||
|
|
||||||
|
public game()
|
||||||
|
{
|
||||||
|
this.scanner = new Scanner(System.in);
|
||||||
|
this.player = createPlayer();
|
||||||
|
this.location
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player createPlayer()
|
||||||
|
{
|
||||||
|
System.out.println("🏰 Welcome to Java Knight!");
|
||||||
|
System.out.println("Enter your name: ");
|
||||||
|
String name = scanner.nextLine();
|
||||||
|
|
||||||
|
System.out.println("1. ⚔️ Knight (High Damage, Balanced HP)");
|
||||||
|
System.out.println("2. 🧙 Wizard (High HP, Magic Power)");
|
||||||
|
System.out.println("3. 🗡️ Assassin (High Mana, Critical Hits)");
|
||||||
|
int choice = getIntInput("Choose your character: ");
|
||||||
|
|
||||||
|
Player newPlayer = null;
|
||||||
|
switch (choice)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
System.out.println("You chose the Knight!");
|
||||||
|
newPlayer = new Knight(name);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
System.out.println("You chose the Wizard!");
|
||||||
|
newPlayer = new Wizard(name);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
System.out.println("You chose the Assassin!");
|
||||||
|
newPlayer = new Assassin(name);
|
||||||
|
default:
|
||||||
|
System.out.println("Invalid choice. Defaulting to Knight.");
|
||||||
|
newPlayer = new Knight(name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getIntInput(String prompt) {
|
||||||
|
System.out.print(prompt);
|
||||||
|
while (!scanner.hasNextInt()) {
|
||||||
|
System.out.println("⚠️ Please enter a valid number!");
|
||||||
|
scanner.next();
|
||||||
|
System.out.print(prompt);
|
||||||
|
}
|
||||||
|
return scanner.nextInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user