/*
Java board game library.
Copyright (C) 2011 Deepesh Garg
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package d.g.boardgames.soccer ;
import d.g.boardgames.*;
public class SoccerBoardEventListener implements BoardEventListener {
enum State {WAITING_FROM, WAITING_TO} ;
int fromRow ;
int toRow ;
int fromCol ;
int toCol ;
State state = State.WAITING_FROM ;
public void boardAction (Board board, int row, int col) {
SoccerBoard soccerBoard = (SoccerBoard) board ;
switch (state) {
case WAITING_FROM:
if (board.getCellState(row, col) != null) {
fromRow = row ;
fromCol = col ;
soccerBoard.actionFromCell(new Cell(row, col)) ;
state = State.WAITING_TO ;
}
break ;
case WAITING_TO:
toRow = row ;
toCol = col ;
//soccerBoard.move (fromRow, fromCol, toRow, toCol) ;
soccerBoard.actionToCell(new Cell (fromRow, fromCol), new Cell(toRow, toCol)) ;
state = State.WAITING_FROM ;
}
System.out.println (row + " " + col) ;
}
}
|