TeamJava Forum

[ Read Responses | Post a New Response | Return to the Index ]
[ Previous | Previous in Thread | Next ]


Connect Four or Four in a Row Help

Posted by David on Friday, 4 July 2003, at 6:49 p.m., in response to TEAM JAVA FORUM, posted by Management on Monday, 14 April 2003, at 10:19 a.m.

Hello,

I'm creating a school project, the game connect 4, or four in a row. I have everything done, except for where the program checks wether the

lines are 4 in a row or not. Can anyone help? Here's the code:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Projecto2 extends Applet implements ActionListener
{

Button botao;

boolean CanPlay = true;

Button [] [] tabela = new Button [8] [8] ;

//Button [] [] tabelaJogada = new Button [8] [8] ;

Label WhichPlayer = new Label("Please play player: X");

Label AvailableHouses = new Label("Available Houses: 63");

Label GiveSpace = new Label(" ");

int numPlay = 0;

int PlaysLeft = 63;

public void init()

{

botao = new Button ("Restart Game");

botao.addActionListener(this);

this.setLayout(new GridLayout(2,1));

Panel p1 = new Panel ();

p1.setLayout (new FlowLayout ());

p1.add (botao);

p1.add (GiveSpace);

p1.add (WhichPlayer);

p1.add (AvailableHouses);

Panel p2 = new Panel ();

p2.setLayout (new FlowLayout ());

Panel p3 = new Panel ();

p3.setLayout (new FlowLayout ());

for (int x = 0; x

{

for (int y = 0; y

{

tabela [x] [y] = new Button (x+" e "+y);

p2.add (tabela[x] [y]);

tabela [x] [y].addActionListener(this);

}

}

this.add (p1);

this.add (p2);

this.add (p3);

}

public void actionPerformed (ActionEvent ae)

{

for (int x = 0; x {

for (int y = 0; y {

if (ae.getSource() == tabela[x] [y] )

if (CanPlay)

{

if (numPlay%2 == 0)

{

tabela[x] [y].setLabel("X");

WhichPlayer.setText("Please play player: 0");

AvailableHouses.setText("Available Houses: "+PlaysLeft);

}

if (numPlay%2 != 0)

{

tabela[x] [y].setLabel("0");

WhichPlayer.setText("Please play player: X");

AvailableHouses.setText("Available Houses: "+PlaysLeft);

}

numPlay++;

PlaysLeft--;

}

}

if (PlaysLeft {

CanPlay = false;

WhichPlayer.setText("Game's Over!");

}

}

}

public void paint (Graphics g)

{

//Dimension tamanho = this.getSize();

setSize(750,600);

//g.drawLine(10, 10, tamanho.width-1, tamanho.height-1);

}
}

Sorry if I wasn't supposed to post this here, just need some help....

.: XonaDick :.


Responses


Post a New Response

Please select: Discussion Question Answer
Pulse Check - enter num: 1060047124

Your Name:

E-Mail Address:

Subject:

Message:


If you'd like to include a link to another page with your message,
please provide both the URL address and the title of the page:

Optional Link URL:

Optional Link Title:


If you'd like to have the option of deleting your post later,
please provide a password (CASE SENSITIVE!):

Password:



Password:

The TeamJava Forum is maintained with WebBBS 2.24.


TeamJavaHome | Ind. Registry | Co. Registry | Java Links
Jobs Listings Forum | TeamJava Books | Java FAQ Archives

AWN

Copyright © 1995-2003 Active Web Networks, all rights reserved.
(Note: We share no direct association with Sun Microsystems, Inc.)