Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- int status[5][5], answer[4][4], c, x1, x2, y11, y2;
- char cover[5][5];
- void khoitao(void);
- void openPoint(int* , int*);
- void display(void);
- void kiemtra(void);
- /* Start CODE */
- int main(void){
- srand(time(0));
- khoitao();
- while(1){
- c= 0;
- display();
- openPoint(&x1, &x2);
- system ("cls");
- status[x1][x2]=1;
- display();
- openPoint(&y11, &y2);
- system ("cls");
- status[y11][y2]=1;
- display();
- kiemtra();
- /* Kiem tra Ket Thuc */
- int i, j;
- for (i=0; i<5; i++)
- for (j=0; j<5; j++)
- if (status[i][j]==0) c++;
- if (c==0) break;
- /* Exit? */
- char t;
- printf ("\n\t'x' de thoat: "); fflush(stdin); scanf ("%c", &t);
- if (t=='x' || t=='X') return 0;
- fflush(stdin);
- system("cls");
- }
- /* Chuc mung */
- printf ("\n\n\t\tCongratulation!\n\tBan da mo thanh cong het tat ca cac o!\n\n");
- getch();
- printf ("\n\n\tCam on da choi game, hen gap lai!\n");
- getch();
- return 0;
- }
- /* KET THUC CHUONG TRINH */
- // Khoi tao
- void khoitao(void){
- int ra[16], h=0, i, j;
- for (i=0; i<5; i++)
- for (j=0; j<5; j++){
- if (i==0 || j==0) {
- status[i][j]=1;
- if (i==0) cover[i][j]= (char) i;
- else if (j==0) cover[i][j]= (char) j;
- }
- else {
- status[i][j]= 0;
- cover[i][j]= '*';
- }
- }
- /* Tao bang ket qua*/
- ra[0]= (rand()%8)+1;
- for (i=1; i<16;){
- int x, t;
- t=0;
- x= rand()%8+1;
- for (j=0; j<i;j++){
- if (x==ra[j]) t++;
- }
- if (t<2){
- ra[i]=x;
- i++;
- }
- }
- for (i=0; i<4; i++){
- for (j=0; j<4; j++){
- answer[i][j]= ra[h];
- h++;
- }
- }
- /* END Tao bang ket qua*/
- }
- //End khoi tao
- // Chon diem
- void openPoint(int *x, int *y){
- int xa, ya, i, j;
- //x1=*x; y1= *y;
- loop:
- printf ("\nChon vi tri de mo (x, y): "); scanf ("%d%d", &xa, &ya);
- if (xa<1 || ya<1 || xa>4 || ya>4) {
- printf ("\nVi tri ban chon khong hop le, vui long chon lai.");
- getch();
- goto loop;
- }
- else{
- *x=xa; *y=ya;
- }
- }
- //End Chon Diem
- // Hien Thi
- void display(void){
- int i, j;
- /* Tao BANNER */
- printf ("\t\t\t \t\t\t\tcoder:NguyenMinhHieu\n\n\t\t ==Game OPEN THE SAME PAIR==\n\n");
- /* Het BANNER */
- for (i=0; i<5; i++)
- for (j=0; j<5; j++){
- if (i==0 || j==0) {
- status[i][j]=1;
- if (i==0) cover[i][j]= 'y';
- else if (j==0) cover[i][j]= 'x';
- }
- else {
- cover[i][j]= '*';
- }
- }
- cover[0][0]=2;
- printf ("\t");
- for (i=0; i<5; i++){
- for (j=0; j<5; j++){
- if (status[i][j]==1 && i!=0 && j!=0) cover[i][j]=answer[i-1][j-1]+48;
- printf ("\t%c", cover[i][j]);
- }
- printf ("\n\n\n\t");
- }
- }
- //End Hien thi
- //Kiem Tra
- void kiemtra(void){
- if (x1==y11 && x2==y2) printf ("\nBan da chon cung mot o!");
- else if (answer[x1-1][x2-1]!=answer[y11-1][y2-1])
- status[x1][x2]=status[y11][y2]=0;
- y11=y2=x1=x2=0;
- }
- //End Kiem Tra
- /* END */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement