Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

A problem with my Java Scrabble game

807607Jan 4 2007 — edited Jan 4 2007
Hello
I am making a Java Scrabble game for a school assignment and I have a problem with the following:
The number of players is input by the user (2 to 4) and i need to create a number of arrays based on the number of players. These arrays must have 7 playing pieces at all times until the "bag" of pieces has less pieces than those required to replace the ones a certain player just used (in wich case the bag would give that player all of it's remaining pieces and, from this point on, the player arrays would not necessarily need to have 7 pieces).

this is my procedure to take a piece from the bag:
	public Piece takePiece() 
	{
		if (this.pieceCounter > 0) {
		
			Arrays.sort(this.pieces, 0, this.pieceCounter);
			int i = this.generator.nextInt(this.pieceCounter);
			Piece p = this.pieces;
this.pieceCounter--;
this.pieces[i] = this.pieces[this.pieceCounter];

return p;
}
else
{
return null;
}
}

this is my Piece class:
public class Piece implements Comparable {
	
	private int scorePiece;
	private char letterPiece;

	public Piece(char letterPiece, int scorePiece)
	{	
		this.scorePiece = scorePiece;
		this.letterPiece = letterPiece;
	}
	
	public int scorePiece()
	{
		return scorePiece;
	}
	
	public String letterPiece()
	{
		return letterPiece();
	}
	
	public String toString()
	{
		return letterPiece+ " " + scorePiece;
	}
	

	public int compareTo(Object a)
	{
		Piece piece= (Piece) a;
		return (int) letterPiece - (int) piece.letterPiece;
	}
}
Thanks in advance for your help
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2007
Added on Jan 4 2007
6 comments
368 views