We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I don't know what to do next... the cards need to be shuffled before there being placed on the display but it doesn't work
here is what I now have:
Cards[] myCard = new Cards[24];
int[] x = new int[24];
int[] y = new int[24];
int[] fv = new int[24];
int[] checkFv = new int[2];
int[] cardUp = new int[2];
boolean[] clicked = new boolean[24];
int scoreS1 = 0;
int scoreS2 = 0;
int beurt = 0;
int winner;
int flipped = 0;
int win = 0;
int spel = 0;
int cardWidth=50;
int cardHeight=75;
int wachttijd;
void settings()
{
size(displayWidth/100*90,displayHeight/100*90);
}
void setup()
{
int myX = width/4;
int myY = height/8;
int myFv = 0;
int count = 1;
for(int i = 0; i<24; i++)
{
clicked[i] = false;
y[i] = myY;
x[i] = myX;
fv[i] = count;
count +=1;
if (count == 13)
{
count =1;
}
if (myX<width*0.75)
{
myX +=60;
}
else if (myX > width*0.75)
{
myX = width/4;
myY +=80;
}
}
shuffle();
for(int i = 0; i<24; i++)
{
myCard[i] = new Cards (x[i], y[i], fv[i]);
}
}
void draw()
{
background(254);
checkTime();
startScherm();
speelScherm();
}
void mouseClicked()
{
if (spel == 1)
{
for (int i = 0; i<24; i++)
{
if (mouseX> x[i] && mouseX<(x[i]+cardWidth) && mouseY > y[i] && mouseY<(y[i]+cardHeight) && (clicked[i] == false))
{
println(fv[i], x[i]);
if (flipped < 2){
myCard[i].displayFront();
clicked[i] = true;
cardUp[flipped] = i;
flipped ++;
}
if (flipped == 2)
{
setTime();
}
}
}
}
}
class Cards
{
PImage cardImage;
int show =0;
int cardX = 0;
int cardY = 0;
int faceValue = 0;
String[] cardName = {"back.jpg","10_of_clubs.jpg",
"10_of_diamonds.jpg",
"10_of_hearts.jpg",
"10_of_spades.jpg",
"2_of_clubs.jpg",
"2_of_diamonds.jpg",
"2_of_hearts.jpg",
"2_of_spades.jpg",
"3_of_clubs.jpg",
"3_of_diamonds.jpg",
"3_of_hearts.jpg",
"3_of_spades.jpg",
"4_of_clubs.jpg",
"4_of_diamonds.jpg",
"4_of_hearts.jpg",
"4_of_spades.jpg",
"5_of_clubs.jpg",
"5_of_diamonds.jpg",
"5_of_hearts.jpg",
"5_of_spades.jpg",
"6_of_clubs.jpg",
"6_of_diamonds.jpg",
"6_of_hearts.jpg",
"6_of_spades.jpg",
"7_of_clubs.jpg",
"7_of_diamonds.jpg",
"7_of_hearts.jpg",
"7_of_spades.jpg",
"8_of_clubs.jpg",
"8_of_diamonds.jpg",
"8_of_hearts.jpg",
"8_of_spades.jpg",
"9_of_clubs.jpg",
"9_of_diamonds.jpg",
"9_of_hearts.jpg",
"9_of_spades.jpg",
"ace_of_clubs.jpg",
"ace_of_diamonds.jpg",
"ace_of_hearts.jpg",
"ace_of_spades.jpg",
"ace_of_spades2.jpg",
"black_joker.jpg",
"jack_of_clubs.jpg",
"jack_of_clubs2.jpg",
"jack_of_diamonds.jpg",
"jack_of_diamonds2.jpg",
"jack_of_hearts.jpg",
"jack_of_hearts2.jpg",
"jack_of_spades.jpg",
"jack_of_spades2.jpg",
"king_of_clubs.jpg",
"king_of_clubs2.jpg",
"king_of_diamonds.jpg",
"king_of_diamonds2.jpg",
"king_of_hearts.jpg",
"king_of_hearts2.jpg",
"king_of_spades.jpg",
"king_of_spades2.jpg",
"queen_of_clubs.jpg",
"queen_of_clubs2.jpg",
"queen_of_diamonds.jpg",
"queen_of_diamonds2.jpg",
"queen_of_hearts.jpg",
"queen_of_hearts2.jpg",
"queen_of_spades.jpg",
"queen_of_spades2.jpg",
"red_joker.jpg", };
Cards(int x, int y, int fv)
{
cardX= x;
cardY = y;
faceValue = fv;
}
void display()
{
cardImage = loadImage(cardName[show]);
image(cardImage, cardX, cardY);
}
void displayFront()
{
show = faceValue;
}
void displayBack()
{
show = 0;
}
void matched()
{
cardX = -150;
}
}
void speelScherm()
{
if (spel == 1){
for (int i = 0; i<24; i++)
{
myCard[i].display();
}
textSize(25);
textAlign(CENTER);
text("Speler 1: " + (scoreS1), (width/100*25)+50, (height/100*75));
text("Speler 2: " + scoreS2, (width/100*25)+50, (height/100*75)+25);
if (beurt == 0)
{
textSize(25);
textAlign(CENTER);
text("Speler 1 is aan de beurt", (width/2), (height/2));
}
if (beurt == 1)
{
textSize(25);
textAlign(CENTER);
text("Speler 2 is aan de beurt", (width/2), (height/2));
}
}
if (spel == 3 && winner == 1){
textSize(25);
textAlign(CENTER);
text("Speler 1 heeft gewonnen!", (width/2), (height/2));
textSize(15);
textAlign(CENTER);
text("Score speler 1: " + scoreS1, (width/2), (height/2)+25);
text("Score speler 2: " + scoreS2, (width/2), (height/2)+25+15);
}
if (spel == 3 && winner == 2){
textSize(25);
textAlign(CENTER);
text("Speler 2 heeft gewonnen!", (width/2), (height/2));
textSize(15);
textAlign(CENTER);
text("Score speler 1: " + scoreS1, (width/2), (height/2)+25);
text("Score speler 2: " + scoreS2, (width/2), (height/2)+25+15);
}
if (spel == 3 && winner == 3){
textSize(25);
textAlign(CENTER);
text("Gelijkspel...", (width/2), (height/2));
textSize(15);
textAlign(CENTER);
text("Score speler 1: " + scoreS1, (width/2), (height/2)+25);
text("Score speler 2: " + scoreS2, (width/2), (height/2)+25+15);
}
}
void startSpel()
{
if (mouseX> (width/100*25) && mouseX< (width/100*25) + 100 && mouseY > height/100*75 && mouseY<height/100*75+50 && spel==0)
{
spel = 1;
}
if (mouseX> (width/100*75) && mouseX< (width/100*75) + 100 && mouseY > height/100*75 && mouseY<height/100*75+50 && spel==0)
{
spel = 2;
}
}
void startScherm(){
if (spel == 0){
fill(0, 102, 153);
textSize(32);
textAlign(CENTER);
text("Memory",width/2, height/4);
textSize(25);
text("Met hoeveel setjes wil je spelen?",width/2, height/2);
rect(width/100*25, height/100*75, 100, 50);
rect(width/100*75, height/100*75, 100, 50);
fill(0, 0, 0);
textSize(25);
textAlign(CENTER);
text("12", (width/100*25)+50, (height/100*75)+25);
text("32", (width/100*75)+50, (height/100*75)+25);
if (mousePressed)
{
startSpel();
}
}
}
void shuffle()
{
int temp=0;
int rand=0;
if (spel == 1){
for (int i=0; i<24; i++)
{
rand = int(random(0,24));
temp = fv[i];
fv[i] = fv[rand];
fv[rand] = temp;
}
}
}
void setTime(){
int huidigeTijd = millis();
wachttijd = huidigeTijd + 2000;
}
void checkTime(){
if (wachttijd <= millis()){
if (flipped == 2){
if (scoreS1 + scoreS2 < 12){
if (beurt == 0 && flipped == 2){
beurt = 1;
clicked[cardUp[0]] = false;
clicked[cardUp[1]] = false;
flipped = 0;
if (fv[cardUp[0]]!=fv[cardUp[1]]){
myCard[cardUp[0]].displayBack();
myCard[cardUp[1]].displayBack();
}
if (fv[cardUp[0]]==fv[cardUp[1]])
{
myCard[cardUp[0]].matched();
myCard[cardUp[1]].matched();
scoreS1 = scoreS1 + 1;
}
}
if (beurt == 1 && flipped == 2){
beurt = 0;
clicked[cardUp[0]] = false;
clicked[cardUp[1]] = false;
flipped = 0;
if (fv[cardUp[0]]!=fv[cardUp[1]]){
myCard[cardUp[0]].displayBack();
myCard[cardUp[1]].displayBack();
}
if (fv[cardUp[0]]==fv[cardUp[1]])
{
myCard[cardUp[0]].matched();
myCard[cardUp[1]].matched();
scoreS2 = scoreS2 + 1;
}
}
}
if (scoreS1 + scoreS2 == 12){
if (scoreS1 > scoreS2){
winner = 1;
}
if (scoreS2 > scoreS2){
winner = 2;
}
if (scoreS1 == scoreS2){
winner = 3;
}
spel = 3;
}
}
}
}
Answers
^ an unreadable mess
edit post, highlight code, press ctrl-o.
updated it, hope it's better now
https://forum.Processing.org/two/discussion/2801/picking-cards-at-random-then-excluding-those-from-further-picking#Item_2