Hi, I'm currently in a the process of making a connect4 game, but what is highly frustrating is that im trying to write a loop that takes i from 0 up to the NUM_COLUMNS. and then make the new object called Connect4Column. When I compile and run this it gives me <identifier> errors and a return type error under the Connect4Model. I don't why this is. I've done much research into these errors and still I dont understan. If there are any way as to getting around this it would be much grateful

Kind Regards.

public class Connect4Column
{
    Connect4Column [] columns;
    private int NUM_COLUMNS; 
    private int NUM_ROWS;   
    private int playerToGoNext = Connect4Column.RED_COUNTER; 

    Connect4Model(int numCols, int numRows);  constructor
     {
        columns = new Connect4Column[NUM_COLUMNS]; // Loop

            for (int i = 0;i < NUM_COLUMNS;i++)
        {
            columns[i] = new Connect4Column(NUM_ROWS); //New object 
        }
    }
     int getNumCols() 
     {
         return 0;
     }

     int getNumRows()
     {
         return 0;
     }
     int getNextPlayer() 
     {
         return 0;
     }

     boolean go(int thisColumn)
     {
         return false;
     }
     int getCounter(thisColumn, thisRow)
     {
         return 0;
     }

     int getNumCounters(thisColumn) 
   {
               return 0;
    }
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Look at this:

Connect4Model(int numCols, int numRows); constructor
{

You have a semicolon after the parenthesis. It means that you ended the command there and the rest: {...} are not inside the constructor. Don't use ';' at the declarations of methods.

In methods like this: int getCounter(thisColumn, thisRow) you don't define the type of the parameters. May I suggest this: int getCounter(int thisColumn, int thisRow) Also don't call the same constructor inside its own constructor:

[B]Connect4Model[/B](int numCols, int numRows)
{

columns[i] = new [B]Connect4Column[/B](NUM_ROWS); //New object 

}

If you do that, the inside constructor will call the constructor which will again call the constructor inside it, which will again call the constructor inside it, which will again call the constructor inside it, ....

It would be better if inside a class you just create a 2D array of type int or String that represents the Connect4 values of the game:

class Connect4 {
  private char [][] array = null;

  public static final char EMPTY = ' ';

  public static final char RED = 'R';
  public static final char BLUE = 'U';
  // OR
  // public static final char P_1 = '1'; // player 1
  // public static final char p_2 = '2'; // player 2

  public Connect4(int rows, int columns) {
      array = new char[rows][columns];
     // loop the array to give it values.
     array[i][j] = EMPTY; // 
  }
}

Then have a method that loops the array to find if there are 4 consecutive occurrences of the characters R or U (variables RED, BLUE)

Edited 6 Years Ago by javaAddict: n/a

This article has been dead for over six months. Start a new discussion instead.