I need to make the integer "order" save to a text file or database (All I need it to do is to count how many times you win & save it there). Every time the game starts up, I want it to read it, & every time the game is beat, I want it to add one(order++;). The game is really simple.
All you do is read the pizza order, and reply to it as it asks for each piece (of the order). Same w/ the house address & number
If anyone can also make things smaller with methods or something, go right ahead.
import java.util.Random;
import java.util.Scanner;
public class PizzaDelivery {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
Random generator = new Random();
int order = 1;
int top1 = generator.nextInt(6)+1;
int top2 = generator.nextInt(6)+1;
int top3 = generator.nextInt(6)+1;
int crust = generator.nextInt(2)+1;
int numhouse = generator.nextInt(50)+1;
int numstreet = generator.nextInt(8)+1;
int numguess = 0;
String streetguess = "nul";
String top12 = "nul";
String top22 = "nul";
String top32 = "nul";
String crust1 = "nul";
String street = "nul";
String cguess = "nul";
String guess = "nul";
if (top1 == top2 || top1 == top3)
{
top1 = generator.nextInt(6)+1;
if(top1 == top2 || top1 == top3)
{
top1 = generator.nextInt(6)+1;
}
if(top2==top3)
{
top2 = generator.nextInt(6)+1;
top3 = generator.nextInt(6)+1;
}
}
if (top2 == top3)
{
top2 = generator.nextInt(6)+1;
if(top2 == top3)
{
top2 = generator.nextInt(6)+1;
}
if(top2==top3)
{
top2 = generator.nextInt(6)+1;
top3 = generator.nextInt(6)+1;
}
}
if(top1 == 1)
{
top12 = "Cheese";
}
else if(top1 == 2)
{
top12 = "Pepperoni";
}
else if(top1 == 3)
{
top12 = "Chicken";
}
else if(top1 == 4)
{
top12 = "Anchovies";
}
else if(top1 == 5)
{
top12 = "Olives";
}
else if(top1 == 6)
{
top12 = "Pineapple";
}
else
{
top12 = "Cheese";
}
if(top2 == 1)
{
top22 = "Cheese";
}
else if(top2 == 2)
{
top22 = "Pepperoni";
}
else if(top2 == 3)
{
top22 = "Chicken";
}
else if(top2 == 4)
{
top22 = "Anchovies";
}
else if(top2 == 5)
{
top22 = "Olives";
}
else if(top2 == 6)
{
top22 = "Pineapple";
}
else
{
top22 = "Pepperoni";
}
if(top3 == 1)
{
top32 = "Cheese";
}
else if(top3 == 2)
{
top32 = "Pepperoni";
}
else if(top3 == 3)
{
top32 = "Chicken";
}
else if(top3 == 4)
{
top32 = "Anchovies";
}
else if(top3 == 4)
{
top32 = "Olives";
}
else if(top3 == 4)
{
top32 = "Pineapple";
}
else
{
top32 = "Chicken";
}
if(crust == 1)
{
crust1 = "Italian";
}
else if(crust == 2)
{
crust1 = "Whole Wheat";
}
else
{
crust1 = "Italian";
}
if(numstreet == 1)
{
street = "Port Washington Boulevard";
}
else if(numstreet == 2)
{
street = "Main Street";
}
else if(numstreet == 3)
{
street = "Fairfield Avenue";
}
else if(numstreet == 3)
{
street = "Fairview Avenue";
}
else if(numstreet == 4)
{
street = "Radcliff Avenue";
}
else if(numstreet == 5)
{
street = "Harbor Road";
}
else if(numstreet == 6)
{
street = "Harbor Acres Road";
}
else if(numstreet == 7)
{
street = "Sandy Hollow Road";
}
else if(numstreet == 8)
{
street = "Beacon Hill Road";
}
if(top12.equals(top22)||top22.equals(top32)||top12.equals(top32))
{
System.out.println("Sorry! Internal Error! Please restart the game");
try
{
Thread.sleep(500); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.exit(0);
}
else
{
System.out.println("Order #"+order+" is one pizza with "+crust1+" crust with "+top12+", "+top22+", and "+top32+".");
}
try
{
Thread.sleep(5000); // do nothing for 5000 milLiseconds (5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("What kind of crust did the order call for?");
cguess = in.nextLine();
if(cguess.equals(crust1))
{
System.out.println("The crust is perfect!");
try
{
Thread.sleep(1000); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
else
{
System.out.println("Wrong crust! You're fired");
try
{
Thread.sleep(1000); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.exit(0);
}
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("What were the toppings? (Ex: Banana)");
guess = in.nextLine();
if(guess.equals(top12)||guess.equals(top22)||guess.equals(top32))
{
if(top12.equals(guess))
{
top12 = "null";
System.out.println("Yep! What else?");
}
else if(top22.equals(guess))
{
System.out.println(top22+"! Anything else?");
top22 = "null";
}
else if(top32.equals(guess))
{
top32 = "null";
System.out.println("Indeed! What were the other ingredients?");
}
else
{
System.out.println("Pizza tastes bad! You're fired!");
try
{
Thread.sleep(1000); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.exit(0);
}
}
else
{
System.out.println("The pizza is horrible! You're fired!");
try
{
Thread.sleep(1000); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.exit(0);
}
guess = in.nextLine();
if(guess.equals(top12)||guess.equals(top22)||guess.equals(top32))
{
if(top12.equals(guess))
{
top12 = "null";
System.out.println("Great! What's the last one??");
}
else if(top22.equals(guess))
{
System.out.println("Mhmm, one more!");
top22 = "null";
}
else if(top32.equals(guess))
{
top32 = "null";
System.out.println("Correct! What's the last ingredient?");
}
else
{
System.out.println("You put the wrong ingrediant on! You're fired!");
try
{
Thread.sleep(1000); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.exit(0);
}
}
else
{
System.out.println("The pizza smells bad! You're fired!");
try
{
Thread.sleep(1000); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.exit(0);
}
guess = in.nextLine();
if(guess.equals(top12)||guess.equals(top22)||guess.equals(top32))
{
if(top12.equals(guess))
{
top12 = "null";
System.out.println("Good! The pizza's done!");
}
else if(top22.equals(guess))
{
System.out.println("Perfection!");
top22 = "null";
}
else if(top32.equals(guess))
{
top32 = "null";
System.out.println("It's finished!");
}
else
{
System.out.println("You messed up the pizza! You're fired!");
try
{
Thread.sleep(1000); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.exit(0);
}
}
else
{
System.out.println("That ingredient wasn't ordered! You're fired!");
try
{
Thread.sleep(1000); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.exit(0);
}
System.out.println("The order has to be delivered to "+numhouse+" "+street+".");
try
{
Thread.sleep(2000); // do nothing for 5000 milLiseconds (5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-Out for delivery--");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("What was the street name? (Ex: Campus Drive)");
streetguess = in.nextLine();
if(streetguess.equals(street))
{
System.out.println("Great, "+street+", what's the house number? (Ex: 65)");
}
else
{
System.out.println("You went to the wrong street! The pizza became cold! You're fired!");
try
{
Thread.sleep(500); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.exit(0);
}
numguess = in.nextInt();
if(numguess == numhouse)
{
System.out.println(numhouse+" "+street+", Good job! You got a great tip!");
order++;
}
else
{
System.out.println("Wrong house! The pizza was stolen! You're fired!");
try
{
Thread.sleep(1000); // do nothing for 500 milliseconds (0.5 seconds)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.exit(0);
}
}
}
*note* I'm a beginner programmer. I have no idea how to make gui's or do more advanced coding then this. Could you send back the code edited? Thanks.