import } //Referencing to the orignal board game

import java.util.Scanner;public class ConnectFour{  //The first signifcant thing we need to do is create the basic visual pattern   public static String createPattern()  {    // First we create a 2D array of 7 rows and 6 columns      String f = new String76;        //Time to loop over each row from up to down    for (int i =0;i=0;i–)    {      if (fic == ” “)      {        fic = “R”;        break;      }          }  }    //Now we repeat the same steps but in the colour yellow  public static void dropYellowPattern(String f)  {    System.out.println(“Drop a yellow disk at column (0–6): “);    Scanner scan = new Scanner (System.in);    int c = 2*scan.nextInt()+1;    for (int i =5;i>=0;i–)    {      if (fic == ” “)      {        fic = “Y”;        break;      }          }  }  //Here we attempt to code for each type of line and the various places where the line can be  public static String checkWinner(String f)  {      //Firstly we try looking for the first type of winning line, which is a horizontal line    //This line can be on any row, which is why we are going to loop over each row starting from 0 – 5    for (int i =0;i<6;i++)    {      //Since our Red, Yellow, and Empty columns can only be in odd places,      //because of how we created the pattern in the first      //method, our count has to be incremented by 2       //and will start from 0 (which will be 1, ----_ _)       //and stop at 6 (which will be 7, _ _----)      for (int j=0;j<7;j+=2)      {        if ((fij+1 != " ")        && (fij+3 != " ")        && (fij+5 != " ")        && (fij+7 != " ")        && ((fij+1 == fij+3)        && (fij+3 == fij+5)        && (fij+5 == fij+7)))        //If we found a same-colored pattern, we'll return         //the color so that we will know who won          return fij+1;        }    }        //For the vertical lines, we first loop over each odd-numbered column by incrementing with 2    //and check for consecutive boxes in the same column that are the same color     for (int i=1;i<15;i+=2)    {      //So our lines will look like ----__ just reversed      //and there is need to our rows by 2 but just one      //and we have to start at the vertical version of ----__ and       //and stop at _ _ ---- so it's from 0 to 2      for (int j =0;j<3;j++)      {            if((fji != " ")            && (fj+1i != " ")            && (fj+2i != " ")            && (fj+3i != " ")            && ((fji == fj+1i)            && (fj+1i == fj+2i)            && (fj+2i == fj+3i)))              return fji;        }      }        //For the left-up to right-down diagonal line wins    //We'll have to loop over the three uppermost    //rows and then go from left column to right     for (int i=0;i<3;i++)    {      {            if((fij != " ")            && (fi+1j+2 != " ")            && (fi+2j+4 != " ")            && (fi+3j+6 != " ")            && ((fij == fi+1j+2)            && (fi+1j+2 == fi+2j+4)            && (fi+2j+4 == fi+3j+6)))              return fij;        }      }        // Now we repeat the same thing however we start with the rightmost column    //instead of the leftmost like up there    for (int i=0;i<3;i++)    {      for (int j=7;j<15;j+=2)      {            if((fij != " ")            && (fi+1j-2 != " ")            && (fi+2j-4 != " ")            && (fi+3j-6 != " ")            && ((fij == fi+1j-2)            && (fi+1j-2 == fi+2j-4)            && (fi+2j-4 == fi+3j-6)))              return fij;        }      }        //If  we go over the table and find no    //same colored lines, we have to display that we have no data to return so we     return null;  }    public static void main (String args)  {     String f = createPattern();w    //Here we condition our game to keep on    //playing and track whose turn it is    boolean loop = true ;    int count = 0;    printPattern(f);    while(loop)    {             if (checkWinner(f) == "R")             System.out.println("The red player won.");          else if (checkWinner(f)== "Y")            System.out.println("The yello player won.");         loop = false;    }  }}

Author:

x

Hi!
I'm Eileen!

Would you like to get a custom essay? How about receiving a customized one?

Check it out