NoNameCracksInc

Java game back up

Jun 16th, 2013
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.62 KB | None | 0 0
  1. This is just for me guys, backing up my game if something happend with my hdd :)
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. public class Game extends Mechanism implements Runnable{
  6. BufferedReader reader;
  7. String name;
  8. Thread thread;
  9. String again;
  10.  
  11. public void start()throws IOException{
  12. structure=new String[3];
  13. structure[0]="house";
  14. structure[1]="ville";
  15. structure[2]="palace";
  16. reader=new BufferedReader(new InputStreamReader(System.in));
  17. thread=new Thread();
  18.  
  19. System.out.print("Choose your name:");
  20. name=reader.readLine();
  21. System.out.println("+---+---+---+"+"\n"+"| 1 | 2 | 3 |"+"\n"+"+---+---+---+");
  22. System.out.print("Hello "+name+", choose your random reward:");
  23. rewardS=reader.readLine();
  24. reward=Integer.parseInt(rewardS);
  25.  
  26. randomReward();
  27.  
  28. System.out.println("Loading...");
  29. try{thread.sleep(3000);}
  30. catch(InterruptedException e){System.out.println(e);}
  31. do{
  32. for(int i=0;i<=20;i++){System.out.println();}
  33. if(building!=structure[0]&&building!=structure[1]&&building!=structure[2]){building="none";}
  34. if(axe!="golden"&&axe!="silver"){axe="basic";}
  35. System.out.println("Your wood is " + wood + ".Your axe is " + axe + "."+"You have chopped " + trees + " trees."+"Your building is " + building + ".");
  36. System.out.print(">");
  37. action=reader.readLine();
  38.  
  39. if(action.equals("log")){
  40. System.out.println("\n"+"Loging...");
  41. logtime();
  42. try{thread.sleep(logtime);}
  43. catch(InterruptedException e){System.out.println(e);}
  44. income();
  45. System.out.println("Done!" + "(+" + prod + " wood)");
  46. }
  47. if(action.equals("buy")){
  48. System.out.println("+------SHOP------+"+"\n"+"|Golden Axe- 450w"+"|"+"\n"+"|Silver Axe- 400w"+"|"+"\n"+"+----------------+");
  49. System.out.print("Do you want to buy something?:");
  50. buy=reader.readLine();
  51. shop();
  52. }
  53. if(action.equals("build " + structure[0])||action.equals("build " + structure[1])||action.equals("build " + structure[2])){
  54. structures();
  55. }
  56. if(action.equals("show city")){
  57. city();
  58. }
  59.  
  60. System.out.print("\n"+"Back>>");
  61. again=reader.readLine();
  62. }while(!again.equals("quit"));
  63. }
  64.  
  65. public static void main(String args[])throws IOException{Game x=new Game();x.start();}
  66. public void run() {}
  67. }
  68.  
  69.  
  70.  
  71. MECHANISM
  72.  
  73.  
  74.  
  75.  
  76. import java.io.*;
  77. import java.util.*;
  78. import javax.swing.*;
  79. import java.awt.*;
  80.  
  81. public class Mechanism implements Runnable{
  82. BufferedReader reader;
  83. Random random;
  84. int randomOne;
  85. int firstBox;
  86. int secondBox;
  87. int thirdBox;
  88. String rewardS;
  89. int reward;
  90. int wood;
  91. String action;
  92. int prod;
  93. String buy;
  94. String axe;
  95. String leave;
  96. int logtime;
  97. int trees;
  98. String[] structure;
  99. String building;
  100. String link;
  101. String cmd;
  102. //////////////////////////////////////////////////////RANDOM REWARD(NE)///////////////////////////////////////////////////////////////////////////
  103. public void randomReward(){
  104. if(reward==1||reward==2||reward==3){
  105. random=new Random();
  106. randomOne=random.nextInt(3);
  107.  
  108. if(randomOne==0){
  109. firstBox=5000;
  110. secondBox=5000;
  111. thirdBox=5000;
  112. }
  113. else if(randomOne==1){
  114. firstBox=5000;
  115. secondBox=5000;
  116. thirdBox=5000;
  117. }
  118. else if(randomOne==2){
  119. firstBox=5000;
  120. secondBox=5000;
  121. thirdBox=5000;
  122. }
  123. }
  124. else{wood=0;}
  125. if(reward==1){wood=firstBox;}
  126. if(reward==2){wood=secondBox;}
  127. if(reward==3){wood=thirdBox;}
  128. }
  129. /////////////////////////////////////////////////////////WOOD INCOME(NE)////////////////////////////////////////////////////////////////////////////////
  130. public void income(){
  131. randomOne=random.nextInt(6);
  132.  
  133. if(randomOne==1){
  134. wood=wood+3;
  135. prod=3;
  136. trees=trees+1;
  137. }
  138. else if(randomOne==2){
  139. wood=wood+4;
  140. prod=4;
  141. trees=trees+1;
  142. }
  143. else if(randomOne==3){
  144. wood=wood+5;
  145. prod=5;
  146. trees=trees+1;
  147. }
  148. else if(randomOne==4){
  149. wood=wood+6;
  150. prod=6;
  151. trees=trees+1;
  152. }
  153. else if(randomOne==5){
  154. wood=wood+7;
  155. prod=7;
  156. trees=trees+1;
  157. }
  158. else{prod=1;wood=wood+1;
  159. trees=trees+1;
  160. }}
  161. /////////////////////////////////////////////////SHOP(EXCEPTION)/////////////////////////////////////////////////////////////////////////////////////////
  162. public void shop()throws IOException{
  163. reader=new BufferedReader(new InputStreamReader(System.in));
  164.  
  165. if(buy.equals("Golden Axe")&&wood>=450){
  166. axe="golden";
  167. wood=wood-450;
  168. System.out.println("You have just bought Golden Axe!");
  169. }
  170. else if(buy.equals("Silver Axe")&&wood>=400){
  171. axe="silver";
  172. wood=wood-400;
  173. System.out.println("You have just bought Silver Axe!");
  174. }
  175. else if(buy.equals("Golden Axe")&&(wood!=450||wood<450)){
  176. System.out.print("Not enough wood.");
  177. }
  178. else if(buy.equals("Silver Axe")&&(wood!=400||wood<400)){
  179. System.out.print("Not enough wood.");
  180. }
  181. else if(!buy.equals("Golden Axe")&&!buy.equals("Silver Axe")){
  182. System.out.println("This item does not exist.");
  183. }
  184. }
  185. /////////////////////////////////////////////////////////LOGTIME(NE)//////////////////////////////////////////////////////////////////////////////
  186. public void logtime(){
  187. if(axe=="basic"){
  188. logtime=3000;
  189. }
  190. if(axe=="golden"){
  191. logtime=1000;
  192. }
  193. if(axe=="silver"){
  194. logtime=1500;
  195. }
  196. }
  197. /////////////////////////////////////////////////////////STRUCTURES(NE)//////////////////////////////////////////////////////////////////////////////
  198. public void structures(){
  199. if(action.equals("build "+structure[0])&&wood>=1200){
  200. wood=wood-1200;
  201. System.out.print("You have built house!");
  202. building=structure[0];
  203. }
  204. else if(action.equals("build "+structure[1])&&wood>=2800){
  205. wood=wood-2800;
  206. System.out.print("You have built ville!");
  207. building=structure[1];
  208. }
  209. else if(action.equals("build "+structure[2])&&wood>=3500){
  210. wood=wood-3500;
  211. System.out.print("You have built palace!");
  212. building=structure[2];
  213. }
  214. else{System.out.println("Wrong syntax/Not enough wood.");}
  215. }
  216. //////////////////////////////////////////////////////CITY(NE)////////////////////////////////////////////////////////////////////////
  217. public void city()throws IOException{
  218. if(building.equals("none")){
  219. String link="C:\\Users\\Jakub\\Desktop\\HTML\\City.html";
  220. String cmd="cmd.exe /c start "+link;
  221. Runtime.getRuntime().exec(cmd);
  222. }
  223. }
  224. public void run(){}}
Advertisement
Add Comment
Please, Sign In to add comment