Created
April 17, 2012 14:17
-
-
Save olalavui/2406228 to your computer and use it in GitHub Desktop.
C Source Code Logic Games. Read full: http://tutorial-share.com/c-source-code-logic-game/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <conio.h> | |
| #include <dos.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| #include<stdio.h> | |
| int day[7] = {-1,-1,-1,-1,-1,-1,-1}; | |
| int number_id[4]; | |
| int number_pc[4]; | |
| int number_test; | |
| int found_text; | |
| void load_logic_game() | |
| { | |
| char game_title[] = "L O G I C G A M E"; | |
| int j, i, destination; | |
| textmode(C40); | |
| clrscr(); | |
| textcolor(YELLOW); | |
| destination = (40 - strlen(game_title)) / 2; | |
| for (i=strlen(game_title)-1; i>=0; i--) | |
| { | |
| movetext(1,3,39,3,2,3); | |
| gotoxy(1,3); | |
| putch(game_title[i]); | |
| delay(40); | |
| } | |
| for (i=1; i<=destination; i++) | |
| { | |
| movetext(1,3,39,3,2,3); | |
| gotoxy(1,3); | |
| putch(' '); | |
| delay(40); | |
| } | |
| randomize(); | |
| for (i=0; i<4; i++) | |
| { | |
| do { | |
| j = random(6)+1; | |
| } while (day[j] != -1); | |
| day[j] = i; | |
| number_pc[i] = j; | |
| // printf ("%d",&j); | |
| } | |
| gotoxy(14,5); cprintf("ÉÍÍÍÍÍÍÑÍÍÍÍÍÍ»"); | |
| for (i=0; i<6; i++) | |
| { | |
| gotoxy(14,5+i*2+1); cprintf("º ³ º"); | |
| gotoxy(14,5+i*2+2); cprintf("ÇÄÄÄÄÄÄÅÄÄÄÄÄĶ"); | |
| } | |
| gotoxy(14,17); cprintf("ÈÍÍÍÍÍÍÏÍÍÍÍÍͼ"); | |
| number_test = 1; | |
| found_text = 0; | |
| textcolor(WHITE); | |
| gotoxy(1, 25); | |
| cprintf("Enter four different numbers from 1 to 6"); | |
| } | |
| void input_number() | |
| { | |
| char c; | |
| int i; | |
| for (i=0; i<4; i++) | |
| number_id[i]=0; | |
| gotoxy(16,5+number_test*2-1); | |
| do { | |
| c = getch(); | |
| switch(c) | |
| { | |
| case '1' : | |
| case '2' : | |
| case '3' : | |
| case '4' : | |
| case '5' : | |
| case '6' : textcolor(c-39); | |
| cprintf("%c",c); | |
| number_id[wherex()-16-1] = c - 48; | |
| if (wherex()==20) | |
| gotoxy(wherex()-1, wherey()); | |
| break; | |
| case 0 : | |
| c = getch(); | |
| switch(c) | |
| { | |
| case 75 : if (wherex()>16) | |
| gotoxy(wherex()-1,wherey()); | |
| break; | |
| case 77 : if (wherex()<19) | |
| gotoxy(wherex()+1,wherey()); | |
| break; | |
| } | |
| break; | |
| default : sound(880); | |
| delay(100); | |
| nosound(); | |
| } | |
| } while (!((c=='\r') && (number_id[0] != 0) && (number_id[1] != 0) | |
| && (number_id[2] != 0) && (number_id[3] != 0))); | |
| } | |
| void logic_test() | |
| { | |
| int diem = 0, i; | |
| for (i=0; i<4; i++) | |
| if (day[number_id[i]] != -1) | |
| if (day[number_id[i]] == i) | |
| diem += 10; | |
| else | |
| diem ++; | |
| if (diem==40) | |
| found_text=1; | |
| else | |
| { | |
| int sotrung, sotrat; | |
| sotrung=diem / 10; | |
| sotrat = diem % 10; | |
| textcolor(GREEN); | |
| gotoxy(23,5+number_test*2-1); | |
| for (i=1; i<=sotrung; i++) | |
| cprintf("+"); | |
| textcolor(WHITE); | |
| for (i=1; i<=sotrat; i++) | |
| cprintf("-"); | |
| number_test ++; | |
| } | |
| } | |
| void main() | |
| { | |
| int i; | |
| load_logic_game(); | |
| do { | |
| input_number(); | |
| logic_test(); | |
| } while ((number_test <= 6) && (found_text==0)); | |
| if (found_text==1) | |
| { | |
| textcolor(YELLOW+BLINK); | |
| gotoxy(1,23); | |
| cprintf("YOU WIN!!!"); | |
| } | |
| else | |
| { | |
| textcolor(GREEN+BLINK); | |
| gotoxy(1,23); | |
| cprintf("YOU LOSE!"); | |
| textcolor(YELLOW); | |
| } | |
| cprintf(" Result = "); | |
| for (i=0; i<4; i++) | |
| { | |
| textcolor(number_pc[i]+9+BLINK); | |
| cprintf("%c",number_pc[i]+48); | |
| } | |
| getch(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <conio.h> | |
| #include <dos.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| #include<stdio.h> | |
| int day[7] = {-1,-1,-1,-1,-1,-1,-1}; | |
| int number_id[4]; | |
| int number_pc[4]; | |
| int number_test; | |
| int found_text; | |
| void load_logic_game() | |
| { | |
| char game_title[] = "L O G I C G A M E"; | |
| int j, i, destination; | |
| textmode(C40); | |
| clrscr(); | |
| textcolor(YELLOW); | |
| destination = (40 - strlen(game_title)) / 2; | |
| for (i=strlen(game_title)-1; i>=0; i--) | |
| { | |
| movetext(1,3,39,3,2,3); | |
| gotoxy(1,3); | |
| putch(game_title[i]); | |
| delay(40); | |
| } | |
| for (i=1; i<=destination; i++) | |
| { | |
| movetext(1,3,39,3,2,3); | |
| gotoxy(1,3); | |
| putch(' '); | |
| delay(40); | |
| } | |
| randomize(); | |
| for (i=0; i<4; i++) | |
| { | |
| do { | |
| j = random(6)+1; | |
| } while (day[j] != -1); | |
| day[j] = i; | |
| number_pc[i] = j; | |
| // printf ("%d",&j); | |
| } | |
| gotoxy(14,5); cprintf("ÉÍÍÍÍÍÍÑÍÍÍÍÍÍ»"); | |
| for (i=0; i<6; i++) | |
| { | |
| gotoxy(14,5+i*2+1); cprintf("º ³ º"); | |
| gotoxy(14,5+i*2+2); cprintf("ÇÄÄÄÄÄÄÅÄÄÄÄÄĶ"); | |
| } | |
| gotoxy(14,17); cprintf("ÈÍÍÍÍÍÍÏÍÍÍÍÍͼ"); | |
| number_test = 1; | |
| found_text = 0; | |
| textcolor(WHITE); | |
| gotoxy(1, 25); | |
| cprintf("Enter four different numbers from 1 to 6"); | |
| } | |
| void input_number() | |
| { | |
| char c; | |
| int i; | |
| for (i=0; i<4; i++) | |
| number_id[i]=0; | |
| gotoxy(16,5+number_test*2-1); | |
| do { | |
| c = getch(); | |
| switch(c) | |
| { | |
| case '1' : | |
| case '2' : | |
| case '3' : | |
| case '4' : | |
| case '5' : | |
| case '6' : textcolor(c-39); | |
| cprintf("%c",c); | |
| number_id[wherex()-16-1] = c - 48; | |
| if (wherex()==20) | |
| gotoxy(wherex()-1, wherey()); | |
| break; | |
| case 0 : | |
| c = getch(); | |
| switch(c) | |
| { | |
| case 75 : if (wherex()>16) | |
| gotoxy(wherex()-1,wherey()); | |
| break; | |
| case 77 : if (wherex()<19) | |
| gotoxy(wherex()+1,wherey()); | |
| break; | |
| } | |
| break; | |
| default : sound(880); | |
| delay(100); | |
| nosound(); | |
| } | |
| } while (!((c=='\r') && (number_id[0] != 0) && (number_id[1] != 0) | |
| && (number_id[2] != 0) && (number_id[3] != 0))); | |
| } | |
| void logic_test() | |
| { | |
| int diem = 0, i; | |
| for (i=0; i<4; i++) | |
| if (day[number_id[i]] != -1) | |
| if (day[number_id[i]] == i) | |
| diem += 10; | |
| else | |
| diem ++; | |
| if (diem==40) | |
| found_text=1; | |
| else | |
| { | |
| int sotrung, sotrat; | |
| sotrung=diem / 10; | |
| sotrat = diem % 10; | |
| textcolor(GREEN); | |
| gotoxy(23,5+number_test*2-1); | |
| for (i=1; i<=sotrung; i++) | |
| cprintf("+"); | |
| textcolor(WHITE); | |
| for (i=1; i<=sotrat; i++) | |
| cprintf("-"); | |
| number_test ++; | |
| } | |
| } | |
| void main() | |
| { | |
| int i; | |
| load_logic_game(); | |
| do { | |
| input_number(); | |
| logic_test(); | |
| } while ((number_test <= 6) && (found_text==0)); | |
| if (found_text==1) | |
| { | |
| textcolor(YELLOW+BLINK); | |
| gotoxy(1,23); | |
| cprintf("YOU WIN!!!"); | |
| } | |
| else | |
| { | |
| textcolor(GREEN+BLINK); | |
| gotoxy(1,23); | |
| cprintf("YOU LOSE!"); | |
| textcolor(YELLOW); | |
| } | |
| cprintf(" Result = "); | |
| for (i=0; i<4; i++) | |
| { | |
| textcolor(number_pc[i]+9+BLINK); | |
| cprintf("%c",number_pc[i]+48); | |
| } | |
| getch(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment