Hello everyone,
I’m making a memory card game in Processing. This is for a homework assignment. I’ve come pretty far with all the information online, but I’m stuck at a few problems.
My game has a few requirements to meet. I have to have a scoreboard, 12 sets of memory cards (so 24 cards) plus a “death card” which means if you click that one, you will lose a point. It needs to be in a 5x5 grid. It’s singleplayer. We cannot use classes.
In my code I have laid out all my functions, so it would be clearer to me which bit I can program first. Now, I have created a shuffleCards function. This does what it’s supposed to do. But now I have to make sure the cards only show up twice each. That’s where I am stuck. I have no idea how to make that. I thought about using modulo? I’m not sure.
Along with that, if that is fixed, I have to check if the cards actually match, and if they do, the card will dissapear off screen, and a point will be added. I have it mapped out on paper, but I need help realizing this as code.
Can someone help me with this? I would be forever grateful.
String cardImages[] = {"img1.png", "img2.png", "img3.png", "img4.png", "img5.png", "img6.png", "img7.png", "img8.png", "img9.png", "img10.png", "img11.png", "img12.png"};
int[][] cards = new int[25][3];
boolean gameStarted = false;
boolean cardFlipped = false;
boolean cardClicked = false;
boolean gameOver = false;
int screenWidth = 1000;
int screenHeight = 1000;
int cardWidth = 175;
int cardHeight = 175;
int marge = 15;
int cardsOnXPos = 5;
int cardsOnYPos = 5;
int show = 0;
PImage cardImage;
void setup(){
size(1500,1500);
background(0,100,0);
setupBoard();
shuffleCards();
drawImageOnScreen();
}
void draw(){
//drawCardsOnScreen();
}
void mousePressed(){
mouseClickedOnCard();
}
void startGame(){
background(0,100,0);
}
void flipCards(){
}
void shuffleCards(){
for (int i = 0; i < cardImages.length; i++){
int index = (int)(random(cardImages.length));
String temp = cardImages[i];
cardImages[i] = cardImages[index];
cardImages[index] = temp;
}
}
void mouseClickedOnCard(){
for (int i = 0; i < cards.length; i++){
if((mouseX >= cards[i][0] && mouseX <= cards[i][0] + cardWidth) && (mouseY >= cards[i][1] && mouseY <= cards[i][1] + cardHeight)){
println("Clicked on " + i);
}
}
}
void cardMatched(){
}
void cardOffScreen(){
}
void drawCard(int cardX, int cardY){
fill(0);
rect(cardX, cardY, cardWidth, cardHeight, 0);
}
void drawImage(int cardX, int cardY){
cardImage = loadImage(cardImages[(int)random(12)]);
image(cardImage, cardX, cardY);
}
void drawImageOnScreen(){
for( int i = 0; i < cards.length; i++){
drawImage(cards[i][0], cards[i][1]);
}
}
void drawCardsOnScreen(){
for( int i = 0; i < cards.length; i++){
drawCard(cards[i][0], cards[i][1]);
}
}
void setupBoard(){
for( int i = 0; i < cards.length; i++){
int horizontalCardIndex = i % cardsOnXPos;
int verticalCardIndex = i / cardsOnYPos;
int cardX = marge + (cardWidth + marge) * horizontalCardIndex;
int cardY = marge + (cardHeight + marge) * verticalCardIndex;
cards[i][0]= cardX;
cards[i][1]= cardY;
cards[i][2]= 0;
}
}
void startScreen(){
}
void gameOver(){
fill(255);
textSize(50);
text("YOU WIN", 200, 800);
}
void scoreBoard(){
}