[Commit] RRClient RRBoardCoord.java,NONE,1.1 RRBoard.java,1.4,1.5
RRBoardPanel.java,1.5,1.6 RRSquare.java,1.2,1.3
Bart Massey
commit at keithp.com
Sat Jun 7 21:53:31 PDT 2003
- Previous message: [Commit] RRClient RRTkProxy.java,NONE,1.1 RRBoardPanel.java,1.4,1.5
RRImages.java,1.4,1.5
- Next message: [Commit] RRClient RRNetIn.java,NONE,1.1 RRNetOut.java,NONE,1.1
RRBoard.java,1.5,1.6 RRBoardCoord.java,1.1,1.2
RRBoardPanel.java,1.6,1.7 RRClient.java,1.3,1.4
RRSquare.java,1.3,1.4
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: bart
Update of /local/src/CVS/RRClient
In directory home.keithp.com:/tmp/cvs-serv26482
Modified Files:
RRBoard.java RRBoardPanel.java RRSquare.java
Added Files:
RRBoardCoord.java
Log Message:
Can move robots legally now by dragging the mouse. Next up,
server interface.
--- NEW FILE: RRBoardCoord.java ---
/*
* Ricochet Robots Board Coordinate
* Created on June 6, 2003
*
*/
/**
* @author Bart Massey <bart at cs.pdx.edu>
*
*/
public class RRBoardCoord {
public int row, col;
public boolean equals(BoardCoord b) {
if (b.row != row)
return false;
if (b.col != col)
return false;
return true;
}
}
Index: RRBoard.java
===================================================================
RCS file: /local/src/CVS/RRClient/RRBoard.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- RRBoard.java 7 Jun 2003 07:18:43 -0000 1.4
+++ RRBoard.java 8 Jun 2003 03:53:29 -0000 1.5
@@ -228,4 +228,51 @@
public RRSquare getSquare(int row, int col) {
return squares[row][col];
}
+
+ public void moveRobot(RRBoardCoord start, RRBoardCoord end) {
+ /* anything to move? */
+ RRSquare ss = squares[start.row][start.col];
+ int robot = ss.getRobot();
+ if (robot == ss.NO_ROBOT)
+ return;
+ /* figure out where it's going */
+ int dr = 0;
+ int dc = 0;
+ int dir = -1;
+ if (start.row == end.row) {
+ if (start.col < end.col) {
+ dir = 1;
+ dc = 1;
+ } else {
+ dir = 3;
+ dc = -1;
+ }
+ } else if (start.col == end.col) {
+ if (start.row < end.row) {
+ dir = 2;
+ dr = 1;
+ } else {
+ dir = 0;
+ dr = -1;
+ }
+ } else {
+ return;
+ }
+ /* move it */
+ ss.clearRobot();
+ while (!start.equals(end)) {
+ RRSquare scur = squares[start.row][start.col];
+ if (scur.getRobot() != scur.NO_ROBOT) {
+ start.row -= dr;
+ start.col -= dc;
+ break;
+ }
+ if (scur.getWall(dir))
+ break;
+ start.row += dr;
+ start.col += dc;
+ }
+ RRSquare se = squares[start.row][start.col];
+ se.setRobot(robot);
+ }
}
Index: RRBoardPanel.java
===================================================================
RCS file: /local/src/CVS/RRClient/RRBoardPanel.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- RRBoardPanel.java 8 Jun 2003 03:20:30 -0000 1.5
+++ RRBoardPanel.java 8 Jun 2003 03:53:29 -0000 1.6
@@ -14,27 +14,15 @@
import java.awt.*;
import java.awt.event.*;
-class BoardCoord {
- public int row, col;
-
- public boolean equals(BoardCoord b) {
- if (b.row != row)
- return false;
- if (b.col != col)
- return false;
- return true;
- }
-}
-
class RobotMover extends MouseInputAdapter {
static final int IDLE = 0;
static final int DRAGGING = 1;
int state = IDLE;
RRBoard board;
RRBoardPanel panel;
- public BoardCoord start = null;
- public BoardCoord stop = null;
- public BoardCoord cur = null;
+ public RRBoardCoord start = null;
+ public RRBoardCoord stop = null;
+ public RRBoardCoord cur = null;
public RobotMover(RRBoard board, RRBoardPanel panel) {
super();
@@ -57,6 +45,8 @@
stop = panel.boardCoord(e.getPoint());
cur = stop;
state = IDLE;
+ if (!start.equals(stop))
+ board.moveRobot(start, stop);
panel.clearHilite();
}
@@ -78,7 +68,7 @@
int dim;
double dcol, drow;
- BoardCoord hilited = null;
+ RRBoardCoord hilited = null;
static int floor(double d) {
return (int)Math.floor(d);
@@ -181,16 +171,16 @@
}
}
- public BoardCoord boardCoord(Point p) {
+ public RRBoardCoord boardCoord(Point p) {
update_dims();
- BoardCoord c = new BoardCoord();
+ RRBoardCoord c = new RRBoardCoord();
c.row = floor(p.y / drow);
c.col = floor(p.x / dcol);
return c;
}
- public void setHilite(BoardCoord c) {
+ public void setHilite(RRBoardCoord c) {
if (hilited == null || !hilited.equals(c))
repaint();
hilited = c;
Index: RRSquare.java
===================================================================
RCS file: /local/src/CVS/RRClient/RRSquare.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- RRSquare.java 7 Jun 2003 06:05:06 -0000 1.2
+++ RRSquare.java 8 Jun 2003 03:53:29 -0000 1.3
@@ -52,6 +52,10 @@
robot = r;
}
+ public void clearRobot() {
+ robot = NO_ROBOT;
+ }
+
public boolean getWall(int w) {
return wall[w];
}
- Previous message: [Commit] RRClient RRTkProxy.java,NONE,1.1 RRBoardPanel.java,1.4,1.5
RRImages.java,1.4,1.5
- Next message: [Commit] RRClient RRNetIn.java,NONE,1.1 RRNetOut.java,NONE,1.1
RRBoard.java,1.5,1.6 RRBoardCoord.java,1.1,1.2
RRBoardPanel.java,1.6,1.7 RRClient.java,1.3,1.4
RRSquare.java,1.3,1.4
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commit
mailing list