Skip to content

Instantly share code, notes, and snippets.

@H4niz
Created March 20, 2018 18:02
Show Gist options
  • Save H4niz/6914f06c20f1a2bd848e08119a0ede8c to your computer and use it in GitHub Desktop.
Save H4niz/6914f06c20f1a2bd848e08119a0ede8c to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
/*Prototype*/
void PlayAgain();
/*---------*/
int MagicNumber[4], \
InputNumber[4];
char inp;
/*Return the Answer*/
void ShowMagicNumber() {
printf("\n\t\t%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", \
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205);
printf("\n\n%c The MagicNumber is: ", 206);
for(int i = 0; i < 4; i++ ) {
printf("%d", MagicNumber[i]);
}
}
/*CheckResult*/
void CheckResult() {
int count = 0, x=0, /*x is correct number and position*/\
p = 0;
int MNumber[4];
for(int i = 0; i < 4; i++) {
MNumber[i] = MagicNumber[i]; //Make clone
}
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
if( InputNumber[j] == MNumber[i] && j == i) {
x++;
InputNumber[j] = -1; //Used
MNumber[i] = -2;
count++;
}
}
}
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
if ( InputNumber[j] == MNumber[i] ) {
p++;
InputNumber[j] = -1; //Used
MNumber[i] = -2;
}
}
}
/*Print hint*/
for(int a = 0; a < x; a++) {
printf("%c", 254);
}
for(int b = 0; b < p; b++) {
printf("%c", 155);
}
if(count == 4) {
Win();
}
count = 0;
x = 0;
p = 0;
}
/*YouWin*/
void Win() {
char Sentences[4][1024] = {0};
strcpy( Sentences[0], "\n\nYou do very good!");
strcpy( Sentences[1], "\n\nYou bet!");
strcpy( Sentences[2], "\n\nYou are so inteligent!");
strcpy( Sentences[3], "\n\nYou are handsome!");
printf("\n § § § YOU WON § § § \n");
printf("%s", Sentences[rand()%4]);
/*Show MagicNumber*/
ShowMagicNumber();
/*Ask to play again*/
PlayAgain();
}
void Lose() {
char Sentencese[4][1024] = {0};
strcpy( Sentencese[0], "\n\nYou are the Vietnamese bug!");
strcpy( Sentencese[1], "\n\nYou are shit!");
strcpy( Sentencese[2], "\n\nYou are buttass!");
strcpy( Sentencese[3], "\n\nYou are OCSCHOS!");
printf("%s", Sentencese[rand()%4]);
/*Show MagicNumber*/
ShowMagicNumber();
/*Ask to play again*/
PlayAgain();
}
/*Show the game rules*/
void Rule() {
printf("\t\t\t\t %c RULES %c \n", 175, 174);
printf("\nYou can guess 4 times with 4 number per time.");
printf("\nIf you have a correct char and its position, I will show you \"%c\"", 254);
printf("\nIf you have a correct char and its position is NOT CORRECT, I will show you \"%c\"", 155);
printf("\nIf there are no char correct, I will show nothing!");
printf("\nAnd the LAST ONE I always TRUE!\n\n");
}
/*GetInputPlayerNumber*/
void GetPlayerInput() {
int buf;
printf("\nGive me your number? \(Ex: 6996\): ");
scanf("%d", &buf);
InputNumber[3] = buf%10;
buf /= 10;
InputNumber[2] = buf%10;
buf /= 10;
InputNumber[1] = buf%10;
InputNumber[0] = buf/10;
// for(int i = 3; i >= 0; i--) {
// printf("\nNumber %d: %d", i, InputNumber[i]);
// }
}
/*GenerateMagicNumber*/
void GenMagicNumber() {
srand( time(0) );
for(int i = 0; i < 4; i++) {
MagicNumber[i] = rand()%6+1;
}
}
/*Welcome to the game*/
void EnterGame() {
printf("\n\t\t%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 201, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 187);
printf("\n\t\t\t\t%c Welcome %c", 175, 174);
printf("\n\t\t%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 200, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 188);
}
int main() {
int time = 0, status = 1;
system("cls");
/*Show Rule*/
Rule();
/*Enter the game*/
EnterGame();
/*Generate Magic number to guess*/
GenMagicNumber();
// ShowMagicNumber();
while(time < 6 && status ) {
printf("\n\nTime: [%d]\n", time);
/*Get number from player and handle*/
GetPlayerInput();
/*Check*/
CheckResult();
/*Increasing time*/
if (time++ == 5) {
/*Lose*/
Lose();
}
}
return 0;
}
/*PlayAgain*/
void PlayAgain() {
printf("\nDo you wanna fuck me again?\(1/0\)");
fflush(stdin);
scanf("%d", &inp);
if(inp) {
system("cls");
return main();
}
else {
exit(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment