Advertisement
Crenox

Self Generation Java Code

Mar 10th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. package com.samkough.selfgeneration;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.Timer;
  6. import java.util.TimerTask;
  7.  
  8. public class Main
  9. {
  10. // 1000 milliseconds == 1 second
  11. public long delay = 2000; // milliseconds
  12. public LoopTask task = new LoopTask();
  13. public Timer timer = new Timer("TaskName");
  14.  
  15. public void start()
  16. {
  17. timer.cancel();
  18. timer = new Timer("TaskName");
  19. Date executionDate = new Date(); // no params = now
  20. timer.scheduleAtFixedRate(task, executionDate, delay);
  21. }
  22.  
  23. public class LoopTask extends TimerTask
  24. {
  25. public ArrayList<Tiles> map = new ArrayList<Tiles>();
  26. public Tiles t1 = new Tiles();
  27. public StringBuilder builder = new StringBuilder();
  28. public String text = "";
  29.  
  30. public void run()
  31. {
  32. // value instantiations
  33. map.add(t1);
  34.  
  35. // gets rid of the commas and the brackets
  36. for (Tiles value : map)
  37. {
  38. builder.append(value);
  39. }
  40. text = builder.toString();
  41.  
  42. System.out.println(text);
  43. }
  44. }
  45.  
  46. public static void main(String[] args)
  47. {
  48. Main runner = new Main();
  49. runner.start();
  50. }
  51. }
  52. ---------------------------------------------------------------------------------------------------------------------------------
  53. package com.samkough.selfgeneration;
  54.  
  55. import java.util.Random;
  56.  
  57. public class Tiles
  58. {
  59. public static int counter;
  60. public int tileId;
  61.  
  62. public String ground, hill;
  63.  
  64. public Tiles()
  65. {
  66. tileId = counter;
  67. counter++;
  68. }
  69.  
  70. // DIFFERENT TILES
  71. public String ground()
  72. {
  73. return "__________";
  74. }
  75.  
  76. public String hill()
  77. {
  78. return " /\\ \n"
  79. + " / \\ \n"
  80. + " / \\ \n";
  81. }
  82.  
  83. public void randomizer()
  84. {
  85. Random rand = new Random();
  86. // 50 is the maximum and the 1 is our minimum
  87. int n = rand.nextInt(50) + 1;
  88. }
  89.  
  90. public String toString()
  91. {
  92. return ground() + "\n" + hill() + "";
  93. }
  94. }
  95. /*
  96. ground = "__________";
  97.  
  98. hill = " /\\ \n"
  99. + " / \\ \n"
  100. + " / \\ \n";
  101. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement