Advertisement
Guest User

PrintMarioBoard

a guest
Jan 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3.  
  4. public class PrintMarioBoard {
  5. static Main main = new Main();
  6. static MarioPlayer player = new MarioPlayer();
  7.  
  8.  
  9.  
  10.  
  11. public static void printScore() {
  12. System.out.print("User Score:");
  13. System.out.println(main.score);
  14. }
  15.  
  16. public static void printTime() {
  17. while (main.playerTime > 0) {
  18.  
  19. System.out.println(main.playerTime--);
  20. try {
  21. Thread.sleep(1000);
  22. } catch (InterruptedException e) {
  23. e.printStackTrace();
  24. }
  25. clearConsole();
  26.  
  27. }
  28. }
  29.  
  30. public static void keyPressed(int e) {
  31.  
  32. // System.out.println(e);
  33.  
  34. switch (e) {
  35. case 119:// up
  36.  
  37. reDrawBoard(player.x++, player.y);
  38. break;
  39. case 97:// left
  40.  
  41. reDrawBoard(player.x, player.y--);
  42. break;
  43. case 100:// right
  44.  
  45. reDrawBoard(player.x, player.y++);
  46. break;
  47. /*
  48. * case 115://down
  49. *
  50. * reDrawBoard(x--,y--); break;
  51. */
  52. default:
  53. break;
  54. }
  55.  
  56. }
  57. public static void die() {
  58. System.out.println("End game");
  59. }
  60. public static void generatePipes() {
  61. Random random = new Random();
  62.  
  63. for (int i = 0; i < main.playerObstacle.length; i++) {
  64. main.playerObstacle[i] = random.nextInt(400);
  65. }
  66. }
  67. public static void printPipes() {
  68.  
  69.  
  70. for (int i = 0; i < main.playerObstacle.length; i++) {
  71. for (int j = 0; j <= main.playerObstacle[i]; j++) {
  72. System.out.print(" ");
  73.  
  74. if (j == main.playerObstacle[i]) {
  75. System.out.print("|");
  76. /*+ "| |\n"
  77. + "| |\n"
  78. + "| |\n"
  79. + "----");*/
  80.  
  81. }
  82. }
  83. }
  84. }
  85. public static void reDrawBoard(int x, int y) {
  86.  
  87. // System.out.print((char)8);
  88. // clearConsole();
  89.  
  90. // System.out.print(ESC1 + "2J");
  91.  
  92. for (int i = 0; i < 100; i++) {
  93. System.out.println("\n");
  94. }
  95.  
  96. for (int i = 0; i <= x; i++) {
  97. System.out.println();
  98. for (int j = 0; j <= y; j++) {
  99. System.out.print(" ");
  100. if (i == x && j == y) {
  101. System.out.print(player.createMarioObject());
  102. }
  103. }
  104.  
  105. }
  106. System.out.flush();
  107. }
  108. public final static void clearConsole() {
  109. try {
  110. final String os = System.getProperty("os.name");
  111.  
  112. if (os.contains("Windows")) {
  113. Runtime.getRuntime().exec("cls");
  114. } else {
  115. Runtime.getRuntime().exec("clear");
  116. }
  117. } catch (final Exception e) {
  118. // Handle any exceptions.
  119. }
  120. }
  121.  
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement