728x90 AdSpace

Trending

XO Game




we can get Scan codes of key boards keys by this code.

1.     ch=getch();
2.      if (ch == 0)
3.         ch=getch();
4.       printf("%d",ch);

because when first time getch() is called ,it will return the ascii code of the pressing key .when second time
it called then it will return the scan code of that pressing key .so when we want to control our
program with arrow keys ,there ascii codes are 0 but scan codes are different.
                      
   Out of 256 character set 128 are called ASCII characters and  128 as Extended ASCII characters.

                               Out of 128 Extended characters few are used for drawing single , double lines and even for drawing boxes.



















'C' Code snippet to draw box .
/*
 main structure of a XO game (BOX)
 date : 26/02/2013
 */
#include</stdio.h>
#include<conio.h>

#define HORIZONTAL 196
#define VERTICAL 179
#define RIGHTUP 218
#define RIGHTDOWN 192
#define LEFTUP 191
#define LEFTDOWN 217
#define PLUS 197
#define TOPPLUS 194
#define DOWNPLUS 193
#define RIGHTPLUS 195
#define LEFTPLUS 180
#define TOPRIGHT 169
#define TOPLEFT 191
#define DOWNRIGHT 192
#define DOWNLEFT 217
int main()
{
box();
getch();
}
int box()
{
 int i;/*looping purpose*/
 int j;
 int num1;
 int num2;
 printf("\n\tENTER ROWS : ");
 scanf("%d",&num1);
 printf("\n\tENTER COLOUMS : ");
 scanf("%d",&num2);
 clrscr();
 num1=2+num1*3+1;    /*boxs start printing from 10,10 point*/     /*CONVERTING IN TO CORDINATES */
 num2=2+num2*2+1;
 textcolor(8);
 gotoxy(2+2,2);           /* CORNERS OF BOX */
 printf("%c",PLUS);
 gotoxy(num1,2);
 printf("%c",TOPLEFT);
 gotoxy(2+2,num2-1);
 printf("%c",DOWNRIGHT);
 gotoxy(num1,num2-1);
 printf("%c",DOWNLEFT);
 for(j=2;j<num2;j+=2)
 {
  for(i=2;i<num1;i+=3)
 {      textcolor(1);
 /* BOUNDARY CONDITION TOP DOWN AND LINES */
if((i>2  && i<=num1-1 ) )
{
gotoxy(i+2,j);
if(j==2 && i!=num1)
{ printf("%c",TOPPLUS);  }
if(j==num2 && i!=num1)
printf("%c",DOWNPLUS);
gotoxy(i,j);
printf("%c",HORIZONTAL);   gotoxy(i+1,j);printf("%c",HORIZONTAL);
gotoxy(i+2,j+1);  textcolor(8);
if(j+1!=num2 )
printf("%c",VERTICAL);
gotoxy(i+2,j+2);
if(j+1!=num2 && i!=num1)
printf("%c",PLUS);
}
 /* BOUNDARY CONDITION RIGHT LEFT AND LINES */
 if(i>=2 || i<=num1)
 {
gotoxy(i+2,j);
if(i==2 && j!=2 && j!=num2-1)
printf("%c",RIGHTPLUS);      textcolor(8);
if(i==num1 && j!=2 && j!=num1)
printf("%c",LEFTPLUS);
gotoxy(i+2,j+1);
if(j+1!=num2)
printf("%c",VERTICAL);
 }
  }
}
}

Try this









XO Game Reviewed by Unknown on 11:52 Rating: 5 we can get Scan codes of key boards keys by this code. 1.     ch=getch(); 2.      if (ch == 0) 3.         ch=getch(); 4.   ...

1 comment:

  1. thanq so much,....i always mess up with the ASCII stuff...this blog is quiet useful

    ReplyDelete