------------------Configuration: 121 - Win32 Debug--------------------
Compiling...
121.cpp
c:\users\asus\desktop\121.cpp(267) : warning C4508: 'main' : function should return a value; 'void' return type assumed
c:\users\asus\desktop\121.cpp(60) : warning C4102: 'loop' : unreferenced label
c:\users\asus\desktop\121.cpp(56) : warning C4101: 'm' : unreferenced local variable
BUILD后
--------------------Configuration: 121 - Win32 Debug--------------------
Linking...
121.obj : error LNK2001: unresolved external symbol __imp__mciSendStringA@16
Debug/121.exe : fatal error LNK1120: 1 unresolved externals
執行 link.exe 時出錯.
121.exe - 1 error(s), 0 warning(s)
全代碼如下:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
#include<graphics.h>
#include<Windows.h>
#define BLOOD_1 3
#define BLOOD_2 2
#define xMAX 30
#define xMIN 10
#define yMAX 23
#define yMIN 2
#define MAXLEN 40
struct Plane{
int x;
int y;
int blood;
}plane,enemy[MAXLEN],bullet[320];
int slow=0; //級訓速度
int reprint=0; //是否重新列印
int score=0; //分數
void gotoxy(int x, int y)//游標移動到(x,y),其中左上角的坐標為(1,1),x為列,y為行
{
COORD coord = {x-1, y-1};
SetConsoleCursorPosition
(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int main()
{
IMAGE img;
//界面背景
IMAGE img1;
//定義滑鼠訊息
MOUSEMSG m;
mciSendString("open music.mp3 alias mymusic",NULL,0,NULL);
mciSendString("play mymusic repeat",NULL,0,NULL);
initgraph(800,600);
loop:
loadimage(&img, "pic.jpg"); // 讀取圖片到 img 物件中
putimage(0, 0, &img); // 在坐標位置顯示 IMAGE 物件
setfillcolor(RGB(201, 136, 92));//幫助顏色
setbkmode(TRANSPARENT);//透明背景設定
settextcolor(WHITE);//幫助字體顏色
setlinecolor(RGB(274, 244, 185));//框框邊界顏色
fillroundrect (500, 290, 700, 360,56, 67);//框框
settextcolor(RGB(255,201,14));//框框里的字
settextstyle(50, 40, "宋體");//字體設定
setbkmode(TRANSPARENT);//透明背景設定
outtextxy(522, 300, "Play");//Play
settextstyle(110, 70, "華文琥珀");//幼圓設定
outtextxy(60, 70, "打飛機");//字符顯示
void Print(); //輸出基本資訊
void del(struct Plane arr[],int n);
void print(struct Plane plane,struct Plane enemy[],int count_1,struct Plane bullet[],int count_2); //列印界面
int enemy_create(struct Plane enemy[],int count); //創建敵機
int bullet_create(struct Plane bullet[],int count,int x,int y); //創建子彈
int count_1=0,count_2=0; //敵機數和子彈數計數
int situation=1,i,j;
char ch; //按鍵
plane.blood=BLOOD_1;
plane.x=(xMAX+xMIN)/2;
plane.y=(yMAX+yMIN)/2; //飛機位置初始化
Print();
while(situation)
//判斷游戲有沒有結束
{
gotoxy(1,1);
slow++;
if(slow>1000000)
slow=0; //減速設定
Sleep(20);
if(kbhit())
{
ch=getch();
for(i=0;kbhit()&&i<30;i++)//新增這個回圈用于清空鍵盤緩沖區的按鍵記錄(不曉得是否真的清空了,反正效果達到了)
ch=getch();
switch(ch)
{
case 'w':plane.y--;break;
case 'a':plane.x--;break;
case 's':plane.y++;break;
case 'd':plane.x++;break;
case 'z':system("pause");
}
if(plane.x<xMIN) //防止飛機越界
plane.x=xMIN;
if(plane.x>xMAX)
plane.x=xMAX;
if(plane.y>yMAX)
plane.y=yMAX;
if(plane.y<yMIN)
plane.y=yMIN;
}
if(slow%5==0) //子彈減速
{
for(i=0;i<count_2;i++)
{
bullet[i].y--; //子彈上升
if(bullet[i].y<yMIN)
{
del(bullet,i);
count_2--;
i--;
}
for(j=0;j<count_2;j++) //判斷敵機血量
if(enemy[j].x==bullet[i].x&&enemy[j].y==bullet[i].y)
{
del(bullet,i);
count_2--;
enemy[j].blood--;
if(enemy[j].blood==0) //判斷血量
{
del(enemy,j);
count_1--;
score++;
}
}
}
count_2=bullet_create(bullet,count_2,plane.x,plane.y);
}
if(slow%25==0) //敵機減速
{
for(i=0;i<count_1;i++) //敵機下降
{
enemy[i].y++;
if(enemy[i].y>yMAX||(enemy[i].x==plane.x&&enemy[i].y==plane.y))
{
del(enemy,i);
count_1--;
i--;
}
}
count_1=enemy_create(enemy,count_1);
}
for(i=0;i<count_1;i++)
if(enemy[i].x==plane.x&&enemy[i].y==plane.y) //與敵機相撞,敵機消失,自己減血
{
plane.blood--;
del(enemy,i);
count_1--;
if(plane.blood==0)
situation=0;
}
system("cls");
print(plane,enemy,count_1,bullet,count_2);
}
gotoxy(1,1);
printf("lose\n");
system("pause");
}
int enemy_create(struct Plane enemy[],int count)
{
int random,x;
srand(time(0));
for(x=xMIN+1;count<7&&x<xMAX-1;x++)
{
random=rand()%20;
if(random==1)
{
enemy[count].x=x;
enemy[count].y=yMIN;
enemy[count].blood=BLOOD_2;
count++;
}
}
return count;
}
int bullet_create(struct Plane bullet[],int count,int x,int y)
{
if(slow%5==0) //延時5倍產生子彈
{
bullet[count].x=x;
bullet[count].y=y-1;
count++;
}
return count;
}
void print(struct Plane plane,struct Plane enemy[],int count_1,struct Plane bullet[],int count_2)
{
int i;
for(i=0;i<count_1;i++) //列印敵機
{
gotoxy(enemy[i].x,enemy[i].y);
printf("%c",4);
}
for(i=0;i<count_2;i++) //列印子彈
{
gotoxy(bullet[i].x,bullet[i].y);
printf("%c",46);
}
gotoxy(plane.x,plane.y); //列印自己
printf("%c",6);
gotoxy(xMAX+2,yMAX);
printf("score:%d\n",score); //列印分數 HP
gotoxy(xMAX+2,yMAX+1);
printf("HP:%d\n",plane.blood);
gotoxy(1,1);
}
void del(struct Plane arr[],int n)
{
int i;
for(i=n;i<MAXLEN-1;i++)
arr[i]=arr[i+1];
}
void Print()
{
printf("\n\n\n\n\n\n\n");
printf(" *****************************************\n");
printf(" * *\n");
printf(" * 打飛機v1.0 *\n");
printf(" * --by Kevince[Bujie] *\n");
printf(" * *\n");
printf(" *****************************************\n");
printf("\n\n\n\n\n\n\n");
Sleep(2000);
system("cls");
system("mode con cols=40 lines=25");
printf("使用w s a d來控制上下左右,z暫停\n");
system("pause");
}
uj5u.com熱心網友回復:
。。留下扣扣或者加我459971737uj5u.com熱心網友回復:
mciSendString 沒有包含進來啊。加上下面2句試試看。
#include <mmsystem.h>
#pragma comment(lib, "WINMM.LIB")
uj5u.com熱心網友回復:
太神奇了,謝謝大神!另外可以運行了,可是我點play不能進去游戲點關閉反而又彈出來游戲界面是怎么回事
uj5u.com熱心網友回復:
這個要跟蹤代碼啊,看看是不是界面的字符設定反了。uj5u.com熱心網友回復:
graphics.h,什么編譯環境支持?uj5u.com熱心網友回復:
vc++6.0。。。。。我也不是很懂
uj5u.com熱心網友回復:
不知你哪找的代碼,很舊很舊,舊的看不懂。uj5u.com熱心網友回復:
http://www.easyx.cnuj5u.com熱心網友回復:
graphics.h是TC環境下的頭檔案,如果你用了VC,那么這個頭檔案是沒有的,或者說你的這個代碼,必須在TC下才能跑
uj5u.com熱心網友回復:
graphics.h,什么編譯環境支持?
vc++6.0。。。。。我也不是很懂
graphics.h是TC環境下的頭檔案,如果你用了VC,那么這個頭檔案是沒有的,或者說你的這個代碼,必須在TC下才能跑
有#include <windows.h>,應該是windows下跑的代碼,我猜這個graphics.h是他不知道從哪copy來的圖形庫
uj5u.com熱心網友回復:
大概看了下你的代碼,沒看到有哪個API是windows.h里的,你可以試試去掉graphics.h看能編譯過,然后去掉widows.h后再編譯下看看uj5u.com熱心網友回復:
打飛機
這個網上有源代碼,下載下來對比吧
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/133288.html
標籤:界面
上一篇:TCP服務多執行緒接收資料的問題
