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

📄 swatgame.bak

📁 一个飞虫在屏幕上飞行
💻 BAK
字号:
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>

class swat
{
	public:
		void draw_swat( int x )
		{
			setcolor( LIGHTCYAN );
			setlinestyle( SOLID_LINE,0,3 );
			line( x,470,x,275);

			setfillstyle( XHATCH_FILL, LIGHTCYAN );
			rectangle( x-80,50,x+80,275);
			floodfill( x,200, LIGHTCYAN );
		}

} swats;

int final_x, final_y;

class fly
{
	private:
		int move_x, move_y, current_x, current_y;

	public:
		void draw_fly( int& );

		void show_fly()
		{
			setcolor( WHITE );
			setfillstyle( SOLID_FILL, getcolor() );
			circle( final_x, final_y, 4 );
			floodfill( final_x, final_y, getcolor() );
		}
} fly;


void fly :: draw_fly( int &time )
{

	randomize();

	current_x = random(600);
	current_y = random(275);

	for( int i=0; i<10; i++ )
	{
		setcolor( WHITE );
		setfillstyle( SOLID_FILL, getcolor() );
		circle( current_x, current_y, 4 );
		floodfill( current_x, current_y, getcolor() );
		sound(200);

		delay( time );
		setcolor( BLACK );
		setfillstyle( SOLID_FILL, getcolor() );
		circle( current_x, current_y, 4 );
		floodfill( current_x, current_y, getcolor() );
		nosound();

		final_x = current_x;
		final_y = current_y;

		move_x = random(300);
		move_y = random(175);

		if ( current_x + move_x > 600 )
			current_x -= 1.25 * move_x;
				else	current_x += move_x;

		if ( current_x <= 0 )
			current_x += 0.75 * move_x;

		if ( current_y + move_y > 275 )
			current_y -= move_y;

		else if( current_y + move_y < 50 )
				current_y += 2 * move_y;
					else	current_y += move_y;


	}
}


void main()
{
	int pos;
	int swat_number;
	int time = 700;

	enum state{ WIN,LOSE };
	state user;

	int driver=DETECT;
	int mode=DETECT;
	initgraph(&driver,&mode,"\\borlandc\\bgi");
		highvideo();


	do
	{
		user = LOSE;
		pos = 120;

		cleardevice();
		fly.draw_fly( time );
		time-= 50;

		for( int i=0; i<3; i++ )
		{

			swats.draw_swat( pos );
			pos+=200;
		}

		settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
		outtextxy( 10,5, "Enter swat number?" );
		swat_number = getch();

		cleardevice();

		switch ( swat_number )
		{
			case '1' :  if( ( final_x < 220 && final_x > 0 ))
					user = WIN;
				    break;

			case '2' :  if( ( final_x < 420 && final_x > 220 ) )
					user = WIN;
				    break;

			case '3' :  if( ( final_x < 620 && final_x > 420 ) )
					user = WIN;
				    break;
		}

		cleardevice();


		if( time <= 700 && user == WIN )
		{
			settextstyle(TRIPLEX_FONT,HORIZ_DIR,11);

			for( int i=1; i<15; i++ )
			{
				setcolor(i);
				outtextxy( 180,10,"FLY" );
				outtextxy( 30,150,"SWATTING" );
				outtextxy( 10,300,"CHAMPION" );
				delay(1000);
			}
			exit( EXIT_SUCCESS );
		}

		fly.show_fly();

		settextstyle(TRIPLEX_FONT,HORIZ_DIR,9);

		if( user == WIN )
		{
			setcolor(LIGHTGREEN);
			outtextxy( 40,350,"YOU WON !!!!" );
		}
		else
		{
			setcolor(LIGHTRED);
			outtextxy( 40,350,"YOU LOSE !!!!" );
		}

		getch();


	}while( user == WIN );
}

⌨️ 快捷键说明

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