Reputation: 19
I know that their are a bunch of different ways to do this, but I am getting pretty good at working with the terminal and want to move on to creating user interfaces and desktop apps! I have written an extremely cheesy and messy "number game" and would like to make it run in an applet with buttons and all of that jazz!
public static void gameStart() {
System.out.println("Welcome to the Game of Awesome V1.2");
System.out.println("-------------------------------------");
spin();
}
public static void spin() {
int spinNum = (int)(10*Math.random());
Scanner input = new Scanner(System.in);
Scanner input2 = new Scanner(System.in);
System.out.println("type a number between 1 and 10:");
int guessNum = input.nextInt();
if(guessNum > 10) {
System.out.println(guessNum + " is greater than 10 you fool!");
spin();
}else if(guessNum < 1) {
System.out.println(guessNum + " is less than 1 you fool!");
spin();
}else {
System.out.println("\nSweet, looks like you chose [" + guessNum + "], good luck...");
System.out.println("\ntype \"s\" to spin and \"quit\" to, quit...");
String run = input2.nextLine();
switch (run.toLowerCase()) {
case "s":
System.out.println("\nyou spun [" + spinNum + "] and guessed [" + guessNum + "]!");
if(guessNum == spinNum) {
win();
askPlay();
}else {
lose();
askPlay();
}
break;
case "quit":
System.out.println("See ya later!");
System.out.println();
System.exit(0);
break;
default:
System.out.println("shit, you broke it! Luckily, I can fix this.");
askPlay();
System.out.println();
break;
}
}
}
public static void askPlay() {
Scanner input = new Scanner(System.in);
System.out.println("\nWanna play again? (Type \"yes\" or \"no\")");
String decideSpin = input.nextLine();
switch (decideSpin.toLowerCase()) {
case "yes":
spin();
break;
case "no":
System.out.println("\nI know it's a crappy game, thanks for playing though!");
System.out.println();
System.exit(0);
break;
default:
System.out.println("\nI'm sorry,\nI was made by a lazy "
+ "programmer and can only understand \"yes\" or \"no\"..");
askPlay();
break;
}
}
public static void win() {
System.out.println("\nWINNER: you won this insanley stupid game, of awesome! Be proud, winner. (:");
}
public static void lose() {
System.out.println("\nLOOOOOSSSSSEEEERRRR: yep, you stand with the majority with this loss.");
}
How can I do that?
Upvotes: 1
Views: 132
Reputation: 3020
Consider running it in Processing (a Java Library/Applet). That's perhaps the fastest most simplest way to get something up and going. You can even export it as an app if you like. Cheers!
Upvotes: 0
Reputation: 347334
I'd suggest you start by having a read through Swing Trail
The other thing you need to understand is Swing is event driven, unlike a console program where it tends to run sequentially
Upvotes: 2
Reputation: 83577
Definitely start learning Swing. This is the standard Java GUI framework.
Upvotes: 1
Reputation: 14826
Well, its simple: Start learning some of Java's GUI, I would recommend one of these two:
Upvotes: 1