【发布时间】:2022-12-01 14:13:43
【问题描述】:
school gave me an assingment. i have to make the memory cards game in processing (java). i am not allowed to use classes. i already created the game and it works, but now i have to add death cards. i am using a 2d array to load the cards. i have put the death cards in the third iteration of the array.
now the problem is, when i am trying to create a shuffle function, it will only shuffle the cards in its own iteration. so all the death cards will appear at the end.
anybody got any ideas?
void shuffle() {
int tijdelijk = 0;
int random = 0;
for (int i=0; i<3; i++) {
if (i == 0 || i == 1) {
for (int j=0; j<aantalSetjes; j++) {
random = int(random(0, aantalSetjes));
tijdelijk = gekozenKaart[i][j];
gekozenKaart[i][j] = gekozenKaart[i][random];
gekozenKaart[i][random] = tijdelijk;
}
} else if (i == 2) {
for (int j=0; j<getAantalDoodsKaarten(); j++) {
random = int(random(0, getAantalDoodsKaarten()));
tijdelijk = gekozenKaart[i][j];
gekozenKaart[i][j] = gekozenKaart[i][random];
gekozenKaart[i][random] = tijdelijk;
}
}
}
}
【问题讨论】:
-
You should make sure your question contains all relevant code for readers to understand and reproduce the error/wrong behavior you are asking about. There is a lot in the short snipped that you didn't include and that we as readers have no idea what it even represents. If you don't give us all relevant information about the variables and methods you use in your methods your code is just a big black box to us and we literally cannot tell you why it behaves the way it does.
-
But that's literally what your code above does - it shuffles row 0 cards among themselves only, then it shuffles row 1 cards among themselves only and then it shuffles row 2 cards among themselves only. I suppose somewhere outside you then append the rows together, placing all row 0 cards first, then all row 1 cards next and so on.
-
please add the rest of the code as well to your example, so that we can see where the rows are then put together.
标签: java processing shuffle