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