NoNameCracksInc icon

Java game back up

NoNameCracksInc | PRO | 06/16/13 12:06:35 PM UTC | 0 ⭐ | 384 👁️ | Never ⏰ | []
text |

6.62 KB

|

None

|

0 👍

/

0 👎

This is just for me guys, backing up my game if something happend with my hdd :)
 import java.io.*;
import java.util.*;
public class Game extends Mechanism implements Runnable{
BufferedReader reader;
String name;
Thread thread;
String again;
 	public void start()throws IOException{
    	structure=new String[3];
    	structure[0]="house";
    	structure[1]="ville";
    	structure[2]="palace";
		reader=new BufferedReader(new InputStreamReader(System.in));
		thread=new Thread();
 		System.out.print("Choose your name:");
		name=reader.readLine();
		System.out.println("+---+---+---+"+"\n"+"| 1 | 2 | 3 |"+"\n"+"+---+---+---+");
		System.out.print("Hello "+name+", choose your random reward:");
		rewardS=reader.readLine();
		reward=Integer.parseInt(rewardS);
 		randomReward();
 		System.out.println("Loading...");
		try{thread.sleep(3000);}
	    catch(InterruptedException e){System.out.println(e);}
		do{
		for(int i=0;i<=20;i++){System.out.println();}
		if(building!=structure[0]&&building!=structure[1]&&building!=structure[2]){building="none";}
        if(axe!="golden"&&axe!="silver"){axe="basic";}
		System.out.println("Your wood is " + wood + ".Your axe is " + axe + "."+"You have chopped " + trees + " trees."+"Your building is " + building + ".");
		System.out.print(">");
		action=reader.readLine();
 		if(action.equals("log")){
				System.out.println("\n"+"Loging...");
				logtime();
				try{thread.sleep(logtime);}
			    catch(InterruptedException e){System.out.println(e);}
				income();
				System.out.println("Done!" + "(+" + prod + " wood)");
		}
				if(action.equals("buy")){
			    	System.out.println("+------SHOP------+"+"\n"+"|Golden Axe- 450w"+"|"+"\n"+"|Silver Axe- 400w"+"|"+"\n"+"+----------------+");
			        System.out.print("Do you want to buy something?:");
			        buy=reader.readLine();
			        shop();
				}
				if(action.equals("build " + structure[0])||action.equals("build " + structure[1])||action.equals("build " + structure[2])){
					structures();
				}
				if(action.equals("show city")){
					city();
				}
  System.out.print("\n"+"Back>>");
 again=reader.readLine();
}while(!again.equals("quit"));	
	}
 public static void main(String args[])throws IOException{Game x=new Game();x.start();}
public void run() {}  
}
   MECHANISM
    import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
 public class Mechanism implements Runnable{
	BufferedReader reader;
	Random random;
	int randomOne;
	int firstBox;
	int secondBox;
	int thirdBox;
	String rewardS;
	int reward;
	int wood;
	String action;
	int prod;
	String buy;
	String axe;
	String leave;
	int logtime;
	int trees;
	String[] structure;
	String building;
	String link;
	String cmd;
//////////////////////////////////////////////////////RANDOM REWARD(NE)///////////////////////////////////////////////////////////////////////////
	public void randomReward(){
		if(reward==1||reward==2||reward==3){
		random=new Random();
		randomOne=random.nextInt(3);
 		if(randomOne==0){
			firstBox=5000;
			secondBox=5000;
			thirdBox=5000;
		}
		else if(randomOne==1){
			firstBox=5000;
			secondBox=5000;
			thirdBox=5000;
		}
		else if(randomOne==2){
			firstBox=5000;
			secondBox=5000;
			thirdBox=5000;
		}
	}
		else{wood=0;}
		if(reward==1){wood=firstBox;}
		if(reward==2){wood=secondBox;}
		if(reward==3){wood=thirdBox;}
}
/////////////////////////////////////////////////////////WOOD INCOME(NE)////////////////////////////////////////////////////////////////////////////////		
	public void income(){
		randomOne=random.nextInt(6);
 		if(randomOne==1){
			wood=wood+3;
			prod=3;
			trees=trees+1;
		}
		else if(randomOne==2){
		    wood=wood+4;
			prod=4;
			trees=trees+1;
		}
		else if(randomOne==3){
			wood=wood+5;
			prod=5;
			trees=trees+1;
		}
		else if(randomOne==4){
			wood=wood+6;
			prod=6;
			trees=trees+1;
		}
		else if(randomOne==5){
			wood=wood+7;
			prod=7;
			trees=trees+1;
		}
		else{prod=1;wood=wood+1;
		trees=trees+1;
		}}
/////////////////////////////////////////////////SHOP(EXCEPTION)/////////////////////////////////////////////////////////////////////////////////////////
    public void shop()throws IOException{
    	reader=new BufferedReader(new InputStreamReader(System.in));
            if(buy.equals("Golden Axe")&&wood>=450){
               axe="golden";
        	   wood=wood-450;
        	   System.out.println("You have just bought Golden Axe!");
           }
           else if(buy.equals("Silver Axe")&&wood>=400){
        	   axe="silver";
        	   wood=wood-400;
        	   System.out.println("You have just bought Silver Axe!");
           }
           else if(buy.equals("Golden Axe")&&(wood!=450||wood<450)){
        	   System.out.print("Not enough wood.");
           }
           else if(buy.equals("Silver Axe")&&(wood!=400||wood<400)){
        	   System.out.print("Not enough wood.");
           }
           else if(!buy.equals("Golden Axe")&&!buy.equals("Silver Axe")){
        	   System.out.println("This item does not exist.");
           }
    }
/////////////////////////////////////////////////////////LOGTIME(NE)//////////////////////////////////////////////////////////////////////////////
    public void logtime(){
    	if(axe=="basic"){
    		logtime=3000;
    	}
    	if(axe=="golden"){
    		logtime=1000;
    	}
    	if(axe=="silver"){
    		logtime=1500;
    	}
    }
/////////////////////////////////////////////////////////STRUCTURES(NE)//////////////////////////////////////////////////////////////////////////////
    public void structures(){
    	if(action.equals("build "+structure[0])&&wood>=1200){
    		wood=wood-1200;
    		System.out.print("You have built house!");
    		building=structure[0];
    	}
    	else if(action.equals("build "+structure[1])&&wood>=2800){
    		wood=wood-2800;
    		System.out.print("You have built ville!");
    		building=structure[1];
    	}
    	else if(action.equals("build "+structure[2])&&wood>=3500){
    		wood=wood-3500;
    		System.out.print("You have built palace!");
    		building=structure[2];
    	}
    	else{System.out.println("Wrong syntax/Not enough wood.");}
    }
//////////////////////////////////////////////////////CITY(NE)////////////////////////////////////////////////////////////////////////
    public void city()throws IOException{
    	if(building.equals("none")){
        	String link="C:\\Users\\Jakub\\Desktop\\HTML\\City.html";
        	String cmd="cmd.exe /c start "+link;
        	Runtime.getRuntime().exec(cmd);
    	}
    }
	public void run(){}}

Comments