package clt;

/* Draws from 1 to 12 dice on a canvas */
import java.awt.*;
import javax.swing.*;

/**
* DicePanel shows dice gifs for CLTApplet.
* @author Charles Stanton
* @version Sun Jul 14 11:50:30 PDT 2002
*/
class DicePanel extends JPanel {
	private Image[] dieGIF = new Image[6];
	private int die[];	//array of dice values
	private int ndice;  	//number of dice
	private Font f = new Font("Serif", Font.BOLD,24);
	private Color dkGreen = new Color(0,140,0); //background color
	private int sumX;  // sum of x values for display
	DiceModel dm;		//DiceModel class does the calculations
	
/**
* DicePanel constructor
* @param _dm the dice model which does all the calculations.
*/
	public  DicePanel(DiceModel _dm){
		dm = _dm;
		setMinimumSize(new Dimension(40,40));
		ndice= dm.getNDice();
		die = dm.getDiceValues();
		sumX = dm.getSumX(); 
		}
	
	public void setDiceImages( Image[] _dieGIF){
		dieGIF = _dieGIF;
		}
		
	public  void updatePanel(){
		ndice = dm.getNDice();
		die = dm.getDiceValues();
		sumX = dm.getSumX();
		repaint();
		}



/*
* paint method is designed for 1 to 12 dice
*/
	public void paint(Graphics g){
		Dimension r=this.getSize();
		g.setColor(dkGreen);
		g.fillRect(0,0,r.width,r.height);  //paint dark green background
		int downshift; // if i >2, put dice in lower half of canvas
		int rightshift; //number of positions to shift over
		for (int i=0;(i <12 & i< ndice);i++) {
			downshift = (i/4)*r.height/3;
			rightshift= (i%4)*r.width/4;
			if(die[i] != 0){
			g.drawImage(dieGIF[die[i]-1],7+rightshift,5+downshift,Color.black,this);
			}
		}
		g.setFont(f);
		g.setColor( Color.black);
		String s="X = "+ sumX;
		g.drawString(s,r.width/4,r.height*4/5); 
	}


}

