Ejemplo n.º 1
0
void main()
{
	int gd=DETECT,gm,x,y,res=-1,clk,chk[3][3],cnt;
	char *n1,*n2;
	clrscr();

	in.x.ax=8;
	in.x.cx=0;
	in.x.dx=480;
	int86(51,&in,&out);

start:  cnt=0;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
		chk[i][j]=0;

	initgraph(&gd,&gm,"c:\\tc\\bgi");

	settextstyle(7,HORIZ_DIR,1);
	cleardevice();
	draw_grid();
	callmouse();

	while(1)
	{
		if(cnt==9)
			break;
back:           delay(150);
		getmouse(x,y,clk);
		if(clk==1)
		{
			if(x>175 && x<240)	//1st col
			{
				if(y>100 && y<166)	//1st row
				{
					if(cnt%2==0)
					{
						if(chk[0][0]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[0][0]=1;
						draw_x(175,100);
					}
					else
					{
						if(chk[0][0]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[0][0]=2;
						draw_o(175,100);
					}
				}
				else if(y>166 && y<232) //2nd row
				{
					if(cnt%2==0)
					{
						if(chk[1][0]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[1][0]=1;
						draw_x(175,166);
					}
					else
					{
						if(chk[1][0]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[1][0]=2;
						draw_o(175,166);
					}
				}
				else if(y>232 && y<300) //3rd row
				{
					if(cnt%2==0)
					{
						if(chk[2][0]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[2][0]=1;
						draw_x(175,232);
					}
					else
					{
						if(chk[2][0]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[2][0]=2;
						draw_o(175,232);
					}
				}
			}
			else if(x>240 && x<306) //2nd col
			{
				if(y>100 && y<166)	//1st row
				{
					if(cnt%2==0)
					{
						if(chk[0][1]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[0][1]=1;
						draw_x(240,100);
					}
					else
					{
						if(chk[0][1]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[0][1]=2;
						draw_o(240,100);
					}
				}
				else if(y>166 && y<232) //2nd row
				{
					if(cnt%2==0)
					{
						if(chk[1][1]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[1][1]=1;
						draw_x(240,166);
					}
					else
					{
						if(chk[1][1]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[1][1]=2;
						draw_o(240,166);
					}
				}
				else if(y>232 && y<300) //3rd row
				{
					if(cnt%2==0)
					{
						if(chk[2][1]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[2][1]=1;
						draw_x(240,232);
					}
					else
					{
						if(chk[2][1]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[2][1]=2;
						draw_o(240,232);
					}
				}
			}
			else if(x>306 && x<375) //3rd col
			{
				if(y>100 && y<166)	//1st row
				{
					if(cnt%2==0)
					{
						if(chk[0][2]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[0][2]=1;
						draw_x(306,100);
					}
					else
					{
						if(chk[0][2]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[0][2]=2;
						draw_o(306,100);
					}
				}
				else if(y>166 && y<232) //2nd row
				{
					if(cnt%2==0)
					{
						if(chk[1][2]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[1][2]=1;
						draw_x(306,166);
					}
					else
					{
						if(chk[1][2]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[1][2]=2;
						draw_o(306,166);
					}
				}
				else if(y>232 && y<300) //3rd row
				{
					if(cnt%2==0)
					{
						if(chk[2][2]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[2][2]=1;
						draw_x(306,232);
					}
					else
					{
						if(chk[2][2]!=0)
						{
							outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN ");
							goto back;
						}
						chk[2][2]=2;
						draw_o(306,232);
					}
				}
			}
			cnt++;
		}
		res=win(chk);
		if(res==1)
		{
			settextstyle(7,HORIZ_DIR,1);
			outtextxy(220,330,"PLAYER_X has WON the Game !!!");
			break;
		}
		if(res==2)
		{
			settextstyle(7,HORIZ_DIR,1);
			outtextxy(220,330,"PLAYER_O has WON the Game !!!");
			break;
		}
	}
	if(res==-1)
	{
		settextstyle(7,HORIZ_DIR,1);
		outtextxy(220,330,"HEY !!! NO ONE WON....");
		outtextxy(225,355,"ONE MORE GAME ??? ");
		if(getche()=='y')
		{
			cleardevice();
			goto start;
		}
		exit(0);
	}
getch();
}
Ejemplo n.º 2
0
void draw_table(void)
{
    float c;
    int i, j;
    int k, l;
    float ov[3], lv[3];

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);

    ov[X] = light_pos[X]-logo_pos[X];
    ov[Y] = light_pos[Y]-logo_pos[Y];
    ov[Z] = light_pos[Z]-logo_pos[Z];

    normalize(ov);

    for (j=0; j<=TABLERES; j++) {
      for (i=0; i<=TABLERES; i++) {
	lv[X] = light_pos[X] - table_points[j][i][X];
	lv[Y] = light_pos[Y] - table_points[j][i][Y];
	lv[Z] = light_pos[Z] - table_points[j][i][Z];
	normalize(lv);
	if ((c = dot(lv, ov))<0.0) c = 0.0;
	c = c * c * c * lv[Y] * 255.0;
	/* fade */
	if ((current_time>TIME-5.0) && (current_time<TIME-3.0)) 
	  c *= 1.0 - (current_time-(TIME-5.0)) * 0.5;
	
	tablecolors[j][i] = (int)c;
      }
    }
    
    
    for (l=0; l<TABLERES; l++) {
      
      glBegin(GL_TRIANGLE_STRIP);
      for (k=0; k<=TABLERES; k++) {
	glColor3ub(tablecolors[l][k],
		   tablecolors[l][k],
		   tablecolors[l][k]);
	glVertex3fv(table_points[l][k]);

	glColor3ub(tablecolors[l+1][k],
		   tablecolors[l+1][k], 
		   tablecolors[l+1][k]);
	glVertex3fv(table_points[l+1][k]);
	
      }
	glEnd();
    }

    if (logo_pos[Y]>-0.33 && logo_pos[Y]<0.33) {
	glEnable(GL_DEPTH_TEST);
    }

    pca = 0.0;
    glBegin(GL_POLYGON);
    for (i=0; i<4; i++) {
      lv[X] = light_pos[X] - paper_points[i][X];
      lv[Y] = light_pos[Y] - paper_points[i][Y];
      lv[Z] = light_pos[Z] - paper_points[i][Z];
      normalize(lv);
      if ((c = dot(lv, ov))<0.0) c = 0.0;
      c = c * c * c * lv[Y];
      /* fade */
      if ((current_time>TIME-5.0) && (current_time<TIME-3.0)) 
	c *= 1.0 - (current_time-(TIME-5.0)) * 0.5;
      
      pcr = c * 255; pcg = c * 255; pcb = c * 200;
      pca += c;
      glColor3ub((GLubyte)pcr,  (GLubyte)pcg,  (GLubyte)pcb);
      glVertex3fv(paper_points[i]);
    }
    glEnd();

    glPushMatrix();
    glRotatef (0.1 * (-184), 0.0, 1.0, 0.0);
    glTranslatef(-0.3, 0.0, -0.8);
    glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
    glScalef(0.015, 0.015, 0.015);


    if (current_time>TIME*1.0-5.0) {
	c = (current_time-(TIME*1.0-5.0))/2.0;
	glColor3ub((GLubyte)(c*255.0),  (GLubyte)(c*255.0),  (GLubyte)(c*255.0));
    } else glColor3ub(0,  0,  0);

    glDisable(GL_DEPTH_TEST);

    draw_i();
    glTranslatef(3.0,  0.0,  0.0);

    draw_d();
    glTranslatef(6.0,  0.0,  0.0);

    draw_e();
    glTranslatef(5.0,  0.0,  0.0);

    draw_a();
    glTranslatef(6.0,  0.0,  0.0);

    draw_s();
    glTranslatef(10.0,  0.0,  0.0);

    draw_i();
    glTranslatef(3.0,  0.0,  0.0);

    draw_n();
    glTranslatef(-31.0,  -13.0,  0.0);

    draw_m();
    glTranslatef(10.0,  0.0,  0.0);

    draw_o();
    glTranslatef(5.0,  0.0,  0.0);

    draw_t();
    glTranslatef(4.0,  0.0,  0.0);

    draw_i();
    glTranslatef(3.5,  0.0,  0.0);

    draw_o();
    glTranslatef(5.0,  0.0,  0.0);

    draw_n();

    glPopMatrix();

}