/* * Copyright (C) 2013-2015 2048FX * Jose Pereda, Bruno Borges & Jens Deters * All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.jpereda.game2048; /** * @author bruno.borges@oracle.com */ public class Location { private final int x; private final int y; public Location(int x, int y) { this.x = x; this.y = y; } public Location offset(Direction direction) { return new Location(x + direction.getX(), y + direction.getY()); } public int getX() { return x; } public int getY() { return y; } @Override public String toString() { return "Location{" + "x=" + x + ", y=" + y + '}'; } @Override public int hashCode() { int hash = 7; hash = 97 * hash + this.x; hash = 97 * hash + this.y; return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Location other = (Location) obj; if (this.x != other.x) { return false; } return this.y == other.y; } public double getLayoutY(int CELL_SIZE) { if (y == 0) { return CELL_SIZE / 2; } return (y * CELL_SIZE) + CELL_SIZE / 2; } public double getLayoutX(int CELL_SIZE) { if (x == 0) { return CELL_SIZE / 2; } return (x * CELL_SIZE) + CELL_SIZE / 2; } public boolean isValidFor(int gridSize) { return x >= 0 && x < gridSize && y >= 0 && y < gridSize; } }