Hey Im sure everyone is familiar with the game connect four right? Well I am trying to make it in Java right now but I am stuck right now. Can anyone help me with this?

Here is the question straight from the book:
Connect four is a two player board game in which the players alternately drop colored disks into a seven column, six row vertically suspended grid. The objective of the game is to connect four same colored disks in a row, a column, or a diagonal before your opponent can do likewise. The program prompts two players to drop a red or yellow disk alternately. Whenever a disk is dropped, the program redisplays the board on the console and determines the status of the game (win, draw, or continue).

import java.util.Scanner;

public class ConnectFour 
{


	public static void main(String[] args) 
	{
		
		
		int[][] board = new int[6][7];
			
		
		int i = 0;
		int j = 0;
		
		board[i][j] = ' ';
		board[i][j] = 'R';
		board[i][j] = 'Y';
		
		

	}



public static void printboard() 
	{
	// Create Scanner
	Scanner input = new Scanner(System.in);
	
		// Create the board
		int[][] board = new int[6][7];
		for (int i = 0; i < 6; i++)
		{
			System.out.print("|");
			for (int j = 0; j < 7; j++)
			{
				board[i][j] = input.nextInt();
				System.out.print("|");
			}	
			
		}
	}
}

This cant be a gui, it has to only be in the java eclipse program.

Probably you don't want to make a new Scanner each time you print the board.That should go in your setup code, not in "printBoard"

For the rest, map out the game in high abstractions. What happens in the game?

Well, each player takes a turn until the game is over. Great! So if you write the code for "take a turn" and "is the game over" then you're set, right?

What does "take a turn" look like? Well, you get a move from a player and you put the piece in the right place. Neither of those sounds very hard.

What does "is the game over?" look like? Well, you've just dropped a piece into the board - does it take part in a row, column, or diagonal of four? If so, report a winner.


You'll probably want to break things down a few more steps, but that's the start of it.

Doing the take a turn and game over shouldnt be very hard to code, just use a boolean value right? But doing the part where you win by connecting four in a row, column, or diagonal is what gets me confused.

So just make a stub method for "is the game over" - return false for now, so you can have the method there, and you can get the other bits going. By the time you have the other bits, maybe you'll have an idea. It'll give you time to think about it, anyway.

Ok yea thank you for the help, hopefully I can get this done before tuesday bc that is when its due for class. Man it would be nice to understand Java lol

Yea but you sound like you know alot more about Java then I do. I bet you could probably write the code for this in like 30 mins lol

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