aboutsummaryrefslogtreecommitdiff
path: root/Java/Beginer training/src/Game_test.java
diff options
context:
space:
mode:
Diffstat (limited to 'Java/Beginer training/src/Game_test.java')
-rw-r--r--Java/Beginer training/src/Game_test.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/Java/Beginer training/src/Game_test.java b/Java/Beginer training/src/Game_test.java
new file mode 100644
index 0000000..e0400dd
--- /dev/null
+++ b/Java/Beginer training/src/Game_test.java
@@ -0,0 +1,72 @@
+import java.util.Arrays;
+import java.io.*;
+import java.text.*;
+
+public class Game_test {
+ public static final char[][] ORIGINAL_MAP = {
+ {' ', '-', '-', '-', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '-', '<', '-', ' '}
+ };
+
+ public static void main(String args[]) {
+ Console cons = System.console();
+
+ while (true){
+ ReWriteMap();
+ System.out.println("Type direction and press enter:");
+ String direction = cons.readLine();
+
+ switch (direction.charAt(0)) {
+ case 'w': Player.yPos++; break;
+ case 's': Player.yPos--; break;
+ case 'a': Player.xPos--; break;
+ case 'd': Player.xPos++; break;
+ }
+
+ try { Thread.sleep(1000); }
+ catch (Exception ex) { }
+ }
+ }
+
+ public static void ReWriteMap(){
+ var map = Arrays.copyOf(ORIGINAL_MAP, ORIGINAL_MAP.length);
+
+ for (int i = 0; i < map.length; i++){
+ for (int j = 0; j < map[0].length; j++){
+ if (i == Player.yPos && j == Player.xPos) map[i][j] = Player.body;
+
+ System.out.print(map[i][j]);
+ }
+ System.out.println();
+ }
+ }
+}
+
+class Player {
+ public static char body = '*';
+
+ public static int yPos = 0, xPos = 1; //y is up/down ; x is left/right
+}