Magic Game in C language

Select Any number from 1 to 60 in your mind and Computer will tell you which number you have selected.
Download this Cool game with source code and implement it.


After receiving many emails, finally i am writing the full steps that how to create and deploy simple graphical games in c language.
This tutorial will help to those who are learning C language and want to develope some Graphical Application.


Game: This is simple game which will tell the user that which number is in his Mind.

User Inputs: User just presses 'Y' only if the number which is in his mind is present in the list or not.
Logic: Adjusted the number between 1 to 60 in 6 different sheets. That if the number is presented in the list.
If number is presented in the sheet then the upper left number is added with previous one.

Code:
/*==================================================================*/
/* This is simple program to get number which is in mind of the user*/
/*Programmer : Vivek Muthal*/
/*Website : http://www.vivsoftware.co.cc*/

/*liabrary files*/

#include
#include
#include

int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int left,right,top,bottom;
int n;
int answer=0;
char resp;

void main();

void setborder()
{
 cleardevice();
 rectangle(left,top,right,bottom);
}
void printanswer()
{
  printf("\n\n\n\n\tMAGIC GAME");
  printf("\n\n\n\n\n\n\n\t\tThe number in you mind is %d",answer);
  printf("\n\n\n\n\n\tProgrammer : VIVEK MUTHAL");
  printf("\n\tWebsite : http://www.vivsoftware.co.cc");
  printf("\n\n\n\tDo you want to continue? Y-Yes  Anykeys-No");
  resp=getche();
  if(resp=='y'||resp=='Y')
  {
   resp='n';
   main();
  }
}
void screen6()
{
 setcolor(WHITE);
 outtextxy(80,70," 32 37 42 47 52 57");
 outtextxy(80,110," 33 38 43 48 53 58");
 outtextxy(80,150," 34 39 44 49 54 59");
 outtextxy(80,190," 35 40 45 50 55 60");
 outtextxy(80,230," 36 41 46 51 56 ");
 setcolor(RED);
 outtextxy(15,300,"Press 'Y' if number is present");
 outtextxy(15,340," the list else press any key");
 resp=getche();
 if(resp=='y'||resp=='Y')
 {
  answer+=32;
  resp='n';
 }
 setbkcolor(BLACK);
 setborder();
 printanswer();
}
void screen5()
{
 setcolor(WHITE);
 outtextxy(80,70," 16 21 26 31 52 57");
 outtextxy(80,110," 17 22 27 48 53 58");
 outtextxy(80,150," 18 23 28 49 54 59");
 outtextxy(80,190," 19 24 29 50 55 60");
 outtextxy(80,230," 20 25 30 51 56 ");
 setcolor(RED);
 outtextxy(15,300,"Press 'Y' if number is present");
 outtextxy(15,340," the list else press any key");
 resp=getche();
 if(resp=='y'||resp=='Y')
 {
  answer+=16;
  resp='n';
 }
 setbkcolor(LIGHTBLUE);
 setborder();
 screen6();
}
void screen4()
{
 setcolor(WHITE);
 outtextxy(80,70,"  8 13 26 31 44 57");
 outtextxy(80,110,"  9 14 27 40 45 58");
 outtextxy(80,150," 10 15 28 41 46 59");
 outtextxy(80,190," 11 24 29 42 47 60");
 outtextxy(80,230," 12 25 30 43 56 ");
 setcolor(RED);
 outtextxy(15,300,"Press 'Y' if number is present");
 outtextxy(15,340," the list else press any key");
 resp=getche();
 if(resp=='y'||resp=='Y')
 {
  answer+=8;
  resp='n';
 }
 setbkcolor(BLACK);
 setborder();
 screen5();
}
void screen3()
{
 setcolor(WHITE);
 outtextxy(80,70,"  4 13 22 31 44 53");
 outtextxy(80,110,"  5 14 23 36 45 54");
 outtextxy(80,150,"  6 15 28 37 46 55");
 outtextxy(80,190,"  7 20 29 38 47 60");
 outtextxy(80,230," 12 21 30 39 52 ");
 setcolor(RED);
 outtextxy(15,300,"Press 'Y' if number is present");
 outtextxy(15,340," the list else press any key");
 resp=getche();
 if(resp=='y'||resp=='Y')
 {
  answer+=4;
  resp='n';
 }
 setbkcolor(BLUE);
 setborder();
 screen4();
}
void screen2()
{
 setcolor(WHITE);
 outtextxy(80,70,"  2 11 22 31 42 51");
 outtextxy(80,110,"  3 14 23 34 43 54");
 outtextxy(80,150,"  6 15 26 35 46 55");
 outtextxy(80,190,"  7 18 27 38 47 58");
 outtextxy(80,230," 10 19 30 39 50 59");
 setcolor(RED);
 outtextxy(15,300,"Press 'Y' if number is present");
 outtextxy(15,340," the list else press any key");
 resp=getche();
 if(resp=='y'||resp=='Y')
 {
  answer+=2;
  resp='n';
 }
 setbkcolor(3);
 setborder();
 screen3();
}
void screen1()
{
 setcolor(WHITE);
 outtextxy(80,70," 1 11 21 31 41 51");
 outtextxy(80,110," 3 13 23 33 46 53");
 outtextxy(80,150," 5 15 25 35 45 55");
 outtextxy(80,190," 7 17 27 37 47 57");
 outtextxy(80,230," 9 19 29 39 49 59");
 setcolor(RED);
 outtextxy(15,300,"Press 'Y' if number is present");
 outtextxy(15,340," the list else press any key");
 resp=getche();
 if(resp=='y'||resp=='Y')
 {
  answer+=1;
  resp='n';
 }
 setbkcolor(MAGENTA);
 setborder();
 screen2();
}
void mainscreen()
{
 setcolor(RED);
 setbkcolor(BLACK);
 settextstyle(3,0,6);
 outtextxy(100,50,"Select any number");
 outtextxy(100,100," between 1 to 60");
 outtextxy(100,150,"  in your mind...");
 settextstyle(3,0,5);
 outtextxy(50,290," Press Enter to Continue...");
 getch();
 setbkcolor(GREEN);
 setborder();
 screen1();
}
void graphicsdo()
{
 /* initialize graphics and local variables */
  initgraph(&gdriver, &gmode, "");

 /* read result of initialization */
 errorcode = graphresult();
 if (errorcode != grOk)  /* an error occurred */
 {
   printf("Graphics error: %s\n", grapherrormsg(errorcode));
   printf("Press any key to halt:");
   getch();
   exit(1); /* terminate with an error code */
 }

 midx = getmaxx() / 2;
 midy = getmaxy() / 2;
 setcolor(1);
 left = 10;
 top = 10;
 right = getmaxx()-10;
 bottom = getmaxy()-10;

 /* draw a rectangle */
 setlinestyle(2,0,0);
 setborder();
}
void main()
{
 answer=0;
 graphicsdo(); /// this is graphics initialization function
 mainscreen();
 closegraph();
}

/*==================================================================*/

Many says that they develop the graphics in C but the game, application runs only on that directory and only on their machine, cause they forget to add additional files to run the application in GUI and with fonts.
There fore you have to add those files where your application (executable) is stored.

To deploy the application and make it full functional you have to add all those font files named as .CHR which fonts you have used in the application in this gamei only usedone font so that only copy pasted that font file in the directory and for all other details of files you can see the magic game folder. 

Download the application with Source Code and see which extra files are included to run the game on different machines.
 Also You can contact me for any information at any time i'll be there to help you.
Email : vmuthal.18@gmail.com  

Here i request all the peoples who want to publish these article on there blog, forum, website kindly please make a link back to the original post or to the website. 
or

Create your own windows media player skin

This does not require any programming lang. knowledge.
How to create a Windows media player skin?

Ans.

1.Go to http://ultimatessoftwareandgame.blogspot.com


2.Download and install the software and also download sample images for making your first skin.

3.Using MS PAINT properly crop images from any picture/image.
ex. i used a nokia 5300

4.Copy all the croped images to one folder give them proper name like play,pause,stop,next etc.

5.Open Skin Maker software.

6.Click on new project always create a folder for your new skin.
or
select a blank folder

7.Type Skin name and author name and save it.

8.Select main image(it is the main look of skin) simple properly crop image like nokia 5300.

9.like that select all Play ,Pause button images etc.

10.Don't forget to check i am using checkbox.

11.Place Song NAME , TIME labels at proper location and from second tab select their font name ,size etc.

12.Like that use images for video, Playlist window.

13. REMEMBER that do not use YELLOW , MAGENTA, PINK colors

13.a. You can use magenta color for transparency.
13.b. Many colors may not work correctly coz theme doesn't supports.

14.Click on Build Code.

15.Wait for few sec. for 6 sec.

16.Click on View Skin.

17.Your skin is ready and install

18.From program files you can then after
distribute it

19.And make back up of folder where you save project.

20.Always use a unique theme name

if you find this useful give link to your
friends.

A Simple game written in C#

Before writing or copy this code please create a text file in 'c:/' having name Test.txt containg following data
/*
MOVIE:tarezameenpar
MOVIE:drona
MOVIE:koimilgaya
MOVIE:guru
MOVIE:darnamanahai
*/
then after copy and try the code given below
using System;
using System.IO;
using System.Threading;
namespace Game
{
public class Hangman
{
string randomString, userString;
int datalength;
// string category;
string[] moviedata = new string[5];
int moviecount = 0;
public Hangman()
{
FillNameValues();
}
private void FillNameValues()
{
string firstline;
StreamReader sRead = new StreamReader("C:\\Test.txt");
sRead.BaseStream.Seek(0, SeekOrigin.Begin);
firstline = sRead.ReadLine();
while (firstline != null)
{
if (firstline.Substring(0, 1) == "M")
{
int stringStartPos = firstline.IndexOf(':');
moviedata[moviecount] = firstline.Substring(stringStartPos + 1);
moviecount++;
}
firstline = sRead.ReadLine();
}
}
public void ExtractName()
{
Random Rgen = new Random();
int rnd = Rgen.Next(0, moviecount - 1);
randomString = moviedata[rnd];
}
public void StartGame()
{
datalength = randomString.Length;
char locatechar;
int correctcnt = 0, incorrectcnt = 0;
int i, k;
char[] s = new char[randomString.Length];
InitializeUserString();
ShowUserInputString();
Console.WriteLine("The total number of characters in the movie:{0}", randomString.Length);
Console.WriteLine("The total number of characters you can enter to guess the nameof Movie:{0}", randomString.Length + 2);
for (i = 1, k = 0; i <= datalength + 2 k == datalength; i++)
{
if (correctcnt == datalength incorrectcnt == datalength)
break;
Console.WriteLine("Enter the character:");
locatechar = Convert.ToChar(Console.ReadLine().ToLower());
int foundpos = 0;
int foundchar = 0;
foreach (char c in randomString)
{
if (c == locatechar)
{
UpdateString(foundpos, locatechar.ToString());
k++;
foundchar = 1;
}
foundpos++;
}
if (foundchar == 0)
{
Console.WriteLine("Wrong Attempt...Better Luck Next Time!!!!!\n\n");
incorrectcnt++;
}
else
{
correctcnt++;
}
ShowUserInputString();
Console.WriteLine("Total Correct Attempts:{0}\t", correctcnt);
Console.WriteLine("Total Incorrect Attempts:{0}\n", incorrectcnt);
if (k == datalength)
break;
}
if (randomString == userString)
{
Console.WriteLine("You have Won\n");
}
else
{
Console.WriteLine("The correct name is {0}", randomString);
Console.WriteLine("You have Lost\n");
}
}
private void UpdateString(int fpos, string updateStr)
{
string beforeString, afterString;
if (fpos != 0 && fpos != datalength - 1)
{
if (fpos == 1)
beforeString = userString.Substring(0, 1);
else
beforeString = userString.Substring(0, fpos);
afterString = userString.Substring(fpos + 1, datalength - (fpos + 1));
userString = beforeString + updateStr + afterString;
}
if (fpos == 0)
{
afterString = userString.Substring(fpos + 1, datalength - (fpos + 1));
userString = updateStr + afterString;
}
if (fpos == datalength - 1)
{
beforeString = userString.Substring(0, fpos);
userString = beforeString + updateStr;
}
}
public void InitializeUserString()
{
userString = " ";
for (int i = 0; i < datalength; i++)
{
userString = userString.Insert(i, "*");
}
}
public void ShowUserInputString()
{
Console.Clear();
Console.WriteLine("Input Value:{0}\n\n", userString);
}
}
class Game
{
static void Main(string[] args)
{
Console.Clear();
Console.WriteLine("You have to complete the Game within 60 Seconds");
Hangman obj = new Hangman();
Thread t=new Thread(new ThreadStart(obj.StartGame));
obj.ExtractName();
t.Start();
Thread.Sleep (60000);
//obj.StartGame();
try
{
t.Abort();
Console.WriteLine("Time Over");
}
catch (ThreadAbortException e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
}

Animation Program in C

In this program you'll find animation a ball is bouncing in a rectangle.
Code is Shown below.

#include"graphics.h"
#include"alloc.h"
void main()
{
int gd=DETECT,gm,area,x=25,y=25,ch,xdirn=1,ydirn=1;
int maxx,maxy;
char *buff;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(WHITE);
setfillstyle(SOLID_FILL,RED);
circle(50,50,25);
floodfill(50,50,WHITE);
area=imagesize(25,25,75,75);
buff=malloc(area);
getimage(25,25,75,75,buff);
maxx=getmaxx();
maxy=getmaxy();
rectangle(0,20,maxx,maxy);
outtextxy(250,10,"Animation");
while(1)
{
if(kbhit())
{
ch=getch();
/*if ENTER is hit reverse the direction of movement*/
if(ch=='\r')
{
xdirn*=-1;
ydirn*=-1;
}
else
{
if(ch==27)
break;
}
}
putimage(x,y,buff,XOR_PUT);
delay(0);
x=x+(xdirn*5);
y=y+(ydirn*2);
putimage(x,y,buff,XOR_PUT);
/*check if the ball touches horizantal boundaries*/
if(x>maxx-50x<0)>maxy-50y<20)
{
sound(50);
delay(10);
nosound();
ydirn*=-1;
}
}
getch();
closegraph();
restorecrtmode();
}

Mouse interface in a c program.

Here with mouse you can scribble in DOS mode.
A C program to interact with mouse.

#include"dos.h"
#include"graphics.h"
#include"stdio.h"
#include"stdlib.h"
#include"conio.h"
union REGS i,o;
void main()
{
int gd=DETECT,gm,maxx,maxy,x,y,button,prevx,prevy;
initgraph(&gd,&gm,"c:\\tc\\bgi");
maxx=getmaxx();
maxy=getmaxy();
rectangle(0,0,maxx,maxy);
setviewport(1,1,maxx-1,maxy-1,1);
if(initmouse()==0)
{
closegraph();
restorecrtmode();
printf("Mouse driver not loaded");
exit(1);
}
restrictmouseptr(1,1,maxx-1,maxy-1);
showmouseptr();
while(!kbhit())
{
getmousepos(&button,&x,&y);
if((button&1)==1)
{
hidemouseptr();
prevx=x;
prevy=y;
while((button&1)==1)
{
line(prevx,prevy,x,y);
prevx=x;
prevy=y;
getmousepos(&button,&x,&y);
}
showmouseptr();
}
}
}
initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
hidemouseptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
}
restrictmouseptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}
getmousepos(int*button,int*x,int*y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}

Graphics under C lang.

This is a simple program. Here you learn how to draw ellipse on screen on screen.
Code is shown below.
with these ellipse how to make a picture.

#include
#include
#include
#include
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx=300, midy=250, i;
int x1=200,y1=210,x2=380,y2=210,x3=290,y3=300;
int stangle = 45, endangle = 130;
int xrad = 100, yrad = 50;
int radius=200;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/* midx = getmaxx() / 2;
midy = getmaxy() / 2; */
setfillstyle(1,10);
fillellipse(midx,midy, radius, radius);
setfillstyle(5,4);
fillellipse(x1,y1, 30, 30);
setfillstyle(5,4);
fillellipse(x2,y2, 30, 30);
sector(x3, y3, stangle, endangle, xrad, yrad);
/* sector(midx, midy, stangle, endangle, xrad, yrad);*/
fillellipse(300,350, 100, 30);
getch();

/* clean up */
closegraph();
return 0;
}

Animation in C lang.

In this Program you can see a man face turning into Wolf face.
Code is shown below for all my programer your TC must be installed in 'c:\'
if any error copy all files from folder 'bin' ,'include', etc and paste them in only one folder 'TC'.

#include"graphics.h"
#include"dos.h"
#include"stdio.h"
#define FALSE 0
#define TRUE 1
#define EMPTY 0
#define EX 1
#define OH 2
int arr[9],nextchar=EX;
struct rect
{
int x1,y1,x2,y2;
};
struct rect square[]={
10,10,49,49,
60,10,99,49,
110,10,149,49,
10,60,49,99,
60,60,99,99,
110,60,149,99,
10,110,49,149,
60,110,99,149,
110,110,149,149,
};
main()
{
int g_error;
int gd=DETECT,gm,button;
int x,y,over,i,flag;
char reset='y';
initgraph(&gd,&gm,"c:\\tc\\bgi");
/*determine success/failure of initialisation operation*/
g_error=graphresult();
/*if failure*/
if(g_error!=0)
{
printf("\nInitgraph error:%s",grapherrormsg(g_error));
exit(1);
}
flag=initmouse();
if(flag==0)
{
printf("Unable to initialise mouse.Press any Key...");
getch();
closegraph();
restorecrtmode();
exit(2);
}
while(reset=='y')
{
drawgrid();
showmouseptr();
for(i=0;i<=8;i++) arr[i]=EMPTY; over=FALSE; while(over==FALSE) { getmousepos(&button,&x,&y); if((button&1)==1) { onlbuttondown(x,y); drawexsandohs(); over=isgameover(); } if((button&2)==2) { onrbuttondown(x,y); drawexsandohs(); over=isgameover(); } } reset=resetgame(); hidemouseptr(); } closegraph(); restorecrtmode(); } initmouse() { union REGS i,o; i.x.ax=0; int86(0x33,&i,&o); return(o.x.ax); } showmouseptr() { union REGS i,o; i.x.ax=1; int86(0x33,&i,&o); } hidemouseptr() { union REGS i,o; i.x.ax=2; int86(0x33,&i,&o); } drawgrid() { cleardevice(); setcolor(BLUE); setfillstyle(SOLID_FILL,BLUE); bar(54,10,60,149); floodfill(55,15,BLUE); bar(10,54,149,60); floodfill(15,55,BLUE); bar(10,104,149,110); floodfill(11,109,BLUE); bar(104,10,110,149); floodfill(105,11,BLUE); } getmousepos(int *button,int *x,int *y) { union REGS i,o; i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx; *x=o.x.cx; *y=o.x.dx; } onlbuttondown(int x,int y) { int i; if(nextchar==OH) return; for(i=0;i<8;i++)>=square[i].x1&&x<=square[i].x2&&y>=square[i].y1&&y<=square[i].y2&&arr[i]==EMPTY) { arr[i]=EX; nextchar=OH; break; } } } onrbuttondown(int x,int y) { int i; if(nextchar==EX) return; for(i=0;i<=8;i++) { if(x>=square[i].x1&&x<=square[i].x2&&y>=square[i].y1&&y<=square[i].y2&&arr[i]==EMPTY) { arr[i]=OH; nextchar=EX; break; } } } drawexsandohs() { int i; for(i=0;i<=8;i++) { if(arr[i]==EX) drawx(i); if(arr[i]==OH) drawoh(i); } } drawx(int i) { setcolor(MAGENTA); setlinestyle(SOLID_LINE,0,THICK_WIDTH); hidemouseptr(); line(square[i].x1+10,square[i].y1+10,square[i].x2-10,square[i].y2-10); line(square[i].x2-10,square[i].y1+10,square[i].x1+10,square[i].y2-10); showmouseptr(); } drawoh(int i) { hidemouseptr(); setcolor(YELLOW); circle((square[i].x1+square[i].x2)/2,(square[i].y1+square[i].y2)/2,10); showmouseptr(); } isgameover() { int winner; winner=findwinner(); settextstyle(1,0,2); setcolor(GREEN); if(winner==EX) { outtextxy(10,250,"X won the game!!"); return(TRUE); } else { if(winner==OH) { outtextxy(10,250,"O won the game!!"); return(TRUE); } else { if(isdrawn()) { outtextxy(10,250,"Game Drawn!!"); return(TRUE); } else return(FALSE); } } } int findwinner() { static int pattern[8][3]={ 0,1,2, 3,4,5, 6,7,8, 0,3,6, 1,4,7, 2,5,8, 0,4,8, 2,4,6 }; int i; for(i=0;i<=7;i++) { if(arr[pattern[i][0]]==EX&&arr[pattern[i][1]]==EX&&arr[pattern[i][2]]==EX) return(EX); if(arr[pattern[i][0]]==OH&&arr[pattern[i][1]]==OH&&arr[pattern[i][2]]==OH) return(OH); } return 0; } isdrawn() { int i; for(i=0;i<=8;i++) { if(arr[i]==EMPTY) return(0); } return(1); } resetgame() { char ch; int i; outtextxy(10,300,"Do you want to continue(Y/N)?"); fflush(stdin); ch=getch(); if(ch=='y'ch=='Y') { nextchar=EX; return('y'); } else return('n'); } Thanks to Graphics Under C Book.

Tic Tac Toe Video Game in C lang.

With help of Graphics under C i make this game.
Code is shown below copy/paste and comment please.
for this program your TurboC++ must be installed at 'C:\', if not then you have to modify code.

#include"graphics.h"
#include"dos.h"
#include"stdio.h"
#define FALSE 0
#define TRUE 1
#define EMPTY 0
#define EX 1
#define OH 2
int arr[9],nextchar=EX;
struct rect
{
int x1,y1,x2,y2;
};
struct rect square[]={
10,10,49,49,
60,10,99,49,
110,10,149,49,
10,60,49,99,
60,60,99,99,
110,60,149,99,
10,110,49,149,
60,110,99,149,
110,110,149,149,
};
main()
{
int g_error;
int gd=DETECT,gm,button;
int x,y,over,i,flag;
char reset='y';
initgraph(&gd,&gm,"c:\\tc\\bgi");
/*determine success/failure of initialisation operation*/
g_error=graphresult();
/*if failure*/
if(g_error!=0)
{
printf("\nInitgraph error:%s",grapherrormsg(g_error));
exit(1);
}
flag=initmouse();
if(flag==0)
{
printf("Unable to initialise mouse.Press any Key...");
getch();
closegraph();
restorecrtmode();
exit(2);
}
while(reset=='y')
{
drawgrid();
showmouseptr();
for(i=0;i<=8;i++) arr[i]=EMPTY; over=FALSE; while(over==FALSE) { getmousepos(&button,&x,&y); if((button&1)==1) { onlbuttondown(x,y); drawexsandohs(); over=isgameover(); } if((button&2)==2) { onrbuttondown(x,y); drawexsandohs(); over=isgameover(); } } reset=resetgame(); hidemouseptr(); } closegraph(); restorecrtmode(); } initmouse() { union REGS i,o; i.x.ax=0; int86(0x33,&i,&o); return(o.x.ax); } showmouseptr() { union REGS i,o; i.x.ax=1; int86(0x33,&i,&o); } hidemouseptr() { union REGS i,o; i.x.ax=2; int86(0x33,&i,&o); } drawgrid() { cleardevice(); setcolor(BLUE); setfillstyle(SOLID_FILL,BLUE); bar(54,10,60,149); floodfill(55,15,BLUE); bar(10,54,149,60); floodfill(15,55,BLUE); bar(10,104,149,110); floodfill(11,109,BLUE); bar(104,10,110,149); floodfill(105,11,BLUE); } getmousepos(int *button,int *x,int *y) { union REGS i,o; i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx; *x=o.x.cx; *y=o.x.dx; } onlbuttondown(int x,int y) { int i; if(nextchar==OH) return; for(i=0;i<8;i++)>=square[i].x1&&x<=square[i].x2&&y>=square[i].y1&&y<=square[i].y2&&arr[i]==EMPTY) { arr[i]=EX; nextchar=OH; break; } } } onrbuttondown(int x,int y) { int i; if(nextchar==EX) return; for(i=0;i<=8;i++) { if(x>=square[i].x1&&x<=square[i].x2&&y>=square[i].y1&&y<=square[i].y2&&arr[i]==EMPTY) { arr[i]=OH; nextchar=EX; break; } } } drawexsandohs() { int i; for(i=0;i<=8;i++) { if(arr[i]==EX) drawx(i); if(arr[i]==OH) drawoh(i); } } drawx(int i) { setcolor(MAGENTA); setlinestyle(SOLID_LINE,0,THICK_WIDTH); hidemouseptr(); line(square[i].x1+10,square[i].y1+10,square[i].x2-10,square[i].y2-10); line(square[i].x2-10,square[i].y1+10,square[i].x1+10,square[i].y2-10); showmouseptr(); } drawoh(int i) { hidemouseptr(); setcolor(YELLOW); circle((square[i].x1+square[i].x2)/2,(square[i].y1+square[i].y2)/2,10); showmouseptr(); } isgameover() { int winner; winner=findwinner(); settextstyle(1,0,2); setcolor(GREEN); if(winner==EX) { outtextxy(10,250,"X won the game!!"); return(TRUE); } else { if(winner==OH) { outtextxy(10,250,"O won the game!!"); return(TRUE); } else { if(isdrawn()) { outtextxy(10,250,"Game Drawn!!"); return(TRUE); } else return(FALSE); } } } int findwinner() { static int pattern[8][3]={ 0,1,2, 3,4,5, 6,7,8, 0,3,6, 1,4,7, 2,5,8, 0,4,8, 2,4,6 }; int i; for(i=0;i<=7;i++) { if(arr[pattern[i][0]]==EX&&arr[pattern[i][1]]==EX&&arr[pattern[i][2]]==EX) return(EX); if(arr[pattern[i][0]]==OH&&arr[pattern[i][1]]==OH&&arr[pattern[i][2]]==OH) return(OH); } return 0; } isdrawn() { int i; for(i=0;i<=8;i++) { if(arr[i]==EMPTY) return(0); } return(1); } resetgame() { char ch; int i; outtextxy(10,300,"Do you want to continue(Y/N)?"); fflush(stdin); ch=getch(); if(ch=='y'ch=='Y') { nextchar=EX; return('y'); } else return('n'); }

Graphics Under C

This is my First Simple program.
In this program you can see a rocket going from one corner to another.

#include
#include
#include
#include
int main(void)
{ /* request auto detection */
int gdriver = DETECT, gmode, errorcode; int maxx, maxy,i;
/* our polygon array */
int poly[10]; int poly1[10];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{ printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch(); /* terminate with an error code */
exit(1); }
/* maxx = getmaxx();
maxy = getmaxy(); */
for(i=400;i>=0;i--)
{ poly[0] = 60+i; /* 1st vertext */
poly[1] = 40+i;
poly[2] = 30+i; /* 2nd */ poly[3] = 20+i;
poly[4] = 10+i; /* 3rd */ poly[5] = 40+i;
poly[6] = 30+i; /* 4th */ poly[7] = 30+i;
/* drawpoly doesn't automatically close the polygon, so we close it.*/
poly[8] = poly[0];
poly[9] = poly[1];
/* draw the polygon */
setfillstyle(1,14); drawpoly(5, poly);
fillpoly(5,poly); setcolor(14);
rectangle(40+i,35+i,25+i,80+i);
clearviewport(); } /* clean up */
closegraph();
return 0;
}

I think you will love this programs. From Vivek