www.wesdabigman.com


/**
 * @author 675509-
 *Wes Corwin
 *Period 2A
 *
 *Reversi Version 1.0 created by Wes Corwin
 */

/*The following is a two player Chess game with an exit button.
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;

//main method which contains everything
public class Chess extends JFrame implements MouseListener
{
        //Board of Tiles which shall be used to play the game
        private Tile[][] board = new Tile[8][8];
        //The default white pawns for the game
        Pawn whitePawn1 = new Pawn("White");
        Pawn whitePawn2 = new Pawn("White");
        Pawn whitePawn3 = new Pawn("White");
        Pawn whitePawn4 = new Pawn("White");
        Pawn whitePawn5 = new Pawn("White");
        Pawn whitePawn6 = new Pawn("White");
        Pawn whitePawn7 = new Pawn("White");
        Pawn whitePawn8 = new Pawn("White");
        //The default black pawns for the game
        Pawn blackPawn1 = new Pawn("Black");
        Pawn blackPawn2 = new Pawn("Black");
        Pawn blackPawn3 = new Pawn("Black");
        Pawn blackPawn4 = new Pawn("Black");
        Pawn blackPawn5 = new Pawn("Black");
        Pawn blackPawn6 = new Pawn("Black");
        Pawn blackPawn7 = new Pawn("Black");
        Pawn blackPawn8 = new Pawn("Black");
        //The default white Rook for the game
        Rook whiteRook = new Rook("White");
        //The default black rook for the game
        Rook blackRook = new Rook("Black");
        //The default white knight for the game
        Knight whiteKnight = new Knight("White");
        //The default black knight for the game
        Knight blackKnight = new Knight("Black");
        //The default white bishop for the game
        Bishop whiteBishop = new Bishop("White");
        //The default black bishop for the game
        Bishop blackBishop = new Bishop("Black");
        //The default white king  for the game
        King whiteKing = new King("White");
        //The default black king  for the game
        King blackKing = new King("Black");
         //Deafult white queen for the game
        Queen whiteQueen = new Queen("White");
        
//The default black queen  for the game
        Queen blackQueen = new Queen("Black");
         //Arraylist that keeps track of all of white's pieces
        private ArrayList<Piece> whitePieces= new ArrayList<Piece>();
        //Arraylist that keeps track of all of black's pieces
        private ArrayList<Piece> blackPieces= new ArrayList<Piece>();
      
//Arraylist that keeps track of all of white's captured pieces
        private ArrayList<Piece> whiteCaptured= new ArrayList<Piece>();
      
//Arraylist that keeps track of all of black's captured pieces
        private ArrayList<Piece> blackCaptured= new ArrayList<Piece>();
        //boolean which shall keep track of whose turn it is
        boolean turn=true;
        //boolean which is used for the moves
        boolean blocked=false;
        JTextField turnKeeper= new JTextField();
        //JLabel used to exit the program...The Exit Button!-"When the X in the top right just isn't convenient enough!"
        JLabel exit= new JLabel();
        //integer to keep track of the columns of the board
        int x=0;
        //integer to keep track of the rows of the board
        int y=0;
        //int to differentiate between the piece picked and the piece's move
        int z=0;
      
        //The part where the GUI is contained and given attributes
        public Chess()
        {

            //The content Pane- where everything was, is, and will be
            Container contentPane =getContentPane();
            //The layout is null because layout's don't apply for this program
            contentPane.setLayout(null);
            //The program has a height and width of 600
            setSize(800,800);
            //The location of the program is (1,1)
            setLocation(1,1);
            //The background of the program is white...even though it looks gray
            setBackground(Color.white);
            //The title is recursive because that's the title of the program
            setTitle("Chess");
            //The program stops when I exit the program for obvious reasons
            setDefaultCloseOperation(EXIT_ON_CLOSE);

            //The JLabel used to exit the program
            JLabel exit= new JLabel("Exit");
            //The bounds of the exit button. Near the bottom and out of the way
            exit.setBounds(250,450,100,33);
            //The exit button's border is black...what's it to you?
            exit.setBorder(BorderFactory.createLineBorder(Color.black));
            //The exit button has a Mouse Listener because in order to work, its need to be able to comprehend Mouse actions
            exit.addMouseListener(this);
            //The text of the exit button is centered for a better look
            exit.setHorizontalAlignment(JLabel.CENTER);
            //And the exit button is added to the content pane
            contentPane.add(exit);
            whitePieces.add(0,whitePawn1);
            whitePieces.add(1,whitePawn2);
            whitePieces.add(2,whitePawn3);
            whitePieces.add(3,whitePawn4);
            whitePieces.add(4,whitePawn5);
            whitePieces.add(5,whitePawn6);
            whitePieces.add(6,whitePawn7);
            whitePieces.add(7,whitePawn8);
            blackPieces.add(0,blackPawn1);
            blackPieces.add(1,blackPawn2);
            blackPieces.add(2,blackPawn3);
            blackPieces.add(3,blackPawn4);
            blackPieces.add(4,blackPawn5);
            blackPieces.add(5,blackPawn6);
            blackPieces.add(6,blackPawn7);
            blackPieces.add(7,blackPawn8);
            for(x=8; x<10; x++)
            {
                whitePieces.add(x, whiteKnight);
                blackPieces.add(x, blackKnight);
            }
            for(x=10; x<12; x++)
            {
                whitePieces.add(x, whiteBishop);
                blackPieces.add(x, blackBishop);
            }
            for(x=12; x<14; x++)
            {
                whitePieces.add(x, whiteRook);
                blackPieces.add(x, blackRook);
            }
            whitePieces.add(14, whiteQueen);
            whitePieces.add(15, whiteKing);
            blackPieces.add(14, blackQueen);
            blackPieces.add(15, blackKing);
            //The double for loop where the board is created and given attributes. The first is for the columns...
            for(int x=0;x<8;x++)
            {
                //The second is for the rows
                for(int y=0;y<8;y++)
                {  
                    //The board! Each is a fifty by fifty square
                    board[y][x] = new Tile();
                    //The location is fifty times the row, fifty times the column
                    board[y][x].setBounds(50*x,50*y, 50, 50);
                    //Yes the border on the board is black. Because blue has become boring.
                    board[y][x].setBorder(BorderFactory.createLineBorder(Color.black));
                    //The board can hear the mouse, thus allowing the game to be played
                    board[y][x].addMouseListener(this);
                    //Now the board knows that the column is its column!!!
                    board[y][x].setColumn(x);
                    //Now the board knows that the row is its row!!!
                    board[y][x].setRow(y);
                    board[y][x].setOpaque(true);
                    //Now the text is centered
                    board[y][x].setHorizontalAlignment(Tile.CENTER);
                    //The number is the value of the board's square in accordance to chess's (letter, number)
                    board[y][x].setNumber(board[y][x].getColumn()+1);    
                    
                    //The letter value is assigned A because this is the first row
                    if(board[y][x].getRow()==0)
                    {
                        board[y][x].setLetter("A");
                    }
                    //The letter value is assigned B because this is the second row, and pawns are placed along this row
                    else if(board[y][x].getRow()==1)
                    {
                        board[y][x].setLetter("B");
                        board[y][x].setFirstMove(true);
                        board[y][x].setText("BP");
                    }
                    //The letter value is assigned C because this is the third row
                    else if(board[y][x].getRow()==2)
                    {
                        board[y][x].setLetter("C");
                    }
                    //The letter value is assigned D because this is the fourth row
                    else if(board[y][x].getRow()==3)
                    {
                        board[y][x].setLetter("D");
                    }
                    //The letter value is assigned E because this is the fifth row  
                    else if(board[y][x].getRow()==4)
                    {
                        board[y][x].setLetter("E");
                    }
                    //The letter value is assigned F because this is the sixth row
                    else if(board[y][x].getRow()==5)
                    {
                        board[y][x].setLetter("F");
                    }
                    //The letter value is assigned G because this is the seventh row, and pawns are placed along this row
                    else if(board[y][x].getRow()==6)
                    {
                        board[y][x].setLetter("G");
                        board[y][x].setFirstMove(true);
                        board[y][x].setText("WP");
                    }
                    //The letter value is assigned H because this is the eighth row
                    else if(board[y][x].getRow()==7)
                    {
                        board[y][x].setLetter("H");
                    }                    
                    //And the board is added to the contentPane
                    contentPane.add(board[y][x]);  
                }
            }
            board[6][0].setPiece(whitePawn1);
            board[6][1].setPiece(whitePawn2);
            board[6][2].setPiece(whitePawn3);
            board[6][3].setPiece(whitePawn4);
            board[6][4].setPiece(whitePawn5);
            board[6][5].setPiece(whitePawn6);
            board[6][6].setPiece(whitePawn7);
            board[6][7].setPiece(whitePawn8);
            board[1][0].setPiece(blackPawn1);
            board[1][1].setPiece(blackPawn2);
            board[1][2].setPiece(blackPawn3);
            board[1][3].setPiece(blackPawn4);
            board[1][4].setPiece(blackPawn5);
            board[1][5].setPiece(blackPawn6);
            board[1][6].setPiece(blackPawn7);
            board[1][7].setPiece(blackPawn8);
            for(x=0; x<8; x=x+2)
            {
                for(y=1; y<8; y=y+2)
                {
                    board[y][x].setBackground(Color.green);
                }
            }
            
            for(x=0; x<8; x=x+2)
            {
                for(y=0; y<8; y=y+2)
                {
                    board[y][x].setBackground(Color.blue);
                }
            }
            
            for(x=1; x<8; x=x+2)
            {
                for(y=0; y<8; y=y+2)
                {
                    board[y][x].setBackground(Color.green);
                }
            }
            
            for(x=1; x<8; x=x+2)
            {
                for(y=1; y<8; y=y+2)
                {
                    board[y][x].setBackground(Color.blue);
                }
            }
            for(x=0; x<8; x=x+7)
            {
                board[0][x].setPiece(blackRook);
                board[0][x].setText("BR");
                board[7][x].setPiece(whiteRook);
                board[7][x].setText("WR");
            }
            for(x=1; x<8; x=x+5)
            {
                board[0][x].setPiece(blackKnight);
                board[0][x].setText("BKn");
                board[7][x].setPiece(whiteKnight);
                board[7][x].setText("WKn");
            }
            
            for(x=2; x<8; x=x+3)
            {
                board[0][x].setPiece(blackBishop);
                board[0][x].setText("BB");
                board[7][x].setPiece(whiteBishop);
                board[7][x].setText("WB");
            }
            
            board[0][3].setPiece(blackQueen);
            board[7][3].setPiece(whiteQueen);
            board[0][4].setPiece(blackKing);
               board[7][4].setPiece(whiteKing);
            board[0][3].setText("BQ");
            board[7][3].setText("WQ");
            board[0][4].setText("BK");
               board[7][4].setText("WK");
               board[7][4].setFirstMove(true);
        }
        //used to make GUI
        public static void main (String[] args)
        {
            //frame of GUI
            Chess frame= new Chess();
            frame.setVisible(true);
        }
      
        //method used when mouse is clicked
        public void mouseClicked(MouseEvent me)
        {
            //Sets all methods that occur when a Tile is clicked
            if(me.getSource() instanceof Tile)      
            {  
                Tile clicked = (Tile)me.getSource();
                {
                    if(turn)
                    {
                        if(z==0)
                        {
                            if(clicked.getPiece()!=null&&clicked.getPiece().getColor()=="White")
                            {
                                    y= clicked.getRow();
                                    x=clicked.getColumn();
                                    System.out.println("("+board[y][x].getLetter()+","+board[y][x].getNumber()+") to...?");
                                    z++;
                            }
                        }
                        else if(z==1&&clicked.getPiece()==null||clicked.getPiece().getColor()!="White")
                        {
                            if(board[y][x].getPiece().pawnCheck==true)
                            {
                                if(clicked.getText()==""&&clicked.getRow()+2==y&&clicked.getColumn()==x&&board[y-1][x].getText()==""&&board[y][x].getFirstMove()==true||clicked.getRow()+1==y&&clicked.getColumn()==x)
                                {
                                    clicked.setPiece(board[y][x].getPiece());
                                    clicked.setText("WP");
                                    clicked.setFirstMove(false);
                                    board[y][x].setPiece(null);
                                    board[y][x].setText("");
                                    z=0;
                                    turn=!turn;
                                }
                                else if(clicked.getRow()+1==y&&Math.abs(clicked.getColumn()-x)==1&&clicked.getPiece()!=null)
                                {
                                    clicked.setPiece(board[y][x].getPiece());
                                    clicked.setText("WP");
                                    clicked.setFirstMove(false);
                                    board[y][x].setPiece(null);
                                    board[y][x].setText("");
                                    z=0;
                                    turn=!turn;
                                }
                                
                                else
                                {
                                    System.out.println("Failure...");
                                }
                            }
                            
                            else if(board[y][x].getPiece()==whiteQueen)
                            {
                                if(Math.abs(clicked.getRow()-y)==Math.abs(clicked.getColumn()-x)||clicked.getRow()==y&&clicked.getColumn()!=x||clicked.getColumn()==x&&clicked.getRow()!=y)
                                {
                                    clicked.setPiece(whiteQueen);
                                    clicked.setText("WQ");
                                    board[y][x].setText("");
                                    board[y][x].setPiece(null);
                                    z=0;
                                    turn=!turn;
                                }
                            }
                            else if(board[y][x].getPiece()==whiteBishop)
                            {
                                blocked=false;
                                int obstacleChecker=0;
                                int obstacleChecker2=0;
                                if(Math.abs(clicked.getRow()-y)==Math.abs(clicked.getColumn()-x)&&blocked==false)
                                {
                                    clicked.setPiece(whiteBishop);
                                    clicked.setText("WB");
                                    board[y][x].setText("");
                                    board[y][x].setPiece(null);
                                    z=0;
                                    turn=!turn;
                                }
                            }
                            else if(board[y][x].getPiece()==whiteKnight)
                            {
                                if(Math.abs(clicked.getRow()-y)+Math.abs(clicked.getColumn()-x)==3&&clicked.getColumn()!=x&&clicked.getRow()!=y)
                                {
                                    clicked.setPiece(whiteKnight);
                                    clicked.setText("WKn");
                                    board[y][x].setText("");
                                    board[y][x].setPiece(null);
                                    z=0;
                                    turn=!turn;
                                }
                            }
                            else if(board[y][x].getPiece()==whiteRook)
                            {        
                                blocked=false;
                                int obstacleChecker=clicked.getRow()-y;
                                int obstacleChecker2=clicked.getColumn()-x;
                                if(obstacleChecker2==0&&obstacleChecker>0)
                                {
                                    for(int b=1; b<obstacleChecker-1; b++)
                                    {
                                        System.out.println("check1");
                                        if(board[y+b][x].getText()!="")
                                        {
                                            System.out.println("STOP TRYING TO BREAK MY GAME!");
                                            blocked=true;
                                            z=0;
                                        }
                                    }
                                }
                                   else if(obstacleChecker2==0&&obstacleChecker<0)
                                {
                                       System.out.println("check2");
                                    for(int b=-1; b>=obstacleChecker+1; b--)
                                    {
                                        if(board[y+b][x].getText()!="")
                                        {
                                            System.out.println("STOP TRYING TO BREAK MY GAME!");
                                            blocked=true;
                                            z=0;
                                        }
                                    }
                                }
                                else if(obstacleChecker==0&&obstacleChecker2>0)
                                {
                                    System.out.println("check3");
                                    for(int b=1; b<=obstacleChecker-1; b++)
                                    {
                                        if(board[y][x+b].getText()!="")
                                        {
                                            System.out.println("STOP TRYING TO BREAK MY GAME!");
                                            blocked=true;
                                            z=0;
                                        }
                                    }
                                }
                                   else if(obstacleChecker==0&&obstacleChecker2<0)
                                {
                                       System.out.println("check4");
                                    for(int b=-1; b>=obstacleChecker+1; b--)
                                    {
                                        if(board[y][x+b].getText()!="")
                                        {
                                            System.out.println("STOP TRYING TO BREAK MY GAME!");
                                            blocked=true;
                                            z=0;
                                        }
                                    }
                                }
                                if(clicked.getRow()==y&&clicked.getColumn()!=x||clicked.getColumn()==x&&clicked.getRow()!=y&&blocked==false)
                                {
                                    clicked.setPiece(whiteRook);
                                    clicked.setText("WR");
                                    board[y][x].setText("");
                                    board[y][x].setPiece(null);
                                    z=0;
                                    turn=!turn;
                                }
                            }
                            else if(board[y][x].getPiece()==whiteKing)
                            {                                                                
                                if(Math.abs(clicked.getRow()-y)<=1&&Math.abs(clicked.getColumn()-x)<=1&&clicked.getText()=="")
                                {
                                    clicked.setPiece(whiteKing);
                                    clicked.setText("WK");
                                    board[y][x].setText("");
                                    board[y][x].setPiece(null);
                                    z=0;
                                    turn=!turn;
                                }
                                else
                                {
                                    System.out.println("STOP TRYING TO BREAK MY GAME!");
                                    z=0;
                                }
                            }
                        }
                    }
                    else
                    {
                        if(z==0)
                        {
                            if(clicked.getPiece()!=null&&clicked.getPiece().getColor()=="Black")
                            {
                                    y=clicked.getRow();
                                    x=clicked.getColumn();
                                    System.out.println("("+board[y][x].getLetter()+","+board[y][x].getNumber()+") to...?");
                                    z++;
                            }
                        }
                        else if(z==1&&clicked.getPiece()==null||clicked.getPiece().getColor()!="Black")
                        {
                            if(board[y][x].getPiece().pawnCheck==true)
                            {
                                if(clicked.getText()==""&clicked.getColumn()==x)
                                {
                                    if(clicked.getRow()-2==y&&board[y][x].getFirstMove()==true||clicked.getRow()-1==y)
                                    {
                                        clicked.setPiece(board[y][x].getPiece());
                                        clicked.setText("BP");
                                        clicked.setFirstMove(false);
                                        board[y][x].setPiece(null);
                                        board[y][x].setText("");
                                        z=0;
                                        turn=!turn;
                                    }
                                }
                                else if(clicked.getRow()-1==y&&Math.abs(clicked.getColumn()-x)==1&&clicked.getPiece()!=null)
                                {
                                    clicked.setPiece(board[y][x].getPiece());
                                    clicked.setText("BP");
                                    clicked.setFirstMove(false);
                                    board[y][x].setPiece(null);
                                    board[y][x].setText("");
                                    z=0;
                                    turn=!turn;
                                }
                            }
                            else if(board[y][x].getPiece()==blackQueen)
                            {
                                if(Math.abs(clicked.getRow()-y)==Math.abs(clicked.getColumn()-x)||clicked.getRow()==y&&clicked.getColumn()!=x||clicked.getColumn()==x&&clicked.getRow()!=y)
                                {
                                    clicked.setPiece(blackQueen);
                                    clicked.setText("BQ");
                                    board[y][x].setText("");
                                    board[y][x].setPiece(null);
                                    z=0;
                                    turn=!turn;
                                }
                            }
                            else if(board[y][x].getPiece()==blackBishop)
                            {
                                if(Math.abs(clicked.getRow()-y)==Math.abs(clicked.getColumn()-x))
                                {
                                    clicked.setPiece(blackBishop);
                                    clicked.setText("BB");
                                    board[y][x].setText("");
                                    board[y][x].setPiece(null);
                                    z=0;
                                    turn=!turn;
                                }
                            }
                            else if(board[y][x].getPiece()==blackKnight)
                            {
                                if(Math.abs(clicked.getRow()-y)+Math.abs(clicked.getColumn()-x)==3&&clicked.getColumn()!=x&&clicked.getRow()!=y)
                                {
                                    clicked.setPiece(blackKnight);
                                    clicked.setText("BKn");
                                    board[y][x].setText("");
                                    board[y][x].setPiece(null);
                                    z=0;
                                    turn=!turn;
                                }
                            }
                            else if(board[y][x].getPiece()==blackRook)
                            {
                                blocked=false;
                                int obstacleChecker=clicked.getRow()-y;
                                int obstacleChecker2=clicked.getColumn()-x;
                                if(obstacleChecker2==0&&obstacleChecker>0)
                                {
                                    for(int b=1; b<obstacleChecker; b++)
                                    {
                                        if(board[y+b][x].getText()!="")
                                        {
                                            System.out.println("STOP TRYING TO BREAK MY GAME!");
                                            blocked=true;
                                            z=0;
                                        }
                                    }
                                }
                                
                                   else if(obstacleChecker==0&&obstacleChecker2<0)
                                {
                                    for(int b=-1; b>=obstacleChecker; b--)
                                    {
                                        if(board[y][x-b].getText()!="")
                                        {
                                            System.out.println("STOP TRYING TO BREAK MY GAME!");
                                            blocked=true;
                                            z=0;
                                        }
                                    }
                                }
                                
                                else if(obstacleChecker==0&&obstacleChecker2>0)
                                {
                                    for(int b=1; b<=obstacleChecker; b++)
                                    {
                                        if(board[y][x+b].getText()!="")
                                        {
                                            System.out.println("STOP TRYING TO BREAK MY GAME!");
                                            blocked=true;
                                            z=0;
                                        }
                                    }
                                }
                                
                                   else if(obstacleChecker2==0&&obstacleChecker<0)
                                {
                                    for(int b=-1; b>=obstacleChecker; b--)
                                    {
                                        if(board[y][x-b].getText()!="")
                                        {
                                            System.out.println("STOP TRYING TO BREAK MY GAME!");
                                            blocked=true;
                                            z=0;
                                        }
                                    }
                                }
                                
                                if(clicked.getRow()==y&&clicked.getColumn()!=x||clicked.getColumn()==x&&clicked.getRow()!=y&&blocked==false)
                                {
                                    clicked.setPiece(blackRook);
                                    clicked.setText("BR");
                                    board[y][x].setText("");
                                    board[y][x].setPiece(null);
                                    z=0;
                                    turn=!turn;
                                }
                            }
                            else if(board[y][x].getPiece()==blackKing)
                            {
                                if(Math.abs(clicked.getRow()-y)<=1&&Math.abs(clicked.getColumn()-x)<=1)
                                {
                                    clicked.setPiece(blackKing);
                                    clicked.setText("BK");
                                    board[y][x].setText("");
                                    board[y][x].setPiece(null);
                                    z=0;
                                    turn=!turn;
                                }
                            }
                        }
                    }
                }
            }
            
            if(me.getSource() instanceof JLabel)
            {
                JLabel clicked = (JLabel)me.getSource();
                {
                    if(clicked.getText().equals("Exit"))
                    {
                        System.exit(0);
                    }
                }
            }
        }
        //method used when mouse is pressed
        public void mousePressed(MouseEvent me)
        {
 
        }
        //method used when mouse is entered
        public void mouseEntered(MouseEvent me)
        {

        }
        //method used when mouse is exited
        public void mouseExited(MouseEvent me)
        {

        }
        //method used when mouse is released
        public void mouseReleased(MouseEvent me)
        {

        }
}

import java.awt.Color;
import javax.swing.*;

public class Piece
{
    String color;
    int points;
    boolean occupied;
    int column=0;
    int row=0;
    boolean pawnCheck;
    boolean knightCheck;
    boolean bishopCheck;
    boolean rookCheck;
    boolean queenCheck;
    boolean kingCheck;
   
    public Piece()
    {
        color="Red";
        points=0;
        occupied=true;
        column=0;
        row=0;
    }
    /**
     * @param args
     */
    public void setColor(String n)
    {
        color=n;
    }
   
    public String getColor()
    {
        return color;
    }
   
    public void setPoints(int n)
    {
        points=n;
    }
   
    public int getPoints()
    {
        return points;
    }
   
    public void setOccupied(boolean n)
    {
        occupied=n;
    }
   
    public boolean getOccupied(boolean n)
    {
        return occupied;
    }
   
    //allows player to set Tile column
    public void setColumn(int n)
    {
        column=n;
    }
    //allows player to get Tile column
    public int getColumn()
    {
        return column;
    }
    //allows player to set Tile row
    public void setRow(int n)
    {
        row=n;
    }
    //allows player to get Tile row
    public int getRow()
    {
        return row;
    }
    public void setText(String string)
    {
        // TODO Auto-generated method stub
       
    }
}

/**
 *
 */
import java.awt.Color;
import javax.swing.*;
/**
 * @author wcorwin
 *
 */
//This is the class that creates the parameters for which the Tile is created
public class Tile extends JLabel
{   
    private static final Piece Pawn = null;
    //The int for the Tile's height
    int height;
    //The int for the Tile's width
    int width;
    //The tile's column
    int column=0;
    //The tile's row
    int row=0;
    String letter= "";
    int number= 100;
    Piece piece= null;
    boolean firstMove=false;
    /**
     *
     */
    public Tile()
    {
        //takes all JLabel attributes for Tile
        super();
        //sets default Tile height
        height=0;
        //sets default Tile width
        width=0;
        //sets default Tile column
        column = 0;
        //sets default Tile row
        row=0;
    }
    //sets another Tile method
    public Tile(int y,int x)
    {
        //takes all JLabel attributes for Tile
        super();
        //sets Tile height as x
        height=0;
        //sets Tile width as y
        width=0;
        //sets default Tile column
        column = y;
        //sets default Tile row
        row=x;
        piece=null;
    }
    //allows player to set Tile column
    public void setColumn(int n)
    {
        column=n;
    }
    //allows player to get Tile column
    public int getColumn()
    {
        return column;
    }
    //allows player to set Tile row
    public void setRow(int n)
    {
        row=n;
    }
    //allows player to get Tile row
    public int getRow()
    {
        return row;
    }   
   
    public void setLetter(String n)
    {
        letter =n;
    }
   
    public String getLetter()
    {
        return letter;
    }
   
    public void setNumber(int n)
    {
        number=n;
    }
   
    public int getNumber()
    {
        return number;
    }
   
    public void setPiece(Piece n)
    {
        piece= n;
    }
       
    public Piece getPiece()
    {
        return piece;
    }
    public void setFirstMove(boolean n)
    {
        firstMove=n;
    }
   
    public boolean getFirstMove()
    {
        return firstMove;
    }
   
    public Pawn getPawn()
    {
        Pawn n= new Pawn();
        if(getPiece()== n)
        {
            return n;
        }
       
        else
        {
            return null;
        }
    }
}

import java.util.ArrayList;
import javax.swing.*;
/**
 * @author wcorwin
 *
 */
public class Pawn extends Piece
{
    private ImageIcon icon = new ImageIcon("sp001.jpg");
    private Tile white = new Tile();
    boolean moveHere;
   
   
    public Pawn()
    {
        super();
        points=1;
        occupied=true;
        pawnCheck=true;
    }
   
    public Pawn(String n)
    {
        super();
        points=1;
        occupied=true;
        color=n;
        pawnCheck=true;
    }
    public boolean doPawnCheck()
    {
        return true;
    }
}

import java.util.ArrayList;
import javax.swing.*;

/**
 * @author wcorwin
 *
 */
public class Rook extends Queen
{
    private ArrayList<Tile> white = new ArrayList<Tile>();
    private ImageIcon icon = new ImageIcon("sp004.jpg");
   
    public Rook(String n)
    {
        super(n);
        points=3;
        occupied=true;
        color=n;
    }
   
    public boolean rookCheck()
    {
        return true;
    }
   
    public ArrayList<Tile> moveHere()
    {
       
        return white;
    }
}

import javax.swing.ImageIcon;


public class Queen extends Piece
{
    private ImageIcon icon = new ImageIcon("queen.jpg");
    public Queen(String n)
    {
        super();
        points=9;
        occupied=true;
        color=n;
    }
   
    public boolean queenCheck()
    {
        return true;
    }
}

import javax.swing.ImageIcon;

/**
 * @author wcorwin
 *
 */
public class King extends Piece
{
    private ImageIcon icon = new ImageIcon("king.jpg");
   
    public King(String n)
    {
        super();
        points=9001;
        occupied=true;
        color=n;
    }
   
    public boolean kingCheck()
    {
        return true;
    }
   
    public void MoveKing(Tile n)
    {
        King King = new King(getColor());
        n.setPiece(King);
    }
}

import java.util.ArrayList;

import javax.swing.ImageIcon;

/**
 * @author wcorwin
 */
public class Knight extends Piece
{
    private ImageIcon icon = new ImageIcon("sp003.jpg");
   
    public Knight()
    {
        super();
        points=3;
        occupied=true;
        ImageIcon icon= new ImageIcon("sp003.jpg");
    }
   
    public boolean moveable()
    {
        for(int a=0; a<8; a++)
        {
            for(int b=0; b<8; b++)
            {
               
            }
        }
        return false;
    }
   
    public Knight(String n)
    {
        super();
        points=3;
        occupied=true;
        color=n;
    }
   
    public boolean KnightCheck()
    {
        return true;
    }
}


Locusts, Foxes, and Heart Attacks

I. Introduction
            A. Lillian Hellman wrote “The Little Foxes” to convey a message

            B. There are three types of people on the Earth: those who eat the Earth, those who watch the eaters, and those who try and fight against them.

II. Topic 1: Person Type 1- The Greedy

            A. “Well, there are people who eat the earth and eat all the people on it.” pg                  205, Addie from “The Little Foxes” and “[Ben] shows no interest in human relations             beyond the use he makes of them to achieve financial domination [of the town] where             he was born,” from DISCovering Authors.

            B. This quote establishes the first type of person- the greedy

            C. The locusts of the people ate the people of Egypt and the land itself endlessly.           They were insatiable and unstoppable.

            D. Addie compares the greedy Hubbards to the locusts of Egypt who destroyed            everything around them without regard for the consequences to those around.

            E. This establishes how the Hubbards are like locusts, without regard to those around    them and looking out entirely for themselves.

            F. “All [of Lillian Hellman’s] plays are built around two consuming obsessions:   family and capital,” Ellen Moers “Family Theatre” in page 187 of American Literary        Criticism.

            G. All the Hubbards desire capital and the privileges that come with it, but if weren’t      for the corrupt around them, the cycle wouldn’t continue.

III. Topic 2: Person Type 2- The Corrupt

            A. “Then there are people who stand around and watch them eat it...”pg 205, Addie,    “Little Foxes” and “Hellman constantly makes the point, equally applicable to private            and public affairs, that it is immoral to remain passive when evil is being done.” From           Katharine M. Rogers on page 305 of American Women Writers.

            B. This quote establishes the second type of person- the corrupt

            C. The quote suggests those that do nothing to assist those being eaten by the locusts,    the ones that look at injustice and do nothing to stop it.

            D. The corrupt are those who can look at injustice and do nothing. Like Birdie, Addie, and originally Oscar, who watched the Hubbards take advantage of those             around them and do nothing to stop them.

            E. This sets up the idea that both kinds of people are evil as neither take any interest      in helping those around them.

            F. “The least attractive qualities of the Hellman people of their claustrophobic     clannishness and their arrogant assumption that the greatest battles of the outside           world are secondary to, but distantly dependent on, their family squabbles.” From         Ellen     Moers “Family Theatre” in page 187 of American Literary Criticism.

            G. Both the greedy and the corrupt perpetuate the cycle that eats the Earth and the        people that live on it, but the character almost non-existent in the play is the systemic             anomaly: The other.

IV. Topic 3: Person Type 3- The Others

            A. “Sometimes I think it ain't right to stand and watch them do it." pg 205, Addie           “Little Foxes” and “[I’ll] be fighting… some place where people don’t just stand around and watch.” Alexandra, “The Little Foxes”

            B. This quote establishes the idea of breaking the norm, to act differently from the          two possibilities.

            C. Presents the thought that someone should stand up against injustice and greed

            D. The play presents those that try to break the mold, but are too weak to do so.          Horace’s resistance poses little to Regina as all she has to do is wait for him to die.             And Zan’s resistance is a glimmer of hope at the end, although there is no guarantee    that anything will come of it.

            E. The fact that most of the nobler characters are too weak to defend justice against      the evil of the Hubbards

            F. “Hellman was disappointed in the frequent reception of Regina and her brothers as    simple villains in a melodrama…’I had meant the audience to recognize some part of         themselves in the money dominated Hubbards…” from the Facts on File Companion         to American Drama.

            G. Hellman desired that people would recognize a piece of themselves in the      Hubbards so they might try and change from greedy and corrupt to more honest and      noble.

V. Conclusion

            A. There are three types of people on the Earth: those who eat the Earth, those who watch the eaters, and those who try and fight against them.

            B. Hellman was reported to be disappointed that the Hubbards were only seen as          melodramatic villains, that her audience didn’t see a part of themselves in each of   them.

            C. The three types of people in the world as suggested by Lillian Hellman are the           greedy- those who eat the earth and those on it- the corrupt – those who watch them         do it- and the others, -those who try and stop them.

            D. Hellman only introduced two kinds of people because she wanted her audience to     create the third. How many will answer the call?

 



import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Random;
/**
 *
 */
/**
 * @author wcorwin
 *
 */
public class Battleship extends JFrame implements MouseListener
{
    //Board of Tiles which shall be used to play the game
    private Tile[][] playerBoard = new Tile[10][10];
    private Tile[][] enemyBoard = new Tile[10][10];
    //JLabel used to exit the program...The Exit Button!-"When the X in the top right just isn't convenient enough!"
    JLabel exit= new JLabel();
    //integer to keep track of the columns of the board
    JLabel yourBoard = new JLabel();
    JLabel hisBoard = new JLabel();
    JLabel battleship = new JLabel();
    JLabel carrier = new JLabel();
    JLabel destroyer= new JLabel();
    JLabel submarine= new JLabel();
    JLabel minesweeper = new JLabel();
    int x=0;
    //integer to keep track of the rows of the board
    int y=0;
    //Later, I'm going to have to reference two different tiles. This will be Tile one's row
    int a=0;
    //Later, I'm going to have to reference two different tiles. This will be Tile one's row
    int b=0;
    int c=0;
    int battleshipCheck=0;
    int carrierCheck=0;
    int destroyerCheck =0;
    int submarineCheck=0;
    int minesweeperCheck=0;
    boolean turn=true;
    int knowledge1=-1;
    int knowledge2=-1;

    public Battleship()
    {
        //The content Pane- where everything was, is, and will be
        Container contentPane =getContentPane();
        //The layout is null because layout's don't apply for this program
        contentPane.setLayout(null);
        //The program has a height and width of 600
        setSize(800,600);
        //The location of the program is (1,1)
        setLocation(1,1);
        //The background of the program is white...even though it looks gray
        setBackground(Color.white);
        //The title is Battleship because that's the title of the program
        setTitle("Battleship");
        //The program stops when I exit the program for obvious reasons
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        
        JLabel yourBoard = new JLabel("Your board");
        //The bounds of the exit button. Near the bottom and out of the way
        yourBoard.setBounds(110,30,90,36);
        //The exit button's border is blue...don't judge me.
        yourBoard.setBorder(BorderFactory.createLineBorder(Color.blue));
        //The exit button has a Mouse Listener because in order to work, its need to be able to comprehend Mouse actions
        yourBoard.addMouseListener(this);
        //The text of the exit button is centered for a better look
        yourBoard.setHorizontalAlignment(JLabel.CENTER);
        //And the exit button is added to the content pane
        contentPane.add(yourBoard);
        
        JLabel hisBoard = new JLabel("Enemy Board");
        //The bounds of the exit button. Near the bottom and out of the way
        hisBoard.setBounds(610,30,90,36);
        //The exit button's border is blue...don't judge me.
        hisBoard.setBorder(BorderFactory.createLineBorder(Color.blue));
        //The exit button has a Mouse Listener because in order to work, its need to be able to comprehend Mouse actions
        hisBoard.addMouseListener(this);
        //The text of the exit button is centered for a better look
        hisBoard.setHorizontalAlignment(JLabel.CENTER);
        //And the exit button is added to the content pane
        contentPane.add(hisBoard);
        
        
        JLabel battleship = new JLabel("Battleship");
        battleship.setBounds(355, 100, 90, 30);
        battleship.setBorder(BorderFactory.createLineBorder(Color.green));
        battleship.addMouseListener(this);
        battleship.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(battleship);
        
        JLabel carrier = new JLabel("Carrier");
        carrier.setBounds(355, 140, 90, 30);
        carrier.setBorder(BorderFactory.createLineBorder(Color.green));
        carrier.addMouseListener(this);
        carrier.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(carrier);
        
        JLabel destroyer= new JLabel("Destroyer");
        destroyer.setBounds(355, 180, 90, 30);
        destroyer.setBorder(BorderFactory.createLineBorder(Color.green));
        destroyer.addMouseListener(this);
        destroyer.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(destroyer);
        
        JLabel submarine= new JLabel("Submarine");
        submarine.setBounds(355, 220, 90, 30);
        submarine.setBorder(BorderFactory.createLineBorder(Color.green));
        submarine.addMouseListener(this);
        submarine.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(submarine);
        
        JLabel minesweeper = new JLabel("Minesweeper");
        minesweeper.setBounds(355, 260, 90, 30);
        minesweeper.setBorder(BorderFactory.createLineBorder(Color.green));
        minesweeper.addMouseListener(this);
        minesweeper.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(minesweeper);
        
        
        if(carrierCheck==3&&battleshipCheck==3&&submarineCheck==3&&minesweeperCheck==3&&destroyerCheck==3)
        {
            JOptionPane.showMessageDialog(null, "All Right, Let's do this!");
        }
        
        //The double for loop where the board is created and given attributes. The first is for the columns...
        for(int x=0;x<10;x++)
        {
            //The second is for the rows
            for(int y=0;y<10;y++)
            {  
                //The board! Each is a thirty by thirty square
                playerBoard[x][y] = new Tile(30,30);
                //The location is fifty times the row, fifty times the column
                playerBoard[x][y].setLocation(30*x,100+30*y);
                //Yes the border on the board is blue. Because black is boring.
                playerBoard[x][y].setBorder(BorderFactory.createLineBorder(Color.blue));
                //The board can hear the mouse, thus allowing the game to be played
                playerBoard[x][y].addMouseListener(this);
                //Now the board knows that the column is its column!!!
                playerBoard[x][y].setColumn(x);
                //Now the board knows that the column is its column!!!
                playerBoard[x][y].setRow(y);
                //Now the text is centered
                playerBoard[x][y].setController("Player");
                playerBoard[x][y].setHorizontalAlignment(Tile.CENTER);
                //And the board is added to the contentPane
                contentPane.add(playerBoard[x][y]);

                //The board! Each is a thirty by thirty square
                enemyBoard[x][y] = new Tile(30,30);
                //The location is fifty times the row, fifty times the column
                enemyBoard[x][y].setLocation(500+30*x,100+30*y);
                //Yes the border on the board is blue. Because black is boring.
                enemyBoard[x][y].setBorder(BorderFactory.createLineBorder(Color.blue));
                //The board can hear the mouse, thus allowing the game to be played
                enemyBoard[x][y].addMouseListener(this);
                //Now the board knows that the column is its column!!!
                enemyBoard[x][y].setColumn(x);
                //Now the board knows that the column is its column!!!
                enemyBoard[x][y].setRow(y);
                //Now the text is centered
                enemyBoard[x][y].setController("Computer");
                enemyBoard[x][y].setHorizontalAlignment(Tile.CENTER);
                //And the board is added to the contentPane
                contentPane.add(enemyBoard[x][y]);
            }
        }
    }
    /**
     * @param args
     */
    public static void main(String[] args)
    {
        //frame of GUI
        Battleship frame= new Battleship();
        frame.setVisible(true);
    }
    
    public void mouseClicked(MouseEvent me)
    {
        if(me.getSource() instanceof Tile)
        {
            Tile clicked = (Tile) me.getSource();
            {
                if(carrierCheck==3&&battleshipCheck==3&&submarineCheck==3&&destroyerCheck==3&&minesweeperCheck==3)
                if(turn)
                {
                    if(clicked.getController().equals("Computer"))
                    {
                        if(clicked.getType().equals("Ship"))
                        {
                            clicked.setText("HIT");
                        }
                        else
                        {
                            clicked.setText("MISS");
                            turn=!turn;
                        }
                    }
                }
                else
                {
                    if(knowledge1==-1&&knowledge2==-1)
                    {
                        Random rand= new Random();
                        int f= rand.nextInt(10);
                        int g= rand.nextInt(10);
                        
                        if(playerBoard[f][g].getType().equals("Ship"))
                        {
                            playerBoard[f][g].setText("HIT");
                            knowledge1=f;
                            knowledge2=g;
                        }
                        else
                        {
                            playerBoard[f][g].setText("MISS");
                            turn=!turn;
                        }
                    }
                    else
                    {
                        if(knowledge1>0)
                        {
                            if(playerBoard[knowledge1-1][knowledge2].getType().equals("Ship"))
                            {
                                playerBoard[knowledge1-1][knowledge2].setText("HIT");
                                knowledge1--;
                            }
                        
                            else
                            {
                                playerBoard[knowledge1-1][knowledge2].setText("MISS");
                                knowledge1=-1;
                                knowledge2=-1;
                                turn=!turn;
                            }
                        }
                        else if(knowledge2>0)
                        {
                            if(playerBoard[knowledge1][knowledge2-1].getType().equals("Ship"))
                            {
                                playerBoard[knowledge1][knowledge2-1].setText("HIT");
                                knowledge2--;
                            }
                        
                            else
                            {
                                playerBoard[knowledge1][knowledge2-1].setText("MISS");
                                knowledge1=-1;
                                knowledge2=-1;
                                turn=!turn;
                            }
                        }
                        else if(knowledge1<10)
                        {
                            if(playerBoard[knowledge1][knowledge2+1].getType().equals("Ship"))
                            {
                                playerBoard[knowledge1+1][knowledge2].setText("HIT");
                                knowledge1++;
                            }
                            
                            else
                            {
                                playerBoard[knowledge1+1][knowledge2].setText("MISS");
                                knowledge1=-1;
                                knowledge2=-1;
                                turn=!turn;
                            }
                        }
                        
                        else if(knowledge2<10)
                        {
                            if(playerBoard[knowledge1][knowledge2+1].getType().equals("Ship"))
                            {
                                playerBoard[knowledge1][knowledge2+1].setText("HIT");
                                knowledge2++;
                            }
                            
                            else
                            {
                                playerBoard[knowledge1][knowledge2+1].setText("MISS");
                                knowledge1=-1;
                                knowledge2=-1;
                                turn=!turn;
                            }
                        }
                    }
                }
            }
        }
        
        if(me.getSource() instanceof JLabel)
        {
            JLabel clicked = (JLabel) me.getSource();
            {
                if(clicked.getText().equals("Battleship")&&battleshipCheck==0)
                {
                    int width= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's width that you would like to place the battleship on?"));
                    int height= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's height that you would like to place the battleship on?"));
                    String direction = JOptionPane.showInputDialog(null, "Which direction would you like it to go? (Up, Down, Left, Right)");
                    
                    if(playerBoard[width][height].getText().equals(""))
                    {
                        if(playerBoard[width][height].getColumn()>2&&direction.equals("Left"))
                        {
                            if(playerBoard[width-1][height].getType().equals("Ship")||playerBoard[width-2][height].getType().equals("Ship")||playerBoard[width-3][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n> width-4; n--)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Bat");
                                        playerBoard[n][height].setType("Ship");
                                        battleshipCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getColumn()<7&&direction.equals("Right"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship")||playerBoard[width+2][height].getType().equals("Ship")||playerBoard[width+3][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n< width+4; n++)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Bat");
                                        playerBoard[n][height].setType("Ship");
                                        battleshipCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()>2&&direction.equals("Up"))
                        {
                            if(playerBoard[width][height-1].getType().equals("Ship")||playerBoard[width][height-2].getType().equals("Ship")||playerBoard[width][height-3].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n> height-4; n--)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Bat");
                                        playerBoard[width][n].setType("Ship");
                                        battleshipCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()<7&&direction.equals("Down"))
                        {
                            if(playerBoard[width][height+1].getType().equals("Ship")||playerBoard[width][height+2].getType().equals("Ship")||playerBoard[width][height+3].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n< height+4; n++)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Bat");
                                        playerBoard[width][n].setType("Ship");
                                        battleshipCheck=1;
                                    }
                                }
                            }
                        }
                    }
                }
                else if(clicked.getText().equals("Carrier")&&carrierCheck==0)
                {
                    int width= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's width that you would like to place the carrier on?"));
                    int height= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's height that you would like to place the carrier on?"));
                    String direction = JOptionPane.showInputDialog(null, "Which direction would you like it to go? (Up, Down, Left, Right)");
                    
                    if(playerBoard[width][height].getText().equals(""))
                    {
                        if(playerBoard[width][height].getColumn()>3&&direction.equals("Left"))
                        {
                            if(playerBoard[width-1][height].getType().equals("Ship")||playerBoard[width-2][height].getType().equals("Ship")||playerBoard[width-3][height].getType().equals("Ship")||playerBoard[width-4][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n> width-5; n--)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Car");
                                        playerBoard[n][height].setType("Ship");
                                        carrierCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getColumn()<6&&direction.equals("Right"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship")||playerBoard[width+2][height].getType().equals("Ship")||playerBoard[width+3][height].getType().equals("Ship")||playerBoard[width+4][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n< width+5; n++)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Car");
                                        playerBoard[n][height].setType("Ship");
                                        carrierCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()>3&&direction.equals("Up"))
                        {
                            if(playerBoard[width][height-1].getType().equals("Ship")||playerBoard[width][height-2].getType().equals("Ship")||playerBoard[width][height-3].getType().equals("Ship")||playerBoard[width][height-4].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n> height-5; n--)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Car");
                                        playerBoard[width][n].setType("Ship");
                                        carrierCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()<6&&direction.equals("Down"))
                        {
                            if(playerBoard[width][height+1].getType().equals("Ship")||playerBoard[width][height+2].getType().equals("Ship")||playerBoard[width][height+3].getType().equals("Ship")||playerBoard[width][height+4].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n< height+5; n++)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Car");
                                        playerBoard[width][n].setType("Ship");
                                        carrierCheck=1;
                                    }
                                }
                            }
                        }
                    }
                }
                else if(clicked.getText().equals("Destroyer")&&destroyerCheck==0)
                {
                    int width= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's width that you would like to place the destroyer on?"));
                    int height= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's height that you would like to place the destroyer on?"));
                    String direction = JOptionPane.showInputDialog(null, "Which direction would you like it to go? (Up, Down, Left, Right)");
                    
                    if(playerBoard[width][height].getText().equals(""))
                    {
                        if(playerBoard[width][height].getColumn()>1&&direction.equals("Left"))
                        {
                            if(playerBoard[width-1][height].getType().equals("Ship")||playerBoard[width-2][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n> width-3; n--)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Des");
                                        playerBoard[n][height].setType("Ship");
                                        destroyerCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getColumn()<8&&direction.equals("Right"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship")||playerBoard[width+2][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n< width+3; n++)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Des");
                                        playerBoard[n][height].setType("Ship");
                                        destroyerCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()>1&&direction.equals("Up"))
                        {
                            if(playerBoard[width][height-1].getType().equals("Ship")||playerBoard[width][height-2].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n> height-3; n--)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Des");
                                        playerBoard[width][n].setType("Ship");
                                        destroyerCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()<8&&direction.equals("Down"))
                        {
                            if(playerBoard[width][height+1].getType().equals("Ship")||playerBoard[width][height+1].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n< height+3; n++)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Des");
                                        playerBoard[width][n].setType("Ship");
                                        destroyerCheck=1;
                                    }
                                }
                            }
                        }
                    }
                }
                
                else if(clicked.getText().equals("Submarine")&&submarineCheck==0)
                {
                    int width= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's width that you would like to place the sub on?"));
                    int height= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's height that you would like to place the sub on?"));
                    String direction = JOptionPane.showInputDialog(null, "Which direction would you like it to go? (Up, Down, Left, Right)");
                    
                    if(playerBoard[width][height].getText().equals(""))
                    {
                        if(playerBoard[width][height].getColumn()>1&&direction.equals("Left"))
                        {
                            if(playerBoard[width-1][height].getType().equals("Ship")||playerBoard[width-2][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n> width-3; n--)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Sub");
                                        playerBoard[n][height].setType("Ship");
                                        submarineCheck=1;
                                    }
                                }
                            }
                        }
                        
                        else if(playerBoard[width][height].getColumn()<8&&direction.equals("Right"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship")||playerBoard[width+2][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n< width+3; n++)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Sub");
                                        playerBoard[n][height].setType("Ship");
                                        submarineCheck=1;
                                    }
                                }
                            }
                        }
                        
                        else if(playerBoard[width][height].getRow()>1&&direction.equals("Up"))
                        {
                            if(playerBoard[width][height-1].getType().equals("Ship")||playerBoard[width][height-2].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n> height-3; n--)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Sub");
                                        playerBoard[width][n].setType("Ship");
                                        submarineCheck=1;
                                    }
                                }
                            }
                        }
                        
                        else if(playerBoard[width][height].getRow()<8&&direction.equals("Down"))
                        {
                            if(playerBoard[width][height+1].getType().equals("Ship")||playerBoard[width][height+2].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n< height+3; n++)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Sub");
                                        playerBoard[width][n].setType("Ship");
                                        submarineCheck=1;
                                    }
                                }
                            }
                        }
                    }
                }
                
                else if(clicked.getText().equals("Minesweeper")&&minesweeperCheck==0)
                {
                    int width= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's width that you would like to place the sweeper on?"));
                    int height= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's height that you would like to place the sweeper on?"));
                    String direction = JOptionPane.showInputDialog(null, "Which direction would you like it to go? (Up, Down, Left, Right)");
                    
                    if(playerBoard[width][height].getText().equals(""))
                    {
                        if(playerBoard[width][height].getColumn()>0&&direction.equals("Left"))
                        {
                            if(playerBoard[width-1][height].getType().equals("Ship"))
                            {    
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n> width-2; n--)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Min");
                                        playerBoard[n][height].setType("Ship");
                                        minesweeperCheck=1;
                                    }
                                }
                            }
                        }
                        
                        else if(playerBoard[width][height].getColumn()<9&&direction.equals("Right"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship"))
                            {    
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n< width+2; n++)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Min");
                                        playerBoard[n][height].setType("Ship");
                                        minesweeperCheck=1;
                                    }
                                }
                            }
                        }
                        
                        else if(playerBoard[width][height].getRow()>0&&direction.equals("Up"))
                        {
                            if(playerBoard[width][height-1].getType().equals("Ship"))
                            {    
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n> height-2; n--)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Min");
                                        playerBoard[width][n].setType("Ship");
                                        minesweeperCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()<9&&direction.equals("Down"))
                        {
                            if(playerBoard[width][height+1].getType().equals("Ship"))
                            {    
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n< height+2; n++)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Min");
                                        playerBoard[width][n].setType("Ship");
                                        minesweeperCheck=1;
                                    }
                                }
                            }
                        }
                    }
                }
                if(carrierCheck==1&&battleshipCheck==1&&destroyerCheck==1&&submarineCheck==1&&minesweeperCheck==1)
                {
                    carrierCheck=2;
                    battleshipCheck=2;
                    submarineCheck=2;
                    destroyerCheck=2;
                    minesweeperCheck=2;
                    
                    if(submarineCheck==2)
                    {
                        Random rand = new Random();
                        int a= rand.nextInt(10);
                        int b= rand.nextInt(10);
                        int c=rand.nextInt(4);
                        if(enemyBoard[a][b].getType().equals(""))
                        {
                            System.out.println(c);
                            enemyBoard[a][b].setType("Ship");
                            enemyBoard[a][b].setText("Sub");
                            if(c==0)
                            {
                                if(a>=2&&enemyBoard[a-1][b].getType().equals("")&&enemyBoard[a-2][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-3; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Sub");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i<a+3; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Sub");
                                    }
                                }
                            }
                            else if(c==1)
                            {
                                if(a<=7&&enemyBoard[a+1][b].getType().equals("")&&enemyBoard[a+2][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+3; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Sub");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i>a-3; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Sub");
                                    }
                                }
                            }
                        
                            else if(c==2)
                            {
                                
                                if(b>=2&&enemyBoard[a][b-1].getType().equals("")&&enemyBoard[a][b-2].getType().equals(""))
                                {
                                    for(int i=b; i>b-3; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Sub");
                                    }
                                }
                                
                                else if(b<=7&&enemyBoard[a][b+1].getType().equals("")&&enemyBoard[a][b+2].getType().equals(""))
                                {
                                    for(int i=b; i<b+3; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Sub");
                                    }
                                }
                            }
                        
                            else if(c==3)
                            {
                                if(b<=7&&enemyBoard[a][b+1].getType().equals("")&&enemyBoard[a][b+2].getType().equals(""))
                                {
                                    for(int i=b; i>b+3; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Sub");
                                    }
                                }
                                
                                else if(b>=2&&enemyBoard[a][b-1].getType().equals("")&&enemyBoard[a][b-2].getType().equals(""))
                                {
                                    for(int i=b; i>b-3; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Sub");
                                    }
                                }
                            }
                        }
                        submarineCheck++;
                    }
                    
                    if(minesweeperCheck==2)
                    {
                        Random rand = new Random();
                        int a= rand.nextInt(10);
                        int b= rand.nextInt(10);
                        int c=rand.nextInt(4);
                        if(enemyBoard[a][b].getType().equals(""))
                        {
                            System.out.println(c);
                            enemyBoard[a][b].setType("Ship");
                            enemyBoard[a][b].setText("Min");
                            if(c==0)
                            {
                                if(a>=1&&enemyBoard[a-1][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-2; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Min");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i<a+2; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Min");
                                    }
                                }
                            }
                            else if(c==1)
                            {
                                if(a<=8&&enemyBoard[a+1][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+2; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Min");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i>a-2; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Min");
                                    }
                                }
                            }
                        
                            else if(c==2)
                            {
                                
                                if(b>=1&&enemyBoard[a][b-1].getType().equals(""))
                                {
                                    for(int i=b; i>b-2; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Min");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i<b+2; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Min");
                                    }
                                }
                            }
                        
                            else if(c==3)
                            {
                                if(b<=8&&enemyBoard[a][b+1].getType().equals(""))
                                {
                                    for(int i=b; i>b+2; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Min");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i>b-2; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Min");
                                    }
                                }
                            }
                        }
                        minesweeperCheck++;
                    }
                    
                    if(destroyerCheck==2)
                    {
                        Random rand = new Random();
                        int a= rand.nextInt(10);
                        int b= rand.nextInt(10);
                        int c=rand.nextInt(4);
                        if(enemyBoard[a][b].getType().equals(""))
                        {
                            System.out.println(c);
                            enemyBoard[a][b].setType("Ship");
                            enemyBoard[a][b].setText("Des");
                            if(c==0)
                            {
                                if(a>=2&&enemyBoard[a-1][b].getType().equals("")&&enemyBoard[a-2][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-3; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Des");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i<a+3; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Des");
                                    }
                                }
                            }
                            else if(c==1)
                            {
                                if(a<=7&&enemyBoard[a+1][b].getType().equals("")&&enemyBoard[a+2][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+3; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Des");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i>a-3; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Des");
                                    }
                                }
                            }
                        
                            else if(c==2)
                            {
                                
                                if(b>=2&&enemyBoard[a][b-1].getType().equals("")&&enemyBoard[a][b-2].getType().equals(""))
                                {
                                    for(int i=b; i>b-3; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Des");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i<b+3; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Des");
                                    }
                                }
                            }
                        
                            else if(c==3)
                            {
                                if(b<=7&&enemyBoard[a][b+1].getType().equals("")&&enemyBoard[a][b+2].getType().equals(""))
                                {
                                    for(int i=b; i>b+3; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Des");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i>b-3; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Des");
                                    }
                                }
                            }
                        }
                        destroyerCheck++;
                    }
                    
                    if(battleshipCheck==2)
                    {
                        Random rand = new Random();
                        int a= rand.nextInt(10);
                        int b= rand.nextInt(10);
                        int c=rand.nextInt(4);
                        if(enemyBoard[a][b].getType().equals(""))
                        {
                            System.out.println(c);
                            enemyBoard[a][b].setType("Ship");
                            enemyBoard[a][b].setText("Bat");
                            if(c==0)
                            {
                                if(a>=3&&enemyBoard[a-1][b].getType().equals("")&&enemyBoard[a-2][b].getType().equals("")&&enemyBoard[a-3][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-4; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Bat");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i<a+4; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Bat");
                                    }
                                }
                            }
                            else if(c==1)
                            {
                                if(a<=6&&enemyBoard[a+1][b].getType().equals("")&&enemyBoard[a+2][b].getType().equals("")&&enemyBoard[a+3][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+4; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Bat");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i>a-4; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Bat");
                                    }
                                }
                            }
                        
                            else if(c==2)
                            {
                                
                                if(b>=3&&enemyBoard[a][b-1].getType().equals("")&&enemyBoard[a][b-2].getType().equals("")&&enemyBoard[a][b-3].getType().equals(""))
                                {
                                    for(int i=b; i>b-4; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Bat");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i<b+4; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Bat");
                                    }
                                }
                            }
                        
                            else if(c==3)
                            {
                                if(b<=6&&enemyBoard[a][b+1].getType().equals("")&&enemyBoard[a][b+2].getType().equals("")&&enemyBoard[a][b+3].getType().equals(""))
                                {
                                    for(int i=b; i>b+4; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Bat");
                                    }
                                }
                                
                                else if(b>=2&&enemyBoard[a][b-1].getType().equals("")&&enemyBoard[a][b-2].getType().equals("")&&enemyBoard[a][b-3].getType().equals(""))
                                {
                                    for(int i=b; i>b-4; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Bat");
                                    }
                                }
                                
                                else if(a<=6&&enemyBoard[a+1][b].getType().equals("")&&enemyBoard[a+2][b].getType().equals("")&&enemyBoard[a+3][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+4; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Bat");
                                    }
                                }
                            }
                        }
                        battleshipCheck++;
                    }
                    
                    if(carrierCheck==2)
                    {
                        Random rand = new Random();
                        int a= rand.nextInt(10);
                        int b= rand.nextInt(10);
                        int c=rand.nextInt(4);
                        if(enemyBoard[a][b].getType().equals(""))
                        {
                            System.out.println(c);
                            enemyBoard[a][b].setType("Ship");
                            enemyBoard[a][b].setText("Car");
                            if(c==0)
                            {
                                if(a>=4&&enemyBoard[a-1][b].getType().equals("")&&enemyBoard[a-2][b].getType().equals("")&&enemyBoard[a-3][b].getType().equals("")&&enemyBoard[a-4][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-5; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Car");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i<a+5; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Car");
                                    }
                                }
                            }
                            else if(c==1)
                            {
                                if(a<=5&&enemyBoard[a+1][b].getType().equals("")&&enemyBoard[a+2][b].getType().equals("")&&enemyBoard[a+3][b].getType().equals("")&&enemyBoard[a+4][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+5; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Car");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i>a-5; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Car");
                                    }
                                }
                            }
                        
                            else if(c==2)
                            {
                                
                                if(b>=4&&enemyBoard[a][b-1].getType().equals("")&&enemyBoard[a][b-2].getType().equals("")&&enemyBoard[a][b-3].getType().equals("")&&enemyBoard[a][b-4].getType().equals(""))
                                {
                                    for(int i=b; i>b-5; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Car");
                                    }
                                }
                                
                                else if(b<=5&&enemyBoard[a][b+1].getType().equals("")&&enemyBoard[a][b+2].getType().equals("")&&enemyBoard[a][b+3].getType().equals("")&&enemyBoard[a][b+4].getType().equals(""))
                                {
                                    for(int i=b; i<b+5; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Car");
                                    }
                                }
                                
                                else if(a<=5&&enemyBoard[a+1][b].getType().equals("")&&enemyBoard[a+2][b].getType().equals("")&&enemyBoard[a+3][b].getType().equals("")&&enemyBoard[a+4][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+5; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Car");
                                    }
                                }
                                else if (a>=4&&enemyBoard[a-1][b].getType().equals("")&&enemyBoard[a-2][b].getType().equals("")&&enemyBoard[a-3][b].getType().equals("")&&enemyBoard[a-4][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-5; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Car");
                                    }
                                }
                            }
                        
                            else if(c==3)
                            {
                                if(b<=5&&enemyBoard[a][b+1].getType().equals("")&&enemyBoard[a][b+2].getType().equals("")&&enemyBoard[a][b+3].getType().equals("")&&enemyBoard[a][b+4].getType().equals(""))
                                {
                                    for(int i=b; i>b+5; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Car");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i>b-5; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Car");
                                    }
                                }
                            }
                        }
                        carrierCheck++;
                    }
                }
            }
        }
    }
    //method used when mouse is pressed
    public void mousePressed(MouseEvent me)
    {
    }
    //method used when mouse is entered
    public void mouseEntered(MouseEvent me)
    {
    }
    //method used when mouse is exited
    public void mouseExited(MouseEvent me)
    {
    }
    //method used when mouse is released
    public void mouseReleased(MouseEvent me)
    {
    }
}

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Random;
/**
 *
 */
/**
 * @author wcorwin
 *
 */
public class Battleship extends JFrame implements MouseListener
{
    //Board of Tiles which shall be used to play the game
    private Tile[][] playerBoard = new Tile[10][10];
    private Tile[][] enemyBoard = new Tile[10][10];
    //JLabel used to exit the program...The Exit Button!-"When the X in the top right just isn't convenient enough!"
    JLabel exit= new JLabel();
    //integer to keep track of the columns of the board
    JLabel yourBoard = new JLabel();
    JLabel hisBoard = new JLabel();
    JLabel battleship = new JLabel();
    JLabel carrier = new JLabel();
    JLabel destroyer= new JLabel();
    JLabel submarine= new JLabel();
    JLabel minesweeper = new JLabel();
    int x=0;
    //integer to keep track of the rows of the board
    int y=0;
    //Later, I'm going to have to reference two different tiles. This will be Tile one's row
    int a=0;
    //Later, I'm going to have to reference two different tiles. This will be Tile one's row
    int b=0;
    int c=0;
    int battleshipCheck=0;
    int carrierCheck=0;
    int destroyerCheck =0;
    int submarineCheck=0;
    int minesweeperCheck=0;

    public Battleship()
    {
        //The content Pane- where everything was, is, and will be
        Container contentPane =getContentPane();
        //The layout is null because layout's don't apply for this program
        contentPane.setLayout(null);
        //The program has a height and width of 600
        setSize(800,600);
        //The location of the program is (1,1)
        setLocation(1,1);
        //The background of the program is white...even though it looks gray
        setBackground(Color.white);
        //The title is Battleship because that's the title of the program
        setTitle("Battleship");
        //The program stops when I exit the program for obvious reasons
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        
        JLabel yourBoard = new JLabel("Your board");
        //The bounds of the exit button. Near the bottom and out of the way
        yourBoard.setBounds(110,30,90,36);
        //The exit button's border is blue...don't judge me.
        yourBoard.setBorder(BorderFactory.createLineBorder(Color.blue));
        //The exit button has a Mouse Listener because in order to work, its need to be able to comprehend Mouse actions
        yourBoard.addMouseListener(this);
        //The text of the exit button is centered for a better look
        yourBoard.setHorizontalAlignment(JLabel.CENTER);
        //And the exit button is added to the content pane
        contentPane.add(yourBoard);
        
        JLabel hisBoard = new JLabel("Enemy Board");
        //The bounds of the exit button. Near the bottom and out of the way
        hisBoard.setBounds(610,30,90,36);
        //The exit button's border is blue...don't judge me.
        hisBoard.setBorder(BorderFactory.createLineBorder(Color.blue));
        //The exit button has a Mouse Listener because in order to work, its need to be able to comprehend Mouse actions
        hisBoard.addMouseListener(this);
        //The text of the exit button is centered for a better look
        hisBoard.setHorizontalAlignment(JLabel.CENTER);
        //And the exit button is added to the content pane
        contentPane.add(hisBoard);
        
        
        JLabel battleship = new JLabel("Battleship");
        battleship.setBounds(355, 100, 90, 30);
        battleship.setBorder(BorderFactory.createLineBorder(Color.green));
        battleship.addMouseListener(this);
        battleship.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(battleship);
        
        JLabel carrier = new JLabel("Carrier");
        carrier.setBounds(355, 140, 90, 30);
        carrier.setBorder(BorderFactory.createLineBorder(Color.green));
        carrier.addMouseListener(this);
        carrier.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(carrier);
        
        JLabel destroyer= new JLabel("Destroyer");
        destroyer.setBounds(355, 180, 90, 30);
        destroyer.setBorder(BorderFactory.createLineBorder(Color.green));
        destroyer.addMouseListener(this);
        destroyer.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(destroyer);
        
        JLabel submarine= new JLabel("Submarine");
        submarine.setBounds(355, 220, 90, 30);
        submarine.setBorder(BorderFactory.createLineBorder(Color.green));
        submarine.addMouseListener(this);
        submarine.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(submarine);
        
        JLabel minesweeper = new JLabel("Minesweeper");
        minesweeper.setBounds(355, 260, 90, 30);
        minesweeper.setBorder(BorderFactory.createLineBorder(Color.green));
        minesweeper.addMouseListener(this);
        minesweeper.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(minesweeper);
        
        //The double for loop where the board is created and given attributes. The first is for the columns...
        for(int x=0;x<10;x++)
        {
            //The second is for the rows
            for(int y=0;y<10;y++)
            {  
                //The board! Each is a thirty by thirty square
                playerBoard[x][y] = new Tile(30,30);
                //The location is fifty times the row, fifty times the column
                playerBoard[x][y].setLocation(30*x,100+30*y);
                //Yes the border on the board is blue. Because black is boring.
                playerBoard[x][y].setBorder(BorderFactory.createLineBorder(Color.blue));
                //The board can hear the mouse, thus allowing the game to be played
                playerBoard[x][y].addMouseListener(this);
                //Now the board knows that the column is its column!!!
                playerBoard[x][y].setColumn(x);
                //Now the board knows that the column is its column!!!
                playerBoard[x][y].setRow(y);
                //Now the text is centered
                playerBoard[x][y].setController("Player");
                playerBoard[x][y].setHorizontalAlignment(Tile.CENTER);
                //And the board is added to the contentPane
                contentPane.add(playerBoard[x][y]);

                //The board! Each is a thirty by thirty square
                enemyBoard[x][y] = new Tile(30,30);
                //The location is fifty times the row, fifty times the column
                enemyBoard[x][y].setLocation(500+30*x,100+30*y);
                //Yes the border on the board is blue. Because black is boring.
                enemyBoard[x][y].setBorder(BorderFactory.createLineBorder(Color.blue));
                //The board can hear the mouse, thus allowing the game to be played
                enemyBoard[x][y].addMouseListener(this);
                //Now the board knows that the column is its column!!!
                enemyBoard[x][y].setColumn(x);
                //Now the board knows that the column is its column!!!
                enemyBoard[x][y].setRow(y);
                //Now the text is centered
                enemyBoard[x][y].setController("Computer");
                enemyBoard[x][y].setHorizontalAlignment(Tile.CENTER);
                //And the board is added to the contentPane
                contentPane.add(enemyBoard[x][y]);
            }
        }
    }
    /**
     * @param args
     */
    public static void main(String[] args)
    {
        //frame of GUI
        Battleship frame= new Battleship();
        frame.setVisible(true);
    }
    
    public void mouseClicked(MouseEvent me)
    {
        if(me.getSource() instanceof Tile)
        {
            Tile clicked = (Tile) me.getSource();
            {
                if(clicked.getController().equals("Computer"))
                {
                    if(clicked.getType().equals("Ship"))
                    {
                        clicked.setText("HIT");
                    }
                    else
                    {
                        clicked.setText("MISS");
                    }

                }
            }
        }
        
        if(me.getSource() instanceof JLabel)
        {
            JLabel clicked = (JLabel) me.getSource();
            {
                if(clicked.getText().equals("Battleship")&&battleshipCheck==0)
                {
                    int width= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's width that you would like to place the battleship on?"));
                    int height= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's height that you would like to place the battleship on?"));
                    String direction = JOptionPane.showInputDialog(null, "Which direction would you like it to go? (Up, Down, Left, Right)");
                    
                    if(playerBoard[width][height].getText().equals(""))
                    {
                        if(playerBoard[width][height].getColumn()>2&&direction.equals("Left"))
                        {
                            if(playerBoard[width-1][height].getType().equals("Ship")||playerBoard[width-2][height].getType().equals("Ship")||playerBoard[width-3][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n> width-4; n--)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Bat");
                                        playerBoard[n][height].setType("Ship");
                                        battleshipCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getColumn()<7&&direction.equals("Right"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship")||playerBoard[width+2][height].getType().equals("Ship")||playerBoard[width+3][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n< width+4; n++)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Bat");
                                        playerBoard[n][height].setType("Ship");
                                        battleshipCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()>2&&direction.equals("Up"))
                        {
                            if(playerBoard[width][height-1].getType().equals("Ship")||playerBoard[width][height-2].getType().equals("Ship")||playerBoard[width][height-3].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n> height-4; n--)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Bat");
                                        playerBoard[width][n].setType("Ship");
                                        battleshipCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()<7&&direction.equals("Down"))
                        {
                            if(playerBoard[width][height+1].getType().equals("Ship")||playerBoard[width][height+2].getType().equals("Ship")||playerBoard[width][height+3].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n< height+4; n++)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Bat");
                                        playerBoard[width][n].setType("Ship");
                                        battleshipCheck=1;
                                    }
                                }
                            }
                        }
                    }
                }
                else if(clicked.getText().equals("Carrier")&&carrierCheck==0)
                {
                    int width= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's width that you would like to place the carrier on?"));
                    int height= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's height that you would like to place the carrier on?"));
                    String direction = JOptionPane.showInputDialog(null, "Which direction would you like it to go? (Up, Down, Left, Right)");
                    
                    if(playerBoard[width][height].getText().equals(""))
                    {
                        if(playerBoard[width][height].getColumn()>3&&direction.equals("Left"))
                        {
                            if(playerBoard[width-1][height].getType().equals("Ship")||playerBoard[width-2][height].getType().equals("Ship")||playerBoard[width-3][height].getType().equals("Ship")||playerBoard[width-4][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n> width-5; n--)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Car");
                                        playerBoard[n][height].setType("Ship");
                                        carrierCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getColumn()<6&&direction.equals("Right"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship")||playerBoard[width+2][height].getType().equals("Ship")||playerBoard[width+3][height].getType().equals("Ship")||playerBoard[width+4][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n< width+5; n++)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Car");
                                        playerBoard[n][height].setType("Ship");
                                        carrierCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()>3&&direction.equals("Up"))
                        {
                            if(playerBoard[width][height-1].getType().equals("Ship")||playerBoard[width][height-2].getType().equals("Ship")||playerBoard[width][height-3].getType().equals("Ship")||playerBoard[width][height-4].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n> height-5; n--)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Car");
                                        playerBoard[width][n].setType("Ship");
                                        carrierCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()<6&&direction.equals("Down"))
                        {
                            if(playerBoard[width][height+1].getType().equals("Ship")||playerBoard[width][height+2].getType().equals("Ship")||playerBoard[width][height+3].getType().equals("Ship")||playerBoard[width][height+4].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n< height+5; n++)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Car");
                                        playerBoard[width][n].setType("Ship");
                                        carrierCheck=1;
                                    }
                                }
                            }
                        }
                    }
                }
                else if(clicked.getText().equals("Destroyer")&&destroyerCheck==0)
                {
                    int width= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's width that you would like to place the destroyer on?"));
                    int height= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's height that you would like to place the destroyer on?"));
                    String direction = JOptionPane.showInputDialog(null, "Which direction would you like it to go? (Up, Down, Left, Right)");
                    
                    if(playerBoard[width][height].getText().equals(""))
                    {
                        if(playerBoard[width][height].getColumn()>1&&direction.equals("Left"))
                        {
                            if(playerBoard[width-1][height].getType().equals("Ship")||playerBoard[width-2][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n> width-3; n--)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Des");
                                        playerBoard[n][height].setType("Ship");
                                        destroyerCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getColumn()<8&&direction.equals("Right"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship")||playerBoard[width+2][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n< width+3; n++)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Des");
                                        playerBoard[n][height].setType("Ship");
                                        destroyerCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()>1&&direction.equals("Up"))
                        {
                            if(playerBoard[width][height-1].getType().equals("Ship")||playerBoard[width][height-2].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n> height-3; n--)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Des");
                                        playerBoard[width][n].setType("Ship");
                                        destroyerCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()<8&&direction.equals("Down"))
                        {
                            if(playerBoard[width][height+1].getType().equals("Ship")||playerBoard[width][height+1].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n< height+3; n++)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Des");
                                        playerBoard[width][n].setType("Ship");
                                        destroyerCheck=1;
                                    }
                                }
                            }
                        }
                    }
                }
                
                else if(clicked.getText().equals("Submarine")&&submarineCheck==0)
                {
                    int width= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's width that you would like to place the sub on?"));
                    int height= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's height that you would like to place the sub on?"));
                    String direction = JOptionPane.showInputDialog(null, "Which direction would you like it to go? (Up, Down, Left, Right)");
                    
                    if(playerBoard[width][height].getText().equals(""))
                    {
                        if(playerBoard[width][height].getColumn()>1&&direction.equals("Left"))
                        {
                            if(playerBoard[width-1][height].getType().equals("Ship")||playerBoard[width-2][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n> width-3; n--)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Sub");
                                        playerBoard[n][height].setType("Ship");
                                        submarineCheck=1;
                                    }
                                }
                            }
                        }
                        
                        else if(playerBoard[width][height].getColumn()<8&&direction.equals("Right"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship")||playerBoard[width+2][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n< width+3; n++)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Sub");
                                        playerBoard[n][height].setType("Ship");
                                        submarineCheck=1;
                                    }
                                }
                            }
                        }
                        
                        else if(playerBoard[width][height].getRow()>1&&direction.equals("Up"))
                        {
                            if(playerBoard[width][height-1].getType().equals("Ship")||playerBoard[width][height-2].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n> height-3; n--)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Sub");
                                        playerBoard[width][n].setType("Ship");
                                        submarineCheck=1;
                                    }
                                }
                            }
                        }
                        
                        else if(playerBoard[width][height].getRow()<8&&direction.equals("Down"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship")||playerBoard[width+2][height].getType().equals("Ship"))
                            {
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n< height+3; n++)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Sub");
                                        playerBoard[width][n].setType("Ship");
                                        submarineCheck=1;
                                    }
                                }
                            }
                        }
                    }
                }
                
                else if(clicked.getText().equals("Minesweeper")&&minesweeperCheck==0)
                {
                    int width= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's width that you would like to place the sweeper on?"));
                    int height= Integer.parseInt(JOptionPane.showInputDialog(null, "What is the piece's height that you would like to place the sweeper on?"));
                    String direction = JOptionPane.showInputDialog(null, "Which direction would you like it to go? (Up, Down, Left, Right)");
                    
                    if(playerBoard[width][height].getText().equals(""))
                    {
                        if(playerBoard[width][height].getColumn()>0&&direction.equals("Left"))
                        {
                            if(playerBoard[width-1][height].getType().equals("Ship"))
                            {    
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n> width-2; n--)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Min");
                                        playerBoard[n][height].setType("Ship");
                                        minesweeperCheck=1;
                                    }
                                }
                            }
                        }
                        
                        else if(playerBoard[width][height].getColumn()<9&&direction.equals("Right"))
                        {
                            if(playerBoard[width+1][height].getType().equals("Ship"))
                            {    
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=width; n< width+2; n++)
                                {
                                    if(playerBoard[n][height].getText().equals(""))
                                    {
                                        playerBoard[n][height].setText("Min");
                                        playerBoard[n][height].setType("Ship");
                                        minesweeperCheck=1;
                                    }
                                }
                            }
                        }
                        
                        else if(playerBoard[width][height].getRow()>0&&direction.equals("Up"))
                        {
                            if(playerBoard[width][height-1].getType().equals("Ship"))
                            {    
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n> height-2; n--)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Min");
                                        playerBoard[width][n].setType("Ship");
                                        minesweeperCheck=1;
                                    }
                                }
                            }
                        }
                        else if(playerBoard[width][height].getRow()<9&&direction.equals("Down"))
                        {
                            if(playerBoard[width][height+1].getType().equals("Ship"))
                            {    
                                JOptionPane.showMessageDialog(null, "I'm afraid I can't do that, Jim...");
                            }
                            else
                            {
                                for(int n=height; n< height+2; n++)
                                {
                                    if(playerBoard[width][n].getText().equals(""))
                                    {
                                        playerBoard[width][n].setText("Min");
                                        playerBoard[width][n].setType("Ship");
                                        minesweeperCheck=1;
                                    }
                                }
                            }
                        }
                    }
                }
                if(carrierCheck==1&&battleshipCheck==1&&destroyerCheck==1&&submarineCheck==1&&minesweeperCheck==1)
                {
                    carrierCheck=2;
                    battleshipCheck=2;
                    submarineCheck=2;
                    destroyerCheck=2;
                    minesweeperCheck=2;
                    
                    if(submarineCheck==2)
                    {
                        Random rand = new Random();
                        int a= rand.nextInt(10);
                        int b= rand.nextInt(10);
                        int c=rand.nextInt(4);
                        if(enemyBoard[a][b].getType().equals(""))
                        {
                            System.out.println(c);
                            enemyBoard[a][b].setType("Ship");
                            enemyBoard[a][b].setText("Sub");
                            if(c==0)
                            {
                                if(a>=2&&enemyBoard[a-1][b].getType().equals("")&&enemyBoard[a-2][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-3; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Sub");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i<a+3; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Sub");
                                    }
                                }
                            }
                            else if(c==1)
                            {
                                if(a<=7&&enemyBoard[a+1][b].getType().equals("")&&enemyBoard[a+2][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+3; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Sub");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i>a-3; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Sub");
                                    }
                                }
                            }
                        
                            else if(c==2)
                            {
                                
                                if(b>=2&&enemyBoard[a][b-1].getType().equals("")&&enemyBoard[a][b-2].getType().equals(""))
                                {
                                    for(int i=b; i>b-3; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Sub");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i<b+3; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Sub");
                                    }
                                }
                            }
                        
                            else if(c==3)
                            {
                                if(b<=7&&enemyBoard[a][b+1].getType().equals("")&&enemyBoard[a][b+2].getType().equals(""))
                                {
                                    for(int i=b; i>b+3; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Sub");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i>b-3; i--)
                                    {
                                        System.out.print("Working here?");
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Sub");
                                    }
                                }
                            }
                        }
                        submarineCheck++;
                    }
                    
                    if(minesweeperCheck==2)
                    {
                        Random rand = new Random();
                        int a= rand.nextInt(10);
                        int b= rand.nextInt(10);
                        int c=rand.nextInt(4);
                        if(enemyBoard[a][b].getType().equals(""))
                        {
                            System.out.println(c);
                            enemyBoard[a][b].setType("Ship");
                            enemyBoard[a][b].setText("Min");
                            if(c==0)
                            {
                                if(a>=1&&enemyBoard[a-1][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-2; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Min");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i<a+2; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Min");
                                    }
                                }
                            }
                            else if(c==1)
                            {
                                if(a<=8&&enemyBoard[a+1][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+2; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Min");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i>a-2; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Min");
                                    }
                                }
                            }
                        
                            else if(c==2)
                            {
                                
                                if(b>=1&&enemyBoard[a][b-1].getType().equals(""))
                                {
                                    for(int i=b; i>b-2; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Min");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i<b+2; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Min");
                                    }
                                }
                            }
                        
                            else if(c==3)
                            {
                                if(b<=8&&enemyBoard[a][b+1].getType().equals(""))
                                {
                                    for(int i=b; i>b+2; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Min");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i>b-2; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Min");
                                    }
                                }
                            }
                        }
                        minesweeperCheck++;
                    }
                    
                    if(destroyerCheck==2)
                    {
                        Random rand = new Random();
                        int a= rand.nextInt(10);
                        int b= rand.nextInt(10);
                        int c=rand.nextInt(4);
                        if(enemyBoard[a][b].getType().equals(""))
                        {
                            System.out.println(c);
                            enemyBoard[a][b].setType("Ship");
                            enemyBoard[a][b].setText("Des");
                            if(c==0)
                            {
                                if(a>=2&&enemyBoard[a-1][b].getType().equals("")&&enemyBoard[a-2][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-3; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Des");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i<a+3; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Des");
                                    }
                                }
                            }
                            else if(c==1)
                            {
                                if(a<=7&&enemyBoard[a+1][b].getType().equals("")&&enemyBoard[a+2][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+3; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Des");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i>a-3; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Des");
                                    }
                                }
                            }
                        
                            else if(c==2)
                            {
                                
                                if(b>=2&&enemyBoard[a][b-1].getType().equals("")&&enemyBoard[a][b-2].getType().equals(""))
                                {
                                    for(int i=b; i>b-3; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Des");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i<b+3; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Des");
                                    }
                                }
                            }
                        
                            else if(c==3)
                            {
                                if(b<=7&&enemyBoard[a][b+1].getType().equals("")&&enemyBoard[a][b+2].getType().equals(""))
                                {
                                    for(int i=b; i>b+3; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Des");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i>b-3; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Des");
                                    }
                                }
                            }
                        }
                        destroyerCheck++;
                    }
                    
                    if(battleshipCheck==2)
                    {
                        Random rand = new Random();
                        int a= rand.nextInt(10);
                        int b= rand.nextInt(10);
                        int c=rand.nextInt(4);
                        if(enemyBoard[a][b].getType().equals(""))
                        {
                            System.out.println(c);
                            enemyBoard[a][b].setType("Ship");
                            enemyBoard[a][b].setText("Bat");
                            if(c==0)
                            {
                                if(a>=3&&enemyBoard[a-1][b].getType().equals("")&&enemyBoard[a-2][b].getType().equals("")&&enemyBoard[a-3][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-4; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Bat");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i<a+4; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Bat");
                                    }
                                }
                            }
                            else if(c==1)
                            {
                                if(a<=6&&enemyBoard[a+1][b].getType().equals("")&&enemyBoard[a+2][b].getType().equals("")&&enemyBoard[a+3][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+4; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Bat");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i>a-4; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Bat");
                                    }
                                }
                            }
                        
                            else if(c==2)
                            {
                                
                                if(b>=3&&enemyBoard[a][b-1].getType().equals("")&&enemyBoard[a][b-2].getType().equals("")&&enemyBoard[a][b-3].getType().equals(""))
                                {
                                    for(int i=b; i>b-4; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Bat");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i<b+4; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Bat");
                                    }
                                }
                            }
                        
                            else if(c==3)
                            {
                                if(b<=6&&enemyBoard[a][b+1].getType().equals("")&&enemyBoard[a][b+2].getType().equals("")&&enemyBoard[a][b+3].getType().equals(""))
                                {
                                    for(int i=b; i>b+4; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Bat");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i>b-4; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Bat");
                                    }
                                }
                            }
                        }
                        battleshipCheck++;
                    }
                    
                    if(carrierCheck==2)
                    {
                        Random rand = new Random();
                        int a= rand.nextInt(10);
                        int b= rand.nextInt(10);
                        int c=rand.nextInt(4);
                        if(enemyBoard[a][b].getType().equals(""))
                        {
                            System.out.println(c);
                            enemyBoard[a][b].setType("Ship");
                            enemyBoard[a][b].setText("Car");
                            if(c==0)
                            {
                                if(a>=4&&enemyBoard[a-1][b].getType().equals("")&&enemyBoard[a-2][b].getType().equals("")&&enemyBoard[a-3][b].getType().equals("")&&enemyBoard[a-4][b].getType().equals(""))
                                {
                                    for(int i=a; i>a-5; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Car");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i<a+5; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Car");
                                    }
                                }
                            }
                            else if(c==1)
                            {
                                if(a<=5&&enemyBoard[a+1][b].getType().equals("")&&enemyBoard[a+2][b].getType().equals("")&&enemyBoard[a+3][b].getType().equals("")&&enemyBoard[a+4][b].getType().equals(""))
                                {
                                    for(int i=a; i<a+5; i++)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Car");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=a; i>a-5; i--)
                                    {
                                        enemyBoard[i][b].setType("Ship");
                                        enemyBoard[i][b].setText("Car");
                                    }
                                }
                            }
                        
                            else if(c==2)
                            {
                                
                                if(b>=4&&enemyBoard[a][b-1].getType().equals("")&&enemyBoard[a][b-2].getType().equals("")&&enemyBoard[a][b-3].getType().equals("")&&enemyBoard[a][b-4].getType().equals(""))
                                {
                                    for(int i=b; i>b-5; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Car");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i<b+5; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Car");
                                    }
                                }
                            }
                        
                            else if(c==3)
                            {
                                if(b<=5&&enemyBoard[a][b+1].getType().equals("")&&enemyBoard[a][b+2].getType().equals("")&&enemyBoard[a][b+3].getType().equals("")&&enemyBoard[a][b+4].getType().equals(""))
                                {
                                    for(int i=b; i>b+5; i++)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Car");
                                    }
                                }
                                
                                else
                                {
                                    for(int i=b; i>b-5; i--)
                                    {
                                        enemyBoard[a][i].setType("Ship");
                                        enemyBoard[a][i].setText("Car");
                                    }
                                }
                            }
                        }
                        carrierCheck++;
                    }
                }
            }
        }
    }
    //method used when mouse is pressed
    public void mousePressed(MouseEvent me)
    {
    }
    //method used when mouse is entered
    public void mouseEntered(MouseEvent me)
    {
    }
    //method used when mouse is exited
    public void mouseExited(MouseEvent me)
    {
    }
    //method used when mouse is released
    public void mouseReleased(MouseEvent me)
    {
    }
}

/**
 *
 */
import java.awt.Color;
import javax.swing.*;
/**
 * @author wcorwin
 *
 */
public class Tile extends JLabel
{   
    int height;
    int width;
    String type;
    String controller;
    boolean movable;
    int column=0;
    int row=0;
    /**
     *
     */
    public Tile()
    {
        // TODO Auto-generated constructor stub
        super();
        height=0;
        width=0;
        type="";
        controller="";
        column = 0;
        row=0;
    }
       
    public Tile(int x,int y)
    {
        super();
        height=x;
        width=y;
        setSize(height,width);
        type="";
        controller="";
        column=0;
        row=0;
    }
       
    public void setType(String n)
    {
        type=n;
    }
       
    public String getType()
    {
        return type;
    }
   
    public void setController(String n)
    {
        controller=n;
    }
       
    public String getController()
    {
        return controller;
    }
   
    public void setColumn(int n)
    {
        column=n;
    }
       
    public int getColumn()
    {
        return column;
    }
       
    public void setRow(int n)
    {
        row=n;
    }
       
    public int getRow()
    {
        return row;
    }   
    /*param args
     *
     */
}

/**
 *
 */
import javax.swing.*;
import java.util.Random;
import java.awt.*;
import java.awt.event.*;
/**
 * @author wcorwin
 *Minesweeper Version 1.0
 */
public class Minesweeper extends JFrame implements MouseListener
{
    int mines=10;
    int horiz=9;
    i