Create a simple text-based console game that implements at least three (3) interfaces. Below is the initial part of a sample program.
Enter your name: Nika
Press 1 or 2 to select your game mode.
1- Story
2 - Survival
Press P to start playing, Nika.
import java.util.Scanner;
public class Main implements Runnable, Comparable<Main>, AutoCloseable {
@Override
public void close() throws Exception {
System.out.println("Gotcha!");
}
@Override
public int compareTo(Main o) {
return 0;
}
@Override
public void run() {
while (true) {
System.out.println("Doing something.");
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = in.nextLine();
System.out.println("Press 1 or 2 to select your game mode.\n1-Story\n2-Survival");
String choice = in.nextLine();
System.out.println("Press P to start playing Nika.");
String play = in.nextLine();
if (play.equalsIgnoreCase("n")) {
if (choice.equalsIgnoreCase("1")) {
System.out.println("Long story short, " + name + ", you lost.");
} else if (choice.equalsIgnoreCase("2")) {
System.out.println(name + ", you didn't survive. ");
}
}
}
}
Comments
Leave a comment