C语言实现愤怒的小鸟游戏(含登录注册,击地碰撞等功能)

说明:
由于csdn无法分享文件,因此需要游戏源代码,图片,音乐等资源的请在评论区评论

所用平台:
windows下装有EasyX的vs2022

主要功能:
请添加图片描述
进度加载条
菜单内选项 1.开始游玩 2.游戏玩法 3.游戏背景介绍 0.退出游戏
请添加图片描述
摁任意键以继续
请添加图片描述
注册界面
请添加图片描述
登录界面,其输入框都可实现输入字符的回文显示功能
请添加图片描述
游戏加载页面
请添加图片描述
游戏主菜单页面
实现开始选择关卡,充值,和退出游戏
充值界面用的是作者的微信付款码,在这里不方便展示
请添加图片描述
关卡的选择,总共有两关,沙滩关卡和糖果关卡
请添加图片描述
沙滩关卡
请添加图片描述
糖果关卡
请添加图片描述
失败界面
请添加图片描述
退出游戏界面

游戏内还有音乐,但csdn无法分享,其均还原游戏内音乐,包括经典的主题音乐,关卡背景音,小鸟发射音等。包括登录注册页面的摁扭,都有属于自己的摁扭音

游戏源代码如下:

game.h

#pragma once
#pragma comment(lib,"Winmm.lib")
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <conio.h>
#include <graphics.h>
#include <time.h>

#define HIGH 600
#define WIDTH 800
#define LEN 25// 加载长度
#define G 2

typedef struct bird {
	int bird_x;
	int bird_y;
	int bird_vx;
	int bird_vy;
	int bird_type;
	struct bird* next;
} SListNodeBird;

typedef struct pig {
	int pig_x;
	int pig_y;
	int pig_vx;
	int pig_vy;
	int pig_type;
	struct pig* next;
} SListNodePig;

//fix
void Gotoxy(int x, int y);
void HideCursor();
void drawAlpha(IMAGE* picture, int  picture_x, int picture_y); //x为要载入图片的X坐标,y为Y坐标

//init
void menu();
void DataInit();
void Game1Init();
void Game2Init();

//login
void WriteRegisterUserInfo();
void WriteLoginUserInfo();
void LoginUpdateWithInput();

//main
void ChooseLevel();
void ShowMainInterface();
void MainInterfaceWithInput();

//show
void ShowGame1();
void ShowGame2();
void ShowLogin();

//game
void Game1UpdateWithoutInput();
void Game1UpdateWithInput();
void Game2UpdateWithoutInput();
void Game2UpdateWithInput();

//birdList
void SListBirdPushBack(SListNodeBird** phead, int x, int y, int vx, int vy,int type);
void SListBirdPopFront(SListNodeBird** phead);
void SListBirdPrint(SListNodeBird* phead);
SListNodeBird* SListBirdFind(SListNodeBird* phead, int x, int y, int vx, int vy, int type);

//pigList
void SListPigPushBack(SListNodePig** phead, int x, int y, int vx, int vy, int type);
void SListPigPopFront(SListNodePig** phead);
void SListPigPrint(SListNodePig* phead);
SListNodePig* SListPigFind(SListNodePig* phead, int x, int y, int vx, int vy, int type);
void SListPigPopBack(SListNodePig** phead);

void Gameover();

fix.cpp

#include "game.h"

//隐藏光标
void HideCursor()
{
	CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };//后边的0代表光标不可见
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

//光标移动
void Gotoxy(int x, int y)
{
	HANDLE hout; //定义句柄变量hout
	COORD coord; //定义结构体coord
	coord.X = x;
	coord.Y = y;
	hout = GetStdHandle(STD_OUTPUT_HANDLE);//获得标准输出(屏幕)句柄
	SetConsoleCursorPosition(hout, coord);//移动光标
}

// 载入PNG图并去透明部分
void drawAlpha(IMAGE* picture, int  picture_x, int picture_y) //x为载入图片的X坐标,y为Y坐标
{

	// 变量初始化
	DWORD* dst = GetImageBuffer();    // GetImageBuffer()函数,用于获取绘图设备的显存指针,EASYX自带
	DWORD* draw = GetImageBuffer();
	DWORD* src = GetImageBuffer(picture); //获取picture的显存指针
	int picture_width = picture->getwidth(); //获取picture的宽度,EASYX自带
	int picture_height = picture->getheight(); //获取picture的高度,EASYX自带
	int graphWidth = getwidth();       //获取绘图区的宽度,EASYX自带
	int graphHeight = getheight();     //获取绘图区的高度,EASYX自带
	int dstX = 0;    //在显存里像素的角标

	// 实现透明贴图 公式: Cp=αp*FP+(1-αp)*BP , 贝叶斯定理来进行点颜色的概率计算
	for (int iy = 0; iy < picture_height; iy++)
	{
		for (int ix = 0; ix < picture_width; ix++)
		{
			int srcX = ix + iy * picture_width; //在显存里像素的角标
			int sa = ((src[srcX] & 0xff000000) >> 24); //0xAArrggbb;AA是透明度
			int sr = ((src[srcX] & 0xff0000) >> 16); //获取RGB里的R
			int sg = ((src[srcX] & 0xff00) >> 8);   //G
			int sb = src[srcX] & 0xff;              //B
			if (ix >= 0 && ix <= graphWidth && iy >= 0 && iy <= graphHeight && dstX <= graphWidth * graphHeight)
			{
				dstX = (ix + picture_x) + (iy + picture_y) * graphWidth; //在显存里像素的角标
				int dr = ((dst[dstX] & 0xff0000) >> 16);
				int dg = ((dst[dstX] & 0xff00) >> 8);
				int db = dst[dstX] & 0xff;
				draw[dstX] = ((sr * sa / 255 + dr * (255 - sa) / 255) << 16)  //公式: Cp=αp*FP+(1-αp)*BP  ; αp=sa/255 , FP=sr , BP=dr
					| ((sg * sa / 255 + dg * (255 - sa) / 255) << 8)         //αp=sa/255 , FP=sg , BP=dg
					| (sb * sa / 255 + db * (255 - sa) / 255);              //αp=sa/255 , FP=sb , BP=db
			}
		}
	}
}

test.cpp

#include "game.h"

IMAGE img_begin;
IMAGE img_bk;//登录背景
IMAGE img_loading;//正在加载
IMAGE img_start;//开始界面
IMAGE img_bg;//游戏内背景
IMAGE img_bg2;//游戏内背景

IMAGE img_bird1;
IMAGE img_pig1;
IMAGE img_bird2;
IMAGE img_pig2;
IMAGE img_bird3;
IMAGE img_pig3;
IMAGE img_bird4;
IMAGE img_pig4;

IMAGE img_board;
IMAGE img_money;
IMAGE img_win;
IMAGE img_level;
IMAGE img_gameover;
IMAGE img_wasted;

int bird1_x, bird1_y;
int bird2_x, bird2_y;
int slingshot_x, slingshot_y;//弹弓位置
int pig1_x, pig1_y;
int pig2_x, pig2_y;
int pig3_x, pig3_y;
int pig4_x, pig4_y;
int board_x, board_y;
int bird1_vx, bird1_vy;//初始化速度
int bird2_vx, bird2_vy;
int board_vx, board_vy;
int pig1_vx, pig1_vy;
int pig2_vx, pig2_vy;

int isPig;//是否有猪
int isBoard;//是否有木板
int isEmission1;//是否已发射
int isEmission2;//是否已发射
int isRegister;//是否激活注册
int isLogin;//是否激活登录
int fillRegistration;//是否开始注册
int isEnter;//是否确定
int isSamePassword;//第二次确认密码是否和第一次相同
int fillLogin;//是否开始登录
int isSuccesslogin;//是否成功登录
int isLoading;//是否需要加载
int money;
int showLogin;
int play;

int isDrawBird1;
int isDrawPig1;
int isDrawBird2;
int isDrawPig2;
int win1;
int win2;
int isBegin;
int level;
int beginLogin;
int rebound1;
int rebound2;
int gameOver;

SListNodeBird* pBirdList1;
SListNodeBird* pBirdList2;

SListNodePig* pPigList1;
SListNodePig* pPigList2;

int main()
{
	DataInit();     //数据初始化
	while (1)
	{
		//登录
		if (showLogin == 1)
		{
			ShowLogin();
		}
		if (showLogin == 1)
		{
			LoginUpdateWithInput();
		}


		//主页面操作
		if (showLogin == 0 && (level != 1 && level != 2))//显示主页面
		{
			ShowMainInterface();
		}
		if (showLogin == 0 && play == 0)//主页面摁纽操作
		{
			MainInterfaceWithInput();
		}
		if (showLogin == 0 && level == 0 && play == 1)//选择关卡
		{
			ChooseLevel();
		}


		//关卡一操作
		if (showLogin == 0 && level == 1 && play == 1)//关卡一
		{
			ShowGame1();
		}
		if (showLogin == 0 && level == 1 && play == 1)//关卡一
		{
			Game1UpdateWithInput();//与用户操作有关的输出
		}
		if (showLogin == 0 && level == 1 && play == 1)//关卡一
		{
			Game1UpdateWithoutInput();//与用户无关的数据更新
		}


		//关卡二操作
		if (showLogin == 0 && level == 2 && play == 1)//关卡二
		{
			ShowGame2();
		}
		if (showLogin == 0 && level == 2 && play == 1)//关卡二
		{
			Game2UpdateWithInput();//与用户操作有关的输出
		}
		if (showLogin == 0 && level == 2 && play == 1)//关卡二
		{
			Game2UpdateWithoutInput();//与用户无关的数据更新
		}

		if (gameOver == 1)
		{
			break;
		}

	}
	Gameover();
	return 0;
}

game.cpp

#include "game.h"

extern IMAGE img_begin;
extern IMAGE img_bk;
extern IMAGE img_bg;//游戏内背景
extern IMAGE img_bg2;//游戏内背景

extern IMAGE img_bird1;
extern IMAGE img_pig1;
extern IMAGE img_bird2;
extern IMAGE img_pig2;
extern IMAGE img_bird3;
extern IMAGE img_pig3;
extern IMAGE img_bird4;
extern IMAGE img_pig4;

extern IMAGE img_board;
extern IMAGE img_loading;//正在加载
extern IMAGE img_start;//开始界面
extern IMAGE img_money;
extern IMAGE img_win;
extern IMAGE img_level;
extern IMAGE img_gameover;
extern IMAGE img_wasted;

extern int bird1_x, bird1_y;
extern int bird2_x, bird2_y;
extern int slingshot_x, slingshot_y;//弹弓位置
extern int pig1_x, pig1_y;
extern int pig2_x, pig2_y;
extern int pig3_x, pig3_y;
extern int pig4_x, pig4_y;
extern int board_x, board_y;
extern int bird1_vx, bird1_vy;//初始化速度
extern int bird2_vx, bird2_vy;
extern int board_vx, board_vy;
extern int pig1_vx, pig1_vy;
extern int pig2_vx, pig2_vy;

extern int isPig;//是否有猪
extern int isBoard;//是否有木板
extern int isEmission1;
extern int isEmission2;
extern int isRegister;//是否激活注册
extern int isLogin;//是否激活登录
extern int fillRegistration;//是否开始注册
extern int isEnter;//是否确定
extern int isSamePassword;//第二次确认密码是否和第一次相同
extern int fillLogin;//是否开始登录
extern int isSuccesslogin;//是否成功登录
extern int isLoading;//是否需要加载
extern int money;
extern int showLogin;
extern int play;

extern int isDrawBird1;
extern int isDrawPig1;
extern int isDrawBird2;
extern int isDrawPig2;
extern int win1;
extern int win2;
extern int isBegin;
extern int level;
extern int beginLogin;
extern int rebound1;
extern int rebound2;
extern int gameOver;

extern SListNodeBird* pBirdList1;
extern SListNodeBird* pBirdList2;

extern SListNodePig* pPigList1;
extern SListNodePig* pPigList2;

void menu()
{
	printf("############################\n");
	printf("####    1.Play          ####\n");
	printf("####    2.Gameplay      ####\n");
	printf("####    3.Introduction  ####\n");
	printf("####    0.Exit          ####\n");
	printf("############################\n");
}

void Game1Init()
{
	isEmission1 = 0;//未发射
	isDrawBird1 = 1;//显示小鸟
	isDrawPig1 = 1;//显示小猪
	rebound1 = 0;
	bird1_x = 55;
	bird1_y = 415;
	pig1_x = 570;
	pig1_y = 400;
	pig3_x = 670;
	pig3_y = 355;

	bird1_vx = 0;//初始化速度
	bird1_vy = 0;
	board_vx = 0;
	board_vy = 0;
	pig1_vx = 0;
	pig1_vy = 0;

	//初始化链表
	pBirdList1 = NULL;
	pPigList1 = NULL;

	SListBirdPushBack(&pBirdList1, bird1_x, bird1_y, bird1_vx, bird1_vy, 1);
	SListBirdPushBack(&pBirdList1, bird1_x, bird1_y, bird1_vx, bird1_vy, 1);
	SListBirdPushBack(&pBirdList1, bird1_x, bird1_y, bird1_vx, bird1_vy, 1);
	SListBirdPushBack(&pBirdList1, bird1_x, bird1_y, bird1_vx, bird1_vy, 3);
	SListBirdPushBack(&pBirdList1, bird1_x, bird1_y, bird1_vx, bird1_vy, 3);
	SListBirdPushBack(&pBirdList1, bird1_x, bird1_y, bird1_vx, bird1_vy, 3);

	SListPigPushBack(&pPigList1, pig1_x, pig1_y, pig1_vx, pig1_vy, 1);
	SListPigPushBack(&pPigList1, pig3_x, pig3_y, pig1_vx, pig1_vy, 3);
}

void Game2Init()
{
	isEmission2 = 0;//未发射
	isDrawBird2 = 1;//显示小鸟
	isDrawPig2 = 1;//显示小猪
	rebound2 = 0;

	bird2_x = 60;//初始化位置
	bird2_y = 470;
	pig2_x = 550;
	pig2_y = 170;
	pig4_x = 275;
	pig4_y = 470;

	bird2_vx = 0;//初始化速度
	bird2_vy = 0;
	pig2_vx = 0;
	pig2_vy = 0;

	//初始化链表
	pBirdList2 = NULL;
	pPigList2 = NULL;

	SListBirdPushBack(&pBirdList2, bird2_x, bird2_y, bird2_vx, bird2_vy, 2);
	SListBirdPushBack(&pBirdList2, bird2_x, bird2_y, bird2_vx, bird2_vy, 2);
	SListBirdPushBack(&pBirdList2, bird2_x, bird2_y, bird2_vx, bird2_vy, 2);
	SListBirdPushBack(&pBirdList2, bird2_x, bird2_y, bird2_vx, bird2_vy, 4);
	SListBirdPushBack(&pBirdList2, bird2_x, bird2_y, bird2_vx, bird2_vy, 4);
	SListBirdPushBack(&pBirdList2, bird2_x, bird2_y, bird2_vx, bird2_vy, 4);

	SListPigPushBack(&pPigList2, pig2_x, pig2_y, pig2_vx, pig2_vy, 2);
	SListPigPushBack(&pPigList2, pig4_x, pig4_y, pig2_vx, pig2_vy, 4);

}
void DataInit()//数据初始化
{
	//初始进度条
	int len;
	HideCursor();
	for (len = 1; len <= LEN; len++) {
		Gotoxy(2 * len, 1);
		printf("█");
		Gotoxy(21, 4);
		printf("已完成%d%%", 4 * len);
		Sleep(100);
	}
	Gotoxy(21, 4);
	printf("游戏加载已完成\n");
	Sleep(700);

	int input = 1;
	beginLogin = 0;
	menu();
	while (beginLogin != 1)
	{
		do
		{
			scanf("%d", &input);
			switch (input)
			{
			case 0:
				printf("Looking forward to the next visit\n");
				exit(-1);
			case 1:
				printf("Have a great time\n");
				beginLogin = 1;
				break;
			case 2:
				printf("The gameplay is as follows\n");
				printf("Use WASD to control the shooting direction of the bird to make it hit the pig\n");
				break;
			case 3:
				printf("The game introduction is as follows\n");
				printf("\"Angry Birds\" is a casual puzzle game developed by Rovio, which was first released on iOS in December 2009.\n");
				printf("The game is based on the background of the bird's revenge on the fat pig who stole the eggs, and tells a series of stories between the bird and the fat pig.\n");
				printf("On March 18, 2016, the then United Nations Secretary-General Ban Ki-moon appointed the red bird in the game as the Green Honorary Ambassador.And in the same year, it was adapted into the movie \"Angry Birds\" of the same name.\n");
				break;
			default:
				printf("error choose\n");
				break;
			}
		} while (input && beginLogin != 1);
	}


	//初始化画布
	initgraph(WIDTH, HIGH, EW_SHOWCONSOLE);// 800 * 600

	//图片变量
	loadimage(&img_begin, ".\\begin.jpg");
	loadimage(&img_bk, ".\\bk.jpg");
	loadimage(&img_loading, ".\\loading.jpg");
	loadimage(&img_bg, ".\\bg.jpg");
	loadimage(&img_bg2, ".\\bg2.jpg");
	loadimage(&img_start, ".\\start.jpg");
	loadimage(&img_money, ".\\money.jpg");

	loadimage(&img_bird1, ".\\bird1.png");
	loadimage(&img_pig1, ".\\pig1.png");
	loadimage(&img_bird2, ".\\bird2.png");
	loadimage(&img_pig2, ".\\pig2.png");
	loadimage(&img_bird3, ".\\bird3.png");
	loadimage(&img_pig3, ".\\pig3.png");
	loadimage(&img_bird4, ".\\bird4.png");
	loadimage(&img_pig4, ".\\pig4.png");

	loadimage(&img_win, ".\\win.png");
	loadimage(&img_level, ".\\level.jpg");
	loadimage(&img_gameover, ".\\gameover.jpg");
	loadimage(&img_wasted, ".\\wasted.jpg");


	//登录变量
	isBegin = 1;//显示 输入任意键以开始
	isLogin = 0;//未登录
	isRegister = 0;//未注册
	fillRegistration = 0;//未填写注册
	fillLogin = 0;//未填写登录
	isEnter = 0;//未点击确认
	isSamePassword = 0;//注册时两次密码不相同
	isSuccesslogin = 0;//未成功登录
	gameOver = 0;


	//主页面变量
	isLoading = 1;//需要加载
	money = 0;//未点击充值
	showLogin = 1;//显示注册
	play = 0;//未开始游玩
	win1 = 0;//未成功击中
	win2 = 0;//未成功击中
	level = -1;// 不选择关卡

	//游戏内数据初始化
	Game1Init();
	Game2Init();

	//未使用变量
	slingshot_x = 500;
	slingshot_y = 100;//弹弓位置
	board_x = 100;
	board_y = 300;
	isPig = 0;//是否有猪
	isBoard = 0;//是否有木板

	BeginBatchDraw();
}




//登录界面设计
void ShowLogin()//显示登录画面
{
	char username[] = "用户名:";
	char password[] = "密码:";
	char passwordConfirm[] = "请确认密码";
	char registered[] = "注册";
	char login[] = "登录";
	char confirm[] = "确认";
	char pleaseEnter[] = "请输入您的用户名和密码:";
	char notSame[] = "第二次输入密码和第一次不匹配";

	if (isBegin == 1)
	{
		putimage(0, 0, &img_begin);
		FlushBatchDraw();

		mciSendString("open .\\title_theme.mp3 alias bkmusic", NULL, 0, NULL);
		mciSendString("play bkmusic repeat", NULL, 0, NULL);//播放背景音乐

		_getch();
		isBegin = 0;
	}
	mciSendString("close bkmusic", NULL, 0, NULL);//暂停背景音乐

	putimage(0, 0, &img_bk);//显示背景
	setbkmode(TRANSPARENT);//设置透明文字
	outtextxy(300, 400, username);//用户名字体输出 宽度300,高度400
	outtextxy(300, 450, password);//密码字体输出 宽度300,高度450
	outtextxy(335, 475, login); //登录字体输出 宽度335,高度475
	outtextxy(435, 475, registered); //注册字体输出 宽度435,高度475

	fillrectangle(350, 400, 500, 415);//用户名方框输出 左350上400右500下415
	fillrectangle(350, 450, 500, 465);//密码方框输出 左350上450右500下465

	if (isRegister == 1)
	{
		setcolor(RED);
		fillrectangle(200, 200, 600, 500);//输出边框 左200上200右600下500
		outtextxy(250, 250, username);//用户名字体输出 宽度250,高度250
		outtextxy(250, 275, password);//密码字体输出 宽度250,高度275
		outtextxy(250, 300, passwordConfirm);//确认密码字体输出 宽度250,高度300
		outtextxy(500, 400, confirm);//确认字体输出 宽度500,高度400

		setcolor(BLACK);
		fillrectangle(300, 250, 500, 265);//用户名方框输出 左300上250右500下265
		fillrectangle(300, 275, 500, 290);//密码方框输出 左300上275右500下290
		fillrectangle(330, 300, 500, 315);//密码方框输出 左330上300右500下315

		if (fillRegistration == 1)//开始填写注册信息
		{
			outtextxy(300, 450, pleaseEnter);//请输入字体输出 宽300,高度450
			FlushBatchDraw();
			WriteRegisterUserInfo();//填写注册用户信息

			if (isSamePassword == 1) //第二次密码和第一次不同
			{
				closegraph();
				printf("Inconsistent password entered twice");
				Sleep(700);
				exit(0);
			}
		}

		if (isEnter == 1)//返回主页面
		{
			putimage(0, 0, &img_bk);//显示背景

			int i = 0;
			char username[] = "用户名:";
			char password[] = "密码:";
			char passwordConfirm[] = "请确认密码";
			char registered[] = "注册";
			char login[] = "登录";
			char confirm[] = "确认";
			char pleaseEnter[] = "请输入您的用户名和密码:";

			setbkmode(TRANSPARENT);//设置透明文字
			outtextxy(300, 400, username);//用户名字体输出 宽度300,高度400
			outtextxy(300, 450, password);//密码字体输出 宽度300,高度450
			outtextxy(335, 475, login); //登录字体输出 宽度335,高度475
			outtextxy(435, 475, registered); //注册字体输出 宽度435,高度475

			fillrectangle(350, 400, 500, 415);//用户名方框输出 左350上400右500下415
			fillrectangle(350, 450, 500, 465);//密码方框输出 左350上450右500下465
		}
	}

	if (fillLogin == 1)//开始填写登录信息
	{
		outtextxy(300, 500, pleaseEnter);//请输入字体输出 宽300,高度500
		FlushBatchDraw();
		WriteLoginUserInfo();//填写注册用户信息
	}

	if (isLogin == 1)//点击登录
	{
		if (isSuccesslogin == 1)//成功登录
		{
			showLogin = 0;
		}
	}

	FlushBatchDraw();
}

void LoginUpdateWithInput()//登录用户交互
{
	MOUSEMSG m;//定义鼠标信息
	while (MouseHit())//检测是否有鼠标信息
	{
		m = GetMouseMsg();

		if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= 430 && m.x <= 465) && (m.y >= 465 && m.y <= 485)) //如果鼠标左键点击注册
		{
			mciSendString("open .\\channel_toggle_button.mp3 alias btmusic", NULL, 0, NULL);
			mciSendString("play btmusic wait", NULL, 0, NULL);
			mciSendString("close btmusic", NULL, 0, NULL);

			isRegister = 1;
		}
		if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= 330 && m.x <= 365) && (m.y >= 465 && m.y <= 485)) //如果鼠标左键点击登录
		{
			mciSendString("open .\\channel_toggle_button.mp3 alias btmusic", NULL, 0, NULL);
			mciSendString("play btmusic wait", NULL, 0, NULL);
			mciSendString("close btmusic", NULL, 0, NULL);

			isLogin = 1;
		}
		if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= 290 && m.x <= 510) && (m.y >= 240 && m.y <= 325)) //如果鼠标左键点击注册信息
		{
			mciSendString("open .\\channel_toggle_button.mp3 alias btmusic", NULL, 0, NULL);
			mciSendString("play btmusic wait", NULL, 0, NULL);
			mciSendString("close btmusic", NULL, 0, NULL);

			fillRegistration = 1;
		}
		if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= 490 && m.x <= 520) && (m.y >= 390 && m.y <= 410)) //如果鼠标左键点击确定
		{
			mciSendString("open .\\channel_toggle_button.mp3 alias btmusic", NULL, 0, NULL);
			mciSendString("play btmusic wait", NULL, 0, NULL);
			mciSendString("close btmusic", NULL, 0, NULL);

			isEnter = 1;
		}
		if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= 330 && m.x <= 510) && (m.y >= 390 && m.y <= 470)) //如果鼠标左键点击登录信息
		{
			mciSendString("open .\\channel_toggle_button.mp3 alias btmusic", NULL, 0, NULL);
			mciSendString("play btmusic wait", NULL, 0, NULL);
			mciSendString("close btmusic", NULL, 0, NULL);

			fillLogin = 1;
		}
	}
}

void WriteRegisterUserInfo()//填写注册信息
{
	setcolor(BLACK);
	int i = 0;
	int j = 0;
	int k = 0;
	char name;
	char pass;
	char passcon;
	
	char ch;
	while ((ch = getchar()) != EOF && ch != '\n')
	{
		;
	}

	FILE* fp;

	char username[10];
	char password[10];
	char confirmPassword[10];

	/*printf("Please input username\n");
	gets_s(username);

	printf("Please input password\n");
	gets_s(password);

	printf("Please concirm password\n");
	gets_s(confirmPassword);*/

	printf("Please input username\n");
	while ((name = _getch()) != '\r')
	{
		username[i] = name;
		username[i + 1] = '\0';
		outtextxy(305, 250, username);
		printf("%c", username[i]);
		i++;
		FlushBatchDraw();
	}

	printf("Please input password\n");
	while ((pass = _getch()) != '\r')
	{
		password[j] = pass;
		password[j + 1] = '\0';
		outtextxy(305, 275, password);
		printf("%c", password[j]);
		j++;
		FlushBatchDraw();
	}

	printf("Please concirm password\n");
	while ((passcon = _getch()) != '\r')
	{
		confirmPassword[k] = passcon;
		confirmPassword[k + 1] = '\0';
		outtextxy(335, 300, confirmPassword);
		printf("%c", confirmPassword[k]);
		k++;
		FlushBatchDraw();
	}

	if (strcmp(password, confirmPassword) != 0) //两次密码输入不一致
	{
		isSamePassword = 1;
	}

	fopen_s(&fp, "userInfo.txt", "w");
	if (fp == NULL)
	{
		printf("Can not open this file\n");
	}
	fprintf(fp, "%s %s %s", username, password, confirmPassword);
	fclose(fp);

	printf("Success register!!\n");

	fillRegistration = 0;//完成注册
}

void WriteLoginUserInfo()//填写登录信息
{
	setcolor(BLACK);
	char ch;
	while ((ch = getchar()) != EOF && ch != '\n')
	{
		;
	}

	FILE* fp;

	char username[10];
	char password[10];
	char usernameTrue[10];
	char passwordTrue[10];
	char confirmPassword[10];

	fopen_s(&fp, "userInfo.txt", "r");
	if (fp == NULL)
	{
		printf("Can not open this file\n");
	}
	fscanf(fp, "%s %s %s", &usernameTrue, &passwordTrue, &confirmPassword);
	//printf("密码为:%s %s\n", usernameTrue, passwordTrue);

	/*printf("Please input username\n");
	gets_s(username);
	outtextxy(350, 400, username);
	FlushBatchDraw();

	printf("Please input password\n");
	gets_s(password);
	outtextxy(350, 450, password);
	FlushBatchDraw();*/

	int i = 0;
	int j = 0;
	int k = 0;
	char name;
	char pass;

	//fillrectangle(350, 400, 500, 415);//用户名方框输出 左350上400右500下415
	//fillrectangle(350, 450, 500, 465);//密码方框输出 左350上450右500下465

	printf("Please input username\n");
	while ((name = _getch()) != '\r')
	{
		username[i] = name;
		username[i + 1] = '\0';
		outtextxy(350, 400, username);
		printf("%c", username[i]);
		i++;
		FlushBatchDraw();
	}

	printf("Please input password\n");
	while ((pass = _getch()) != '\r')
	{
		password[j] = pass;
		password[j + 1] = '\0';
		outtextxy(350, 450, password);
		printf("%c", password[j]);
		j++;
		FlushBatchDraw();
	}

	printf("%s %s\n", username, password);

	if (strcmp(username, usernameTrue) == 0 && strcmp(password, passwordTrue) == 0)//登录成功
	{
		printf("Success login\n");
		isSuccesslogin = 1;
	}
	else//登陆失败
	{
		closegraph();
		printf("Wrong password,login failed\n");
		Sleep(700);
		exit(0);
	}
	fclose(fp);

	fillLogin = 0;
}




//游戏主页面设计
void ShowMainInterface()//显示主页面
{
	mciSendString("open .\\funky_theme.mp3 alias thememusic", NULL, 0, NULL);//播放主页面背景音乐
	mciSendString("play thememusic repeat", NULL, 0, NULL);

	if (isLoading == 1)
	{
		putimage(0, 0, &img_loading);
		FlushBatchDraw();
		isLoading = 0;
		Sleep(5000);
	}
	putimage(0, 0, &img_start);

	if (money == 1 && play == 0)
	{
		putimage(0, 0, &img_money);
		FlushBatchDraw();
	}

	if (play == 1)
	{
		level = 0;
		putimage(0, 0, &img_level);
		FlushBatchDraw();
	}
	FlushBatchDraw();
}

void MainInterfaceWithInput()//主页面用户交互
{
	MOUSEMSG m;//定义鼠标信息
	while (MouseHit())//检测是否有鼠标信息
	{
		m = GetMouseMsg();
		if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= 370 && m.x <= 450) && (m.y >= 120 && m.y <= 230))//如果鼠标左键点击充值
		{
			money = 1;
			printf("please give me money\n");
		}

		if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= 370 && m.x <= 430) && (m.y >= 290 && m.y <= 390))//如果鼠标左键点击开始游戏
		{
			mciSendString("close thememusic", NULL, 0, NULL);

			mciSendString("open .\\toons_transition.mp3 alias transmusic", NULL, 0, NULL);
			mciSendString("play transmusic wait", NULL, 0, NULL);
			mciSendString("close transmusic", NULL, 0, NULL);

			play = 1;
			printf("play\n");
		}

		if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= 0 && m.x <= 100) && (m.y >= 500 && m.y <= 600))//如果鼠标左键点击退出游戏
		{
			gameOver = 1;
		}
	}
}

void ChooseLevel()//选择关卡
{
	MOUSEMSG m;//定义鼠标信息
	while (MouseHit())//检测是否有鼠标信息
	{
		fillrectangle(250, 0, 530, 600);
		m = GetMouseMsg();
		if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= 250 && m.x <= 530) && (m.y >= 0 && m.y <= 600)) //如果鼠标左键点击关卡一
		{
			printf("1");
			level = 1;
			Game1Init();

			mciSendString("open .\\level_start_military_a1.mp3 alias startmusic", NULL, 0, NULL);//开始声音
			mciSendString("play startmusic wait", NULL, 0, NULL);
			mciSendString("close startmusic", NULL, 0, NULL);
		}
		if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= 530 && m.x <= 800) && (m.y >= 0 && m.y <= 600)) //如果鼠标左键点击关卡二
		{
			printf("2");
			level = 2;
			Game2Init();

			mciSendString("open .\\level_start_military_a2.mp3 alias start2music", NULL, 0, NULL);//开始声音
			mciSendString("play start2music wait", NULL, 0, NULL);
			mciSendString("close start2music", NULL, 0, NULL);
		}
	}
}



//关卡一游戏内设计
void ShowGame1()//关卡一游戏画面显示
{
	putimage(0, 0, &img_bg);
	//fillrectangle(0, 500, 800, 600);地面位置
	mciSendString("close thememusic", NULL, 0, NULL);
	mciSendString("open .\\BeachAmbience.mp3 alias beachmusic", NULL, 0, NULL);//背景音效
	mciSendString("play beachmusic repeat", NULL, 0, NULL);

	//小鸟
	if (pBirdList1 != NULL)
	{
		if (isDrawBird1 == 1 && pBirdList1->bird_x < 790 && pBirdList1->bird_x > 10 && pBirdList1->bird_y < 590 && pBirdList1->bird_y > 10 && pBirdList1->bird_type == 1)
		{
			drawAlpha(&img_bird1, pBirdList1->bird_x, pBirdList1->bird_y);
		}
		else if (isDrawBird1 == 1 && pBirdList1->bird_x < 790 && pBirdList1->bird_x > 10 && pBirdList1->bird_y < 590 && pBirdList1->bird_y > 10 && pBirdList1->bird_type == 3)
		{
			drawAlpha(&img_bird3, pBirdList1->bird_x, pBirdList1->bird_y);
		}
		else
		{
			isEmission1 = 0;
			SListBirdPopFront(&pBirdList1);
		}
	}
	else
	{
		printf("wasted");
		putimage(0, 0, &img_wasted);
		FlushBatchDraw();
		Sleep(3000);
		level = 0;
		play = 0;
	}
	//小猪
	SListNodePig* cur = pPigList1;
	while (cur != NULL && level == 1)
	{
		if (isDrawPig1 == 1 && cur->pig_x < 790 && cur->pig_x > 0 && cur->pig_y < 590 && cur->pig_y > 30)
		{
			if (cur != NULL && cur->pig_type == 1)
			{
				drawAlpha(&img_pig1, cur->pig_x, cur->pig_y);
			}
			if (cur != NULL && cur->pig_type == 3)
			{
				drawAlpha(&img_pig3, cur->pig_x, cur->pig_y);
			}
			if (cur != NULL)
			{
				cur = cur->next;
			}
		}
	}


	if (win1 == 1)
	{
		mciSendString("open .\\rock_destroyed_a2.mp3 alias destorymusic", NULL, 0, NULL);
		mciSendString("play destorymusic wait", NULL, 0, NULL);
		mciSendString("close destorymusic", NULL, 0, NULL);

		drawAlpha(&img_win, 250, 200);
		FlushBatchDraw();

		mciSendString("close beachmusic", NULL, 0, NULL);

		mciSendString("open .\\level_complete.mp3 alias completemusic", NULL, 0, NULL);
		mciSendString("play completemusic wait", NULL, 0, NULL);
		mciSendString("close completemusic", NULL, 0, NULL);

		printf("you win!!!\n");
		//gameOver = 1;
		level = 0;
		play = 0;

		Sleep(2000);
	}

	FlushBatchDraw();
}

void Game1UpdateWithInput()//关卡一游戏内与用户操作有关的输出
{
	char input;
	MOUSEMSG m;//定义鼠标信息

	if (pBirdList1 != NULL)
	{
		while (MouseHit())//检测是否有鼠标信息
		{
			m = GetMouseMsg();
			if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= pBirdList1->bird_x - 20 && m.x <= pBirdList1->bird_x + 20) && (m.y >= pBirdList1->bird_y - 20 && m.y <= pBirdList1->bird_y + 20))//如果鼠标左键点击小鸟
			{
				isEmission1 = 1;
				mciSendString("open .\\cannon_shot_01.mp3 alias cmshotmusic", NULL, 0, NULL);//射击声音
				mciSendString("play cmshotmusic wait", NULL, 0, NULL);
				mciSendString("close cmshotmusic", NULL, 0, NULL);

				mciSendString("open .\\bird_01_flying.mp3 alias fly1music", NULL, 0, NULL);//飞翔声音
				mciSendString("play fly1music wait", NULL, 0, NULL);
				mciSendString("close fly1music", NULL, 0, NULL);
			}
		}


		if (_kbhit())
		{
			input = _getch();
			if (input == 'w')
			{
				pBirdList1->bird_vy--;
				printf("w");
				SListBirdPrint(pBirdList1);
			}
			if (input == 's')
			{
				pBirdList1->bird_vy++;
				printf("s");
				SListBirdPrint(pBirdList1);
			}
			if (input == 'a')
			{
				pBirdList1->bird_vx--;
				printf("a");
				SListBirdPrint(pBirdList1);
			}
			if (input == 'd')
			{
				pBirdList1->bird_vx++;
				printf("d");
				SListBirdPrint(pBirdList1);
			}
		}
	}
}

void Game1UpdateWithoutInput()//关卡一与用户无关的数据更新
{
	// y是纵向
	if (pBirdList1 != NULL && isEmission1 == 1)
	{

		if (pBirdList1 != NULL && pBirdList1->bird_x <= WIDTH && pBirdList1->bird_x >= 10)
		{
			pBirdList1->bird_x = pBirdList1->bird_x + pBirdList1->bird_vx;
		}
		else
		{
			isEmission1 = 0;
			SListBirdPopFront(&pBirdList1);
		}

		if (pBirdList1 != NULL && pBirdList1->bird_y <= HIGH && pBirdList1->bird_y >= 10 )
		{
			pBirdList1->bird_y = pBirdList1->bird_y + pBirdList1->bird_vy;
			pBirdList1->bird_vy = pBirdList1->bird_vy + G;
		}
		else
		{
			isEmission1 = 0;
			SListBirdPopFront(&pBirdList1);
		}
		Sleep(100);

		SListBirdPrint(pBirdList1);

		//击地碰撞
		if (pBirdList1 != NULL && pBirdList1->bird_y >= 500)
		{
			if (pBirdList1->bird_vy > 5)
			{
				pBirdList1->bird_vy -= 10;
				pBirdList1->bird_vy *= -1;
			}
		}

		if (pBirdList1 != NULL && pBirdList1->bird_y >= 520)
		{
			isEmission1 = 0;
			SListBirdPopFront(&pBirdList1);
		}

		if (pPigList1 != NULL && pBirdList1 != NULL)
		{
			if (pBirdList1 != NULL && pPigList1 != NULL && pBirdList1->bird_x >= pPigList1->pig_x - 20 && pBirdList1->bird_x <= pPigList1->pig_x + 20 && pBirdList1->bird_y >= pPigList1->pig_y - 20 && pBirdList1->bird_y <= pPigList1->pig_y + 20)
			{
				isEmission1 = 0;
				SListBirdPopFront(&pBirdList1);
				SListPigPopFront(&pPigList1);
			}
			if (pPigList1 != NULL && pPigList1->next != NULL)
			{
				if (pBirdList1 != NULL && pPigList1 != NULL && pBirdList1->bird_x >= pPigList1->next->pig_x - 20 && pBirdList1->bird_x <= pPigList1->next->pig_x + 20 && pBirdList1->bird_y >= pPigList1->next->pig_y - 20 && pBirdList1->bird_y <= pPigList1->next->pig_y + 20)
				{
					isEmission1 = 0;
					SListBirdPopFront(&pBirdList1);
					SListPigPopBack(&pPigList1);
				}
			}
			
		}
		if(pPigList1 == NULL)
		{
			printf("1");
			isDrawBird1 = 0;
			isDrawPig1 = 0;
			win1 = 1;
		}
	}

}



//关卡二游戏内设计
void ShowGame2()//关卡二游戏画面显示
{
	putimage(0, 0, &img_bg2);

	mciSendString("close thememusic", NULL, 0, NULL);
	mciSendString("open .\\ambience_waterfall.mp3 alias watermusic", NULL, 0, NULL);//背景音效
	mciSendString("play watermusic repeat", NULL, 0, NULL);

	if (pBirdList2 != NULL)
	{
		if (isDrawBird2 == 1 && pBirdList2->bird_x < 790 && pBirdList2->bird_x > 0 && pBirdList2->bird_y < 590 && pBirdList2->bird_y > 30 && pBirdList2->bird_type == 2)
		{
			drawAlpha(&img_bird2, pBirdList2->bird_x, pBirdList2->bird_y);
		}
		else if (isDrawBird2 == 1 && pBirdList2->bird_x < 790 && pBirdList2->bird_x > 0 && pBirdList2->bird_y < 590 && pBirdList2->bird_y > 30 && pBirdList2->bird_type == 4)
		{
			drawAlpha(&img_bird4, pBirdList2->bird_x, pBirdList2->bird_y);
		}
		else
		{
			isEmission2 = 0;
			SListBirdPopFront(&pBirdList2);
		}
	}
	else
	{
		printf("wasted");
		putimage(0, 0, &img_wasted);
		FlushBatchDraw();
		Sleep(3000);
		level = 0;
		play = 0;
	}

	SListNodePig* cur = pPigList2;
	while (cur != NULL && level == 2)
	{
		if (cur != NULL && isDrawPig2 == 1 && cur->pig_x < 790 && cur->pig_x > 0 && cur->pig_y < 590 && cur->pig_y > 30)
		{
			if (cur->pig_type == 2)
			{
				drawAlpha(&img_pig2, cur->pig_x, cur->pig_y);
			}
			if (cur->pig_type == 4)
			{
				drawAlpha(&img_pig4, cur->pig_x, cur->pig_y);
			}
			if (cur != NULL)
			{
				cur = cur->next;
			}
		}
	}


	if (win2 == 1)
	{
		mciSendString("open .\\rock_destroyed_a2.mp3 alias destorymusic", NULL, 0, NULL);
		mciSendString("play destorymusic wait", NULL, 0, NULL);
		mciSendString("close destorymusic", NULL, 0, NULL);

		drawAlpha(&img_win, 250, 200);
		FlushBatchDraw();

		mciSendString("close watermusic", NULL, 0, NULL);

		mciSendString("open .\\level_complete.mp3 alias completemusic", NULL, 0, NULL);
		mciSendString("play completemusic wait", NULL, 0, NULL);
		mciSendString("close completemusic", NULL, 0, NULL);

		printf("you win!!!\n");
		level = 0;
		play = 0;

		Sleep(2000);
	}
	FlushBatchDraw();
}

void Game2UpdateWithInput()//关卡二游戏内与用户操作有关的输出
{
	char input;
	MOUSEMSG m;//定义鼠标信息

	if (pBirdList2 != NULL)
	{
		while (MouseHit())//检测是否有鼠标信息
		{
			m = GetMouseMsg();
			if ((m.uMsg == WM_LBUTTONDOWN) && (m.x >= pBirdList2->bird_x - 20 && m.x <= pBirdList2->bird_x + 20) && (m.y >= pBirdList2->bird_y - 20 && m.y <= pBirdList2->bird_y + 20))//如果鼠标左键点击小鸟
			{
				printf("1");
				isEmission2 = 1;
				mciSendString("open .\\super_slingshot.mp3 alias spshotmusic", NULL, 0, NULL);//射击声音
				mciSendString("play spshotmusic wait", NULL, 0, NULL);
				mciSendString("close spshotmusic", NULL, 0, NULL);

				mciSendString("open .\\bird_05_flying.mp3 alias fly2music", NULL, 0, NULL);//飞翔声音
				mciSendString("play fly2music wait", NULL, 0, NULL);
				mciSendString("close fly2music", NULL, 0, NULL);
			}
		}

		if (_kbhit())
		{
			input = _getch();
			if (input == 'w')
			{
				pBirdList2->bird_vy--;
				printf("w");
				SListBirdPrint(pBirdList2);
			}
			if (input == 's')
			{
				pBirdList2->bird_vy++;
				printf("s");
				SListBirdPrint(pBirdList2);
			}
			if (input == 'a')
			{
				pBirdList2->bird_vx--;
				printf("a");
				SListBirdPrint(pBirdList2);
			}
			if (input == 'd')
			{
				pBirdList2->bird_vx++;
				printf("d");
				SListBirdPrint(pBirdList2);
			}
		}
	}
}

void Game2UpdateWithoutInput()//关卡二与用户无关的数据更新
{
	// y是纵向
	if (isEmission2 == 1 && pBirdList2 != NULL)
	{
		if (pBirdList2->bird_x <= WIDTH && pBirdList2->bird_x >= 10 && pBirdList2 != NULL)
		{
			pBirdList2->bird_x = pBirdList2->bird_x + pBirdList2->bird_vx;
		}
		else
		{
			isEmission2 = 0;
			SListBirdPopFront(&pBirdList2);
		}

		if (pBirdList2->bird_y <= HIGH && pBirdList2->bird_y >= 10 && pBirdList2 != NULL)
		{
			pBirdList2->bird_y = pBirdList2->bird_y + pBirdList2->bird_vy;
			pBirdList2->bird_vy = pBirdList2->bird_vy + G;
		}
		else
		{
			isEmission2 = 0;
			SListBirdPopFront(&pBirdList2);
		}
		Sleep(100);

		SListBirdPrint(pBirdList2);

		//击地碰撞
		if (pBirdList2->bird_y >= 500 && pBirdList2 != NULL)
		{
			if (pBirdList2->bird_vy > 5)
			{
				pBirdList2->bird_vy -= 10;
				pBirdList2->bird_vy *= -1;
			}
		}

		if (pBirdList2->bird_y >= 520 && pBirdList2 != NULL)
		{
			isEmission2 = 0;
			SListBirdPopFront(&pBirdList2);
		}

		if (pPigList2 != NULL && pBirdList2 != NULL)
		{
			if (pPigList2 != NULL &&pBirdList2->bird_x >= pPigList2->pig_x - 20 && pBirdList2->bird_x <= pPigList2->pig_x + 20 && pBirdList2->bird_y >= pPigList2->pig_y - 20 && pBirdList2->bird_y <= pPigList2->pig_y + 20)
			{
				isEmission2 = 0;
				SListBirdPopFront(&pBirdList2);
				SListPigPopFront(&pPigList2);
			}
			if (pPigList2 != NULL && pPigList2->next != NULL)
			{
				if (pBirdList2 != NULL && pPigList2->next != NULL && pBirdList2->bird_x >= pPigList2->next->pig_x - 20 && pBirdList2->bird_x <= pPigList2->next->pig_x + 20 && pBirdList2->bird_y >= pPigList2->next->pig_y - 20 && pBirdList2->bird_y <= pPigList2->next->pig_y + 20)
				{
					isEmission2 = 0;
					SListBirdPopFront(&pBirdList2);
					SListPigPopBack(&pPigList2);
				}
			}

		}
		if (pPigList2 == NULL)
		{
			printf("1");
			isDrawBird2 = 0;
			isDrawPig2 = 0;
			win2 = 1;
		}
	}
}




//小鸟链表
void SListBirdPushBack(SListNodeBird** phead, int x, int y, int vx, int vy, int type)
{
	SListNodeBird* newNode = (SListNodeBird*)malloc(sizeof(SListNodeBird));
	if (newNode == NULL)
	{
		printf("申请节点失败\n");
		perror("malloc");
		exit(1);
	}
	newNode->bird_x = x;
	newNode->bird_y = y;
	newNode->bird_vx = vx;
	newNode->bird_vy = vy;
	newNode->bird_type = type;
	newNode->next = NULL;

	if (*phead == NULL)
	{
		*phead = newNode;
		return;
	}

	SListNodeBird* tail = *phead;
	while (tail->next != NULL)
	{
		tail = tail->next;
	}
	
	tail->next = newNode;

}

void SListBirdPopFront(SListNodeBird** pphead)
{
	if (*pphead == NULL)
	{
		return;
	}
	else
	{
		(*pphead)->bird_x = 0;
		(*pphead)->bird_vx = 0;
		(*pphead)->bird_y = 0;
		(*pphead)->bird_vy = 0;

		SListNodeBird* next = (*pphead)->next;
		free(*pphead);
		*pphead = next;
	}
}

SListNodeBird* SListBirdFind(SListNodeBird* phead, int x, int y, int vx, int vy, int type)
{
	SListNodeBird* cur = phead;
	while (cur != NULL)
	{
		if (cur->bird_x == x && cur->bird_y == y && cur->bird_vx == vx && cur->bird_vy == vy && cur->bird_type == type)
		{
			return cur;
		}
		cur = cur->next;
	}
}

void SListBirdPrint(SListNodeBird* phead)
{
	SListNodeBird* cur = phead;
	while (cur != NULL)
	{
		printf("bird: x:%d  y:%d  vx:%d  vy:%d ->", cur->bird_x, cur->bird_y, cur->bird_vx, cur->bird_vy);
		cur = cur->next;
	}
	printf("\n");
}

//小猪链表
void SListPigPushBack(SListNodePig** phead, int x, int y, int vx, int vy,int type)
{
	SListNodePig* newNode = (SListNodePig*)malloc(sizeof(SListNodePig));
	if (newNode == NULL)
	{
		printf("申请节点失败\n");
		perror("malloc");
		exit(1);
	}
	newNode->pig_x = x;
	newNode->pig_y = y;
	newNode->pig_vx = vx;
	newNode->pig_vy = vy;
	newNode->pig_type = type;
	newNode->next = NULL;

	if (*phead == NULL)
	{
		*phead = newNode;
		return;
	}

	SListNodePig* tail = *phead;
	while (tail->next != NULL)
	{
		tail = tail->next;
	}

	tail->next = newNode;

}

void SListPigPopFront(SListNodePig** pphead)
{
	if (*pphead == NULL)
	{
		return;
	}
	else
	{
		SListNodePig* next = (*pphead)->next;
		free(*pphead);
		*pphead = next;
	}
}

SListNodePig* SListPigFind(SListNodePig* phead, int x, int y, int vx, int vy, int type)
{
	SListNodePig* cur = phead;
	while (cur != NULL)
	{
		if (cur->pig_x == x && cur->pig_y == y && cur->pig_vx == vx && cur->pig_vy == vy)
		{
			return cur;
		}
		cur = cur->next;
	}
}

void SListPigPopBack(SListNodePig** phead)
{
	if (*phead == NULL)
	{
		return;
	}
	else
	{
		free((*phead)->next);
		(*phead)->next = NULL;
	}
}

void SListPigPrint(SListNodePig* phead)
{
	SListNodePig* cur = phead;
	while (cur != NULL)
	{
		printf("pig: x:%d  y:%d  vx:%d  vy:%d ->", cur->pig_x, cur->pig_y, cur->pig_vx, cur->pig_vy);
		cur = cur->next;
	}
	printf("\n");
}

void Gameover()
{
	putimage(0, 0, &img_gameover);
	FlushBatchDraw();
	Sleep(5000);

	EndBatchDraw();
	//_getch();
	closegraph();
	exit(0);
}
  • 12
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值