Results 1 to 4 of 4

Thread: Connect Four

  1. #1
    chick is offline Member
    Join Date
    Mar 2010
    Rep Power

    Default Connect Four

    i am creating a code to make the grid and play the game Connect Four, I am stuck on a few elements and was wondering if anyone had any advice

    Java Code:
    import java.awt.*;
    import java.util.*;
     * Class that holds the different items to play Connect Four
     * @
    public class ConnectFour 
      private int [][] grid;
      private Referee ref;
      private Picture display;
      private static final Color [] CHECKER_COLORS = {Color.GRAY, Color.RED, Color.BLACK};
     public ConnectFour (); /// this method that will initalize the grid, Referee ,and display
      public void board(); // method to start creating the board
     graphics.setColor(Color.yellow); // sets the paint color to yellow
     graphics.fillRect(0,200,700,600); // fill the rectangle in with yellow
     graphics.setColor(Color.gray); // sets the paint color back to gray
     graphics.setColor(; //sets the paint color back to black 
        // create the grid
        grid = new int[7][6];
        // initialize the grid
        for (int row=0; row<6; row++) {
         for (int column=0; column<7; column++) {
          // set the position to a default value
          grid[column][row] = 0;
      public void updateDisplay() // this method updates the display picture (from the grid) and repaints it
      public void dropChecker(int column, int player) // this method should drop a checker for player player in column column
        Scanner sc = new Scanner(;
        System.out.println("What Column Would You Like: ");
        int column = sc.nextColumn();
      public int findWinner() // this method will simply ask the referee to find the winner. it will return winner, draw, or not finished call referee
      return Winner();
      public void opponentMove() // this method will carry out an opponent move. opponent should choose a column at random and drop a checker at that column
        Random randNumGen = new Random();
        double num = randNumGen.nextDouble();
        int steps = randNumGen.nextInt(8);
    } ///end of Connect Four method
    the elements required are listed but incomplete. and I have a seperate main method to play this method..
    thanks in advance for any advice

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

  3. #3
    chick is offline Member
    Join Date
    Mar 2010
    Rep Power


    I am unsure on how to check and see what my grid looks like, so I know what I have to do still, and I am also unsure of how to go about making a drop Checker method, I have some ideas but none of them really come together to make sense. I have been also researching, how to reference another method, like I am trying to reference a code called in order to check for a winner.

  4. #4
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Rep Power


    None of your code compiles, and I'm not sure if it is because you haven't posted all of it, or if the code is truly borked, or if it's a combination of both.

    First of all you need to fix any compilation problems if you have any, one at a time, using the error messages as a guide. Then come on back if any are unfixable (show the code and the message).

Similar Threads

  1. Connect to SQL Server
    By ddatta8 in forum JDBC
    Replies: 2
    Last Post: 03-08-2010, 04:28 PM
  2. Connect 4
    By pansylea in forum New To Java
    Replies: 0
    Last Post: 12-11-2009, 03:36 PM
  3. connect to ftp
    By anki.gulsvart in forum Networking
    Replies: 21
    Last Post: 10-20-2009, 08:19 PM
  4. how to connect with my GUI
    By doha786 in forum New To Java
    Replies: 2
    Last Post: 04-01-2009, 04:59 PM
  5. how connect
    By herfnai in forum JDBC
    Replies: 1
    Last Post: 08-18-2008, 06:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts