Public feed #381297

Mine

public text v1 · immutable
Raw Edit
·published 2007-03-04 19:30 UTC
rendered paste body
/*
 * Pit.java
 *
 * Created on January 20, 2007, 6:51 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Mancala;

/**
 * Used to represent a playing pit or scoring pit (kalaha) in the Mancala game
 * @author Sophie Quigley
 */
public class Pit {

    // CLASS CONSTANTS
    
    /**
     * Indicates that pit is used for scoring only (pit is a kalaha)
     */
    public static final boolean SCORING = true;
    /**
     * Indicates that pit is used for playing (is a simple pit)
     */
    public static final boolean PLAYING = false;
    
    // CLASS VARIABLES
    
    // INSTANCE VARIABLES
    
    /**
     * Swing user interface associated with this pit
     */
    private MancalaUI ui;
    /**
     * Player owning this pit (0-1)
     */
    private int owner;
    /**
     * Index of this pit in the board and user interface (0-11)
     */
    private int index;
    /**
     * Number of seeds in this pit
     */
    private static int seeds = 0;
    /**
     * True iff this pit is a kalaha
     */
    private boolean kalaha = false;

    // CLASS METHODS
    
    /**
     * Creates a new instance of Pit
     * @param owner Number of the player who owns the pit (0-1)
     * @param index Index of the pit in the board and in the ui
     * @param kalaha SCORING for kalahas, or PLAYING otherwise
     */
    public Pit( int owner, int index, boolean kalaha) {
        this.owner = owner;
        this.index = index;
        this.kalaha = kalaha;
    }
    
    // INSTANCE METHODS
    
    /**
     * Represents pit with a string
     * @return String representing the pit
     */
    public String toString() {
        if (kalaha) 
            return "kalaha belongs to player " + owner + " and contains " + seeds + " seeds";
        else        
            return "pit belongs to player " + owner + " and contains " + seeds + " seeds";
    }

    /**
     * Gets the owner of the pit
     * @return Owner of the pit: player number (0-1)
     */
    public int getOwner() {
        return owner;
    }

    /**
     * Gets the number of seeds in the pit
     * @return Number of seeds in the pit
     */
    public static int getSeeds() {
        return seeds;
    }

    /**
     * Sets the number of seeds in the pit
     * @param seeds New value for seeds property
     */
    public void setSeeds(int seeds) {
       this.seeds = seeds;
       if (kalaha)
           ui.showKalahaSeeds(index,seeds);
       else
           ui.showPitSeeds(index,seeds);
    }

    /**
     * Used to test whether pit is a kalaha
     * @return True iff pit is a kalaha
     */
    public boolean isKalaha() {
        return kalaha;
    }

    /**
     * Sets the ui property: user interface associated with this pit
     * @param ui New value for the ui property
     */
    public void setUi(MancalaUI ui) {
        this.ui = ui;
    }
}