import java.util.Scanner; public class SimpleShooter { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int playerPosition = 0; int bulletPosition = -1; while (true) { // Clear console System.out.print("\033[H\033[2J"); System.out.flush(); // Draw game for (int i = 0; i < 20; i++) { if (i == playerPosition) { System.out.print("P"); } else if (i == bulletPosition) { System.out.print("B"); } else { System.out.print("-"); } } System.out.println("\nUse 'a' and 'd' to move, 's' to shoot, or 'q' to quit."); // User input char input = scanner.nextLine().charAt(0); if (input == 'a' && playerPosition > 0) { playerPosition--; } else if (input == 'd' && playerPosition < 19) { playerPosition++; } else if (input == 's' && bulletPosition == -1) { bulletPosition = playerPosition; } else if (input == 'q') { break; } if (bulletPosition >= 0) { bulletPosition--; if (bulletPosition < 0) { bulletPosition = -1; } } } System.out.println("Game over!"); } }