Need some serious help with Connect Four Code
in
Programming Questions
•
1 year ago
I'm a bit of a new comer to processing & am struggling completing this code for an assignment. I'm stuck right now with getting the fill color to change for player 2. Basically - player one will take a turn & will make the ellipse fill red & then player two will click an ellipse, making it black. Then player one again will create red ellipse & so on & so fourth!
This is seriously holding me back, I want to get onto the more troubling problem of Win detection!! Please help me out guys!
Here's what i've come up with so far :
color yellow = color (255, 217, 0);
color red = color (255, 0, 0);
color blue = color (0, 0, 255);
class Circle {
float x;
float y;
float diameter;
boolean isFilled;
color fillColor;
color strokeColor;
Circle(float init_x, float init_y,
float init_diameter,
color init_color)
{
x = init_x;
y = init_y;
diameter = init_diameter;
fillColor = init_color;
strokeColor = init_color;
isFilled = false;
}
void render () {
fill (fillColor);
stroke (strokeColor);
ellipse (x, y, diameter, diameter);
}
void mouseOver() { // determines which cirlce the mouse is over, can help with making next move
if(isFilled == false){
if (mouseX > x - diameter / 2 &&
mouseX < x + diameter / 2 &&
mouseY > y - diameter / 2 &&
mouseY < y + diameter / 2)
{
fillColor = red;
}
else {
fillColor = (255);
}
}
}
} // class Ball
Circle [][] a = new Circle[7][6];
void setup() {
size(700, 600);
smooth();
for (int i = 0; i < 7; i++){
for (int j = 0; j < 6; ++j){
a[i][j] = new Circle (50 + 100*(i), 50 + 100*(j), 90, color (255, 255, 255));
}
}
}
void draw () {
smooth();
background (blue);
for (int i = 0; i < 7; i++){
for (int j = 0; j < 6; j++){
a[i][j].render();
a[i][j].mouseOver();
}
}
stroke (20);
line (100, 0, 100, 600);
line (200, 0, 200, 600);
line (300, 0, 300, 600);
line (400, 0, 400, 600);
line (500, 0, 500, 600);
line (600, 0, 600, 600);
line (0, 100, 700, 100);
line (0, 200, 700, 200);
line (0, 300, 700, 300);
line (0, 400, 700, 400);
line (0, 500, 700, 500);
}
void mouseClicked() {
for (int i = 0; i < 7; i++){
for (int j = 0; j < 6; j++){
if(a[i][j].isFilled == false){
if (mouseX > a[i][j].x - a[i][j].diameter / 2 &&
mouseX < a[i][j].x + a[i][j].diameter / 2 &&
mouseY > a[i][j].y - a[i][j].diameter / 2 &&
mouseY < a[i][j].y + a[i][j].diameter / 2)
{
a[i][j].fillColor = red;
a[i][j].isFilled = true;
}
}
}
}
}
1