Pillar - private int r; /** number of times J*Man moves*/...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.awt.*; /** An instance of this class is a Pillar.*/ public class Pillar extends Piece { /** Constructor: a new Pillar at position (x, y) on Map m with color red if c = 0, green if c = 1, and yellow if c = 2. */ public Pillar(int x, int y, int c, Map m){ super(Piece.PILLAR, m); setX(x); setY(y); if (c==0){ setColor(Color.RED);} if (c==1){ setColor(Color.GREEN);} if (c==2){ setColor(Color.YELLOW);} } /** Constructor: a new Pillar at position (x, y) on Map m with color c. Precondition: c is one of Color.RED, Color.GREEN, and Color.YELLOW.*/ public Pillar(int x, int y, Color c, Map m){ super(Piece.PILLAR, m); setX(x); setY(y); setColor(c); } /** Initialize variables for number of times J*Man moves and random colors*/
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: private int r; /** number of times J*Man moves*/ private int rCol; /** random color (red, green or yellow).*/ /** Pillars should not move, but Pillars will randomly change colors. */ public void act(){ r = rand (1,3); if (r==1 && !(hasActed())){ rCol= rand(0,2); if (rCol==0){ setColor(Color.RED);} if (rCol==1){ setColor(Color.GREEN);} if (rCol==2){ setColor(Color.YELLOW);} } setActed(true); } /** = representation of this piece */ public String toString() { String color= ""; return getColorWord() + " Pillar at (" + getX() + ", " + getY() + ")"; } }...
View Full Document

This document was uploaded on 02/24/2010.

Ask a homework question - tutors are online