Array and Cardgame
in
Programming Questions
•
1 year ago
Hey,
So I'm trying to make a card game and managed to make a little array that grabs PImages and randomises them so when I click It shows a different card.
Could you guys help me with randoming the array and having no repetitions of cards? I'm really stuck :(
int numCards = 12; //number of images
String[] imageNames = { "Aclubs.png", "2clubs.png", "3clubs.png","4clubs.png", "5clubs.png", "6clubs.png", "7clubs.png", "8clubs.png", "9clubs.png", "Jclubs.png", "Qclubs.png", "Kclubs.png"};
PImage[] images = new PImage[imageNames.length];
void setup() {
size (1240, 1547);
for (int i=0; i < imageNames.length; i++){
String imageName = imageNames[i];
images[i] = loadImage(imageName);
}
}
void mousePressed(){
delay(1000);
int r = int(random(imageNames.length));
image(images[r], 0, 0);
}
void draw() {
if (mousePressed){
int r = int(random(imageNames.length));
image(images[r], 0, 0);
}
}
So I'm trying to make a card game and managed to make a little array that grabs PImages and randomises them so when I click It shows a different card.
Could you guys help me with randoming the array and having no repetitions of cards? I'm really stuck :(
int numCards = 12; //number of images
String[] imageNames = { "Aclubs.png", "2clubs.png", "3clubs.png","4clubs.png", "5clubs.png", "6clubs.png", "7clubs.png", "8clubs.png", "9clubs.png", "Jclubs.png", "Qclubs.png", "Kclubs.png"};
PImage[] images = new PImage[imageNames.length];
void setup() {
size (1240, 1547);
for (int i=0; i < imageNames.length; i++){
String imageName = imageNames[i];
images[i] = loadImage(imageName);
}
}
void mousePressed(){
delay(1000);
int r = int(random(imageNames.length));
image(images[r], 0, 0);
}
void draw() {
if (mousePressed){
int r = int(random(imageNames.length));
image(images[r], 0, 0);
}
}
1