I'm trying to write a simple tic tac toe. I'm able to get the cell to have a "o" state when the mouse is pressed but when I attempt to write in an "x" state, it's acting really wonky. Ellipses seem to work fine, but other objects such as lines or rects don't seem to work. Can someone explain this to me....thanks in advance.
I'm trying to learn 2D arrays in processing by creating a simple tic-tac-toe game. I tried to write a function that when the mouse is clicked it creates an ellipse. But I don't understand why it is only doing it for the top left square. Can anyone enlighten me? :) thanks in advance. Code is below:
Hi, I'm trying to write a function that gets the min value from an array but returns its index. But I keep on getting some errors. What am I doing wrong?
Here is the beginnings of my function:
int getIndex (float[] a) {
for (int i=0; i < a.length; i++) {
if (a[i] == min(a)) {
return i;
}
}
}
Another attempt, basically creating a float[] sqDist that takes a function mouseDist (basically a function that calculates the distance between the x-y of an object and the mouse) as its values. I then used an if statement to perhaps obtain the minimum value associated with the index. But it's giving an error saying that the variables for the function and the return function are not the same! What am I missing here?
int Indexget() {
int gI;
float[] sqDist = new float[squares.length];
for (gI=0; gI < squares.length; gI++) {
sqDist[gI] = mouseDist(squares[gI]);
if (sqDist[gI] == min(sqDist)) {
return gI;
}
}
}
So in another class, I have created a variable of type Pt[ ], as one of its variables/arguments. I made a function called void render () which draws an ellipse through a for loop. How would I access the value, of a variable/argument (posX), of an object Pt that is within an array? Is this possible?
I know that if it is just one instance, you would access it through: nameVariable.posX
if it's within an array how would you write it? nameVariable.posX[i]? I tried several things but it didn't work?
let's say, for variable Pt[] ptXY;
for (int i = 0; i < ptXY.length; i ++) {
ellipse(
[goes here],
[goes here], Esize, Esize);
}
What I currently have is a square that is following a "terrain". When the mouse is clicked anywhere on the screen, the square is grabbed. When the mouse is clicked again, it begins to walk everywhere on the screen.
What I would want to happen is that after the mouse is clicked and the square is grabbed that when the mouse is clicked again, the square starts at the left hand side of the screen and follows the terrain once again.
I tried several things to no avail.
I was thinking that the problem was in the 'if' statement associated with the boolean mouseClick. But I'm not too sure.
I'm just trying to learn processing and I appreciate any help! :)