1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#include <stdio.h>
#include <iostream>
#include <windows.h>
void main()
{
int num[4][4]={1,2,3,4,1,2,3,4,5,6,7,8,5,6,7,8};
int row,col;
int x,y,i,k;
system("cls");
printf("Welcome Player2 !");
printf("\n\n");
printf("**************************************************************************\n");
printf("GUESS THE TWO LOCATION OF A NUMBER GAME<guess the number behind the zero:>\n");
printf("**************************************************************************\n");
for(row=0;row<4;row++)
{
for(col=0;col<4;col++)
{
printf("0\t");
}
printf("\n");
}
printf("\n\n");
do
{
do
{
flushall();
printf("Which array would you like to open:<e.g: 1 1>: ");
scanf("%d%d",&x,&y);
if(x>4 || y>4 || x<1 || y<1)
{
printf("\nInvalid position please retry\n\n");
}
}
while(x>4 || y>4 || x<1 || y<1);
system("cls");
for(row=0;row<4;row++)
{
for(col=0;col<4;col++)
{
if(row == x-1 && col == y-1)
{
printf("%d\t",num[x-1][y-1]);
}
else
{
printf("%d\t",0);
}
}
printf("\n");
}
do
{
printf("Which 2nd array would you like to guess as a match: ");
scanf("%d%d",&i,&k);
if(i>4 || k>4 || i<1 || k<1)
{
printf("\nInvalid position please retry");
}
else if(i==x && k==y)
{
printf("\nYou already guess this postion please reselect second position");
}
flushall();
printf("\n\n");
}
while(i>4 || k>4 || i<1 || k<1 || i ==x && k==y);
for(row=0;row<4;row++)
{
for(col=0;col<4;col++)
{
if(row == i-1 && col == k-1)
{
printf("%d\t",num[i-1][k-1]);
}
else if(row == x-1 && col == y-1)
{
printf("%d\t",num[x-1][y-1]);
}
else
{
printf("0\t");
}
}
printf("\n");
}
if(num[i-1][k-1] != num[x-1][y-1])
{
Sleep(1000);
system("cls");
for(row=0;row<4;row++)
{
for(col=0;col<4;col++)
{
printf("0\t");
}
printf("\n");
}
}
}
while(num[i-1][k-1] != num[x-1][y-1]);
printf("\n\n");
}
|