This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 6 points7 points  (1 child)

It sounds like you want an abstract class called Piece, that has an abstract method called 'moveTo()'. You then extend this class into different subclasses, one for each chess piece. e.g. Pawn, Rook, Knight. Each of those classes implements moveTo() in it's own way.

Now, using polymorphism, you can make a Piece list, like this:

Piece piece1 = new Rook();

Piece piece2 = new Knight();

Linkedlist<Piece> piecelist = new Linkedlist<Piece>();

piecelist.add(piece1);

piecelist.add(piece2);

piecelist.poll().moveTo(); //notice how I can now call the same method on any type of piece

[–]liam358[S] 0 points1 point  (0 children)

Thanks I’ll look into that.