/********************************************************************
Class game_panel
 --individual panels that make up the board, and each player's tiles

Authors: Kristi Garner, Mary Garland    
CS406: Java and Internet Programming
*******************************************************************/
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.util.*;
import java.applet.*;
import java.net.*;
import java.applet.Applet;


class game_panel extends Panel implements MouseListener
{  


  private Image panelimage;		// the image on the panel
  private Image backimage;		// stores the original image for undo
  private board_panel board;		// game board	
  private tiles_panel tiles;		// player 1's tiles
  private boolean isEmpty = true;	// true if tile or board square is empty
  private boolean isTile;		// true if this is a tile, false if a board square
  private int playerNbr;		// player number
  private char letter;			// letter either on tile or board	
  private boolean current = false;	// if this tile or board square has been used this turn, current = true
  private int letter_x = 1;		// 2 for double letter score, 3 for triple, 1 otherwise
  private int word_x = 1;		// 2 for double word score, 3 for triple, 1 otherwise
  private int letter_ptvalue;		// this particular letter's score
  private int gridx, gridy;		// this panel's row, col location


  /*******************************************************************/
  // constructor game_panel-
  // parameters: myimage- image to be displayed on the panel
  //             row, col - location of panel
  //             ch - letter either on tile 
  //             bp - game board
  //		 tp1 - player 1's tiles
  //             tp2 - player 2's tiles     
  //             type - true if this is a tile, false if a game board piece
  //             pn - player number        
  public game_panel(Image myimage, int row, int col, board_panel bp, tiles_panel tp1, boolean type) 
  {
    panelimage = myimage;
    gridx = col;
    gridy = row;
    board = bp;
    tiles = tp1;
    isTile = type;
    backimage = myimage;

    // tiles are not empty until they are played
    if(isTile) {
      isEmpty = false;
    }

    this.setBackground(Color.black);
    this.setLocation(gridx*27, gridy*27);
    this.setSize(27,27);
    this.addMouseListener(this);

  } 

  /*******************************************************************/
  // paint - draw panelimage 
  public void paint(Graphics g) 
  {
    g.drawImage(panelimage,0,0,this);
  } 

  /*******************************************************************/
  public void mouseClicked(MouseEvent e)
  {
  }

  /*******************************************************************/
  public void mouseEntered(MouseEvent e)
  {
  }

  /*******************************************************************/
  public void mouseExited(MouseEvent e)
  {
  }

  /*******************************************************************/
  // mousePressed - 
  public void mousePressed(MouseEvent e)
  {       
 
    if(isTile && !isEmpty) {
      tiles.setSelectedFirst(this);

    } else if(!isTile && isEmpty) {
      board.setSelectedEmpty(this);
    }

  } 

  /*******************************************************************/
  public void mouseReleased(MouseEvent e)
  {
    repaint();
  } 

  /*******************************************************************/
  // setImage - sets the current image
  public void setImage(Image i) 
  {
    panelimage = i;
    repaint();
  }

  /*******************************************************************/
  // setBackImage - sets the back image
  public void setBackImage(Image i) 
  {
    backimage = i;
  }

  /*******************************************************************/
  // setOrigImage - resets the panel's image to the original one
  public void setOrigImage() 
  {
    panelimage = backimage;
    repaint();
  } 

  /*******************************************************************/
  // getImage - returns current image
  public Image getImage()
  {
    return panelimage;
  } 

  /*******************************************************************/
  // setLetter - sets this panel's letter
  public void setLetter(char l) 
  {
    letter = l;
  } 

  /*******************************************************************/
  // getLetter - returns panel's letter
  public char getLetter() 
  {
    return letter;
  } 

  /*******************************************************************/
  // setEmpty - sets this panel to empty/not empty
  public void setEmpty(boolean b) 
  {
    if(b) {
      isEmpty = true;
      } else {
      isEmpty = false;
    }
  } 

  /*******************************************************************/
  // isEmpty - returns whether or not this panel is empty
  public boolean isEmpty() 
  {
    return isEmpty;
  } 

  /*******************************************************************/
  // setCurrent - if tile or board square was used this turn, current set to true
  public void setCurrent(boolean b) 
  {
    if(b) {
      current = true;
    } else {
      current = false;
    }
  } 

  /*******************************************************************/
  // getCurrent - returns if this panel was used during the current turn
  public boolean getCurrent() 
  {
    return current;
  } 

  /*******************************************************************/
  // setLetterPtValue - sets this particular letter's point value
  public void setLetterPtValue(int p) 
  {
    letter_ptvalue = p;
  } 

  /*******************************************************************/
  // getLetterPtValue - returns this particular letter's point value
  public int getLetterPtValue() 
  {
    return letter_ptvalue;
  } 

  /*******************************************************************/
  // setLetterX - sets letter_x to 2 for double letter score, 3 for triple, 1 otherwise
  public void setLetterX(int x) 
  {
    letter_x = x;
  } 

  /*******************************************************************/
  // getLetterX - returns single, double, triple letter score
  public int getLetterX() 
  {
    return letter_x;
  } 

  /*******************************************************************/
  // setWordX - sets 2 for double word score, 3 for triple, 1 otherwise
  public void setWordX(int x) 
  {
    word_x = x;
  } 

  /*******************************************************************/
  // getWordX - returns single, double, triple word score
  public int getWordX() 
  {
    return word_x;
  } 
  
  public void setPlayerNbr(int pn) {
    playerNbr = pn;
  }
    


} // end Game_Panel class


