- #1
Firestrider
- 104
- 0
Homework Statement
To code a dots and boxes game variant. Basically I need to code the same game except instead of drawing lines you choose two dots to form a line. I would need MouseListener for clicking and entering/exiting dots, a graphics update for changing colors of the dots and forming lines, a score tracker for "boxes" completed, and I guess an adjacent dot checker for creating boxes.
Homework Equations
N/A
The Attempt at a Solution
Can someone tell me what is wrong with this code? I want it to paint out 64 dots, but for some reason it will only paint out one.
Also I'm trying to figure out a way to have a MouseListener on each Dot so when you enter/exit the dot the color will change, and when you click on the dot the color will stay and the MouseListener will be removed. The color would be based on the current player. I'm not sure how to do this because you can't have a mouseClicked(MouseEvent e) inside the paint(Graphics g).
Here is the relevant code:
Code:
public void paint(Graphics g)
{
Dot[] dots = new Dot[63];
for(int i = 0; i < dots.length; i++)
{
for(int j = 25; j < 400; j += 50)
{
for(int k = 25; k < 400; k += 50)
{
dots[i] = new Dot(j, k);
}
}
}
for(Dot d : dots)
{
g.setColor(Color.black);
g.fillOval(d.getX(), d.getY(), 10, 10);
}
Code:
public class Dot
{
private int x;
private int y;
public Dot(int x, int y)
{
this.x = x;
this.y = y;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
}
Also any alternative pathways to get this problem done would be helpful. I know exactly what I want to be done but I've lost on how to implement it all in code :\
Last edited: