Beginner Question - How to edit my Array-data using "for()"?
in
Programming Questions
•
4 months ago
Hello everybody.
Started working with processing 2 days ago, works good so far. I'm trying to program a little game where you have to collect rectangles, and once you've collected all it should say "you win".
Well actually I'm stuck at the problem if how-to-detect if i collected a rectangle, but i think i got a solution. But that solution causes a Problem:
(My squares are called cows, cause i want to replace them with cow-pictures later on)
On the very top of my code i've put in this part:
Started working with processing 2 days ago, works good so far. I'm trying to program a little game where you have to collect rectangles, and once you've collected all it should say "you win".
Well actually I'm stuck at the problem if how-to-detect if i collected a rectangle, but i think i got a solution. But that solution causes a Problem:
(My squares are called cows, cause i want to replace them with cow-pictures later on)
On the very top of my code i've put in this part:
- int [] xkord = {176, 114, 298, 402, 385, 245, 462, 382, 503, 544};
int [] ykord = {424, 180, 308, 288, 410, 72, 122, 169, 200, 267};
char [] cow= {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
// Für jede Kuh eine Variable erstellen und "F" setzen
char A = 'F';
char B = 'F';
char C = 'F';
char D = 'F';
char E = 'F';
char F = 'F';
char G = 'F';
char H = 'F';
char I = 'F';
char J = 'F';
So this first sets the coordinates for the squares in 2 arrays, then gives each cow a "name", and then creates a variable for each cow that says "F".
I think so far ir should work.
Well, the fun starts at the draw-part. My idea is:
1. Check, if the mouse is in the 80x80-Area arround one of the squares
2. If thats the case, it should set the char-variable of the cow to "T" (for "True").
Now it should check if the char-variable is "F" or not. If its F, it should create the square, because i havent touched it yet. If its T, nothing should happen.
At the very last it should check if all char-variables are "T", if thats the case, it should print "Winner".
Well, i think this should work?
Now, my problem is that i dont know how to change the letter of the char-Variable using a for-loop. This is my try:
I think so far ir should work.
Well, the fun starts at the draw-part. My idea is:
1. Check, if the mouse is in the 80x80-Area arround one of the squares
2. If thats the case, it should set the char-variable of the cow to "T" (for "True").
Now it should check if the char-variable is "F" or not. If its F, it should create the square, because i havent touched it yet. If its T, nothing should happen.
At the very last it should check if all char-variables are "T", if thats the case, it should print "Winner".
Well, i think this should work?
Now, my problem is that i dont know how to change the letter of the char-Variable using a for-loop. This is my try:
- for(int i = 0; i < 10; i++){
if (mouseX > xkord[i]-40 && mouseX < xkord[i]+40 && mouseY > ykord[i]-40 && mouseY < ykord[i]+40){
char g = cow[i];
}
}
So, it pretty much repeates 10 times, and each time it takes the coodinates from the kord-array und checks if the mouse is there. If thats the case, it should get the "name" of the cow from the array above. that works (tryed it by printing the "g"-variable created.
But now i want to use the result of "g", which is, depending on the cow, "A,B,C,...J", whatever cow you hit. I want to update the char-variable created above from "F" to "T", so i can see wich cow was hit(T) and which was not(F).
But how can i achive this?
But now i want to use the result of "g", which is, depending on the cow, "A,B,C,...J", whatever cow you hit. I want to update the char-variable created above from "F" to "T", so i can see wich cow was hit(T) and which was not(F).
But how can i achive this?
1