Subversion Repositories sokoban

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 daniel-mar 1
package gdi1sokoban.globals;
2
 
3
/**
4
 * class to store a point on the map
5
 */
6
public class Point{
7
        // top and left position of point
8
        public int top, left;
9
        /**
10
         * constructor for given position
11
         * @param top top position of point
12
         * @param left left position of point
13
         */
14
        public Point(final int top, final int left){
15
                this.top = top;
16
                this.left = left;
17
        }
18
 
19
        /**
20
         * constructor for given point
21
         * @param p point
22
         */
23
        public Point(final Point p){
24
                this.top = p.top;
25
                this.left = p.left;
26
        }
27
 
28
        /**
29
         * returns a new point
30
         * containing the position of the right, left, up, or down field
31
         * of this point
32
         * @param dir direction in {R, U, L, D}-format
33
         */
34
        public Point moveDirection(final char dir){
35
                switch(dir){
36
                case 'U':
37
                        return new Point(top-1, left);
38
                case 'R':
39
                        return new Point(top, left+1);
40
                case 'D':
41
                        return new Point(top+1, left);
42
                case 'L':
43
                        return new Point(top, left-1);
44
                }
45
                // invalid direction-char
46
                return new Point(top, left);
47
        }
48
        /**
49
         * get Point as String
50
         * @return point as string format: {top, left}
51
         */
52
        @Override
53
        public String toString(){
54
                return "{"+top+","+left+"}";
55
        }
56
 
57
 
58
}