maintest.cpp

来自「作品功能介绍:这个软件的功能是娱乐作用,玩家可以同过四个键(分别为WASD,W为」· C++ 代码 · 共 222 行

CPP
222 行
字号
#include<iostream.h>
#include<ctype.h>
#include<graphics.h>
#include<stdlib.h>
#include<alloc.h>
#include<conio.h>
#include"topic.h"
#include <bios.h>

char way;
int x=175,y=105;
unsigned size,*resize;
void character();
void up(int& x,int& y);
void down(int& x,int& y);
void left(int& x,int& y);
void right(int& x, int& sy);


void main() //.....main from here.........
{int driver,mode=0;
 driver=DETECT;
 closegraph();
 initgraph(&driver,&mode,"c:\\Tc\\Bgi");
 Picture s;
 s.map();
 size=imagesize(x-10,y-10,x+10,y+10);
 (void*)resize=malloc(size);
 getimage(x-10,y-10,x+10,y+10,resize);
 for(;x!=300||y!=230;)
{start:
 ;
  way = bioskey(0);

  switch(way)
  {
	case 7777://a or A
	case 7745: way = 'A';break;
	case 8051://s or S
	case 8019: way = 'S';break;
	case 4471://w or W
	case 4439: way = 'W';break;
	case 8292://d or D
	case 8260: way = 'D';break;
  }

 way=toupper(way);
 if(way=='A'||way=='S'||way=='D'||way=='W')//...judge from here.....
 {if(x==175&&y==105||x==225&&y==155)//...the 1
  {if(way=='D')
  {right(x,y);
  continue;
  }
  if(way=='S')
  {down(x,y);
  continue;
  }
  continue;
 };
 if(x==425&&y==105||x==375&&y==155)//...the 2
  {if(way=='A')
  {left(x,y);
  continue;
  }
  if(way=='S')
  {down(x,y);
   continue;
   }
   continue;
  };
 if(x==175&&y==355||x==225&&y==305)//....the 3
  {if(way=='W')
  {up(x,y);
  continue;
  }
  if(way=='D')
  {right(x,y);
  continue;
  }
  continue;
  };
 if(x==425&&y==355||x==375&&y==305)//....the 4
  {if(way=='A')
  {left(x,y);
  continue;
  }
  if(way=='W')
  {up(x,y);
  continue;
  }
  continue;
  };
 if(x==175&&y==230||x==375&&y==230)//....the 5
  {if(way=='W')
  {up(x,y);
  continue;
  }
  if(way=='S')
  {down(x,y);
  continue;
  }
  if(way=='D')
  {right(x,y);
  continue;
  }
  continue;
 };
 if(x==225&&y==230||x==425&&y==230)//.......the 6
  {if(way=='W')
  {up(x,y);
  continue;
  }
  if(way=='S')
  {down(x,y);
  continue;
  }
  if(way=='A')
  {left(x,y);
  continue;
  }
  continue;
  };
 if(x==300&&y==155)//....the 7
  {if(way=='S')
  {down(x,y);
  continue;
  }
  if(way=='A')
  {left(x,y);
  continue;
  }
  if(way=='D')
  {right(x,y);
  continue;
  }
  continue;
  };
 if(x==300&&y==305)//.......the 8
  {if(way=='W')
  {up(x,y);
  continue;
  }
  if(way=='A')
  {left(x,y);
  continue;
  }
  if(way=='D')
  {right(x,y);
  continue;
  }
  continue;
 };
 if((x>175&&x<355&&(y==105||y==355))||((x>175&&x<225||x>375&&x<425)&&y==230)||(x>225&&x<300&&(y==155||y==305))||(x>300&&x<375&&(y==155||y==305)))//...the 10
  {if(way=='A')
  {left(x,y);
  continue;
  }
  if(way=='D')
  {right(x,y);
  continue;
  }
  continue;
 };
 if(((x==175||x==425)&&y>105&&y<230)||((x==175||x==425)&&y>230&&y<355)||((x==225||x==300||x==375)&&y>155&&y<230)||((x==225||x==300||x==375)&&y>230&&y<305))//...the 11
  {if(way=='W')
  {up(x,y);
  continue;
  }
  if(way=='S')
  {down(x,y);
  continue;
  }
  continue;
 };
}//........judge end here..............
 if(way!='A'&&way!='S'&&way!='D'&&way!='W')
 //goto start;
 continue;

}

 character();//........output text.......

 bioskey(0);

 closegraph();
}

void character() //........text function decleration..........
{//int a=6,b=14;
 //textbackground(a);
 //textcolor(b);
 setcolor(RED);
 //cout<<"You arrived!"<<endl;
 outtextxy(272,236,"SHIT! You arrived!");
}

void up(int& x,int& y) //...four functions decleration begin.....
{
 putimage(x-10,y-10,resize,XOR_PUT);
 x=x,y-=1;
 putimage(x-10,y-10,resize,XOR_PUT);
 }
void down(int& x,int& y)
{
 putimage(x-10,y-10,resize,XOR_PUT);
 x=x,y+=1;
 putimage(x-10,y-10,resize,XOR_PUT);
}
void left(int& x,int& y)
{
 putimage(x-10,y-10,resize,XOR_PUT);
 x-=1,y=y;
 putimage(x-10,y-10,resize,XOR_PUT);
}
void right(int& x,int& y)
{
 putimage(x-10,y-10,resize,XOR_PUT);
 x+=1,y=y;
 putimage(x-10,y-10,resize,XOR_PUT);
}//.............four functions decleration end..........

⌨️ 快捷键说明

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