[Commit] RRClient ChangeLog, NONE, 1.1 RRMessages.java, NONE, 1.1 RRBoard.java, 1.8, 1.9 RRClient.java, 1.11, 1.12 RRController.java, 1.1, 1.2 RRNetIn.java, 1.3, 1.4 RRNetOut.java, 1.3, 1.4

Keith Packard commit at keithp.com
Wed Jan 7 20:48:49 PST 2004


Committed by: keithp

Update of /local/src/CVS/RRClient
In directory home.keithp.com:/tmp/cvs-serv24603

Modified Files:
	RRBoard.java RRClient.java RRController.java RRNetIn.java 
	RRNetOut.java 
Added Files:
	ChangeLog RRMessages.java 
Log Message:
2004-01-07  Keith Packard  <keithp at keithp.com>

	* RRBoard.java: (RRBoard.moveRobot):
	* RRClient.java: (RRClient.main):
	* RRController.java: (RRController):
	* RRMessages.java: (RRMessages), (RRMessages.RRMessages),
	(RRMessages.message):
	* RRNetIn.java: (RRNetIn.ResetHandler.match),
	(RRNetIn.ResetHandler), (RRNetIn):
	* RRNetOut.java: (RRNetOut..uniprint), (RRNetOut..move),
	(RRNetOut.), (RRNetOut..revoke), (RRNetOut..abandon),
	(RRNetOut..nobid), (RRNetOut..turn), (RRNetOut..pass),
	(RRNetOut..part), (RRNetOut..quit), (RRNetOut..message):
	Add a bunch of buttons and message handling.


--- NEW FILE: ChangeLog ---
2004-01-07  Keith Packard  <keithp at keithp.com>

	* RRBoard.java: (RRBoard.moveRobot):
	* RRClient.java: (RRClient.main):
	* RRController.java: (RRController):
	* RRMessages.java: (RRMessages), (RRMessages.RRMessages),
	(RRMessages.message):
	* RRNetIn.java: (RRNetIn.ResetHandler.match),
	(RRNetIn.ResetHandler), (RRNetIn):
	* RRNetOut.java: (RRNetOut..uniprint), (RRNetOut..move),
	(RRNetOut.), (RRNetOut..revoke), (RRNetOut..abandon),
	(RRNetOut..nobid), (RRNetOut..turn), (RRNetOut..pass),
	(RRNetOut..part), (RRNetOut..quit), (RRNetOut..message):
	Add a bunch of buttons and message handling.

--- NEW FILE: RRMessages.java ---
/*
 * Ricochet Robots Messages
 * Created on January 7, 2003
 *
 */

/**
 * @author Keith Packard <keithp at keithp.com>
 */

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class RRMessages extends TextArea {
    public RRMessages (int rows, int cols) {
	super ("", rows, cols, TextArea.SCROLLBARS_BOTH);
    }
    
    public void message (String user, String message) {
	this.append (user + ": " + message + "\n");
    }
}

Index: RRBoard.java
===================================================================
RCS file: /local/src/CVS/RRClient/RRBoard.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- RRBoard.java	9 Jun 2003 01:54:44 -0000	1.8
+++ RRBoard.java	8 Jan 2004 04:48:46 -0000	1.9
@@ -266,8 +266,6 @@
 	} else {
 	    return;
 	}
-	/* move it */
-	ss.clearRobot();
 	while (!cur.equals(end)) {
 	    RRSquare scur = squares[cur.row][cur.col];
 	    if (scur.getRobot() != scur.NO_ROBOT) {
@@ -283,8 +281,6 @@
 	/* deal with it */
 	if (cur.equals(start))
 	    return;
-	RRSquare se = squares[cur.row][cur.col];
-	se.setRobot(robot);
 	ctl.netout.move(robot, dir);
     }
 
@@ -298,7 +294,10 @@
 		}
 	    }
 	}
-	moveRobot(start, end);
+	RRSquare ss = squares[start.row][start.col];
+	ss.clearRobot();
+	RRSquare se = squares[end.row][end.col];
+	se.setRobot(color);
     }
 
     public void setActive(boolean active) {

Index: RRClient.java
===================================================================
RCS file: /local/src/CVS/RRClient/RRClient.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- RRClient.java	5 Jul 2003 07:31:42 -0000	1.11
+++ RRClient.java	8 Jan 2004 04:48:46 -0000	1.12
@@ -48,7 +48,7 @@
 	class BidListener implements ActionListener {
 	    public void actionPerformed(ActionEvent e) {
 		JComboBox b = (JComboBox) e.getSource();
-		ctl.netout.bid(Integer.parseInt((String)(b.getSelectedItem())) + 3);
+		ctl.netout.bid(Integer.parseInt((String)(b.getSelectedItem())));
 	    }
 	};
 	BidListener bid_listener = new BidListener();
@@ -56,6 +56,75 @@
 
 	JPanel bx = new JPanel();
 	bx.add(bidBox);
+	
+	/* reset turn button */
+	class ResetListener implements ActionListener {
+	    public void actionPerformed (ActionEvent e) {
+		ctl.netout.reset ();
+	    }
+	}
+	ResetListener reset_listener = new ResetListener();
+	
+	Button resetButton = new Button ("Reset");
+	resetButton.addActionListener (reset_listener);
+	
+	bx.add(resetButton);
+	
+	/* next turn button */
+	class NextListener implements ActionListener {
+	    public void actionPerformed (ActionEvent e) {
+		ctl.netout.turn ();
+	    }
+	}
+	NextListener next_listener = new NextListener();
+	
+	Button nextButton = new Button ("Next");
+	nextButton.addActionListener (next_listener);
+	
+	bx.add(nextButton);
+	
+	/* Quit button */
+	class QuitListener implements ActionListener {
+	    public void actionPerformed (ActionEvent e) {
+		ctl.netout.quit ();
+	    }
+	}
+	QuitListener quit_listener = new QuitListener();
+	
+	Button quitButton = new Button ("Quit");
+	quitButton.addActionListener (quit_listener);
+	
+	bx.add(quitButton);
+	
+	/* Message Display */
+	ctl.messages = new RRMessages (10, 30);
+	ctl.messages.setEditable (false);
+
+	/* Messages live below the board */
+
+	JPanel mx = new JPanel ();
+	mx.setLayout (new BorderLayout());
+	
+	mx.add(ctl.messages, BorderLayout.CENTER);
+
+	class MessageListener implements ActionListener {
+	    public void actionPerformed (ActionEvent e) {
+		TextField f = (TextField) e.getSource ();
+		ctl.netout.message (f.getText ());
+		f.setText ("");
+	    }
+	}
+		
+	MessageListener message_listener = new MessageListener ();
+	
+	TextField message = new TextField (30);
+	message.setEditable (true);
+	message.addActionListener (message_listener);
+
+	mx.add (message, BorderLayout.SOUTH);
+	
+	f.getContentPane().add (mx, BorderLayout.SOUTH);
+	
 	Border border = BorderFactory.createTitledBorder(null, "Bid");
 	bx.setBorder(border);
 	bx.setMaximumSize(bx.getPreferredSize());

Index: RRController.java
===================================================================
RCS file: /local/src/CVS/RRClient/RRController.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- RRController.java	9 Jun 2003 04:01:25 -0000	1.1
+++ RRController.java	8 Jan 2004 04:48:46 -0000	1.2
@@ -4,4 +4,5 @@
     public RRNetIn netin;
     public RRNetOut netout;
     public RRImages images;
+    public RRMessages messages;
 };

Index: RRNetIn.java
===================================================================
RCS file: /local/src/CVS/RRClient/RRNetIn.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- RRNetIn.java	9 Jun 2003 01:54:45 -0000	1.3
+++ RRNetIn.java	8 Jan 2004 04:48:46 -0000	1.4
@@ -132,10 +132,21 @@
 
     class ResetHandler implements NoticeHandler {
 	public boolean match(String[] notice) {
-	    if (notice.length != 1 ||
-		!notice[0].equals("RESET"))
+	    if (notice.length != 2 ||
+		!notice[0].equals("NOTICE"))
+		!notice[1].equals("RESET"))
 		return false;
-	    ctl.netout.show();
+	    return true;
+	}
+    }
+
+    class MessageHandler implements NoticeHandler {
+	public boolean match(String[] notice) {
+	    if (notice.length != 4 ||
+		!notice[0].equals("NOTICE") ||
+		!notice[1].equals("MESSAGE"))
+		return false;
+	    ctl.messages.message (notice[2], notice[3]);
 	    return true;
 	}
     }
@@ -183,6 +194,7 @@
 	new ActiveHandler(),
 	new DoneHandler(),
 	new ResetHandler(),
+	new MessageHandler(),
 	new DefaultHandler()
     };
 

Index: RRNetOut.java
===================================================================
RCS file: /local/src/CVS/RRClient/RRNetOut.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- RRNetOut.java	9 Jun 2003 01:54:45 -0000	1.3
+++ RRNetOut.java	8 Jan 2004 04:48:46 -0000	1.4
@@ -23,7 +23,7 @@
 	boolean isodd = false;
 	for (int i = 0; i < s.length(); i++) {
 	    int c = s.charAt(i);
-	    if (c >= 0x7f || c == '"') {
+	    if (c <= ' ' || c >= 0x7f || c == '"') {
 		isodd = true;
 		break;
 	    }
@@ -85,7 +85,7 @@
 
     public void move(int color, int dir) {
 	out.println("move " +
-		    RRSquare.colorname[color] +
+		    RRSquare.colorname[color] + " " +
 		    dirname[dir]);
     }
 
@@ -96,4 +96,38 @@
     public void reset() {
 	out.println("reset");
     }
+
+    public void revoke () {
+	out.println("revoke");
+    }
+
+    public void abandon () {
+	out.println ("abandon");
+    }
+
+    public void nobid () {
+	out.println ("nobid");
+    }
+
+    public void turn () {
+	out.println ("turn");
+    }
+
+    public void pass () {
+	out.println ("pass");
+    }
+
+    public void part () {
+	out.println ("part");
+    }
+
+    public void quit () {
+	out.println ("quit");
+    }
+    
+    public void message (String text) {
+	out.print ("message ");
+	uniprint (text);
+	out.println();
+    }
 }




More information about the Commit mailing list