2 * Class to represent a Piece
4 * @website http://progcomp.ucc.asn.au
7 import java.lang.Exception;
8 import java.util.Vector;
12 //Normally in the Java Way (TM) you would have to make these private, and add "Getters" and "Setters" and all sorts of crap.
13 // Disclaimer: The author is not responsible for the repercussions of not following the Java Way (TM)
14 public int x; //x coord
15 public int y; //y coord
16 public char rank; //Rank of the piece
17 public String colour; //The colour of the Piece
18 public Vector<int[]> positions; //All positions the piece has been at
19 public boolean beenRevealed; //True if the piece has been revealed in combat
21 public static char ranks[] = {'B','1','2','3','4','5','6','7','8','9','s','F', '?', '+'}; //List of all the possible ranks
22 //'?' is an unknown piece, '+' is an obstacle
26 * @param c The new colour
27 * @param r The new rank
28 * @param xx The new x coord
29 * @param yy The new y coord
31 public Piece(String c, char r, int xx, int yy)
38 this.positions = new Vector<int[]>();
39 this.beenRevealed = false;
41 positions.add(new int[2]);
42 positions.elementAt(0)[0] = x;
43 positions.elementAt(0)[1] = y;
47 * @returns True if the piece can move, based on its rank
49 public boolean Mobile()
51 return (rank != 'F' && rank != 'B' && rank != '+' && rank != '?');
55 * @returns The value of the piece's rank
57 public int ValuedRank()
59 for (int ii=0; ii < ranks.length; ++ii)
61 if (ranks[ii] == rank)
62 return (ranks.length - 2 - ii);
68 * @returns the index in ranks of a rank
69 * @throws Exception if the rank doesn't exist
71 public static int Index(char rank) throws Exception
73 for (int ii=0; ii < ranks.length; ++ii)
75 if (ranks[ii] == rank)
78 throw new Exception("Piece.Index - No such rank as " + rank);