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

📄 realball.cpp

📁 一个在tc3.0下面写的棋类游戏 很经典 值得好好研究
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	 putimage(pt->x,pt->y,pt->oldbuf,COPY_PUT);
	 return 0;
       }

    pt->x+=pt->vx;
    pt->y+=pt->vy;
    putimage(pt->oldx,pt->oldy,pt->oldbuf,COPY_PUT);
    putimage(pt->x,pt->y,pt->buf,COPY_PUT);
    pt->oldx=pt->x;
    pt->oldy=pt->y;
    return 1;
}
void loadpictures()
{

 setfillstyle(1,0);
 bar(0,0,639,479);

 buf_normalball=malloc(imagesize(10,10,10+2*RADIUS,10+2*RADIUS));
 setcolor(2);
 circle(RADIUS,RADIUS,RADIUS);
 setfillstyle(1,2);
 floodfill(RADIUS,RADIUS,2);
 getimage(0,0,2*RADIUS,2*RADIUS,buf_normalball);

 border.buf=malloc(imagesize(50,50,100,60));

 bar(50,50,100,60);
 getimage(50,50,100,60,border.buf);

  buf_block1=malloc(imagesize(200,200,200+BLOCKWIDTH,200+BLOCKHEIGHT));
  setfillstyle(1,14);
  bar(200,200,200+BLOCKWIDTH,200+BLOCKHEIGHT);
  getimage(200,200,200+BLOCKWIDTH,200+BLOCKHEIGHT,buf_block1);

  buf_block2=malloc(imagesize(200,200,200+BLOCKWIDTH,200+BLOCKHEIGHT));
  setfillstyle(1,13);
  bar(200,200,200+BLOCKWIDTH,200+BLOCKHEIGHT);
  getimage(200,200,200+BLOCKWIDTH,200+BLOCKHEIGHT,buf_block2);

 buf_blockbg=malloc(imagesize(200,200,200+BLOCKWIDTH,200+BLOCKHEIGHT));
 getimage(400,400,400+BLOCKWIDTH,400+BLOCKHEIGHT,buf_blockbg);
 border.oldbuf=malloc(imagesize(0,0,50,10));
 getimage(500,300,500+border.width,300+border.height,border.oldbuf);
 buf_treasurebg=malloc(imagesize(200,200,200+TREASUREWIDTH,200+TREASUREHEIGHT));
 getimage(500,400,500+TREASUREWIDTH,400+TREASUREHEIGHT,buf_treasurebg);
 buf_treasureslow=malloc(imagesize(200,200,200+TREASUREWIDTH,200+TREASUREHEIGHT));
 setfillstyle(1,13);
 bar(200,200,200+TREASUREWIDTH,200+TREASUREHEIGHT);
 settextstyle(0,0,1);
 outtextxy(205,205,"S");
 getimage(200,200,200+TREASUREWIDTH,200+TREASUREHEIGHT,buf_treasureslow);
 bar(200,200,200+TREASUREWIDTH,200+TREASUREHEIGHT);
 outtextxy(205,205,"Q");
 buf_treasurequick=malloc(imagesize(200,200,200+TREASUREWIDTH,200+TREASUREHEIGHT));
 getimage(200,200,200+TREASUREWIDTH,200+TREASUREHEIGHT,buf_treasurequick);
 buf_ballbg=malloc(imagesize(600,450,600+2*RADIUS+2,450+2*RADIUS+2));
 getimage(600,450,600+2*RADIUS+1,450+2*RADIUS+1,buf_ballbg);
 cleardevice();
}
void initblocks(int round)
{    int i;

for(i=1;i<=TOTALBLOCKNUM;i++)
   {  block[i].thick=random(2)+1;
      block[i].height=BLOCKHEIGHT;
      block[i].width=BLOCKWIDTH;
      if(block[i].thick==2)
	    block[i].buf=buf_block2;
      else
	    block[i].buf=buf_block1;
      block[i].treasure=random(2)+1;   /*-----0:normal -----1:slow -------2:quick--------*/
      if(i==1)
	{
	   block[i].x=LEFTAREA+10;
	   block[i].y=TOPAREA+50+10*round;
	 }
      else
      {
      block[i].x=block[i-1].x+BLOCKWIDTH+10;
      block[i].y=block[i-1].y;
      }
      if(block[i].x>RIGHTAREA)
	{
	   block[i].x=LEFTAREA+10;
	   block[i].y=block[i].y+BLOCKHEIGHT+20;
	}
      block[i].active=1;
   }
}
void freemem_realball()
{
int i;
free(buf_normalball);
free(buf_blockbg);
free(buf_block1);
free(buf_block2);
free(border.buf);


free(buf_ballbg);
free(buf_treasurebg);
free(buf_treasureslow);
free(buf_treasurequick);

}
 void set_screen()
 {

 setcolor(12);
 setlinestyle(0,0,3);
 line(LEFTAREA-2,0,LEFTAREA-2,479);
 line(RIGHTAREA+3,0,RIGHTAREA+3,479);
 setlinestyle(0,0,1);
 newbutton(RealsaveBtn.x,RealsaveBtn.y,RealsaveBtn.x+RealsaveBtn.width,RealsaveBtn.y+RealsaveBtn.height);
 newbutton(RealexitBtn.x,RealexitBtn.y,RealexitBtn.x+RealexitBtn.width,RealexitBtn.y+RealexitBtn.height);
 ShowBmp16("savebtn.bmp",RealsaveBtn.x-5,RealsaveBtn.y-5);
 ShowBmp16("realball.bmp",RIGHTAREA,0);
 }
 void paint_blocks()
 {
 int i;
 for(i=1;i<=TOTALBLOCKNUM;i++)
   { if(block[i].active!=0)
     putimage(block[i].x,block[i].y,block[i].buf,COPY_PUT);
     }

 }
 void show_score()
  {
  if(user.score!=oldscore)
	 {
	  char score[3];
	  sprintf(score,"%d",user.score);
	  oldscore=user.score;
	  settextstyle(7,0,2);
	  setcolor(13);
	  outtextxy(0,0,"Score:");
	  setfillstyle(1,0);
	  bar(0,50,60,100);
	  outtextxy(0,50,score);
	  }
  if(user.round!=oldround)
	{
	   char round[3];
	  sprintf(round,"%d",user.round);
	  oldround=user.round;
	  settextstyle(7,0,2);
	  setcolor(13);
	  outtextxy(0,100,"Round:");
	  setfillstyle(1,0);
	  bar(0,150,60,200);
	  outtextxy(0,150,round);

	}
 }
  void show_life()
 {
 char life[2];

 if(oldlife!=user.life)
   {
      sprintf(life,"%d",user.life);
      oldlife=user.life;
      settextstyle(7,0,2);
      setcolor(13);
      outtextxy(0,200,"Life :");
      setfillstyle(1,0);
      bar(0,250,60,300);
      outtextxy(0,250,life);
   }
 }
 int play()
 {
  int mkey,mx,my;
  do
    {
    readmouse(&mkey,&mx,&my);
     if(mx<LEFTAREA||mx>RIGHTAREA+border.width)
       {
	  switch (pause())
	  {  case 1:/*save or load*/
		     int round,life;
		     long score;
		      round=olduser.round;
		      life=olduser.life;
		      score=olduser.score;
		      showmouse();
		      saveoptions(&olduser.round,&olduser.score,&olduser.life);
		      hidemouse();
		      if(round!=olduser.round||life!=olduser.life||score!=olduser.score)
			       { oldlife=-2;
				 oldscore=-2;
				 oldround=-2;
				 user.round=olduser.round;
				 user.score=olduser.score;
				 user.life=olduser.life;
				return 2;     /*mean loading new round*/
			       }
		      else
			{
			set_screen();
			paint_blocks();
			oldlife=-2;
			oldscore=-2;
			oldround=-2;
			}
		     break;
	     case 2:/*exit*/
		     settextstyle(7,0,1);
		     setcolor(13);
		     outtextxy(125,200,"Are you sure to quit realball ? y/n");
		     if(getch()=='y')
		      return 3;
		     else
		       setfillstyle(1,0);
		       bar(125,200,500,250);
		       bar(250,250,350,300);
		      break;
	   default:
	     break;
	  }
       }
     if(user.life==0)
      {
       return 0;/*mean failure*/
      }
     if(pbhead==NULL&&user.life>=1)
	{
	  pbhead=(BALL *)malloc(sizeof(BALL));
	  pbhead->oldbuf=buf_ballbg;
	  pbhead->x=300;
	  pbhead->y=400;
	  pbhead->oldx=pbhead->x;
	  pbhead->oldy=pbhead->y;
	  pbhead->vx=1;
	  pbhead->vy=-1;
	  pbhead->radius=RADIUS;
	  pbhead->attribute=3;
	}
   else
      {
      switch (paint_ball(pbhead,&user))
      {
      case 0:
	putimage(pbhead->x,pbhead->y,pbhead->oldbuf,COPY_PUT);
	free(pbhead);
	pbhead=NULL;
	user.life--;
	break;
      case 2:
	 settextstyle(1,0,3);
	 setcolor(13);
	 outtextxy(230,200,"round clear");
	 delay(1000);
	 setfillstyle(1,0);
	 bar(230,200,380,300);
	 setcolor(13);
	 char showround[3];
	 sprintf(showround,"Round %d",user.round+1);
	 outtextxy(230,200,showround);
	 delay(1000);
	 setfillstyle(1,0);
	 bar(230,200,380,300);

	 pbhead->x=250;
	 pbhead->y=250;


	 return 1;/*mean round clear*/
	 }

      }
    if(pthead!=NULL)
     {
	   if(paint_treasure(pthead)!=1)
		{
		   free(pthead);
		   pthead=NULL;
		}
      }

     paint_border(&border);

     show_score();
     show_life();

     delay(speed);
    }while(1);

 }
 int  pause()
 {
 void *buf_pause;
 int mkey,mx,my,exit_flagppause=0;
 showmouse();
 setcolor(13);
 outtextxy(250,250,"PAUSE");
 do{
 readmouse(&mkey,&mx,&my);
  if(mx>LEFTAREA&&mx+border.width<RIGHTAREA)
     exit_flagppause=1;
  if(mkey==LEFTKEY)
   { if(mx>RealsaveBtn.x&&mx<RealsaveBtn.x+RealsaveBtn.width
       &&my>RealsaveBtn.y&&my<RealsaveBtn.y+RealsaveBtn.height)
       { pushbutton(RealsaveBtn.x,RealsaveBtn.y,RealsaveBtn.x+RealsaveBtn.width,RealsaveBtn.y+RealsaveBtn.height);
	 delay(200);
	 newbutton(RealsaveBtn.x,RealsaveBtn.y,RealsaveBtn.x+RealsaveBtn.width,RealsaveBtn.y+RealsaveBtn.height);
	 hidemouse();
	 return 1;}
    if(mx>RealexitBtn.x&&mx<RealexitBtn.x+RealexitBtn.width
      &&my>RealexitBtn.y&&my<RealexitBtn.y+RealexitBtn.height)
      { pushbutton(RealexitBtn.x,RealexitBtn.y,RealexitBtn.x+RealexitBtn.width,RealexitBtn.y+RealexitBtn.height);
	delay(200);
	newbutton(RealexitBtn.x,RealexitBtn.y,RealexitBtn.x+RealexitBtn.width,RealexitBtn.y+RealexitBtn.height);
	hidemouse();
	return 2;}
   }
 }while(exit_flagppause!=1);
 setfillstyle(1,0);
 bar(250,250,350,300);
 hidemouse();
 delay(100);
 return  0;
 }

⌨️ 快捷键说明

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