Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h> //random
- #include <string.h> // char commands
- #include <windows.h> //for colors [works only on windows]
- #define LIVES 11
- //functionnal wihtout the feature to check letters that have been guessed.
- //remove comment at line 90 to add feature but break when mistakes are done.
- //normal difficulty does not work because it doesn't attribute the last few characters when the word is from 5 to 10 characters
- // prototypes
- void play(char *word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount);
- void generate(char *word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount);
- void difficulty(char *word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount);
- //
- void play(char *word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount)
- {
- chainlength = strlen(word); //takes value of length of word
- char wordend[chainlength];
- fchoice = 3;
- char wordtemp[15] = "_______________";
- for(i = 0; i <= chainlength; i++)
- {
- wordend[i] = wordtemp[i];
- }
- char *check = word;
- char *checkend = wordend;
- char *letterguessed = wordend;
- unsigned int checkcounter = 0;
- system("PAUSE");
- system("cls");
- while(strcmp(word,wordend) != 0) //compares word with word end and returns 0 if they're equal
- {
- loop:
- if(life < 1)
- {
- if(wincount > 0)
- wincount = 0;
- if(wincount <= 0)
- wincount = wincount-1;
- color = 14;
- SetConsoleTextAttribute(hConsole, color);
- printf("\n\n\t\t\t\t\tWin count: ");
- color = 12;
- SetConsoleTextAttribute(hConsole, color);
- printf("%d\n", wincount);
- color = 15;
- SetConsoleTextAttribute(hConsole, color);
- do{
- printf("\n\t\t\tYou lost.\n\n\tThe word was %s.\n\n\tBetter luck next time!\n\n", word);
- system("PAUSE");
- printf("Would you like to play again?\n\n1 - Yes\n\n 2 - No");
- scanf("%d",&fchoice);
- }while(fchoice < 1 || fchoice > 2);
- if(fchoice == 1)
- difficulty(word, easy, normal, hard, fchoice, i, random, chainlength, letter, life, color, hConsole, wincount/*, Varirables*/);
- if(fchoice == 2)
- exit(0);
- }
- color = 14;
- SetConsoleTextAttribute(hConsole, color);
- printf("\t\tCurrent lives left: ");
- color = 12;
- SetConsoleTextAttribute(hConsole, color);
- printf("%d\n", life);
- color = 14;
- SetConsoleTextAttribute(hConsole, color);
- printf("\n\n\t\t\t\t\tWin count: ");
- color = 12;
- SetConsoleTextAttribute(hConsole, color);
- printf("%d\n", wincount);
- color = 14;
- SetConsoleTextAttribute(hConsole, color);
- printf("\n\nInput \" . \"to see previous letters that were decided.\t [COSTS A LIFE]\n\n");
- color = 15;
- SetConsoleTextAttribute(hConsole, color);
- printf(" %s\t", wordend);
- //printf("The word is %s\n\n", word);
- printf("\nGuess a letter.\n\n");
- scanf(" %c", &*letter);
- if(*letter == '.')
- {
- checkcounter++;
- life--;
- printf("Letters guessed:");
- for(i = LIVES; i > life+checkcounter; i--)
- {
- printf(" %c ", letterguessed[i]);
- }
- printf("\n\n\n");
- system("PAUSE");
- system("cls");
- goto loop;
- }
- check = word;
- for(i = 0; i < chainlength; i++)
- {
- if(strchr(check, *letter))
- {
- //printf(" %c at position %d", *letter, i+1);
- if(word[i] == *letter)
- {
- printf(" _%c_\t", *letter);
- wordend[i] = *letter;
- }
- }
- if(word[i] != *letter)
- printf("__\t");
- }
- if(!strchr(check, *letter))
- {
- //letterguessed[life] = *letter; //LINE THAT BREAKS HARD DIFFICTULY BUT MAKES THE REMIND CHECK WORK
- life--;
- }
- printf("\n\n");
- system("PAUSE");
- system("cls");
- }
- if(wincount > 0)
- wincount = wincount+1;
- if(wincount <= 0)
- wincount = 1;
- color = 14;
- SetConsoleTextAttribute(hConsole, color);
- printf("\n\n\t\t\t\t\tWin count: ");
- color = 12;
- SetConsoleTextAttribute(hConsole, color);
- printf("%d\n", wincount);
- color = 15;
- SetConsoleTextAttribute(hConsole, color);
- do{
- printf("Congratulation! You have found the word.\n\nWould you like to play again?\n\n1 - Yes\n\n 2 - No");
- system("PAUSE");
- scanf("%d",&fchoice);
- }while(fchoice < 1 || fchoice > 2);
- if(fchoice == 1)
- difficulty(word, easy, normal, hard, fchoice, i, random, chainlength, letter, life, color, hConsole, wincount/*, Varirables*/);
- if(fchoice == 2)
- exit(0);
- //printf("The word is %s\n\n", word);1
- system("PAUSE");
- }
- void generate(char *word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount)
- {
- random = rand()%9;
- if (fchoice == 1)
- strcpy(word, easy[random]);
- if (fchoice == 2)
- strcpy(word, normal[random]);
- if (fchoice == 3)
- strcpy(word, hard[random]);
- play(word, easy, normal, hard, fchoice, i, random, chainlength, letter, life, color, hConsole, wincount/*, Varirables*/);
- }
- void difficulty(char* word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount)
- {
- life = LIVES;
- do{
- printf("Select the difficulty.\n1 = Easy\n2 = Normal\n3 = Hard\n\n");
- scanf("%d", &fchoice);
- if(fchoice < 1 || fchoice > 3)
- {
- printf("%d is not a valid choice. Please select a number beetween 1 and 3.\n", fchoice);
- }
- }while(fchoice < 1 || fchoice > 3);
- generate(word, easy, normal, hard, fchoice, i, random, chainlength, letter, life, color, hConsole, wincount/*, Varirables*/);
- }
- int main()
- {
- srand(time(NULL));
- char word[15];
- unsigned int chainlength = 0;
- unsigned int life = LIVES;
- char* easy[9];
- easy[0] = "dog";
- easy[1] = "cat";
- easy[2] = "pat";
- easy[3] = "eye";
- easy[4] = "pie";
- easy[5] = "tie";
- easy[6] = "sigh";
- easy[7] = "cry";
- easy[8] = "love";
- easy[9] = "chick";
- char* normal[9];
- normal[0] = "figure";
- normal[1] = "window";
- normal[2] = "shadow";
- normal[3] = "output";
- normal[4] = "rewinding";
- normal[5] = "sorrow";
- normal[6] = "capture";
- normal[7] = "adventure";
- normal[8] = "magician";
- normal[9] = "earlier";
- char* hard[9];
- hard[0] = "unrelatable"; //glitches
- hard[1] = "constitution"; //glitches
- hard[2] = "scientifique"; //glitches
- hard[3] = "unbelievable";// glitches
- hard[5] = "microbiology";
- hard[4] = "optimizable";
- hard[6] = "irresponsible";
- hard[7] = "unstoppable";
- hard[8] = "fundementally";
- hard[9] = "loathfull";
- unsigned int fchoice = 0;
- unsigned int random = 0;
- unsigned int i = 0;
- HANDLE hConsole;
- hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- int color = 0;
- char letter[] = "a";
- int wincount = 0;
- difficulty(word, easy, normal, hard, fchoice, i, random, chainlength, letter, life, color, hConsole, wincount/*, Varirables*/);
- fflush(stdin); // option ONE to clean stdin
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement