Advertisement
shadowsofme

SurroundGame

Feb 7th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.22 KB | None | 0 0
  1. package package1;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5. public class SurroundGame {
  6.     private int cellBoardRow = 10, cellBoardColumn = 10, players = 2, currentPlayer = 1, startingPlayer = 1;
  7.     private int player1Score = 0, player2Score = 0, player3Score = 0, player4Score = 0, player5Score = 0;
  8.     private int player6Score = 0, player7Score = 0, player8Score = 0, player9Score = 0, player10Score = 0;
  9.     private String status;
  10.     private String name1, name2, name3, name4, name5, name6, name7, name8, name9, name10;
  11.  
  12.     public Cell[][] cellBoard;
  13.  
  14.     public SurroundGame() {
  15.         // Asks the user for the number of rows that the cellBoard will have.
  16.         String string1 = JOptionPane.showInputDialog("How many rows should the cellBoard have?:"
  17.                 + "\n(NOTE: Non-numeric characters will be ignored)");
  18.  
  19.         // Removes any non-numeric values.
  20.         string1 = string1.replaceAll("[^0-9.]", "");
  21.  
  22.         // So long as an integer between 3 and 20 is entered, the cellBoard will have the number of rows entered.
  23.         // Otherwise, the number of rows is set to 10.
  24.         if (string1.equals("") == true || Integer.parseInt(string1) < 3 || Integer.parseInt(string1) > 20){
  25.             JOptionPane.showMessageDialog (
  26.                     null, "Please enter an integer between 3 and 20 for the number of rows.\nRows set to 10.",
  27.                     "Number Error",
  28.                     JOptionPane.ERROR_MESSAGE);
  29.             cellBoardRow = 10;
  30.         }else {
  31.             cellBoardRow = Integer.parseInt(string1);
  32.         }
  33.  
  34.         // Asks the user for the number of columns that the cellBoard will have.
  35.         String string2 = JOptionPane.showInputDialog("How many columns should the cellBoard have?:"
  36.                 + "\n(NOTE: Non-numeric characters will be ignored)");
  37.  
  38.         // Removes any non-numeric values.
  39.         string2 = string2.replaceAll("[^0-9.]", "");
  40.  
  41.         // So long as an integer between 3 and 20 is entered, the cellBoard will have the number of columns entered.
  42.         // Otherwise, the number of columns is set to 10.
  43.         if (string2.equals("") == true || Integer.parseInt(string2) < 3 || Integer.parseInt(string2) > 20){
  44.             JOptionPane.showMessageDialog (
  45.                     null, "Please enter an integer between 3 and 20 for the number of columns.\nColumns set to 10.",
  46.                     "Number Error",
  47.                     JOptionPane.ERROR_MESSAGE);
  48.             cellBoardColumn = 10;
  49.         }else {
  50.             cellBoardColumn = Integer.parseInt(string2);
  51.         }
  52.  
  53.         cellBoard = new Cell[cellBoardRow][cellBoardColumn];
  54.         for (int row = 0; row < cellBoardRow; row++){
  55.             for(int col = 0; col < cellBoardColumn; col++){
  56.                 cellBoard[row][col] = new Cell(null, null);
  57.             }
  58.         }
  59.  
  60.         // Asks the user for the number of players that will play.
  61.         String string3 = JOptionPane.showInputDialog("How many players?:"
  62.                 + "\n(NOTE: Non-numeric characters will be ignored)");
  63.  
  64.         // Removes any non-numeric values.
  65.         string3 = string3.replaceAll("[^0-9.]", "");
  66.  
  67.         // So long as the user entered an integer above 2, the game will set the entered value to the number of players.
  68.         // Otherwise, the game is set to play with two players.
  69.         if (string3.equals("") == true || Integer.parseInt(string3) < 2 || Integer.parseInt(string3) > 10){
  70.             JOptionPane.showMessageDialog (
  71.                     null, "Please enter an integer between 2 and 10 for the number of players.\nPlayers set to 2.",
  72.                     "Number Error",
  73.                     JOptionPane.ERROR_MESSAGE);
  74.             players = 2;
  75.         }else {
  76.             players = Integer.parseInt(string3);
  77.         }
  78.  
  79.  
  80.  
  81.         // Asks the user which player will begin the match.
  82.         String string4 = JOptionPane.showInputDialog("Which player will begin the match?:"
  83.                 + "\n(NOTE: Non-numeric characters will be ignored)");
  84.  
  85.         // Removes any non-numeric values.
  86.         string4 = string4.replaceAll("[^0-9.]", "");
  87.  
  88.         // So long as the user entered an int above zero and less than or equal to the set number of players, the
  89.         // game will have the player who was selected go first. Otherwise, player #1 goes first.
  90.         if (string4.equals("") == true || Integer.parseInt(string4) <= 0 || Integer.parseInt(string4) > players){
  91.             JOptionPane.showMessageDialog (
  92.                     null, "Please enter a valid player number for who will begin.\nPlayer 1 will begin.",
  93.                     "Number Error",
  94.                     JOptionPane.ERROR_MESSAGE);
  95.             currentPlayer = 1;
  96.             startingPlayer = 1;
  97.         }else {
  98.             currentPlayer = Integer.parseInt(string4);
  99.             startingPlayer = Integer.parseInt(string4);
  100.         }
  101.  
  102.         setNames();
  103.  
  104.         setMessage();
  105.     }
  106.  
  107.     public void setNames(){
  108.         int nameDialog1  = JOptionPane.showConfirmDialog(null, "Will Player 1 create a "
  109.                 + "custom name?","Name Select", JOptionPane.YES_NO_OPTION);
  110.         if (nameDialog1  == JOptionPane.YES_OPTION){
  111.             String nameInput1 = JOptionPane.showInputDialog("Player 1: what is your name?");
  112.             if (nameInput1.equals("") == true){
  113.                 JOptionPane.showMessageDialog (
  114.                         null, "Nothing entered. Player name set to player number.",
  115.                         "Name Error",
  116.                         JOptionPane.ERROR_MESSAGE);
  117.                 nameInput1 = "Player #1";
  118.                 name1 = nameInput1;
  119.             }else {
  120.                 name1 = nameInput1;
  121.             }
  122.         }else {
  123.             name1 = "Player #1";
  124.         }
  125.         int nameDialog2  = JOptionPane.showConfirmDialog(null, "Will Player 2 create a "
  126.                 + "custom name?","Name Select", JOptionPane.YES_NO_OPTION);
  127.         if (nameDialog2  == JOptionPane.YES_OPTION){
  128.             String nameInput2 = JOptionPane.showInputDialog("Player 2: what is your name?");
  129.             if (nameInput2.equals("") == true){
  130.                 JOptionPane.showMessageDialog (
  131.                         null, "Nothing entered. Player name set to player number.",
  132.                         "Name Error",
  133.                         JOptionPane.ERROR_MESSAGE);
  134.                 nameInput2 = "Player #2";
  135.                 name2 = nameInput2;
  136.             }else {
  137.                 name2 = nameInput2;
  138.             }
  139.         }else {
  140.             name2 = "Player #2";
  141.         }
  142.         if (players >= 3){
  143.             int nameDialog3  = JOptionPane.showConfirmDialog(null, "Will Player 3 create a "
  144.                     + "custom name?","Name Select", JOptionPane.YES_NO_OPTION);
  145.             if (nameDialog3  == JOptionPane.YES_OPTION){
  146.                 String nameInput3 = JOptionPane.showInputDialog("Player 3: what is your name?");
  147.                 if (nameInput3.equals("") == true){
  148.                     JOptionPane.showMessageDialog (
  149.                             null, "Nothing entered. Player name set to player number.",
  150.                             "Name Error",
  151.                             JOptionPane.ERROR_MESSAGE);
  152.                     nameInput3 = "Player #3";
  153.                     name3 = nameInput3;
  154.                 }else {
  155.                     name3 = nameInput3;
  156.                 }
  157.             }else {
  158.                 name3 = "Player #3";
  159.             }
  160.         }
  161.         if (players >= 4){
  162.             int nameDialog4  = JOptionPane.showConfirmDialog(null, "Will Player 4 create a "
  163.                     + "custom name?","Name Select", JOptionPane.YES_NO_OPTION);
  164.             if (nameDialog4  == JOptionPane.YES_OPTION){
  165.                 String nameInput4 = JOptionPane.showInputDialog("Player 4: what is your name?");
  166.                 if (nameInput4.equals("") == true){
  167.                     JOptionPane.showMessageDialog (
  168.                             null, "Nothing entered. Player name set to player number.",
  169.                             "Name Error",
  170.                             JOptionPane.ERROR_MESSAGE);
  171.                     nameInput4 = "Player #4";
  172.                     name4 = nameInput4;
  173.                 }else {
  174.                     name4 = nameInput4;
  175.                 }
  176.             }else {
  177.                 name4 = "Player #4";
  178.             }
  179.         }
  180.         if (players >= 5){
  181.             int nameDialog5  = JOptionPane.showConfirmDialog(null, "Will Player 5 create a "
  182.                     + "custom name?","Name Select", JOptionPane.YES_NO_OPTION);
  183.             if (nameDialog5  == JOptionPane.YES_OPTION){
  184.                 String nameInput5 = JOptionPane.showInputDialog("Player 5: what is your name?");
  185.                 if (nameInput5.equals("") == true){
  186.                     JOptionPane.showMessageDialog (
  187.                             null, "Nothing entered. Player name set to player number.",
  188.                             "Name Error",
  189.                             JOptionPane.ERROR_MESSAGE);
  190.                     nameInput5 = "Player #5";
  191.                     name5 = nameInput5;
  192.                 }else {
  193.                     name5 = nameInput5;
  194.                 }
  195.             }else {
  196.                 name5 = "Player #5";
  197.             }
  198.         }
  199.         if (players >= 6){
  200.             int nameDialog6  = JOptionPane.showConfirmDialog(null, "Will Player 6 create a "
  201.                     + "custom name?","Name Select", JOptionPane.YES_NO_OPTION);
  202.             if (nameDialog6  == JOptionPane.YES_OPTION){
  203.                 String nameInput6 = JOptionPane.showInputDialog("Player 6: what is your name?");
  204.                 if (nameInput6.equals("") == true){
  205.                     JOptionPane.showMessageDialog (
  206.                             null, "Nothing entered. Player name set to player number.",
  207.                             "Name Error",
  208.                             JOptionPane.ERROR_MESSAGE);
  209.                     nameInput6 = "Player #6";
  210.                     name6 = nameInput6;
  211.                 }else {
  212.                     name6 = nameInput6;
  213.                 }
  214.             }else {
  215.                 name6 = "Player #6";
  216.             }
  217.         }
  218.         if (players >= 7){
  219.             int nameDialog7  = JOptionPane.showConfirmDialog(null, "Will Player 7 create a "
  220.                     + "custom name?","Name Select", JOptionPane.YES_NO_OPTION);
  221.             if (nameDialog7  == JOptionPane.YES_OPTION){
  222.                 String nameInput7 = JOptionPane.showInputDialog("Player 7: what is your name?");
  223.                 if (nameInput7.equals("") == true){
  224.                     JOptionPane.showMessageDialog (
  225.                             null, "Nothing entered. Player name set to player number.",
  226.                             "Name Error",
  227.                             JOptionPane.ERROR_MESSAGE);
  228.                     nameInput7 = "Player #7";
  229.                     name7 = nameInput7;
  230.                 }else {
  231.                     name7 = nameInput7;
  232.                 }
  233.             }else {
  234.                 name7 = "Player #7";
  235.             }
  236.         }
  237.         if (players >= 8){
  238.             int nameDialog8  = JOptionPane.showConfirmDialog(null, "Will Player 8 create a "
  239.                     + "custom name?","Name Select", JOptionPane.YES_NO_OPTION);
  240.             if (nameDialog8  == JOptionPane.YES_OPTION){
  241.                 String nameInput8 = JOptionPane.showInputDialog("Player 8: what is your name?");
  242.                 if (nameInput8.equals("") == true){
  243.                     JOptionPane.showMessageDialog (
  244.                             null, "Nothing entered. Player name set to player number.",
  245.                             "Name Error",
  246.                             JOptionPane.ERROR_MESSAGE);
  247.                     nameInput8 = "Player #8";
  248.                     name8 = nameInput8;
  249.                 }else {
  250.                     name8 = nameInput8;
  251.                 }
  252.             }else {
  253.                 name8 = "Player #8";
  254.             }
  255.         }
  256.         if (players >= 9){
  257.             int nameDialog9  = JOptionPane.showConfirmDialog(null, "Will Player 9 create a "
  258.                     + "custom name?","Name Select", JOptionPane.YES_NO_OPTION);
  259.             if (nameDialog9  == JOptionPane.YES_OPTION){
  260.                 String nameInput9 = JOptionPane.showInputDialog("Player 9: what is your name?");
  261.                 if (nameInput9.equals("") == true){
  262.                     JOptionPane.showMessageDialog (
  263.                             null, "Nothing entered. Player name set to player number.",
  264.                             "Name Error",
  265.                             JOptionPane.ERROR_MESSAGE);
  266.                     nameInput9 = "Player #9";
  267.                     name9 = nameInput9;
  268.                 }else {
  269.                     name9 = nameInput9;
  270.                 }
  271.             }else {
  272.                 name9 = "Player #9";
  273.             }
  274.         }
  275.         if (players >= 10){
  276.             int nameDialog10  = JOptionPane.showConfirmDialog(null, "Will Player 10 create a "
  277.                     + "custom name?","Name Select", JOptionPane.YES_NO_OPTION);
  278.             if (nameDialog10  == JOptionPane.YES_OPTION){
  279.                 String nameInput10 = JOptionPane.showInputDialog("Player 10: what is your name?");
  280.                 if (nameInput10.equals("") == true){
  281.                     JOptionPane.showMessageDialog (
  282.                             null, "Nothing entered. Player name set to player number.",
  283.                             "Name Error",
  284.                             JOptionPane.ERROR_MESSAGE);
  285.                     nameInput10 = "Player #10";
  286.                     name10 = nameInput10;
  287.                 }else {
  288.                     name10 = nameInput10;
  289.                 }
  290.             }else {
  291.                 name10 = "Player #10";
  292.             }
  293.         }
  294.     }
  295.  
  296.     public int getRows(){
  297.         return cellBoardRow;
  298.     }
  299.  
  300.     public int getCol(){
  301.         return cellBoardColumn;
  302.     }
  303.  
  304.     public int getPlayers(){
  305.         return players;
  306.     }  
  307.  
  308.     public int currentPlayer(){
  309.         return currentPlayer;
  310.     }
  311.  
  312.     public String getCurrentPlayerName(){
  313.         if (currentPlayer == 1){
  314.             return name1;
  315.         }else if (currentPlayer == 2){
  316.             return name2;
  317.         }else if (currentPlayer == 3){
  318.             return name3;
  319.         }else if (currentPlayer == 4){
  320.             return name4;
  321.         }else if (currentPlayer == 5){
  322.             return name5;
  323.         }else if (currentPlayer == 6){
  324.             return name6;
  325.         }else if (currentPlayer == 7){
  326.             return name7;
  327.         }else if (currentPlayer == 8){
  328.             return name8;
  329.         }else if (currentPlayer == 9){
  330.             return name9;
  331.         }else{
  332.             return name10;
  333.         }
  334.     }
  335.  
  336.     public int getStartPlayer(){
  337.         return startingPlayer;
  338.     }
  339.  
  340.     public int setStartPlayer(int plyr){
  341.         startingPlayer = plyr;
  342.         return startingPlayer;
  343.     }
  344.  
  345.     public String getMessage(){
  346.         return status;
  347.     }
  348.  
  349.     public String setMessage(){
  350.         status = "Victories: " + name1 + ": " + player1Score + " " + name2 + ": " + player2Score + "   ";
  351.         if (players >= 3){
  352.             status = status  + name3 + ": " + player3Score + "   ";
  353.         }
  354.         if (players >= 4){
  355.             status = status + name4 + ": " + player4Score + "   ";
  356.         }
  357.         if (players >= 5){
  358.             status = status + name5 + ": " + player5Score + "   ";
  359.         }
  360.         if (players >= 6){
  361.             status = status + name6 + ": " + player6Score + "   ";
  362.         }
  363.         if (players >= 7){
  364.             status = status + name7 + ": " + player7Score + "   ";
  365.         }
  366.         if (players >= 8){
  367.             status = status + name8 + ": " + player8Score + "   ";
  368.         }
  369.         if (players >= 9){
  370.             status = status + name9 + ": " + player9Score + "   ";
  371.         }
  372.         if (players >= 10){
  373.             status = status + name10 + ": " + player10Score + "   ";
  374.         }
  375.         return status;
  376.     }
  377.  
  378.     public int addToScore(int winner){
  379.         if (winner == 1){
  380.             player1Score++;
  381.         }
  382.         if (winner == 2){
  383.             player2Score++;
  384.         }
  385.         if (winner == 3){
  386.             player3Score++;
  387.         }
  388.         if (winner == 4){
  389.             player4Score++;
  390.         }
  391.         if (winner == 5){
  392.             player5Score++;
  393.         }
  394.         if (winner == 6){
  395.             player6Score++;
  396.         }
  397.         if (winner == 7){
  398.             player7Score++;
  399.         }
  400.         if (winner == 8){
  401.             player8Score++;
  402.         }
  403.         if (winner == 9){
  404.             player9Score++;
  405.         }
  406.         if (winner == 10){
  407.             player10Score++;
  408.         }
  409.         return winner;
  410.     }
  411.  
  412.     public Cell getCell(int row, int col){
  413.         Cell c =  cellBoard[row][col];
  414.         return c;
  415.     }
  416.  
  417.     public void nextPlayer(){
  418.         if (currentPlayer == players){
  419.             currentPlayer = 1;
  420.         }else {
  421.             currentPlayer++;
  422.         }
  423.     }
  424.  
  425.     public int setPlayer(int plyr){
  426.         currentPlayer = plyr;
  427.         return currentPlayer;
  428.     }
  429.  
  430.     public Boolean select (int row, int col){
  431.         Integer buttonNum = cellBoard[row][col].getPlayerNumber();
  432.  
  433.         if (buttonNum != null){
  434.             return false;
  435.         }else {
  436.             return true;
  437.         }
  438.  
  439.     }
  440.  
  441.     public Boolean catsCheck(){
  442.         for (int row=0; row< getRows(); row++){ //beginning of first chunk of code given to us
  443.             for(int col=0; col< getCol(); col++){
  444.                 if (cellBoard[row][col].getPlayerNumber() == null){
  445.                     return false;
  446.                 }
  447.             }
  448.         }
  449.         return true;
  450.     }
  451.    
  452.     public void reset() {
  453.         for(int row = 0; row < getRows(); row++){
  454.             for(int col= 0; col < getCol(); col++){
  455.                 cellBoard[row][col] = new Cell(null, null);
  456.             }
  457.         }
  458.     }
  459.  
  460.  
  461.     public int isWinner() {
  462.         int endResult = -1;
  463.         int rowConstant = (getRows() - 1);
  464.         int colConstant = (getCol() - 1);
  465.  
  466.         if (catsCheck() == true){
  467.             endResult = 0;
  468.             return endResult;
  469.         }
  470.        
  471.         for (int row=0; row< getRows(); row++){ //beginning of first chunk of code given to us
  472.             for(int col=0; col< getCol(); col++){
  473.                 if (row == 0 && col == 0){      // Top-Left corner case (check 2 sides).
  474.                     if (cellBoard[row][col+1].getPlayerNumber() == cellBoard[row+1][col].getPlayerNumber()){        // Checks to see if numbers are the same.
  475.                         if (cellBoard[row][col].getPlayerNumber() != cellBoard[row][col+1].getPlayerNumber()){      // Makes sure you are not surrounding yourself.
  476.                             if (cellBoard[row+1][col].getPlayerNumber() != null){       // Makes sure the squares next to you aren't null.
  477.                                 endResult =  cellBoard[row][col+1].getPlayerNumber();       // Get the winner player.
  478.                             }
  479.                         }
  480.                     }
  481.                 }else if (row == 0 && col == colConstant){      // Top-Right corner case (check 2 sides).
  482.                     if (cellBoard[row][col-1].getPlayerNumber() == cellBoard[row+1][col].getPlayerNumber()){        // Checks to see if numbers are the same.
  483.                         if (cellBoard[row][col].getPlayerNumber() != cellBoard[row][col-1].getPlayerNumber()){      // Makes sure you are not surrounding yourself.
  484.                             if (cellBoard[row+1][col].getPlayerNumber() != null){       // Makes sure the squares next to you aren't null.
  485.                                 endResult = cellBoard[row][col-1].getPlayerNumber();        // Get the winner player.
  486.                             }
  487.                         }
  488.                     }
  489.                 }else if (row == rowConstant && col == 0){      // Bottom-Left corner case (check 2 sides).
  490.                     if (cellBoard[row-1][col].getPlayerNumber() == cellBoard[row][col+1].getPlayerNumber()){        // Checks to see if numbers are the same.
  491.                         if (cellBoard[row][col].getPlayerNumber() != cellBoard[row][col+1].getPlayerNumber()){      // Makes sure you are not surrounding yourself.
  492.                             if (cellBoard[row-1][col].getPlayerNumber() != null){       // Makes sure the squares next to you aren't null.
  493.                                 endResult = cellBoard[row-1][col].getPlayerNumber();        // Get the winner player.
  494.                             }
  495.                         }
  496.                     }
  497.                 }else if (row == rowConstant && col == colConstant){        // Bottom-Right corner case (check 2 sides).
  498.                     if (cellBoard[row-1][col].getPlayerNumber() == cellBoard[row][col-1].getPlayerNumber()){        // Checks to see if numbers are the same.
  499.                         if (cellBoard[row][col].getPlayerNumber() != cellBoard[row][col-1].getPlayerNumber()){      // Makes sure you are not surrounding yourself.
  500.                             if (cellBoard[row-1][col].getPlayerNumber() != null){       // Makes sure the squares next to you aren't null.
  501.                                 endResult = cellBoard[row-1][col].getPlayerNumber();        // Get the winner player.
  502.                             }
  503.                         }
  504.                     }
  505.                 }else if (row == 0 && col != colConstant && col != 0){      // Top wall case (check 3 sides).
  506.                     if (cellBoard[row+1][col].getPlayerNumber() == cellBoard[row][col-1].getPlayerNumber()){        // Checks to see if numbers are the same.
  507.                         if (cellBoard[row+1][col].getPlayerNumber() == cellBoard[row][col+1].getPlayerNumber()){
  508.                             if (cellBoard[row][col].getPlayerNumber() != cellBoard[row][col+1].getPlayerNumber()){      // Makes sure you are not surrounding yourself.
  509.                                 if (cellBoard[row+1][col].getPlayerNumber() != null){       // Makes sure the squares next to you aren't null.
  510.                                     endResult = cellBoard[row-1][col].getPlayerNumber();        // Get the winner player.
  511.                                 }
  512.                             }
  513.                         }
  514.                     }
  515.                 }else if (row == rowConstant && col != colConstant && col != 0){        // Bottom wall case (check 3 sides).
  516.                     if (cellBoard[row-1][col].getPlayerNumber() == cellBoard[row][col+1].getPlayerNumber()){        // Checks to see if numbers are the same.
  517.                         if (cellBoard[row-1][col].getPlayerNumber() == cellBoard[row][col-1].getPlayerNumber()){       
  518.                             if (cellBoard[row][col].getPlayerNumber() != cellBoard[row][col+1].getPlayerNumber()){      // Makes sure you are not surrounding yourself.
  519.                                 if (cellBoard[row-1][col].getPlayerNumber() != null){       // Makes sure the squares next to you aren't null.
  520.                                     endResult = cellBoard[row+1][col].getPlayerNumber();        // Get the winner player.
  521.                                 }
  522.                             }
  523.                         }
  524.                     }
  525.                 }else if (col == colConstant && row != rowConstant && row != 0){        // Right wall case (check 3 sides).
  526.                     if (cellBoard[row+1][col].getPlayerNumber() == cellBoard[row-1][col].getPlayerNumber()){        // Checks to see if numbers are the same.
  527.                         if (cellBoard[row+1][col].getPlayerNumber() == cellBoard[row][col-1].getPlayerNumber()){       
  528.                             if (cellBoard[row][col].getPlayerNumber() != cellBoard[row][col-1].getPlayerNumber()){      // Makes sure you are not surrounding yourself.
  529.                                 if (cellBoard[row-1][col].getPlayerNumber() != null){       // Makes sure the squares next to you aren't null.
  530.                                     endResult = cellBoard[row][col-1].getPlayerNumber();        // Get the winner player.
  531.                                 }
  532.                             }
  533.                         }
  534.                     }
  535.                 }else if (col == 0 && row != rowConstant && row != 0){      // Left wall case (check 3 sides).
  536.                     if (cellBoard[row+1][col].getPlayerNumber() == cellBoard[row-1][col].getPlayerNumber()){        // Checks to see if numbers are the same.
  537.                         if (cellBoard[row+1][col].getPlayerNumber() == cellBoard[row][col+1].getPlayerNumber()){       
  538.                             if (cellBoard[row][col].getPlayerNumber() != cellBoard[row][col+1].getPlayerNumber()){      // Makes sure you are not surrounding yourself.
  539.                                 if (cellBoard[row-1][col].getPlayerNumber() != null){       // Makes sure the squares next to you aren't null.
  540.                                     endResult = cellBoard[row][col+1].getPlayerNumber();        // Get the winner player.
  541.                                 }
  542.                             }
  543.                         }
  544.                     }
  545.                 }else if (cellBoard[row+1][col].getPlayerNumber() == cellBoard[row-1][col].getPlayerNumber()){      // Checks to see if numbers are the same.
  546.                     if (cellBoard[row+1][col].getPlayerNumber() == cellBoard[row][col+1].getPlayerNumber()){
  547.                         if (cellBoard[row+1][col].getPlayerNumber() == cellBoard[row][col-1].getPlayerNumber()){       
  548.                             if (cellBoard[row][col].getPlayerNumber() != cellBoard[row][col+1].getPlayerNumber()){      // Makes sure you are not surrounding yourself.
  549.                                 if (cellBoard[row-1][col].getPlayerNumber() != null){       // Makes sure the squares next to you aren't null.
  550.                                     endResult = cellBoard[row][col+1].getPlayerNumber();        // Get the winner player.
  551.                                 }
  552.                             }
  553.                         }
  554.                     }
  555.                 }
  556.             }
  557.         }
  558.         return endResult;
  559.     }
  560. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement