Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 SOMEONE PLEASE HELP MEEE gr 12 java
Index -> General Discussion
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kevin




PostPosted: Thu May 28, 2009 6:15 pm   Post subject: SOMEONE PLEASE HELP MEEE gr 12 java

my program is the game of othello. i need help its due tmrw im rushing it last minute. i know its wrong. but i need help. basically the method is suppost to check if the block above it is the oposite color and if it is check if the one above it is the same color as urs.
i know its a poor explanation but the problem is in the "Checkvalid" method.
Sponsor
Sponsor
Sponsor
sponsor
Kevin




PostPosted: Thu May 28, 2009 6:16 pm   Post subject: Re: SOMEONE PLEASE HELP MEEE gr 12 java

Heres the code:


// The "GameBoard" class.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class GameBoard extends Applet implements ActionListener
{

int board[] [] = new int [10] [10];
JFrame gameFrame;
JPanel center;
JButton button[] [] = new JButton [8] [8];
boolean checkValid;

public GameBoard ()
{
checkValid = false;
for (int r = 0 ; r < 10 ; r++)
{
for (int c = 0 ; c < 10 ; c++)
{
board [r] [c] = 0;
}
}
board [4] [4] = 1; // white
board [4] [5] = 2; // black
board [5] [5] = 1;
board [5] [4] = 2;
gameFrame = new JFrame ("OTHELLO");
gameFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

center = new JPanel ();
center.setBackground (Color.BLACK);
center.setLayout (new GridLayout (0, 8, 1, 1));

////////////////////////////////////////////////////////////

button [0] [0] = new JButton (" ");
button [0] [0].setBackground (Color.red);
button [0] [0].setActionCommand ("button[0][0]");
button [0] [0].addActionListener (this);

button [0] [1] = new JButton (" ");
button [0] [1].setBackground (Color.red);
button [0] [1].setActionCommand ("button[0][1]");
button [0] [1].addActionListener (this);

button [0] [2] = new JButton (" ");
button [0] [2].setBackground (Color.red);
button [0] [2].setActionCommand ("button[0][2]");
button [0] [2].addActionListener (this);

button [0] [3] = new JButton (" ");
button [0] [3].setBackground (Color.red);
button [0] [3].setActionCommand ("button[0][3]");
button [0] [3].addActionListener (this);

button [0] [4] = new JButton (" ");
button [0] [4].setBackground (Color.red);
button [0] [4].setActionCommand ("button[0][4]");
button [0] [4].addActionListener (this);

button [0] [5] = new JButton (" ");
button [0] [5].setBackground (Color.red);
button [0] [5].setActionCommand ("button[0][5]");
button [0] [5].addActionListener (this);

button [0] [6] = new JButton (" ");
button [0] [6].setBackground (Color.red);
button [0] [6].setActionCommand ("button[0][6]");
button [0] [6].addActionListener (this);

button [0] [7] = new JButton (" ");
button [0] [7].setBackground (Color.red);
button [0] [7].setActionCommand ("button[0][7]");
button [0] [7].addActionListener (this);

////////////////////////////////////////////////////

button [1] [0] = new JButton (" ");
button [1] [0].setBackground (Color.red);
button [1] [0].setActionCommand ("button[1][0]");
button [1] [0].addActionListener (this);

button [1] [1] = new JButton (" ");
button [1] [1].setBackground (Color.red);
button [1] [1].setActionCommand ("button[1][1]");
button [1] [1].addActionListener (this);

button [1] [2] = new JButton (" ");
button [1] [2].setBackground (Color.red);
button [1] [2].setActionCommand ("button[1][2]");
button [1] [2].addActionListener (this);

button [1] [3] = new JButton (" ");
button [1] [3].setBackground (Color.red);
button [1] [3].setActionCommand ("button[1][3]");
button [1] [3].addActionListener (this);

button [1] [4] = new JButton (" ");
button [1] [4].setBackground (Color.red);
button [1] [4].setActionCommand ("button[1][4]");
button [1] [4].addActionListener (this);

button [1] [5] = new JButton (" ");
button [1] [5].setBackground (Color.red);
button [1] [5].setActionCommand ("button[1][5]");
button [1] [5].addActionListener (this);

button [1] [6] = new JButton (" ");
button [1] [6].setBackground (Color.red);
button [1] [6].setActionCommand ("button[1][6]");
button [1] [6].addActionListener (this);

button [1] [7] = new JButton (" ");
button [1] [7].setBackground (Color.red);
button [1] [7].setActionCommand ("button[1][7]");
button [1] [7].addActionListener (this);

////////////////////////////////////////////////////

button [2] [0] = new JButton (" ");
button [2] [0].setBackground (Color.red);
button [2] [0].setActionCommand ("button[2][0]");
button [2] [0].addActionListener (this);

button [2] [1] = new JButton (" ");
button [2] [1].setBackground (Color.red);
button [2] [1].setActionCommand ("button[2][1]");
button [2] [1].addActionListener (this);

button [2] [2] = new JButton (" ");
button [2] [2].setBackground (Color.red);
button [2] [2].setActionCommand ("button[2][2]");
button [2] [2].addActionListener (this);

button [2] [3] = new JButton (" ");
button [2] [3].setBackground (Color.red);
button [2] [3].setActionCommand ("button[2][3]");
button [2] [3].addActionListener (this);

button [2] [4] = new JButton (" ");
button [2] [4].setBackground (Color.red);
button [2] [4].setActionCommand ("button[2][4]");
button [2] [4].addActionListener (this);

button [2] [5] = new JButton (" ");
button [2] [5].setBackground (Color.red);
button [2] [5].setActionCommand ("button[2][5]");
button [2] [5].addActionListener (this);

button [2] [6] = new JButton (" ");
button [2] [6].setBackground (Color.red);
button [2] [6].setActionCommand ("button[2][6]");
button [2] [6].addActionListener (this);

button [2] [7] = new JButton (" ");
button [2] [7].setBackground (Color.red);
button [2] [7].setActionCommand ("button[2][7]");
button [2] [7].addActionListener (this);

////////////////////////////////////////////////////

button [3] [0] = new JButton (" ");
button [3] [0].setBackground (Color.red);
button [3] [0].setActionCommand ("button[3][0]");
button [3] [0].addActionListener (this);

button [3] [1] = new JButton (" ");
button [3] [1].setBackground (Color.red);
button [3] [1].setActionCommand ("button[3][1]");
button [3] [1].addActionListener (this);

button [3] [2] = new JButton (" ");
button [3] [2].setBackground (Color.red);
button [3] [2].setActionCommand ("button[3][2]");
button [3] [2].addActionListener (this);

button [3] [3] = new JButton (" ");
button [3] [3].setBackground (Color.white);

button [3] [4] = new JButton (" ");
button [3] [4].setBackground (Color.black);

button [3] [5] = new JButton (" ");
button [3] [5].setBackground (Color.red);
button [3] [5].setActionCommand ("button[3][5]");
button [3] [5].addActionListener (this);

button [3] [6] = new JButton (" ");
button [3] [6].setBackground (Color.red);
button [3] [6].setActionCommand ("button[3][6]");
button [3] [6].addActionListener (this);

button [3] [7] = new JButton (" ");
button [3] [7].setBackground (Color.red);
button [3] [7].setActionCommand ("button[3][7]");
button [3] [7].addActionListener (this);

////////////////////////////////////////////////////

button [4] [0] = new JButton (" ");
button [4] [0].setBackground (Color.red);
button [4] [0].setActionCommand ("button[4][0]");
button [4] [0].addActionListener (this);

button [4] [1] = new JButton (" ");
button [4] [1].setBackground (Color.red);
button [4] [1].setActionCommand ("button[4][1]");
button [4] [1].addActionListener (this);

button [4] [2] = new JButton (" ");
button [4] [2].setBackground (Color.red);
button [4] [2].setActionCommand ("button[4][2]");
button [4] [2].addActionListener (this);

button [4] [3] = new JButton (" ");
button [4] [3].setBackground (Color.black);

button [4] [4] = new JButton (" ");
button [4] [4].setBackground (Color.white);

button [4] [5] = new JButton (" ");
button [4] [5].setBackground (Color.red);
button [4] [5].setActionCommand ("button[4][5]");
button [4] [5].addActionListener (this);

button [4] [6] = new JButton (" ");
button [4] [6].setBackground (Color.red);
button [4] [6].setActionCommand ("button[4][6]");
button [4] [6].addActionListener (this);

button [4] [7] = new JButton (" ");
button [4] [7].setBackground (Color.red);
button [4] [7].setActionCommand ("button[4][7]");
button [4] [7].addActionListener (this);

////////////////////////////////////////////////////

button [5] [0] = new JButton (" ");
button [5] [0].setBackground (Color.red);
button [5] [0].setActionCommand ("button[5][0]");
button [5] [0].addActionListener (this);

button [5] [1] = new JButton (" ");
button [5] [1].setBackground (Color.red);
button [5] [1].setActionCommand ("button[5][1]");
button [5] [1].addActionListener (this);

button [5] [2] = new JButton (" ");
button [5] [2].setBackground (Color.red);
button [5] [2].setActionCommand ("button[5][2]");
button [5] [2].addActionListener (this);

button [5] [3] = new JButton (" ");
button [5] [3].setBackground (Color.red);
button [5] [3].setActionCommand ("button[5][3]");
button [5] [3].addActionListener (this);

button [5] [4] = new JButton (" ");
button [5] [4].setBackground (Color.red);
button [5] [4].setActionCommand ("button[5][4]");
button [5] [4].addActionListener (this);

button [5] [5] = new JButton (" ");
button [5] [5].setBackground (Color.red);
button [5] [5].setActionCommand ("button[5][5]");
button [5] [5].addActionListener (this);

button [5] [6] = new JButton (" ");
button [5] [6].setBackground (Color.red);
button [5] [6].setActionCommand ("button[5][6]");
button [5] [6].addActionListener (this);

button [5] [7] = new JButton (" ");
button [5] [7].setBackground (Color.red);
button [5] [7].setActionCommand ("button[5][7]");
button [5] [7].addActionListener (this);

////////////////////////////////////////////////////

button [6] [0] = new JButton (" ");
button [6] [0].setBackground (Color.red);
button [6] [0].setActionCommand ("button[6][0]");
button [6] [0].addActionListener (this);

button [6] [1] = new JButton (" ");
button [6] [1].setBackground (Color.red);
button [6] [1].setActionCommand ("button[6][1]");
button [6] [1].addActionListener (this);

button [6] [2] = new JButton (" ");
button [6] [2].setBackground (Color.red);
button [6] [2].setActionCommand ("button[6][2]");
button [6] [2].addActionListener (this);

button [6] [3] = new JButton (" ");
button [6] [3].setBackground (Color.red);
button [6] [3].setActionCommand ("button[6][3]");
button [6] [3].addActionListener (this);

button [6] [4] = new JButton (" ");
button [6] [4].setBackground (Color.red);
button [6] [4].setActionCommand ("button[6][4]");
button [6] [4].addActionListener (this);

button [6] [5] = new JButton (" ");
button [6] [5].setBackground (Color.red);
button [6] [5].setActionCommand ("button[6][5]");
button [6] [5].addActionListener (this);

button [6] [6] = new JButton (" ");
button [6] [6].setBackground (Color.red);
button [6] [6].setActionCommand ("button[6][6]");
button [6] [6].addActionListener (this);

button [6] [7] = new JButton (" ");
button [6] [7].setBackground (Color.red);
button [6] [7].setActionCommand ("button[6][7]");
button [6] [7].addActionListener (this);

////////////////////////////////////////////////////

button [7] [0] = new JButton (" ");
button [7] [0].setBackground (Color.red);
button [7] [0].setActionCommand ("button[7][0]");
button [7] [0].addActionListener (this);

button [7] [1] = new JButton (" ");
button [7] [1].setBackground (Color.red);
button [7] [1].setActionCommand ("button[7][1]");
button [7] [1].addActionListener (this);

button [7] [2] = new JButton (" ");
button [7] [2].setBackground (Color.red);
button [7] [2].setActionCommand ("button[7][2]");
button [7] [2].addActionListener (this);

button [7] [3] = new JButton (" ");
button [7] [3].setBackground (Color.red);
button [7] [3].setActionCommand ("button[7][3]");
button [7] [3].addActionListener (this);

button [7] [4] = new JButton (" ");
button [7] [4].setBackground (Color.red);
button [7] [4].setActionCommand ("button[7][4]");
button [7] [4].addActionListener (this);

button [7] [5] = new JButton (" ");
button [7] [5].setBackground (Color.red);
button [7] [5].setActionCommand ("button[7][5]");
button [7] [5].addActionListener (this);

button [7] [6] = new JButton (" ");
button [7] [6].setBackground (Color.red);
button [7] [6].setActionCommand ("button[7][6]");
button [7] [6].addActionListener (this);

button [7] [7] = new JButton (" ");
button [7] [7].setBackground (Color.red);
button [7] [7].setActionCommand ("button[7][7]");
button [7] [7].addActionListener (this);

////////////////////////////////////////////////////
for (int i = 0 ; i <= 7 ; i++)
{
for (int k = 0 ; k <= 7 ; k++)
{
center.add (button [i] [k]);
}
}
////////////////////////////////////////////////////////////

gameFrame.setContentPane (center);
gameFrame.pack ();
gameFrame.setVisible (true);

}


public void actionPerformed (ActionEvent e)
{
int x, y;
x = -1;
y = -1;
String event = e.getActionCommand ();

if (event.equals ("button[0][0]"))
{
x = 1;
y = 1;
if (validMove (x, y, 2, 1))
{
button [0] [0].setBackground (Color.black);
}
}
else if (event.equals ("button[0][1]"))
{
x = 1;
y = 2;
if (validMove (x, y, 2, 1))
{
button [0] [1].setBackground (Color.black);
}
}
else if (event.equals ("button[0][2]"))
{
x = 1;
y = 3;
if (validMove (x, y, 2, 1))
{
button [0] [2].setBackground (Color.black);
}
}
else if (event.equals ("button[0][3]"))
{
x = 1;
y = 4;
if (validMove (x, y, 2, 1))
{
button [0] [3].setBackground (Color.black);
}
}
else if (event.equals ("button[0][4]"))
{
x = 1;
y = 5;
if (validMove (x, y, 2, 1))
{
button [0] [4].setBackground (Color.black);
}
}
else if (event.equals ("button[0][5]"))
{
x = 1;
y = 6;
if (validMove (x, y, 2, 1))
{
button [0] [5].setBackground (Color.black);
}
}
else if (event.equals ("button[0][6]"))
{
x = 1;
y = 7;
if (validMove (x, y, 2, 1))
{
button [0] [6].setBackground (Color.black);
}
}
else if (event.equals ("button[0][7]"))
{
x = 1;
y = 8;
if (validMove (x, y, 2, 1))
{
button [0] [7].setBackground (Color.black);
}
}
///////////////////////////////////////////
else if (event.equals ("button[1][0]"))
{
x = 2;
y = 1;
if (validMove (x, y, 2, 1))
{
button [2] [0].setBackground (Color.black);
}
}
else if (event.equals ("button[1][1]"))
{
x = 2;
y = 2;
if (validMove (x, y, 2, 1))
{
button [1] [1].setBackground (Color.black);
}
}
else if (event.equals ("button[1][2]"))
{
x = 2;
y = 3;
if (validMove (x, y, 2, 1))
{
button [1] [2].setBackground (Color.black);
}
}
else if (event.equals ("button[1][3]"))
{
x = 2;
y = 4;
if (validMove (x, y, 2, 1))
{
button [1] [3].setBackground (Color.black);
}
}
else if (event.equals ("button[1][4]"))
{
x = 2;
y = 5;
if (validMove (x, y, 2, 1))
{
button [1] [4].setBackground (Color.black);
}
}
else if (event.equals ("button[1][5]"))
{
x = 2;
y = 6;
if (validMove (x, y, 2, 1))
{
button [1] [5].setBackground (Color.black);
}
}
else if (event.equals ("button[1][6]"))
{
x = 2;
y = 7;
if (validMove (x, y, 2, 1))
{
button [1] [6].setBackground (Color.black);
}
}
else if (event.equals ("button[1][7]"))
{
x = 2;
y = 8;
if (validMove (x, y, 2, 1))
{
button [1] [7].setBackground (Color.black);
}
}
///////////////////////////////////////////
else if (event.equals ("button[2][0]"))
{
x = 3;
y = 1;
if (validMove (x, y, 2, 1))
{
button [2] [0].setBackground (Color.black);
}
}
else if (event.equals ("button[2][1]"))
{
x = 3;
y = 2;
if (validMove (x, y, 2, 1))
{
button [2] [1].setBackground (Color.black);
}
}
else if (event.equals ("button[2][2]"))
{
x = 3;
y = 3;
if (validMove (x, y, 2, 1))
{
button [2] [2].setBackground (Color.black);
}
}
else if (event.equals ("button[2][3]"))
{
x = 3;
y = 4;
if (validMove (x, y, 2, 1))
{
button [2] [3].setBackground (Color.black);
}
}
else if (event.equals ("button[2][4]"))
{
x = 3;
y = 5;
if (validMove (x, y, 2, 1))
{
button [2] [4].setBackground (Color.black);
}
}
else if (event.equals ("button[2][5]"))
{
x = 3;
y = 6;
if (validMove (x, y, 2, 1))
{
button [2] [5].setBackground (Color.black);
}
}
else if (event.equals ("button[2][6]"))
{
x = 3;
y = 7;
if (validMove (x, y, 2, 1))
{
button [2] [6].setBackground (Color.black);
}
}
else if (event.equals ("button[2][7]"))
{
x = 3;
y = 8;
if (validMove (x, y, 2, 1))
{
button [2] [7].setBackground (Color.black);
}
}
///////////////////////////////////////////
else if (event.equals ("button[3][0]"))
{
x = 4;
y = 1;
if (validMove (x, y, 2, 1))
{
button [3] [0].setBackground (Color.black);
}
}
else if (event.equals ("button[3][1]"))
{
x = 4;
y = 2;
if (validMove (x, y, 2, 1))
{
button [3] [1].setBackground (Color.black);
}
}
else if (event.equals ("button[3][2]"))
{
x = 4;
y = 3;
if (validMove (x, y, 2, 1))
{
button [3] [2].setBackground (Color.black);
}
}
else if (event.equals ("button[3][5]"))
{
x = 4;
y = 6;
if (validMove (x, y, 2, 1))
{
button [3] [5].setBackground (Color.black);
}
}
else if (event.equals ("button[3][6]"))
{
x = 4;
y = 7;
if (validMove (x, y, 2, 1))
{
button [3] [6].setBackground (Color.black);
}
}
else if (event.equals ("button[3][7]"))
{
x = 4;
y = 8;
if (validMove (x, y, 2, 1))
{
button [3] [7].setBackground (Color.black);
}
}
///////////////////////////////////////////
else if (event.equals ("button[4][0]"))
{
x = 5;
y = 1;
if (validMove (x, y, 2, 1))
{
button [4] [0].setBackground (Color.black);
}
}
else if (event.equals ("button[4][1]"))
{
x = 5;
y = 2;
if (validMove (x, y, 2, 1))
{
button [4] [1].setBackground (Color.black);
}
}
else if (event.equals ("button[4][2]"))
{
x = 5;
y = 3;
if (validMove (x, y, 2, 1))
{
button [4] [2].setBackground (Color.black);
}
}
else if (event.equals ("button[4][5]"))
{
x = 5;
y = 6;
if (validMove (x, y, 2, 1))
{
button [4] [5].setBackground (Color.black);
}
}
else if (event.equals ("button[4][6]"))
{
x = 5;
y = 7;
if (validMove (x, y, 2, 1))
{
button [4] [6].setBackground (Color.black);
}
}
else if (event.equals ("button[4][7]"))
{
x = 5;
y = 8;
if (validMove (x, y, 2, 1))
{
button [4] [7].setBackground (Color.black);
}
}
///////////////////////////////////////////
else if (event.equals ("button[5][0]"))
{
x = 6;
y = 1;
if (validMove (x, y, 2, 1))
{
button [5] [0].setBackground (Color.black);
}
}
else if (event.equals ("button[5][1]"))
{
x = 6;
y = 2;
if (validMove (x, y, 2, 1))
{
button [5] [1].setBackground (Color.black);
}
}
else if (event.equals ("button[5][2]"))
{
x = 6;
y = 3;
if (validMove (x, y, 2, 1))
{
button [5] [2].setBackground (Color.black);
}
}
else if (event.equals ("button[5][3]"))
{
x = 6;
y = 4;
if (validMove (x, y, 2, 1))
{
button [5] [3].setBackground (Color.black);
}

}
else if (event.equals ("button[5][4]"))
{
x = 6;
y = 5;
if (validMove (x, y, 2, 1))
{
button [5] [4].setBackground (Color.black);
}

}
else if (event.equals ("button[5][5]"))
{
x = 6;
y = 6;
if (validMove (x, y, 2, 1))
{
button [5] [5].setBackground (Color.black);
}

}
else if (event.equals ("button[5][6]"))
{
x = 6;
y = 7;
if (validMove (x, y, 2, 1))
{
button [5] [6].setBackground (Color.black);
}

}
else if (event.equals ("button[5][7]"))
{
x = 6;
y = 8;
if (validMove (x, y, 2, 1))
{
button [5] [7].setBackground (Color.black);
}
}
///////////////////////////////////////////
else if (event.equals ("button[6][0]"))
{
x = 7;
y = 1;
if (validMove (x, y, 2, 1))
{
button [6] [0].setBackground (Color.black);
}
}
else if (event.equals ("button[6][1]"))
{
x = 7;
y = 2;
if (validMove (x, y, 2, 1))
{
button [6] [1].setBackground (Color.black);
}
}
else if (event.equals ("button[6][2]"))
{
x = 7;
y = 3;
if (validMove (x, y, 2, 1))
{
button [6] [2].setBackground (Color.black);
}

}
else if (event.equals ("button[6][3]"))
{
x = 7;
y = 4;
if (validMove (x, y, 2, 1))
{
button [6] [3].setBackground (Color.black);
}

}
else if (event.equals ("button[6][4]"))
{
x = 7;
y = 5;
if (validMove (x, y, 2, 1))
{
button [6] [4].setBackground (Color.black);
}
}
else if (event.equals ("button[6][5]"))
{
x = 7;
y = 6;
if (validMove (x, y, 2, 1))
{
button [6] [5].setBackground (Color.black);
}
}
else if (event.equals ("button[6][6]"))
{
x = 7;
y = 7;
if (validMove (x, y, 2, 1))
{
button [6] [6].setBackground (Color.black);
}
}
else if (event.equals ("button[6][7]"))
{
x = 7;
y = 8;
if (validMove (x, y, 2, 1))
{
button [6] [7].setBackground (Color.black);
}
}
///////////////////////////////////////////
else if (event.equals ("button[7][0]"))
{
x = 8;
y = 1;
if (validMove (x, y, 2, 1))
{
button [7] [0].setBackground (Color.black);
}
}
else if (event.equals ("button[7][1]"))
{
x = 8;
y = 2;
if (validMove (x, y, 2, 1))
{
button [7] [1].setBackground (Color.black);
}
}
else if (event.equals ("button[7][2]"))
{
x = 8;
y = 3;
if (validMove (x, y, 2, 1))
{
button [7] [2].setBackground (Color.black);
}
}
else if (event.equals ("button[7][3]"))
{
x = 8;
y = 4;
if (validMove (x, y, 2, 1))
{
button [7] [3].setBackground (Color.black);
}
}
else if (event.equals ("button[7][4]"))
{
x = 8;
y = 5;
if (validMove (x, y, 2, 1))
{
button [7] [4].setBackground (Color.black);
}
}
else if (event.equals ("button[7][5]"))
{
x = 8;
y = 6;
if (validMove (x, y, 2, 1))
{
button [7] [5].setBackground (Color.black);
}
}
else if (event.equals ("button[7][6]"))
{
x = 8;
y = 7;
if (validMove (x, y, 2, 1))
{
button [7] [6].setBackground (Color.black);
}
}
else if (event.equals ("button[7][7]"))
{
x = 8;
y = 8;
if (validMove (x, y, 2, 1))
{
button [7] [7].setBackground (Color.black);
}
}
if (validMove (x, y, 2, 1))
{
board [x] [y] = 2;

computer ();
}

///////////////////////////////////////////
///////////////////////////////////////////
}


public boolean validMove (int x, int y, int color, int opC)
{
checkValid = false;
/////////////////////UP
if (board [x - 1] [y] == opC)
{
for (int i = x - 2 ; i <= 0 ; i--)
{
if (board [i] [y] == color)
{
checkValid = true;
break;
}
}
}
return (checkValid);
}


public void computer ()
{

int x = (int) (Math.random () * 8 + 1);
int y = (int) (Math.random () * 8 + 1);

while (validMove (x, y, 1, 2))
{
x = (int) (Math.random () * 8 + 1);
y = (int) (Math.random () * 8 + 1);
}
}



public boolean checkUP (int x, int y, int color, int opC)
{
checkValid = false;
//////////////////////UP
if (board [x - 1] [y] == opC)
{
for (int i = x - 2 ; i <= 0 ; i--)
{
if (board [i] [y] == color)
{
checkValid = true;
break;
}
}
}
return (checkValid);
}


public boolean checkDN (int x, int y, int color, int opC)
{
checkValid = false;
/////////////////////DOWN
if (board [x + 1] [y] == opC)
{
for (int i = x + 2 ; i >= 10 ; i++)
{
if (board [i] [y] == color)
{
checkValid = true;
break;
}
}
}
return (checkValid);
}


public boolean checkLT (int x, int y, int color, int opC)
{
checkValid = false;
////////////////////LEFT
if (board [x] [y - 1] == opC)
{
for (int i = y - 2 ; i <= 0 ; i--)
{
if (board [i] [y] == color)
{
checkValid = true;
break;
}
}
}
return (checkValid);
}


public boolean checkRT (int x, int y, int color, int opC)
{
checkValid = false;
////////////////////RIGHT
if (board [x] [y + 1] == opC)
{
for (int i = y + 2 ; i <= 10 ; i++)
{
if (board [i] [y] == color)
{
checkValid = true;
break;
}
}
}
return (checkValid);
}
} // GameBoard class
andrew.




PostPosted: Thu May 28, 2009 6:28 pm   Post subject: RE:SOMEONE PLEASE HELP MEEE gr 12 java

1. This should be in the Java Help section.
2. Use syntax tags:
code:
[syntax="Java"]Your code[/syntax]

3. Sorry I don't know much Java so I can't really help you.
Zren




PostPosted: Thu May 28, 2009 8:36 pm   Post subject: Re: SOMEONE PLEASE HELP MEEE gr 12 java

well first off, you can get rid of a massive chunk of code with two for loops... When you have to copy and paste something 20 times, your doing something wrong.

button [0] [7] = new JButton (" ");
button [0] [7].setBackground (Color.red);
button [0] [7].setActionCommand ("button[0][7]");
button [0] [7].addActionListener (this);

code:
for y=0;y<8;y++
    for x=0;x<8;x++
        button[x][y] ....
    end for
end for


Same with your other code...

code:
for y=0;y<8;y++
    for x=0;x<8;x++
        if event.equals ("button[x][y]")
            squarex = x + 1
            squarey = y + 1
        end if
    end for
end for


When you copy and paste code, your probably following a pattern, which usually means you can use a loop.

As for your actual problem... not sure.
Insectoid




PostPosted: Thu May 28, 2009 9:10 pm   Post subject: RE:SOMEONE PLEASE HELP MEEE gr 12 java

Good thing I learned Othello recently Smile.

I notice your program doesn't support capturing multiple pieces at a time. That's not good.

Programming is one class you CANNOT procrastinate in. I'm lucky, I enjoy it enough that it's not work for me.
Display posts from previous:   
   Index -> General Discussion
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: