summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/model/Hand.java
blob: 8864a174244315690d35ec3374cffddfeabfb166 (plain)
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
package jrummikub.model;

import jrummikub.util.Pair;

import static jrummikub.model.StoneTray.Direction.*;

/** Class managing a {@link Player}'s {@link Stone}s */
public class Hand extends StoneTray<Stone> implements IHand {

	@Override
	protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos,
			Direction dir) {
		float x = pos.getX();
		float y = pos.getY();

		if (x >= 0 && x <= 13) {
			return null;
		}
		if (x < 0) {
			if (y == 0) {
				return new Pair<Position, Direction>(new Position(0, 0), RIGHT);
			} else {
				return new Pair<Position, Direction>(new Position(13, 0), LEFT);
			}
		} else {
			if (y == 0) {
				return new Pair<Position, Direction>(new Position(0, 1), RIGHT);
			} else {
				return new Pair<Position, Direction>(new Position(13, 1), LEFT);
			}
		}
	}
}