Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mario.bros.game;
- import java.awt.event.KeyEvent;
- import java.io.IOException;
- import java.util.Scanner;
- public class StartMarioGame {
- public static int x;
- public static int y;
- public static void main(String[] args) {
- //System.out.println(createMarioObject());
- // left 8592;
- // 8593 up
- // 8594 right
- // 8595 down
- char test = 8592;
- System.out.println(test);
- Scanner input = new Scanner(System.in);
- while (true) {
- reDrawBoard( x, y);
- char keyPressed = input.next().charAt(0);
- keyPressed(Integer.valueOf(keyPressed));
- }
- }
- public static String createMarioObject() {
- String marioObj = " o"
- // +"\\|/\n"
- // +"/\\"
- ;
- return marioObj;
- }
- public static void keyPressed(int e) {
- //System.out.println(e);
- switch (e) {
- case 119://up
- reDrawBoard(x++,y);
- break;
- case 97://left
- reDrawBoard(x,y--);
- break;
- case 100://right
- reDrawBoard(x,y++);
- break;
- /*
- * case 115://down
- *
- * reDrawBoard(x--,y--); break;
- */
- default:
- break;
- }
- }
- public final static void clearConsole()
- {
- try
- {
- final String os = System.getProperty("os.name");
- if (os.contains("Windows"))
- {
- Runtime.getRuntime().exec("cls");
- }
- else
- {
- Runtime.getRuntime().exec("clear");
- }
- }
- catch (final Exception e)
- {
- // Handle any exceptions.
- }
- }
- public static void reDrawBoard(int x, int y) {
- clearConsole();
- for (int i = 0; i <= y; i++) {
- System.out.println();
- for (int j = 0; j <= y; j++) {
- System.out.print(" ");
- if ( i == x && j == y) {
- System.out.println(createMarioObject());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement