int main()
{
	int gDriver=DETECT,gMode=0,i;
	initgraph(&gDriver,&gMode,"C:\\TC\\BGI");

	float rad=0.01;
	int string_bottom_x,string_bottom_y;
	int ball_x,ball_y,sign=1;

	background();
	drawString(320,300);
	eraseString(320,300);
	//drawBall(320,320);

	for(rad=0.01;rad<T;rad+=(sign*0.01))
	{	string_bottom_y=cos(rad)*L;
		string_bottom_x=sin(rad)*L;
		ball_y=cos(rad)*(L+20);
		ball_x=sin(rad)*(L+20);
		//cout<<"("<<ball_x<<"|"<<ball_y<<")";
		drawString(320-string_bottom_x,100+string_bottom_y);
		drawBall(320-ball_x,100+ball_y);
		delay(60);
		eraseString(320-string_bottom_x,100+string_bottom_y);
		eraseBall(320-ball_x,100+ball_y);
		if(ball_y==190&&ball_x==109)
		{	sign=-1;
		}
		if(ball_y==190&&ball_x==-109)
		{	sign=1;
			//getch();
		}
	}


	getch();
	return 0;
}
int main(void)
{
    //Enable background 2 and set mode to MODE_4
	setMode(MODE_4 | OBJ_MAP_1D | BG2_ENABLE);
	
	showGameIntro();
	WaitForStart();
	EraseScreen();

	initGameBasicParameters();
	
    //game loop
    while(1)
    {
	    if(score1 != MAX_POINTS_TO_WIN && score2 != MAX_POINTS_TO_WIN){
		    waitRetrace();
        
	        eraseBall();
	        erasePaddle1();
	        erasePaddle2();
	
	        updatePaddle1();
	        updatePaddle2();
	        updateBall();
	
	        drawPaddle1();
	        drawPaddle2();
	
	        checkCollisions();
	        drawBall();
	
	        printScores();
	    }else{
		    if(score1 == MAX_POINTS_TO_WIN && state ==  0){ // PLAYER-CHINA
			    score1 = 0;
			    score2 = 0;
			    
			    //Enable background 2 and set mode to MODE_4
				setMode(MODE_4 | OBJ_MAP_1D | BG2_ENABLE);
			    showChinaEnding();
			    EraseScreen();
		    }
		    if(score1 == MAX_POINTS_TO_WIN && state ==  1){ // PLAYER-USA
				score1 = 0;
			    score2 = 0;
			    
			    //Enable background 2 and set mode to MODE_4
				setMode(MODE_4 | OBJ_MAP_1D | BG2_ENABLE);
			    showUSAEnding();
			    EraseScreen();
		    }
		    if(score2 == MAX_POINTS_TO_WIN && state ==  0){ // CPU-CHINA
			    score2 = 0;
			    score1 = 0;
			    
			    //Enable background 2 and set mode to MODE_4
				setMode(MODE_4 | OBJ_MAP_1D | BG2_ENABLE);
			    //showChinaEnding();
				showPlayerDefeatedByEEUU();
			    EraseScreen();
		    }
		    if(score2 == MAX_POINTS_TO_WIN && state ==  1){ // CPU-USA
			    score2 = 0;
			    score1 = 0;
			    
			    //Enable background 2 and set mode to MODE_4
				setMode(MODE_4 | OBJ_MAP_1D | BG2_ENABLE);
			    //showUSAEnding();
				showPlayerDefeatedByChina();
			    EraseScreen();
		    }   
		    
		    initGameBasicParameters();
	    }
    }

    return 0;
}