aboutsummaryrefslogtreecommitdiff
path: root/Java/Beginer training/src/Game_test.java
blob: e0400dd5c7ccf5a608f63c6de5d2f07949a6612a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
}