Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. package mario.bros.game;
  2.  
  3. import java.awt.event.KeyEvent;
  4. import java.io.IOException;
  5. import java.util.Scanner;
  6.  
  7. public class StartMarioGame {
  8.  
  9.     public static int x;
  10.     public static int y;
  11.    
  12.    
  13.     public static void main(String[] args) {
  14.         //System.out.println(createMarioObject());
  15.  
  16.         // left 8592;
  17.         // 8593 up
  18.         // 8594 right
  19.         // 8595 down
  20.         char test = 8592;
  21.         System.out.println(test);
  22.         Scanner input = new Scanner(System.in);
  23.  
  24.         while (true) {
  25.            
  26.             reDrawBoard( x,  y);
  27.             char keyPressed = input.next().charAt(0);
  28.             keyPressed(Integer.valueOf(keyPressed));
  29.            
  30.         }
  31.     }
  32.  
  33.     public static String createMarioObject() {
  34.         String marioObj = " o"
  35.         // +"\\|/\n"
  36.         // +"/\\"
  37.         ;
  38.  
  39.         return marioObj;
  40.     }
  41.  
  42.     public static void keyPressed(int e) {
  43.  
  44.         //System.out.println(e);
  45.  
  46.         switch (e) {
  47.         case 119://up
  48.            
  49.             reDrawBoard(x++,y);
  50.             break;
  51.         case 97://left
  52.            
  53.             reDrawBoard(x,y--);
  54.             break;
  55.         case 100://right
  56.            
  57.             reDrawBoard(x,y++);
  58.             break;
  59.         /*
  60.          * case 115://down
  61.          *
  62.          * reDrawBoard(x--,y--); break;
  63.          */
  64.         default:
  65.             break;
  66.         }
  67.  
  68.     }
  69.    
  70.     public final static void clearConsole()
  71.     {
  72.         try
  73.         {
  74.             final String os = System.getProperty("os.name");
  75.  
  76.             if (os.contains("Windows"))
  77.             {
  78.                 Runtime.getRuntime().exec("cls");
  79.             }
  80.             else
  81.             {
  82.                 Runtime.getRuntime().exec("clear");
  83.             }
  84.         }
  85.         catch (final Exception e)
  86.         {
  87.             //  Handle any exceptions.
  88.         }
  89.     }
  90.  
  91.    
  92.     public static void reDrawBoard(int x, int y) {
  93.         clearConsole();
  94.        
  95.        
  96.         for (int i = 0; i <= y; 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.println(createMarioObject());
  102.                 }
  103.             }
  104.            
  105.         }
  106.     }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement