Missing multiple labeled functions. Card matching game in C. Shouldn't need any more functions. I am lost on how to complete the main function (play_card_match) without the sub functions complete. The program runs fine as is, but does not actually have a working turn system. It should display question marks on unflipped cards when the player is taking a turn and should also clear the screen so the player can't scroll up to cheat. Thank you
#include "cardMatch.h"
//main function
/*
-asks for player name
-asks player to choose difficulty
-opens the associated card table file
-reads in the turns to be played
-reads in the card table state
-closes the card table file
-lets the player take turns
-stops when all cards are flipped or turns run
out
-calculates player's score
-prints out the game end state results to properly
named file
-asks player if they want to play again. Ask for
difficulty again if player wants to play again
*/
void play_card_match(void) {
char playerName[255];
char cardTable[B_SIZE][B_SIZE] = { 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
char flippedCards[B_SIZE][B_SIZE] = { 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int difficulty, turns_left;
player_name(playerName);
char replay, game_in_progress = 1;
while (game_in_progress) {
difficulty = game_choice();
FILE* infile = open_game_file(difficulty);
turns_left = get_turns(infile);
build_table(cardTable, infile);
close_game_file(infile);
//player's turn
do {
printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("++ You are playing a game of Card Matching!
Turns Left: %d ++\n", turns_left--);
printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n");
player_turn(flippedCards, cardTable);
} while (!game_finished(flippedCards));
//todo: calculate score
//todo: save game data to a file named
"+playername+gamesplayed".txt
printf("\nWould you like to play again? (Y/N):
");
replay = _getch();
printf("%c\n", replay);
if (replay == 'n' || replay == 'N') {
printf("\nThank you for playing!\n");
game_in_progress = 0;
}
}
printf("Press any key to exit:");
getch();
}
//prints current board
void print_table(bool flippedCards[B_SIZE][B_SIZE],
char cardTable[B_SIZE][B_SIZE]) {
}
//asks for difficulty input 1-4, 4 being a random
choice of 1-3
int game_choice(void) {
int difficulty = 0;
printf("Choose difficulty level:\nEnter 1 For Easy, 2
For Medium, 3 For Hard, 4 For Random:");
difficulty = _getch();
printf("%c\n", difficulty);
difficulty = char_to_integer(difficulty);
if (difficulty == 4) {
difficulty = random_number(1, 3);
};
return difficulty;
}
//opens board based on game_choice difficulty
selection
FILE* open_game_file(int difficulty) {
char filename[] = "./MatchCardFiles/00.txt";
FILE* infile = NULL;
int num = random_number(0, 9);
filename[17] = integer_to_char(difficulty);
filename[18] = integer_to_char(num);
infile = fopen(filename, "r");
return infile;
}
//closes the opened board file
void close_game_file(FILE* infile) {
fclose(infile);
return;
}
//converts char to int
int char_to_integer(char character) {
int value = 48;
value = character - value;
return value;
}
//converts int to char
char integer_to_char(int number) {
char letter = 48;
letter = letter + number;
return letter;
}
//reads turns from MatchCardFiles folder and
returns as an integer
int get_turns(FILE* infile) {
int turns;
fscanf(infile, "%d\n", &turns);
return turns;
}
//gets player name
void player_name(char playerName[]) {
printf("Please enter player name: \n");
scanf("%c", &playerName);
}
//reads data from file to fill board
array
void build_table(char cardTable[B_SIZE][B_SIZE], FILE*
infile) {
cardTable[0][0] = 'A';
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
fscanf(infile, "%c", &cardTable[i][j]);
}
fscanf(infile, "\n");
}
}
/*
gets input from user in xy form
| 00 | 01 | 02 | 03 |
| 10 | 11 | 12 | 13 |
| 20 | 21 | 22 | 23 |
| 30 | 31 | 32 | 33 |
*/
int player_turn(bool flippedCards[B_SIZE][B_SIZE],
char cardTable[B_SIZE][B_SIZE]) {
int x1, y1, x2, y2;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("%c", cardTable[i][j]);
}
printf("\n");
}
printf("Please choose a card to flip:");
y1 = _getche();
x1 = _getche();
y1 = char_to_integer(y1);
x1 = char_to_integer(x1);
printf("\n You flipped over the %c card.",
cardTable[y1][x1]);
printf("\nWhich card will you flip next:");
y2 = _getche();
x2 = _getche();
y2 = char_to_integer(y2);
x2 = char_to_integer(x2);
printf("\nYou flipped over the %c card.",
cardTable[y2][x2]);
return 0;
}
//calculates score based on flipped cards,
difficulty, and turns
//Score = #flippedcards*difficulty +
turns*difficulty
int get_score(bool flippedCards[B_SIZE][B_SIZE], int
difficulty, int turns) {
}
//returns 0 if there are more cards to flip,
returns 1 if all cards are matched
int game_finished(bool flippedCards[B_SIZE][B_SIZE])
{
}
void clear_screen(void) {
system("cls");
}
void clear_board(char cardTable[B_SIZE][B_SIZE], bool
flippedCards[B_SIZE][B_SIZE]) {
}
void print_game_end_state(char playerName[], int
difficulty, int score, int turns, int gamesPlayed, char
cardTable[B_SIZE][B_SIZE], bool flippedCards[B_SIZE][B_SIZE])
{
if (playerName == 2) {
printf("Player %c Won: Play again? Enter 1 to continue
or 2 to quit\n", &playerName);
scanf("%d");
}
else {
printf("Player %c has Lost: Play again? Enter 1 To
continue or 2 to quit", &playerName);
scanf("%d");
}
return 0;
}
int random_number(int range_min, int range_max)
{
return (int)(rand() % (range_max - range_min +
1));
}
Code implemented in C
Note: Comments are written for code explanation
Filename: main.c
#include "cardMatch.h"
int main(void) {
play_card_match();
return 0;
}
Filename: cardMatch.c
#include "cardMatch.h"
void play_card_match(void) {
char playerName[255];
char cardTable[B_SIZE][B_SIZE] = { 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
char flippedCards[B_SIZE][B_SIZE] = { 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int difficulty, turns_left;
player_name(playerName);
char replay, game_in_progress = 1;
while (game_in_progress) {
difficulty = game_choice();
FILE* infile = open_game_file(difficulty);
turns_left = get_turns(infile);
build_table(cardTable, infile);
close_game_file(infile);
// let's player take turns
do {
printf("**************************************************************\n");
printf("** You
are playing a game of Card Matching! Turns Left: %d **\n",
turns_left--);
printf("**************************************************************\n");
player_turn(flippedCards, cardTable);
} while
(!game_finished(flippedCards));
// player_turn function stops the
game
// calculates player score
// save the game over data to a file named print_game_end_state
printf("\nWould you like to play
again? (Y/N): ");
replay = _getch();
printf("%c\n", replay);
if (replay == 'n' || replay == 'N')
{
printf("\n\nThank-you for playing the card game!\n");
game_in_progress
= 0;
};
};
printf("Press any key to exit...");
getch();
}
void print_table(bool flippedCards[B_SIZE][B_SIZE], char cardTable[B_SIZE][B_SIZE]) {
}
int game_choice(void) {
int difficulty = 0;
printf("What Difficulty Would You Like to
Play?\nEnter 1 For Easy | 2 For Medium | 3 For Hard | 4 For Random:
");
difficulty = _getch();
printf("%c\n", difficulty);
difficulty = char_to_integer(difficulty);
if (4 == difficulty) {
difficulty =
random_number_generator(1, 3);
};
return difficulty;
}
int random_number_generator(int range_min, int range_max)
{
return (int)(rand() % (range_max - range_min +
1));
}
FILE* open_game_file(int difficulty) {
char filename[] = "./MatchCardFiles/00.txt";
FILE* infile = NULL;
int num = random_number_generator(0, 9);
filename[17] = integer_to_char(difficulty);
filename[18] = integer_to_char(num);
infile = fopen(filename, "r");
return infile;
}
void close_game_file(FILE* infile) {
// TODO: CLose the file handle `infile`.
fclose(infile);
return;
}
int char_to_integer(char character) {
int value = 48;
value = character - value;
return value;
}
char integer_to_char(int number) {
char letter = 48;
letter = letter + number;
return letter;
}
int get_turns(FILE* infile) {
int turns;
fscanf(infile, "%d\n", &turns);
return turns;
}
void player_name(char playerName[]) {
printf("Please Enter Player Name \n");
scanf("%c", &playerName);
}
// Scans the current board state
// Grid position #'s were added for user ease during their
turn.
void build_table(char cardTable[B_SIZE][B_SIZE], FILE* infile)
{
cardTable[0][0] = 'A';
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 4;
col++) {
fscanf(infile,
"%c", &cardTable[row][col]);
}
fscanf(infile, "\n");
}
}
int player_turn(bool flippedCards[B_SIZE][B_SIZE], char
cardTable[B_SIZE][B_SIZE]) {
int x1, y1, x2, y2;
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 4;
col++) {
printf("%c",
cardTable[row][col]);
}
printf("\n");
}
printf("Which card will you flip first: ");
y1 = _getche();
x1 = _getche();
y1 = char_to_integer(y1);
x1 = char_to_integer(x1);
printf("\n You flipped over the %c card.",
cardTable[y1][x1]);
printf("\nWhich card will you flip next: ");
y2 = _getche();
x2 = _getche();
y2 = char_to_integer(y2);
x2 = char_to_integer(x2);
printf("\n You flipped over the %c card.",
cardTable[y2][x2]);
return 0;
}
int get_score(bool flippedCards[B_SIZE][B_SIZE], int difficulty,
int turns) {
}
// Returns 0 if the game is NOT finished
// Returns 1 if the game IS finished and done
int game_finished(bool flippedCards[B_SIZE][B_SIZE]) {
return 0;
}
void clear_screen(void) {
}
void clear_board(char cardTable[B_SIZE][B_SIZE], bool flippedCards[B_SIZE][B_SIZE]) {
}
void print_game_end_state(char playerName[], int difficulty, int score, int turns, int gamesPlayed, char cardTable[B_SIZE][B_SIZE], bool flippedCards[B_SIZE][B_SIZE]) {
if (playerName == 2) {
printf("Player %c Won : Play Again?
Enter 1 To Continue or 2 to Quit\n", &playerName);
scanf("%d");
}
else {
printf("Player %c has Lost : Play
Again? Enter 1 To Continue or 2 to Quit", &playerName);
scanf("%d");
}
return 0;
}
Filename: cardMatch.h
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define B_SIZE 4
void print_table(bool flippedCards[B_SIZE][B_SIZE], char
cardTable[B_SIZE][B_SIZE]);
int game_choice(void);
int random_number_generator(int range_min, int range_max);
FILE* open_game_file(int difficulty);
void close_game_file(FILE* infile);
char integer_to_char(int number);
int get_turns(FILE* infile);
void player_name(char playerName[]);
void build_table(char cardTable[B_SIZE][B_SIZE], FILE*
infile);
int player_turn(bool flippedCards[B_SIZE][B_SIZE], char
cardTable[B_SIZE][B_SIZE]);
int get_score(bool flippedCards[B_SIZE][B_SIZE], int difficulty,
int turns);
int game_finished(bool flippedCards[B_SIZE][B_SIZE]);
void clear_screen(void);
void clear_board(char cardTable[B_SIZE][B_SIZE], bool
flippedCards[B_SIZE][B_SIZE]);
void print_game_end_state(char playerName[], int difficulty, int
score, int turns, int gamesPlayed, char cardTable[B_SIZE][B_SIZE],
bool flippedCards[B_SIZE][B_SIZE]);
If you like my answer, hit thumbs up. Thank you
Missing multiple labeled functions. Card matching game in C. Shouldn't need any more functions. I am...
Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...
please complete the missing function only to figure out how many numbers fall within the range of 90 through 99 total of 29 values in C 6 finclude "lab5.h" 8 const char *FILENAME() - / array of the data file names * ("lab5a.dat", "lab5b.dat", NULL); 12 int main(void) 13 int file count = 0; keeps track of which file we are on/ int check overflow - 0; / counter to prevent array overflow int real filesize = 0; /actual count...
Hi there! I need to fix the errors that this code is giving me and also I neet to make it look better. thank you! #include <iostream> #include <windows.h> #include <ctime> #include <cstdio> #include <fstream> // file stream #include <string> #include <cstring> using namespace std; const int N=10000; int *freq =new int [N]; int *duration=new int [N]; char const*filename="filename.txt"; int songLength(140); char MENU(); // SHOWS USER CHOICE void execute(const char command); void About(); void Save( int freq[],int duration[],int songLength); void...
Please help in C: with the following code, i am getting a random 127 printed in front of my reverse display of the array. The file i am pulling (data.txt) is: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 when the reverse prints, it prints: 127 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 not sure why...please...
-I need to write a program in C to store a list of names (the last name first) and age in parallel arrays , and then later to sort them into alphabetical order, keeping the age with the correct names. - Could you please fix this program for me! #include <stdio.h> #include <stdlib.h> #include <string.h> void data_sort(char name[100],int age[100],int size){ int i = 0; while (i < size){ int j = i+1; while (j < size){...
Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...
Need help with shuffle function and give 8 cards to user and computer from shuffle deck? #include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> typedef struct card_s{ char suit; int face; struct card_s *listp; } card; void card_create(card* thisNode, char cardSuit, int cardFace, card* nextLoc) { thisNode->suit = cardSuit; thisNode->face = cardFace; thisNode->listp = nextLoc; return; } void card_insertAfter(card* thisNode, card* newNode) { card* tmpNext = NULL; ...
I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves the array of structures to file. It is already implemented for you. // You should understand how this code works so that you know how to use it for future assignments. void save(char* fileName) { FILE* file; int i; file = fopen(fileName, "wb"); fwrite(&count, sizeof(count), 1, file); for (i = 0; i < count; i++) { fwrite(list[i].name, sizeof(list[i].name), 1, file); fwrite(list[i].class_standing, sizeof(list[i].class_standing), 1, file);...
package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...
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...