Question

Hi, I need help with my assignment. •Create a memory game in C •Function oriented with...

Hi, I need help with my assignment.

•Create a memory game in C

•Function oriented with several functions

•Structured programming

•All cards are randomly placed on the board with face down •The player pick one card from the board and the symbol is shown •The player picks another card, with the aim to get pair (same symbol twice), and the symbol is shown

•If two equal card is found (pair) the player gets one point and the pair is removed from the board •The game continues until the board is empty

•NxM board size •Random board

my code not working becaus I cant get the random board to work.

Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include "stdafx.h"

#include "stdlib.h"

#include <stdio.h>

#include <cstdlib>

#include <ctime>

int _tmain(int argc, _TCHAR* argv[])

{

    char comma;

    int r1, c1, r2, c2, cards[4][4];

    srand((unsigned)time(NULL));

    //fill board

    for (int r=0; r<4; r++)

    {

        for (int c=0; c<4; c++)

        {

            cards[r][c]=rand()%8+1;

  

    //display board

    printf("    1 2 3 4\n");

    printf("");

    for (int i=0; i<=8; i++)

    {

        printf("-");

    }

    printf("");

    for (int r=0; r<4; r++)

    {

        printf("%d",r+1);

        for (int c=0; c<4; c++)

        {

         printf("*");

        }

       printf("");

    }

    printf("");

    //selection

     printf(" enter first card row and column:.\n");

    scanf("%d,%d",&r1,&c1);

    printf("enter second card row and column:.\n");

  

scanf("%d,%d",&r2,&c2);

    //fix

    r1--;

    c1--;

    r2--;

    c2--;

    //reveal

    printf("    1 2 3 4\n");

   printf("");

    for (int i=0; i<=8; i++)

    {

        printf("-");

    }

    printf("");

    for (int r=0; r<4; r++)

    {

        printf("%d",r+1);

        for (int c=0; c<4; c++)

        {

            if ((r==r1)&&(c==c1))

            {

                printf("%d",cards[r][c]);

            }

            else if((r==r2)&&(c==c2))

            {

                printf("%d",cards[r][c]);

            }

            else

            {

                printf("*");

            }

        }

       printf("");

    }

    //match?

    if (cards[r1][c1]==cards[r2][c2])

    {

    }

    else

    {

    }

   

    printf("Enter 1 to play again. Enter 0 to quit: ");

    scanf("%d",&r1);

    if (r1 == 1)

    {

        system("CLS");

        goto loop;

    }

    return 0;

}

Add a comment
Know the answer?
Add Answer to:
Hi, I need help with my assignment. •Create a memory game in C •Function oriented with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have to create a game for my stats class and my card game is that...

    I have to create a game for my stats class and my card game is that each play, every player is given 4 cards and their goal is to match the suits. for every pair they win $2, for every 3 its $5, and for all four of the same suit its $10. What are the odds of winning 1 pair, 2 pairs, 3, and all 4? thank you :)

  • Need a blackjack code for my assignment its due in 3 hours: it has to include...

    Need a blackjack code for my assignment its due in 3 hours: it has to include classes and object C++. Create a fully functioning Blackjack game in three separate phases. A text based version with no graphics, a text based object oriented version and lastly an object oriented 2D graphical version. Credits (money) is kept track of throughout the game by placing a number next to the player name. Everything shown to the user will be in plain text. No...

  • Problem Develop a simple C++ memory puzzle game. The description of the game is as follows:...

    Problem Develop a simple C++ memory puzzle game. The description of the game is as follows: A board has 4 by 4 overturned cards. There is a pair for each card. The player flips over two cards. If they match, then they stay overturned. Otherwise they flip back after 3 seconds. The player needs to overturn all the cards in the fewest moves to win. This is a console game. Use the alphabetical letters from A to H as cards....

  • Problem Develop a simple C++ memory puzzle game. The description of the game is as follows: A board has 4 by 4 overturn...

    Problem Develop a simple C++ memory puzzle game. The description of the game is as follows: A board has 4 by 4 overturned cards. There is a pair for each card. The player flips over two cards. If they match, then they stay overturned. Otherwise they flip back after 3 seconds. The player needs to overturn all the cards in the fewest moves to win. This is a console game. Use the alphabetical letters from A to H as cards....

  • C++ Project - Create a memory game in c++ using structs and pointers. For this exercise,...

    C++ Project - Create a memory game in c++ using structs and pointers. For this exercise, you will create a simple version of the Memory Game. You will again be working with multiple functions and arrays. You will be using pointers for your arrays and you must use a struct to store the move and pass it to functions as needed. Program Design You may want to create two different 4x4 arrays. One to store the symbols the player is...

  • 1. create a class called MemoryBoard. a. MemoryBoard will represent a grid of memory squares. it...

    1. create a class called MemoryBoard. a. MemoryBoard will represent a grid of memory squares. it needs to track all of the squares on the board, the cars set it's using, the width and the height of the board, the number of turns that have been taken, and the current player's id. 2. create a arraylist to store the squares on the board. it should store Square objects. the class should also store the width(an int), the number of turns...

  • NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET...

    NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...

  • I need a basic program in C to modify my program with the following instructions: Create...

    I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...

  • Tic Tac Toe Game: Help, please. Design and implement a console based Tic Tac Toe game....

    Tic Tac Toe Game: Help, please. Design and implement a console based Tic Tac Toe game. The objective of this project is to demonstrate your understanding of various programming concepts including Object Oriented Programming (OOP) and design. Tic Tac Toe is a two player game. In your implementation one opponent will be a human player and the other a computer player. ? The game is played on a 3 x 3 game board. ? The first player is known as...

  • I need help with my programming assignment. The language used should be java and the algorithm...

    I need help with my programming assignment. The language used should be java and the algorithm should use search trees so that you play against the computer and he chooses the best move. The tree should have all possibilities on the leaves and you could use recursion to so that it populates itself. The game can be a 3*3 board (no need the make it n*n). Please put comments so that I can understand it. Thanks The game of ‘Walls’...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT