⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thirdy5c.c

📁 Tic tac toe is (exactly what re your thinking) and it s the first game I made. Made it in one whole
💻 C
字号:
/* tictactoe in C using Turbo C by Thirdy 1ITD, 1ITC, 1CSC, hehehe */
/*ver1.0 bug unsolved in left diagonal win condition */
/*ver1.1 bug solved in left diagonal win condition*/
/*ver1.2b updated GUI, bitmap source:Crayon Shin Chan Animated
Series*/
/*ver1.3 created self extracting installer*/
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<bitmap.h>
int start();
char exit1();
char exit2();
char exit3();
void draw1();
void draw2();
void draw3();
void draw4();
void draw5();
void draw6();
void draw7();
void draw8();
void draw9();
void draw12();
void draw22();
void draw32();
void draw42();
void draw52();
void draw62();
void draw72();
void draw82();
void draw92();
void drawx(int x, int y);
void drawo(int x, int y);
void music(int f, int s);


void main()

{
 int q[9];
 int win[9];
 int once[9];
 int gd=DETECT,gm;
 int x,y,a,b,enter,thirdy;
 int choice,player,winner=0;
 int corx,cory,corxn,coryn;
 corx=250;
 cory=160;
 initgraph(&gd, &gm, "c:/program files/tictactoe");
 end2:
 clearviewport();
 setcolor(15);
 enter=start();
 if(enter!=13){if(exit1()=='y') goto end1; else goto end2;}
 begin:
 clearviewport();
 setbkcolor(7);
 setcolor(4);
 //installuserfont("goth2.chr");
 settextstyle(10,HORIZ_DIR,3);
 outtextxy(210,24,"TIC");
 setcolor(1);
 outtextxy(280,24,"TAC");
 setcolor(4);
 outtextxy(365,24,"TOE");
 settextstyle(0,HORIZ_DIR,1);
 for(a=190;a<450;a+=10)
 {
  setcolor(1);
  outtextxy(a,70,"x");
  a+=10;
  setcolor(4);
  outtextxy(a,70,"o");
 }
 for(a=190;a<450;a+=10)
 {
  setcolor(1);
  outtextxy(a,30,"x");
  a+=10;
  setcolor(4);
  outtextxy(a,30,"o");
 }


/*Draw board*/
 for(x=284,y=100;y<=360;y++)
 {
 putpixel(x,y,4);
 }
 for(x=348,y=100;y<=360;y++)
 {
 putpixel(x,y,4);
 }
 for(x=190,y=198;x<450;x++)
 {
 putpixel(x,y,4);
 }
 for(x=190,y=258;x<450;x++)
 {
 putpixel(x,y,4);
 }
 setcolor(4);
 rectangle(220,130,420,330);
 setcolor(WHITE);
 rectangle(180,20,460,420);
 setfillstyle(3,WHITE);
 floodfill(2,2,WHITE);
 moveto(204,385);
 setcolor(RED);
 outtext("ENTER CHOICE(   )ESC FOR     :");
 setcolor(BLUE);
 outtextxy(308,385,"1-9");
 outtextxy(404,385,"EXIT");
 player=1;

/*Draw # on the board*/
 draw1();
 draw2();
 draw3();
 draw4();
 draw5();
 draw6();
 draw7();
 draw8();
 draw9();

cagain:
 if(q[0]==49&&once[0]==1){draw12();once[0]=0;}
 if(q[1]==50&&once[1]==1){draw22();once[1]=0;}
 if(q[2]==51&&once[2]==1){draw32();once[2]=0;}
 if(q[3]==52&&once[3]==1){draw42();once[3]=0;}
 if(q[4]==53&&once[4]==1){draw52();once[4]=0;}
 if(q[5]==54&&once[5]==1){draw62();once[5]=0;}
 if(q[6]==55&&once[6]==1){draw72();once[6]=0;}
 if(q[7]==56&&once[7]==1){draw82();once[7]=0;}
 if(q[8]==57&&once[8]==1){draw92();once[8]=0;}

switch(choice)
{

 case 49:
 if(player==0)
 drawx(250-14,160-11);  /*bug solved after replacing var corx, cory as input in drawx and drawo*/
 else drawo(250+2,160+5);
 break;
 case 50:
 if(player==0)
 drawx(315-14,160-11);
 else drawo(315+2,160+5);
 break;
  case 51:
 if(player==0)
 drawx(380-14,160-11);
 else drawo(380+2,160+5);
 break;
  case 52:
 if(player==0)
 drawx(250-14,225-11);
 else drawo(250+2,225+5);
 break;
  case 53:
 if(player==0)
 drawx(315-14,225-11);
 else drawo(315+2,225+5);
 break;
 case 54:
 if(player==0)
 drawx(380-14,225-11);
 else drawo(380+2,225+5);
 break;
  case 55:
 if(player==0)
 drawx(250-14,290-11);
 else drawo(250+2,290+5);
 break;
 case 56:
 if(player==0)
 drawx(315-14,290-11);
 else drawo(315+2,290+5);
 break;
 case 57:
 if(player==0)
 drawx(380-14,290-11);
 else drawo(380+2,290+5);
 break;

}

/*player1 condition win */
 if(win[0]==1&&win[1]==1&&win[2]==1){winner=1;goto quit;}
 if(win[3]==1&&win[4]==1&&win[5]==1){winner=1;goto quit;}
 if(win[6]==1&&win[7]==1&&win[8]==1){winner=1;goto quit;}
 if(win[0]==1&&win[4]==1&&win[8]==1){winner=1;goto quit;}
 if(win[2]==1&&win[4]==1&&win[6]==1){winner=1;goto quit;}
 if(win[0]==1&&win[3]==1&&win[6]==1){winner=1;goto quit;}
 if(win[1]==1&&win[4]==1&&win[7]==1){winner=1;goto quit;}
 if(win[2]==1&&win[5]==1&&win[8]==1){winner=1;goto quit;}
/*player2 condition win*/
 if(win[0]==2&&win[1]==2&&win[2]==2){winner=2;goto quit;}
 if(win[3]==2&&win[4]==2&&win[5]==2){winner=2;goto quit;}
 if(win[6]==2&&win[7]==2&&win[8]==2){winner=2;goto quit;}
 if(win[0]==2&&win[4]==2&&win[8]==2){winner=2;goto quit;}
 if(win[2]==2&&win[4]==2&&win[6]==2){winner=2;goto quit;}
 if(win[0]==2&&win[3]==2&&win[6]==2){winner=2;goto quit;}
 if(win[1]==2&&win[4]==2&&win[7]==2){winner=2;goto quit;}
 if(win[2]==2&&win[5]==2&&win[8]==2){winner=2;goto quit;}

again:  /*go here if user entered a used block*/
 choice=getch();
 if(choice==27)
 {
 ent0:
 b=exit3();
 if(b=='y')main();
 else if(b=='n')
  {
  exit2();
  goto end1;
  }
 else goto ent0;
 }
 else
 {

 switch(choice)
 {

 case 49:
 if(q[0]!=49)
 {
 q[0]=49;once[0]=1;
 if(player==1){player=0;win[0]=1;}
 else{player=1;win[0]=2;}
 goto cagain;
 }
 else goto again;
 break;

 case 50:
 if(q[1]!=50)
 {
 q[1]=50;once[1]=1;
 if(player==1){player=0;win[1]=1;}
 else{player=1;win[1]=2;}
 goto cagain;
 }
 else goto again;
 break;

 case 51:
 if(q[2]!=51)
 {
 q[2]=51;once[2]=1;
 if(player==1){player=0;win[2]=1;}
 else{player=1;win[2]=2;}
 goto cagain;
 }
 else goto again;
 break;

 case 52:
 if(q[3]!=52)
 {
 q[3]=52;once[3]=1;
 if(player==1){player=0;win[3]=1;}
 else{player=1;win[3]=2;}
 goto cagain;
 }
 else goto again;
 break;

 case 53:
 if(q[4]!=53)
 {
 q[4]=53;once[4]=1;
 if(player==1){player=0;win[4]=1;}
 else{player=1;win[4]=2;}
 goto cagain;
 }
 else goto again;
 break;

 case 54:
 if(q[5]!=54)
 {
 q[5]=54;once[5]=1;
 if(player==1){player=0;win[5]=1;}
 else{player=1;win[5]=2;}
 goto cagain;
 }
 else goto again;
 break;

 case 55:
 if(q[6]!=55)
 {
 q[6]=55;once[6]=1;
 if(player==1){player=0;win[6]=1;}
 else{player=1;win[6]=2;}
 goto cagain;
 }
 else goto again;
 break;

 case 56:
 if(q[7]!=56)
 {
 q[7]=56;once[7]=1;
 if(player==1){player=0;win[7]=1;}
 else{player=1;win[7]=2;}
 goto cagain;
 }
 else goto again;
 break;

 case 57:
 if(q[8]!=57)
 {
 q[8]=57;once[8]=1;
 if(player==1){player=0;win[8]=1;}
 else{player=1;win[8]=2;}
 goto cagain;
 }
 else goto again;

 default:goto again;

 }
 }

 quit:
 clearviewport();
 setbkcolor(0);
 if(winner==1)
 {
 outtextxy(270,300,"player 1 wins!!!");
 displaybitmap(290,180,"shin2.bmp");
 music(1500,500);delay(1000);ent1:b=exit3();
 if(b=='y')main();else if(b=='n') goto end1; else goto ent1;
 }
 else if(winner==2)
 {
 outtextxy(270,300,"player 2 wins!!!");
 displaybitmap(290,180,"shin3.bmp");
 music(1600,500);delay(1000);ent:b=exit3();
 if(b=='y')main();else if(b=='n') goto end1; else goto ent;
 }
 else if(winner==0){outtextxy(270,300,"draW!!!");music(1700,500);}
 outtextxy(150,330,"Thanks for playing!");
 end1:  /*if user quits from the start scr*/
 clearviewport();
 setbkcolor(0);
 displaybitmap(190,70,"shin9.bmp");
 setcolor(YELLOW);
 outtextxy(150,330,"For bugs, please email me thirdy_boxster@yahoo.com");
 outtextxy(150,360,"Press any key to continue...");


 /*under construction*/
 /*
 outtextxy(270,330,"Press space to play again");
 outtextxy(0,449,"                   thanx for playing! Press any key to continue...");
 thirdy=getch();
 if(thirdy==32){q[0,1,2,3,4,5,6,7,8]=0;win[0,1,2,3,4,5,6,7,8]=0;
 once[0,1,2,3,4,5,6,7,8]=0;winner=0;goto begin;}
 else
 */


 getch();
 closegraph();
 restorecrtmode();
 }
 char exit1()
 {
 setfillstyle(1,YELLOW);
 bar3d(230,200,410,258,0,0);
 setcolor(BLUE);
 outtextxy(270,210,"Are you sure");
 outtextxy(255,225,"you want to quit?");
 outtextxy(295,240,"(y/n)");
 return getch();
 }
 char exit2()
 {
 setfillstyle(1,YELLOW);
 bar3d(230,200,410,258,0,0);
 setcolor(BLUE);
 outtextxy(245,210,"TIC TAC TOE ver 1.3");
 outtextxy(245,225,"Created by:Thirdy");
 outtextxy(245,240,"Thanx for playing!!!");
 delay(300);
 return getch();
 }
 char exit3()
 {
 setfillstyle(1,YELLOW);
 bar3d(240,200,390,258,0,0);
 setcolor(BLUE);
 outtextxy(245,210,"   Do you want");
 outtextxy(245,225,"  to play again?");
 outtextxy(245,240,"      (y/n)");
 delay(300);
 return getch();
 }


void draw1()
{
setcolor(1);
moveto(250,160);
outtext("1");
}
void draw12()
{
setcolor(7);
moveto(250,160);
outtext("1");
}

void draw2()
{
setcolor(1);
moveto(315,160);
outtext("2");
}
void draw22()
{
setcolor(7);
moveto(315,160);
outtext("2");
}

void draw3()
{
setcolor(1);
moveto(380,160);
outtext("3");
}
void draw32()
{
setcolor(7);
moveto(380,160);
outtext("3");
}

void draw4()
{
setcolor(1);
moveto(250,225);
outtext("4");
}
void draw42()
{
setcolor(7);
moveto(250,225);
outtext("4");
}

void draw5()
{
setcolor(1);
moveto(315,225);
outtext("5");
}
void draw52()
{
setcolor(7);
moveto(315,225);
outtext("5");
}

void draw6()
{
setcolor(1);
moveto(380,225);
outtext("6");
}
void draw62()
{
setcolor(7);
moveto(380,225);
outtext("6");
}

void draw7()
{
setcolor(1);
moveto(250,290);
outtext("7");
7:25 AM 1/5/2005}
void draw72()
{
setcolor(7);
moveto(250,290);
outtext("7");
}

void draw8()
{
setcolor(1);
moveto(315,290);
outtext("8");
}
void draw82()
{
setcolor(7);
moveto(315,290);
outtext("8");
}

void draw9()
{
setcolor(1);
moveto(380,290);
outtext("9");
}
void draw92()
{
setcolor(7);
moveto(380,290);
outtext("9");
}


void drawx(int x, int y)
{
setcolor(BLUE);
line(x,y,x+30,y+30);
line(x+1,y,x+31,y+30);
line(x+2,y,x+32,y+30);
line(x+3,y,x+33,y+30);
line(x+30,y,x,y+30);
line(x+31,y,x,y+31);
line(x+32,y,x,y+32);
line(x+33,y,x,y+33);
}

void drawo(int x, int y)
{
setcolor(RED);
circle(x,y,20);
circle(x,y,19);
circle(x,y,18);
}

void music(int f, int s)
{
sound(f);
delay(s);
nosound();
}

int start()
{

 setfillstyle(EMPTY_FILL,BLUE);
 bar3d(220,220,260,220,120,1);
 bar3d(310+40,155,350,210+10,30,0);
 bar3d(260,220,350,220,30,1);
 outtextxy(200,350,"Welcome to Tic Tac Toe Ver 1.3");
 outtextxy(90,365,"Instruction:Press the # that corresponds to player's choice.");
 outtextxy(220,380,"Player 1:   Player 2:  ");
 setcolor(BLUE);
 outtextxy(300,380,"X");
 setcolor(RED);
 outtextxy(390,380,"O");
 setcolor(WHITE);
 outtextxy(220,400,"press enter to continue");
 return getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -