1. 程式人生 > >C語言編寫的坦克大戰exe小遊戲

C語言編寫的坦克大戰exe小遊戲

C語言編寫的坦克大戰exe小遊戲! (含有部分C++函式,不過不需要知道實現細節,主要用於鍵盤讀取等)
適合初學者學習的坦克大戰程式碼,無圖片,遊戲全部功能畫面顯示全部由 printf 列印的哦!

C++視訊跟筆記都是全網最新最全的,加群玖四捌,玖伍四,四捌四

C語言/C艹程式設計入門經典小遊戲坦克大戰!

在這裡插入圖片描述
C語言/C艹程式設計入門經典小遊戲坦克大戰!

在這裡插入圖片描述

在這裡插入圖片描述
game.h下的程式碼

#ifndef GAME

#define GAME

#include’‘tankdef.h’’

oid ImportMapGameAreaArry();

oid ImportHomeGameAreaArry();

oid ImportMyTankGameAreaArry();

oid DrawGame_Info();

int ConsoleSwtichArrX(int x);

int ConsoleSwtichArrY(int y);

oid TankAdjustUp(Tank *ptank, Dir dir);

oid TankAdjustLeft(Tank *ptank);

oid TankAdjustRight(Tank *ptank);

oid TankAdjustDown(Tank *ptank);

oid TankAdjustUpE(Tank *ptank, Dir dir);

//發射炮彈,引數為發射改炮彈的坦克

SHELLNODE *shot(Tank *ptank);

//炮彈向上移動

int ShellMoeUP(SHELLNODE *psn);

int ShellMoeDOWN(SHELLNODE *psn);

int ShellMoeLEFT(SHELLNODE *psn);

int ShellMoeRIGHT(SHELLNODE *psn);

//檢查連結串列

SHELLNODE *CheckLinkList(int owner,int x,int y);

//執行緒處理函式

DWORD WINAPI ShellDispes(LPO lpParam);

//oid WriteFile1();

oid HitTarget(SHELLNODE *psn, int tagert);

//根據炮彈的座標銷燬相應的坦克

oid DestroyEnemy(SHELLNODE *psn);

//清空敵方坦克的資料

oid ClearEnemyTank(Tank *ptank);

//炮彈節點的比較函式

int ShellCompareByNum(NODE *pNode1, NODE *pNode2);

//敵方坦克移動函式

DWORD WINAPI EnemyMoe(LPO lpParam);

#endif

game.c下的程式碼

#define _CRT_SECURE_NO_WARNINGS

#include’‘tankdef.h’’

#include’‘interface.h’’

#include

#include

#include

#include

#include ‘‘game.h’’

int g_start;

oid Game_Start()

{

HANDLE hThread;

//初始化臨界區資源

system(’‘mode con cols=95 lines=25’’);

SetConsoleTitle(TEXT(’‘坦克大戰’’));

InitializeCriticalSection(&g_cs);

srand((unsigned int)time(NULL));

DrawGameBord();

DrawGame_Info();

LoadMap();

DrawHome();

InitMyTnak(&MyselfTanke);

DrawTnak(&MyselfTanke);

ImportMapGameAreaArry();

ImportHomeGameAreaArry();

ImportMyTankGameAreaArry();

PlaySound(TEXT(’'sound/Tnak.wa ‘’), NULL, SND_LOOP);

PlaySound(TEXT(’'sound/TankMoe.wa ‘’), NULL, SND_LOOP);

int i;

for (i = 0; i

{

EnemyTank[i] = InitEnemtyTank();

DrawEnmpty(&EnemyTank[i]);

ImportEnemyTankGameAreaArry(&EnemyTank[i]);

}

while (i–)

{

hThread = CreateThread(NULL, 0, EnemyMoe, &EnemyTank[i], 0, NULL);

CloseHandle(hThread);

}

//初始化炮彈連結串列

InitLinkList(&g_shell_list);

//WriteFile1();

}

oid InitMyTnak(Tank *ptank)

{

ptank->belong = MYSELF;

ptank->dir = UP;

ptank->lief = 1;

ptank->x = Left_Top_X 24;

ptank->y = Left_Top_Y 18;

}

Tank InitEnemtyTank()

{

int row, col, oerlp;

int i, j;

Tank tank;

tank.belong = ENEMY;

tank.dir = rand() % 4;

tank.lief = 1;

tank.speed = 400;

tank.y = Left_Top_Y 1;

while (1)

{

oerlp = 0;

tank.x = rand() % 29 * 2 Left_Top_X 2;

row = ConsoleSwtichArrY(tank.y);

col = ConsoleSwtichArrX(tank.x);

for (i = row; i

{ //取非為真

for (j = col; j

{

if (g_area_data[i][j])

{

oerlp = 1;

}

}

}

if (!oerlp)

break;

}

return tank;

}

Tank InitEnemtyTankSpeed()

{

int row, col, oerlp;

int i, j;

Tank tank;

tank.belong = ENEMY;

tank.dir = rand() % 4;

tank.lief = 1;

tank.speed = 100;

tank.y = Left_Top_Y 1;

while (1)

{

oerlp = 0;

tank.x = rand() % 29 * 2 Left_Top_X 2;

row = ConsoleSwtichArrY(tank.y);

col = ConsoleSwtichArrX(tank.x);

for (i = row; i

{ //取非為真

for (j = col; j

{

if (g_area_data[i][j])

{

oerlp = 1;

}

}

}

if (!oerlp)

break;

}

return tank;

}

//將地圖匯入到二維陣列

oid ImportMapGameAreaArry()

{

int i, j;

for (i = 0; i

{

for (j = 0; j

{

g_area_data[i 3][j] = map[i][j];

}

}

}

//將老家匯入到二維陣列

oid ImportHomeGameAreaArry()

{

int i, j;

int row, col;

row = ConsoleSwtichArrY(Left_Top_Y 18);

col = ConsoleSwtichArrX(Left_Top_X 30);

for (i = 0; i

{

for (j = 0; j

{

if (i == 1 && j == 1)

g_area_data[row i][col j] = AREA_HOME;

else

g_area_data[row i][col j] = AREA_WALL;

}

}

}

oid ImportMyTankGameAreaArry()

{

int i, j;

int row, col;

row = ConsoleSwtichArrY(MyselfTanke.y);

col = ConsoleSwtichArrX(MyselfTanke.x);

for (i = 0; i

{

for (j = 0; j

{

if (tank[MyselfTanke.dir][i][j])

{

g_area_data[i row][j col] = AREA_SELF;

}

else

g_area_data[i row][j col] = AREA_SPACE;

}

}

}

oid ImportEnemyTankGameAreaArry(Tank *ptank)

{

int i, j;

int row, col;

row = ConsoleSwtichArrY(ptank->y);

col = ConsoleSwtichArrX(ptank->x);

for (i = 0; i

{

for (j = 0; j

{

if (tank[ptank->dir][i][j])

{

g_area_data[i row][j col] = AREA_ENEMY;

}

else

g_area_data[i row][j col] = AREA_SPACE;

}

}

}

oid ImportMyClearTankGameAreaArry()

{

int i, j;

int row, col;

row = ConsoleSwtichArrY(MyselfTanke.y);

col = ConsoleSwtichArrX(MyselfTanke.x);

for (i = 0; i

{

for (j = 0; j

{

if (tank[MyselfTanke.dir][i][j])

{

g_area_data[i row][j col] = AREA_SPACE;

}

}

}

}

int ConsoleSwtichArrX(int x)

{

return (x - (Left_Top_X 2)) / 2;

}

int ConsoleSwtichArrY(int y)

{

return y - (Left_Top_Y 1);

}

oid WriteFile1()

{

int i,j;

FILE *fp = fopen(’‘1.txt’’, ‘‘w’’);

if (fp == NULL)

return;

for (i = 0; i

{

for (j = 0; j

{

fprintf_s(fp, ‘’-’’, g_area_data[i][j]);

}

fprintf_s(fp,’’ ‘’);

}

fclose(fp);

}

oid TankAdjustUp(Tank *ptank,Dir dir)

{

ptank->dir = dir;

DrawTnakClear(ptank);

DrawTnak(ptank);

}

oid TankAdjustLeft(Tank *ptank)

{

ptank->dir = LEFT;

DrawTnakClear(ptank);

DrawTnak(ptank);

}

oid TankAdjustRight(Tank *ptank)

{

ptank->dir = RIGHT;

DrawTnakClear(ptank);

DrawTnak(ptank);

}

oid TankAdjustDown(Tank *ptank)

{

ptank->dir = DOWN;

DrawTnakClear(ptank);

DrawTnak(ptank);

}

oid TankAdjustUpE(Tank *ptank, Dir dir)

{

ptank->dir = dir;

DrawTnakClear(ptank);

DrawEnmpty(ptank);

}

SHELLNODE *shot(Tank *ptank)

{

static unsigned int num = 0;

SHELLNODE psn = (SHELLNODE)malloc(sizeof(SHELLNODE));

if (psn == NULL)

{

return NULL;

}

psn->node.next = NULL;

psn->shell.belong = ptank->belong;

psn->shell.dir = ptank->dir;

psn->shell.isshow = 0;

psn->shell.speed = 70;

psn->shell.left = 1;

psn->shell.num = num ;

switch (ptank->dir)

{

case UP:

psn->shell.x = ptank->x 2;

psn->shell.y = ptank->y;

break;

case DOWN:

psn->shell.x = ptank->x 2;

psn->shell.y = ptank->y 2;

break;

case LEFT:

psn->shell.x = ptank->x;

psn->shell.y = ptank->y 1;

break;

case RIGHT:

psn->shell.x = ptank->x 4;

psn->shell.y = ptank->y 1;

break;

}

//放入連結串列中

AddNode(g_shell_list, (NODE*)psn);

return psn;

}

int ShellMoeUP(SHELLNODE *psn)

{

int x, y;

SHELLNODE *ps;

x = ConsoleSwtichArrX(psn->shell.x);

y = ConsoleSwtichArrY(psn->shell.y);

if (psn->shell.isshow)//如果炮彈之前已經執行

DrawShell(&psn->shell, ‘’ ‘’);//擦除炮彈

if (y

return OER_LOW;//越界

//如果上方有牆壁或坦克,就返回

if (g_area_data[y - 1][x] != AREA_SPACE)//撞到其它物體

{

psn->shell.isshow = 0;//停止執行

psn->shell.y -= 1;//調整炮彈座標

return g_area_data[y - 1][x];

}

//如果上方有對方炮彈,就返回

//遍歷連結串列,查詢有無對方炮彈存在

if (ps = CheckLinkList(!psn->shell.belong, psn->shell.x, psn->shell.y - 1))

{

ps->shell.left = 0;//讓對方的炮彈的生命結束

/*sprintf_s(buf, 100, ‘‘Owner %d Shell Num %d died of x:%d,y:%d’’, ps->shell.owner, ps->shell.num, ps->shell.x, ps->shell.y);

WriteToFile(buf);*/

return AREA_SHELL;

}

//其它情況,則顯示該炮彈

psn->shell.y -= 1;//調整炮彈座標

if (psn->shell.left)

DrawShell(&psn->shell, SHELL_LETTER);

psn->shell.isshow = 1;

return 0;

}

int ShellMoeDOWN(SHELLNODE *pShell)

{

int x, y;

SHELLNODE *ps;

x = ConsoleSwtichArrX(pShell->shell.x);

y = ConsoleSwtichArrY(pShell->shell.y);

if (pShell->shell.isshow)//如果炮彈之前已經執行

DrawShell(&pShell->shell, ‘’ ‘’);//擦除炮彈

if (y >= Gmae_Arr_Height - 1)

return OER_LOW;//越界

//如果上方有牆壁或坦克,就返回

if (g_area_data[y 1][x] != AREA_SPACE)//撞到其它物體

{

pShell->shell.isshow = 0;//停止執行

pShell->shell.y = 1;//調整炮彈座標

return g_area_data[y 1][x];

}//如果上方有對方炮彈,就返回

//遍歷連結串列,查詢有無對方炮彈存在

if (ps = CheckLinkList(!pShell->shell.belong, pShell->shell.x, pShell->shell.y 1))

{

ps->shell.left = 0;//讓對方的炮彈的生命結束

/*sprintf_s(buf, 100, ‘‘Owner %d Shell Num %d died of x:%d,y:%d’’, ps->shell.owner, ps->shell.num, ps->shell.x, ps->shell.y);

WriteToFile(buf);*/

return AREA_SHELL;

}

//其它情況,則顯示該炮彈

pShell->shell.y = 1;//調整炮彈座標

if (pShell->shell.left)

DrawShell(&pShell->shell, SHELL_LETTER);

pShell->shell.isshow = 1;

return 0;

}

int ShellMoeLEFT(SHELLNODE *pShell)

{

int x, y;

SHELLNODE *ps;

x = ConsoleSwtichArrX(pShell->shell.x);

y = ConsoleSwtichArrY(pShell->shell.y);

if (pShell->shell.isshow)//如果炮彈之前已經執行

DrawShell(&pShell->shell, ‘’ ‘’);//擦除炮彈

if (x

return OER_LOW;//越界

//如果上方有牆壁或坦克,就返回

if (g_area_data[y][x - 1] != AREA_SPACE)//撞到其它物體

{

pShell->shell.isshow = 0;//停止執行

pShell->shell.x -= 2;//調整炮彈座標

return g_area_data[y][x - 1];

}//如果上方有對方炮彈,就返回

//遍歷連結串列,查詢有無對方炮彈存在

if (ps = CheckLinkList(!pShell->shell.belong, pShell->shell.x - 2, pShell->shell.y))

{

ps->shell.left = 0;//讓對方的炮彈的生命結束

/*sprintf_s(buf, 100, ‘‘Owner %d Shell Num %d died of x:%d,y:%d’’, ps->shell.owner, ps->shell.num, ps->shell.x, ps->shell.y);

WriteToFile(buf);*/

return AREA_SHELL;

}

//其它情況,則顯示該炮彈

pShell->shell.x -= 2;//調整炮彈座標

if (pShell->shell.left)

DrawShell(&pShell->shell, SHELL_LETTER);

pShell->shell.isshow = 1;

return 0;

}

int ShellMoeRIGHT(SHELLNODE *pShell)

{

int x, y;

SHELLNODE *ps;

x = ConsoleSwtichArrX(pShell->shell.x);

y = ConsoleSwtichArrY(pShell->shell.y);

if (pShell->shell.isshow)//如果炮彈之前已經執行

DrawShell(&pShell->shell, ‘’ ‘’);//擦除炮彈

if (x >= Game_Arr_Width - 1)

return OER_LOW;//越界

//如果右方有牆壁或坦克,就返回

if (g_area_data[y][x 1] != AREA_SPACE)//撞到其它物體

{

pShell->shell.isshow = 0;//停止顯示

pShell->shell.x = 2;//調整炮彈座標

return g_area_data[y][x 1];

}//如果上方有對方炮彈,就返回

//遍歷連結串列,查詢有無對方炮彈存在

if (ps = CheckLinkList(!pShell->shell.belong, pShell->shell.x 2, pShell->shell.y))

{

ps->shell.left = 0;//讓對方的炮彈的生命結束

/*sprintf_s(buf, 100, ‘‘Owner %d Shell Num %d died of x:%d,y:%d’’, ps->shell.owner, ps->shell.num, ps->shell.x, ps->shell.y);

WriteToFile(buf);*/

return AREA_SHELL;

}

//其它情況,則顯示該炮彈

pShell->shell.x = 2;//調整炮彈座標

if (pShell->shell.left)

DrawShell(&pShell->shell, SHELL_LETTER);

pShell->shell.isshow = 1;

return 0;

}

//查詢連結串列中有沒有敵方的炮彈

SHELLNODE *CheckLinkList(int owner, int x, int y)

{

SHELLNODE *psn = NULL;

int i;

for (i = 0; i

{

psn = (SHELLNODE *)GetNode(g_shell_list, i);

if (psn->shell.x == x && psn->shell.y == y

&& psn->shell.belong == owner)

{

return psn;

}

}

return NULL;

}

DWORD WINAPI ShellDispes(LPO lpParam)

{

SHELLNODE *psm = (SHELLNODE *)lpParam;

int ret; //返回值

while (psm->shell.left == 1)

{

if (g_start == 1)

continue;

EnterCriticalSection(&g_cs);

switch (psm->shell.dir)

{

case UP:

if (ret = ShellMoeUP(psm))

{

HitTarget(psm, ret);

}

break;

case DOWN:

if (ret = ShellMoeDOWN(psm))

HitTarget(psm, ret);

break;

case LEFT:

if (ret = ShellMoeLEFT(psm))

HitTarget(psm, ret);

break;

case RIGHT:

if (ret = ShellMoeRIGHT(psm))

HitTarget(psm, ret);

break;

}

LeaeCriticalSection(&g_cs);

Sleep(psm->shell.speed);

}

//為了保護連結串列刪除時要同步

EnterCriticalSection(&g_cs);

if (psm->shell.isshow)

DrawShell(&psm->shell, ‘’ ‘’);

if (psm->shell.belong == MYSELF)

–g_self_shell_cout;

if (DeleteNode(g_shell_list, (NODE*)psm, ShellCompareByNum))

free(psm);

LeaeCriticalSection(&g_cs);

return 0;

}

int g_die_Enemy = 0;

oid HitTarget(SHELLNODE *psn, int tagert)

{

switch (tagert)

{

case AREA_SHELL:

case OER_LOW:

psn->shell.left = 0;

break;

case AREA_WALL:

HitWall(&psn->shell);

psn->shell.left = 0;

PlaySound(TEXT(’'sound/擊碎.wa ‘’), NULL,SND_ASYNC );

break;

case AREA_HOME:

HitHome(&psn->shell);

psn->shell.left = 0;

break;

case AREA_ENEMY:

if (psn->shell.belong == MYSELF)

{

g_die_Enemy;

psn->shell.left = 0;

DestroyEnemy(psn);

PlaySound(TEXT(’'sound/爆炸.wa ‘’), NULL, SND_ASYNC );

DrawGame_Info();

}

break;

case AREA_SELF:

if (psn->shell.belong == ENEMY)

{

psn->shell.left = 0;

ClearEnemyTank(&MyselfTanke);

DrawTnakClear(&MyselfTanke);

g_die_shellf;

DrawGame_Info();

if (g_die_shellf == 3)

{

music = 0;

PrintGameOer();

}

else

{

InitMyTnak(&MyselfTanke);

DrawTnak(&MyselfTanke);

ImportMyTankGameAreaArry();

PlaySound(TEXT(’'sound/爆炸.wa ‘’), NULL, SND_ASYNC);

}

}

break;

}

}

oid DestroyEnemy(SHELLNODE *psn)

{

int i;//用於遍歷陣列

Tank t; //一個臨時的坦克

for (i = 0; i

{

t = EnemyTank[i];

if (psn->shell.x >= t.x && psn->shell.x

psn->shell.y >= t.y && psn->shell.y

{

//清除坦克

DrawTnakClear(&t);

//修改坦克的生命值

EnemyTank[i].lief = 0;

//清空敵方坦克的資料

ClearEnemyTank(&t);

}

}

}

oid ClearEnemyTank(Tank *ptank)

{

int row, col;

int i, j;

row = ConsoleSwtichArrY(ptank->y);

col = ConsoleSwtichArrX(ptank->x);

for (i = row; i

{

for (j = col; j

{

g_area_data[i][j] = AREA_SPACE;

}

}

}

//炮彈節點比較函式

int ShellCompareByNum(NODE *pNode1, NODE *pNode2)

{

SHELLNODE p1 = (SHELLNODE)pNode1;

SHELLNODE P2 = (SHELLNODE)pNode2;

return p1->shell.num == P2->shell.num ? 0 : 1;

}

int x = 0;

DWORD WINAPI EnemyMoe(LPO lpParam)

{

Tank * pTank = (Tank*)lpParam;

SHELLNODE *psn = NULL;

HANDLE hThread;

unsigned int nStep = 0;

unsigned int nShot = 0;

nShot = 2;

int nDir = rand() % 5 5;

while (pTank->lief)

{

if(g_start == 1)

continue;

EnterCriticalSection(&g_cs);

nStep;

if(nStep % nDir == 0)

TankAdjustUpE(pTank, rand()%4);

if (nStep % nShot == 0) //改發射炮彈了

{

if (psn = shot(pTank))

{

hThread = CreateThread(NULL, 0, ShellDispes, psn, 0, NULL);

CloseHandle(hThread);

}

}

switch (pTank->dir)

{

case UP:

if (TankMoeUpE(pTank))

{

TankAdjustUpE(pTank, (pTank->dir 1) % 4);

}

break;

case DOWN:

if(TankMoeDownE(pTank))

TankAdjustUpE(pTank, (pTank->dir 1) % 4);

break;

case LEFT: if(TankMoeLeftE(pTank))

TankAdjustUpE(pTank, (pTank->dir 1) % 4);

break;

case RIGHT: if(TankMoeRightE(pTank))

TankAdjustUpE(pTank, (pTank->dir 1) % 4);

break;

}

LeaeCriticalSection(&g_cs);

Sleep(pTank->speed);

}

Die_Enemy_Tank_Count;

// The number of tanks on the map Number of dead tanks

if (ENEMY_Tank Die_Enemy_Tank_Count

{

//Create a new enemy tank

HANDLE hThread;

EnterCriticalSection(&g_cs);

if (Die_Enemy_Tank_Count % 1 == 0)

{

*pTank = InitEnemtyTankSpeed();

ImportEnemyTankGameAreaArry(pTank);

}

else

{

*pTank = InitEnemtyTank();

ImportEnemyTankGameAreaArry(pTank);

}

hThread = CreateThread(NULL, 0, EnemyMoe, pTank, 0, NULL);

CloseHandle(hThread);

LeaeCriticalSection(&g_cs);

}

else if(Die_Enemy_Tank_Count == ENEMY_Z_ALL_TANK)

{

EnterCriticalSection(&g_cs);

Printictory();

LeaeCriticalSection(&g_cs);

}

return 0;

}

oid DrawGame_Info()

{

EnterCriticalSection(&g_cs);

SetConsoleTextAttribute(g_hout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);

COORD pos;

pos.X = Left_Top_X Game_Arr_Width * 2 8;

pos.Y = Left_Top_Y 1;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘C語言坦克大戰專案’’);

pos.Y = 2;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘資訊視窗:’’);

pos.Y;

if (g_start == 1)

{

SetConsoleCursorPosition(g_hout, pos);

printf(’‘遊戲執行狀態: Pause’’);

}

if(g_start == 0)

{

SetConsoleCursorPosition(g_hout, pos);

printf(’'遊戲執行狀態: Run ‘’);

}

pos.Y = 2;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘敵方坦克總數:%d’’, ENEMY_Z_ALL_TANK);

pos.Y ;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘敵方坦克陣亡數量:%d’’, g_die_Enemy);

pos.Y ;

SetConsoleCursorPosition(g_hout, pos);

printf(’'敵方坦克剩餘數量:%d ‘’,ENEMY_Z_ALL_TANK - g_die_Enemy);

pos.Y = 2;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘我方坦克總數:%d’’, AREA_SELF);

pos.Y ;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘我方坦克陣亡數量:%d’’, g_die_shellf);

pos.Y ;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘我方坦克剩餘數量:%d’’, AREA_SELF - g_die_shellf);

pos.Y = 2;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘遊戲暫停或開始:P’’);

pos.Y ;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘坦克向上移動:W’’);

pos.Y ;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘坦克向左移動:A’’);

pos.Y ;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘坦克向右移動:D’’);

pos.Y ;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘坦克向下移動:S’’);

pos.Y ;

SetConsoleCursorPosition(g_hout, pos);

printf(’‘坦克發射炮彈:J’’);

LeaeCriticalSection(&g_cs);

}

interface.h

#include

#include’‘tankdef.h’’

#ifndef INTERFACE

#define INTERFACE

//開始遊戲

oid Game_Start();

C語言/C艹程式設計入門經典小遊戲坦克大戰!

//畫遊戲介面

oid DrawGameBord();

oid LoadMap();

oid DrawHome();

oid InitMyTnak(Tank *ptank);

oid DrawTnak(Tank *ptank);

Tank InitEnemtyTank();

oid DrawEnmpty(Tank *pEtank);

oid DrawTnakClear(Tank *ptank);

oid ImportEnemyTankGameAreaArry();

oid ImportMyClearTankGameAreaArry();

int TankMoeUp(Tank *ptank);

int TankMoeLeft(Tank *ptank);

int TankMoeRight(Tank *ptank);

int TankMoeDown(Tank *ptank);

oid DrawShell(SHELL *Pshell,const char *liter);

oid WriteFile1();

oid HitWall(SHELL *pShell);

oid HitHome(SHELL *pShell);

oid PrintGameOer();

int TankMoeUpE(Tank *ptank);

int TankMoeDownE(Tank *ptank);

int TankMoeLeftE(Tank *ptank);

int TankMoeRightE(Tank *ptank);

oid Printictory();

#endif

interface.c

#include’‘tankdef.h’’

#include’‘interface.h’’

#include

#include’‘game.h’’

HANDLE g_hout;

HWND hwnd = NULL;

CONSOLE_SCREEN_BUFFER_INFO csbi;

int music = 1;

oid DrawGameBord()

{

g_hout = GetStdHandle(STD_OUTPUT_HANDLE);

CONSOLE_CURSOR_INFO c;

GetConsoleCursorInfo(g_hout, &c);

c.bisible = 0;

SetConsoleCursorInfo(g_hout, &c);

int row, col;

DWORD count;

COORD pos;

pos.X = Left_Top_X;

pos.Y = Left_Top_Y;

for (row = 0; row

{

SetConsoleCursorPosition(g_hout, pos);

for (col = 0; col

{

if (row == 0 || row == Gmae_Arr_Height 1 ||

col == 0 || col == Game_Arr_Width 1)

{

GetConsoleScreenBufferInfo(g_hout, &csbi);

printf(’’’’);

FillConsoleOutputAttribute(g_hout, BORDER_Color,2,csbi.dwCursorPosition, &count);

}

else

printf(’’ ‘’);

}

pos.Y ;

}

pos.X = 34;

SetConsoleCursorPosition(g_hout, pos);

GetConsoleScreenBufferInfo(g_hout, &csbi);

printf(’‘坦克大戰’’);

FillConsoleOutputAttribute(g_hout, TANKTEXT, 8, csbi.dwCursorPosition, &count);

}

oid LoadMap()

{

int row, col;

COORD pos;

DWORD count;

pos.X = Left_Top_X 2;

pos.Y = Left_Top_Y 4;

for (row = 0; row

{

SetConsoleCursorPosition(g_hout, pos);

for (col = 0; col

{

if (map[row][col])

{

GetConsoleScreenBufferInfo(g_hout, &csbi);

printf(’’%s’’, TANKLE_LETTER);

FillConsoleOutputAttribute(g_hout, BORDER_Color1, 2, csbi.dwCursorPosition, &count);

}

else

printf(’’ ‘’);

}

pos.Y ;

}

}

oid DrawHome()

{

int row, col;

COORD pos;

DWORD count;

pos.X = Left_Top_X 30;

pos.Y = Left_Top_Y 18;

for (row = 0; row

{

SetConsoleCursorPosition(g_hout, pos);

for (col = 0; col

{

if (row == 1 && col == 1)

{

GetConsoleScreenBufferInfo(g_hout, &csbi);

printf(’’%s’’, HOME_LETTER);

FillConsoleOutputAttribute(g_hout,HOME_Color, 2, csbi.dwCursorPosition, &count);

}

else

printf(’’%s’’, BORDER_LEFTER);

}

pos.Y ;

}

}

oid DrawTnak(Tank *ptank)

{

COORD pos;

DWORD count;

int row, col;

pos.X = ptank->x;

pos.Y = ptank->y;

for (row = 0; row

{

SetConsoleCursorPosition(g_hout, pos);

for (col = 0; col

{

if (tank[ptank->dir][row][col] == 1)

{

GetConsoleScreenBufferInfo(g_hout, &csbi);

printf(’’’’);

FillConsoleOutputAttribute(g_hout, Tank_Color, 2, csbi.dwCursorPosition, &count);

}

else

{

if (tank[0][row][col] == 0 || tank[1][row][col] == 0)

printf(’‘│’’);

if (tank[ptank->dir][row][col] == 2)

{

printf(’’’’);

}

if (tank[3][row][col] == 0 || tank[2][row][col] == 0)

printf(’‘─’’);

}

}

pos.Y ;

}

}

oid DrawEnmpty(Tank *pEtank)

{

COORD pos;

DWORD count;

pos.X = pEtank->x;

pos.Y = pEtank->y;

int row, col;

for (row = 0; row

{

SetConsoleCursorPosition(g_hout, pos);

for (col = 0; col

{

if (tankE[pEtank->dir][row][col])

{

GetConsoleScreenBufferInfo(g_hout, &csbi);

printf(’’’’);

FillConsoleOutputAttribute(g_hout, FOREGROUND_GREEN | FOREGROUND_INTENSITY, 2, csbi.dwCursorPosition, &count);

}

else

printf(’’ ‘’);

}

pos.Y ;

}

}

oid DrawTnakClear(Tank *ptank)

{

COORD pos;

int row, col;

pos.X = ptank->x;

pos.Y = ptank->y;

for (row = 0; row

{

SetConsoleCursorPosition(g_hout, pos);

for (col = 0; col

{

if (tank[ptank->dir][row][col])

{

printf(’’ ‘’);

}

else

printf(’’ ‘’);

}

pos.Y ;

}

}

int TankMoeUp(Tank *ptank)

{

int row, col;

int i, j;

row = ConsoleSwtichArrY(ptank->y);

col = ConsoleSwtichArrX(ptank->x);

//判斷是否越界

if (row

return OER_LOW;

//判斷是否撞牆

for (i = col; i

{

if (g_area_data[row - 1][i])

return g_area_data[row - 1][i];

}

for (i = row - 1; i

{

for (j = col; j

{

if (i == row 2)

g_area_data[i][j] = 0;

else

g_area_data[i][j] = g_area_data[i 1][j];

}

}

DrawTnakClear(ptank);

–ptank->y;

DrawTnak(ptank);

return 0;

}

int TankMoeLeft(Tank *ptank)

{

int row, col;

int i, j;

row = ConsoleSwtichArrY(ptank->y);

col = ConsoleSwtichArrX(ptank->x);

//判斷是否越界

if (col

return OER_LOW;

//判斷是否撞牆

for (i = row; i

{

if (g_area_data[i][col - 1])

return g_area_data[i][col - 1];

}

for (i = row; i

{

for (j = col - 1; j

{

if (j == col 2)

g_area_data[i][j] = 0;

else

g_area_data[i][j] = g_area_data[i][j 1];

}

}

DrawTnakClear(ptank);

ptank->x -= 2;

DrawTnak(ptank);

return 0;

}

int TankMoeRight(Tank *ptank)

{

int row, col;

int i, j;

row = ConsoleSwtichArrY(ptank->y);

col = ConsoleSwtichArrX(ptank->x);

//判斷是否越界

if (col 2 >= Game_Arr_Width - 1)

return OER_LOW;

//判斷是否撞牆

for (i = row; i

{

if (g_area_data[i][col 3])

return g_area_data[i][col 3];

}

for (i = row; i

{

for (j = col 3; j >= col; --j)

{

if (j == col)

g_area_data[i][j] = 0;

else

g_area_data[i][j] = g_area_data[i][j - 1];

}

}

DrawTnakClear(ptank);

ptank->x = 2;

DrawTnak(ptank);

return 0;

}

int TankMoeDown(Tank *ptank)

{

int row, col;

int i, j;

row = ConsoleSwtichArrY(ptank->y);

col = ConsoleSwtichArrX(ptank->x);

//判斷是否越界

if (row 2 >= Gmae_Arr_Height - 1)

return OER_LOW;

//判斷是否撞牆

for (i = col; i

{

if (g_area_data[row 3][i])

return g_area_data[row 3][i];

}

for (i = row 3; i >= row; --i)

{

for (j = col; j

{

if (i == row)

g_area_data[i][j] = 0;

else

g_area_data[i][j] = g_area_data[i - 1][j];

}

}

DrawTnakClear(ptank);

ptank->y;

DrawTnak(ptank);

return 0;

}

int TankMoeUpE(Tank *ptank)

{

int row, col;

int i, j;

row = ConsoleSwtichArrY(ptank->y);

col = ConsoleSwtichArrX(ptank->x);

//判斷是否越界

if (row

return OER_LOW;

//判斷是否撞牆

for (i = col; i

{

if (g_area_data[row - 1][i])

return g_area_data[row - 1][i];

}

for (i = row - 1; i

{

for (j = col; j

{

if (i == row 2)

g_area_data[i][j] = 0;

else

g_area_data[i][j] = g_area_data[i 1][j];

}

}

DrawTnakClear(ptank);

–ptank->y;

if (x == 0)

DrawEnmpty(ptank);

/*if (x == 1)

DrawEnmptySpeed(ptank);*/

return 0;

}

int TankMoeDownE(Tank *ptank)

{

int row, col;

int i, j;

row = ConsoleSwtichArrY(ptank->y);

col = ConsoleSwtichArrX(ptank->x);

//判斷是否越界

if (row 2 >= Gmae_Arr_Height - 1)

return OER_LOW;

//判斷是否撞牆

for (i = col; i

{

if (g_area_data[row 3][i])

return g_area_data[row 3][i];

}

for (i = row 3; i >= row; --i)

{

for (j = col; j

{

if (i == row)

g_area_data[i][j] = 0;

else

g_area_data[i][j] = g_area_data[i - 1][j];

}

}

DrawTnakClear(ptank);

ptank->y;

if(x == 0)

DrawEnmpty(ptank);

//if (x == 1)

//DrawEnmptySpeed(ptank);

return 0;

}

int TankMoeRightE(Tank *ptank)

{

int row, col;

int i, j;

row = ConsoleSwtichArrY(ptank->y);

col = ConsoleSwtichArrX(ptank->x);

//判斷是否越界

if (col 2 >= Game_Arr_Width - 1)

return OER_LOW;

//判斷是否撞牆

for (i = row; i

{

if (g_area_data[i][col 3])

return g_area_data[i][col 3];

}

for (i = row; i

{

for (j = col 3; j >= col; --j)

{

if (j == col)

g_area_data[i][j] = 0;

else

g_area_data[i][j] = g_area_data[i][j - 1];

}

}

DrawTnakClear(ptank);

ptank->x = 2;

if (x == 0)

DrawEnmpty(ptank);

/* if (x == 1)

DrawEnmptySpeed(ptank);*/

return 0;

}

int TankMoeLeftE(Tank *ptank)

{

int row, col;

int i, j;

row = ConsoleSwtichArrY(ptank->y);

col = ConsoleSwtichArrX(ptank->x);

//判斷是否越界

if (col

return OER_LOW;

//判斷是否撞牆

for (i = row; i

{

if (g_area_data[i][col - 1])

return g_area_data[i][col - 1];

}

for (i = row; i

{

for (j = col - 1; j

{

if (j == col 2)

g_area_data[i][j] = 0;

else

g_area_data[i][j] = g_area_data[i][j 1];

}

}

DrawTnakClear(ptank);

ptank->x -= 2;

if (x == 0)

DrawEnmpty(ptank);

/* if (x == 1)

DrawEnmptySpeed(ptank);*/

return 0;

}

oid DrawShell(SHELL *Pshell,const char *litter)

{

DWORD cout;

COORD pos = { Pshell->x,Pshell->y };

SetConsoleCursorPosition(g_hout, pos);

printf(’’%s’’, litter);

FillConsoleOutputAttribute(g_hout, FOREGROUND_RED | FOREGROUND_INTENSITY, 2, pos, &cout);

}

oid HitWall(SHELL *pShell)

{

int i;

int row, col;

row = ConsoleSwtichArrY(pShell->y);

col = ConsoleSwtichArrX(pShell->x);

if (pShell->dir == UP || pShell->dir == DOWN)

{

COORD pos = { pShell->x - 2,pShell->y };

for (i = col - 1; i

{

SetConsoleCursorPosition(g_hout, pos);

if(g_area_data[row][i] == AREA_WALL)

{

printf(’’ ‘’);

g_area_data[row][i] = AREA_SPACE;

}

pos.X = 2;

}

}

else

{

COORD pos = { pShell->x,pShell->y - 1 };

for (i = row - 1; i

{

SetConsoleCursorPosition(g_hout, pos);

if(g_area_data[i][col] == AREA_WALL)

{

printf(’’ ‘’);

g_area_data[i][col] = AREA_SPACE;

}

pos.Y ;

}

}

}

oid HitHome(SHELL *pShell)

{

COORD pos = { pShell->x,pShell->y };

SetConsoleCursorPosition(g_hout, pos);

printf(’’ ‘’);

PrintGameOer();

}

oid PrintGameOer()

{

system(’‘cls’’);

DWORD count;

COORD pos = { 32,10};

SetConsoleCursorPosition(g_hout, pos);

printf(’‘Game Oer!’’);

FillConsoleOutputAttribute(g_hout, FOREGROUND_GREEN | FOREGROUND_INTENSITY |

BACKGROUND_RED | BACKGROUND_INTENSITY, 10, pos, &count);

PlaySound(TEXT(’'sound/Dath.wa ‘’), NULL, SND_LOOP);

DeleteCriticalSection(&g_cs);

DestroyList(&g_shell_list);

exit(0);

}

oid Printictory()

{

PlaySound(TEXT(’'sound/勝利.wa ‘’), NULL, SND_LOOP);

system(’‘cls’’);

DWORD count;

COORD pos = { 32,10 };

SetConsoleCursorPosition(g_hout, pos);

printf(’’ octiory ‘’);

FillConsoleOutputAttribute(g_hout, FOREGROUND_GREEN | FOREGROUND_INTENSITY |

BACKGROUND_RED | BACKGROUND_INTENSITY, 10, pos, &count);

DeleteCriticalSection(&g_cs);

DestroyList(&g_shell_list);

exit(0);

}

#ifndef LIKLIST

#define LIKLIST

//定義節點結構

typedef struct node

{

struct node *next; //指向下一個節點

}NODE;

typedef struct linklist

{

NODE head; //頭節點

int size; //大小

}LINKLIST;

//連結串列操作函式

//連結串列初始化

oid InitLinkList(LINKLIST **list);

//銷燬連結串列

oid DestroyList(LINKLIST **list);

//新增一個節點的連結串列到尾部

oid AddNode(LINKLIST *list, NODE *pNode);

//刪除一個指定的節點,刪除成功返回成功節點的指標,失敗返回NULL

NODE *DeleteNode(LINKLIST *list, NODE *pNode, int(*compare)(NODE *, NODE *));

//返回連結串列中節點的個數

int CountOfLinkList(LINKLIST *list);

//返回指定位置的節點

NODE *GetNode(LINKLIST *list, int pos);

#endif

linklist.c 下的程式碼

#include’‘linklist.h’’

#include

#include

//連結串列操作函式

//連結串列初始化

oid InitLinkList(LINKLIST **list)

{

list = (LINKLIST)malloc(sizeof(LINKLIST));

if (*list == NULL)

return;

(*list)->head.next = NULL;

(*list)->size = 0;

}

//銷燬連結串列

oid DestroyList(LINKLIST **list)

{

if (list && *list)

{

free(*list);

*list = NULL;

}

}

//新增一個節點的連結串列到尾部

oid AddNode(LINKLIST *list, NODE *pNode)

{

NODE *p = &list->head;

while (p->next)

p = p->next;

p->next = pNode;

list->size ; //節點的大小 1

}

//刪除一個指定的節點,刪除成功返回成功節點的指標,失敗返回NULL

NODE *DeleteNode(LINKLIST *list, NODE *pNode, int(*compare)(NODE *, NODE *))

{

NODE *p = &list->head;

NODE *pfree = NULL;

while (p->next)

{

if (compare(p->next, pNode) == 0)

{

pfree = p->next;

p->next = p->next->next;

list->size–;

break;

}

p = p->next;

}

return pfree;

}

//返回連結串列中節點的個數

int CountOfLinkList(LINKLIST *list)

{

return list->size;

}

NODE *GetNode(LINKLIST *list, int pos)

{

int i;

NODE *p = list->head.next;

if (pos

return NULL;

for (i = 0; i

{

p = p->next;

}

return p;

}

tankdef.h

#include

#include ‘‘linklist.h’’

#include’‘game.h’’

#ifndef TANKDEFH

#define TANKDEFH

#define Game_Arr_Width 31 //遊戲區域的寬度

#define Gmae_Arr_Height 20 //遊戲區域的高度

#define Left_Top_X 4 //初始x座標

#define Left_Top_Y 1 //初始y座標

#define BORDER_LEFTER ‘’’’ //遊戲邊框字元

#define TANKLE_LETTER ‘’’’ //坦克字元

#define HOME_LETTER ‘‘★’’ //老家字元

#define SHELL_LETTER ‘’’’ //炮彈字元

#define MYSELF 1 //我方坦克

#define ENEMY 0 //敵方坦克

#define BORDER_Color FOREGROUND_BLUE | FOREGROUND_INTENSITY //視窗的顏色

#define BORDER_Color1 FOREGROUND_GREEN | FOREGROUND_INTENSITY | FOREGROUND_BLUE//關卡顏色

#define TANKTEXT FOREGROUND_RED | FOREGROUND_INTENSITY //文字

#define HOME_Color FOREGROUND_RED | FOREGROUND_INTENSITY //老家顏色

#define Tank_Color FOREGROUND_RED | FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN //坦克顏色

#define ENEMY_Tank 4

#define ENEMY_Z_ALL_TANK 10

#define AREA_SPACE 0 //空

#define AREA_WALL 1 //牆

#define AREA_HOME 2 //老家

#define AREA_SELF 3 //自己

#define AREA_ENEMY 4 //敵人

#define AREA_SHELL 5 //炮彈

#define OER_LOW -1 //越界

#define Game_Oer 0 //遊戲結束

#define Myself_Shell_Count 3 //我方炮彈的數量

typedef enum { UP, DOWN, LEFT, RIGHT }Dir;

typedef struct

{

int lief; //宣告

int x; //x座標

int y; //y座標

Dir dir; //方向

int belong; //屬於

int speed; //速度

}Tank;

typedef struct

{

int x;

int y;

Dir dir;

int left;

int speed;

int belong;

int isshow; //是否顯示

int num;

}SHELL;

//炮彈節點

typedef struct

{

NODE node;

SHELL shell;

}SHELLNODE;

//***********宣告全域性變數

extern HANDLE g_hout;

extern char map[14][Game_Arr_Width];

extern char tank[4][3][3];

extern Tank MyselfTanke; //我方坦克

extern Tank EnemyTank[ENEMY_Tank]; //敵方坦克

extern char g_area_data[Gmae_Arr_Height][Game_Arr_Width];

extern LINKLIST * g_shell_list;

extern char tankE[4][3][3];

extern char tankSpeed[4][3][3];

extern int g_self_shell_cout;

extern CRITICAL_SECTION g_cs;

extern int Die_Enemy_Tank_Count;

extern int x;

extern int g_die_shellf;

extern int g_start;

extern int g_die_Enemy;

extern int music;

#endif

gamedata.c 下的檔案

#include’‘tankdef.h’’

#include’‘interface.h’’

char map[14][Game_Arr_Width] = {

{ 0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0 },

{ 0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0 },

{ 0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0 },

{ 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0 },

{ 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0 },

{ 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0 },

{ 1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1 },

{ 1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1 },

{ 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0 },

{ 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0 },

{ 0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0 },

{ 0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0 },

{ 0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0 },

{ 0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0 }

};

char tank[4][3][3] = {

{

1,0,1,

1,2,1,

1,1,1

},

{

1,1,1,

1,2,1,

1,0,1

},

{

1,1,1,

0,2,1,

1,1,1

},

{

1,1,1,

1,2,0,

1,1,1

}

};

char tankE[4][3][3] = {

{

0,1,0,

1,1,1,

1,0,1

},

{

1,0,1,

1,1,1,

0,1,0

},

{

0,1,1,

1,1,0,

0,1,1

},

{

1,1,0,

0,1,1,

1,1,0

}

};

char tankSpeed[4][3][3] = {

{

0,3,0,

1,2,1,

1,0,1

},

{

1,0,1,

1,2,1,

0,3,0

},

{

0,1,1,

3,2,0,

0,1,1

},

{

1,1,0,

0,2,3,

1,1,0

}

};

char g_area_data[Gmae_Arr_Height][Game_Arr_Width];

Tank MyselfTanke; //我方坦克

Tank EnemyTank[ENEMY_Tank]; //敵方坦克

//炮彈連結串列

LINKLIST * g_shell_list;

// 我放炮彈的數量

int g_self_shell_cout = 0;

int Die_Enemy_Tank_Count = 0; //The number of enemy tank deaths

int g_die_shellf = 0; // 敵方陣亡的坦克數量

CRITICAL_SECTION g_cs;

main.c 下的檔案

#include ‘‘tankdef.h’’

#include ‘‘interface.h’’

#include

#include

#include ‘‘game.h’’

#include

#pragma comment(lib,’‘winmm.lib’’)

int main()

{

char ch;

HANDLE hThread;

SHELLNODE *psn = NULL;

Game_Start();

//PlaySound(TEXT(’'G:\s2015\坦克大戰\坦克大戰\sound\Back.wa ‘’), NULL, SND_ASYNC | SND_LOOP | SND_FILENAME);

/*PlaySound(TEXT(’'G:\s2015\坦克大戰\坦克大戰\hit.wa ‘’), NULL, SND_LOOP | SND_FILENAME);

PlaySound(TEXT(’'G:\s2015\坦克大戰\坦克大戰\Bang.wa ‘’), NULL, SND_LOOP | SND_FILENAME);

PlaySound(TEXT(’'G:\s2015\坦克大戰\坦克大戰\Fanfare.wa ‘’), NULL, SND_LOOP | SND_FILENAME);*/

mciSendString(TEXT(’‘open sound\Back.wa alias music’’), NULL, 0, NULL);

mciSendString(TEXT(’‘play music’’), NULL, 0, NULL);

while (1)

{

if (_kbhit())

{

ch = _getch();

if(ch == ‘p’)

while (1)

{

g_start = 1;

DrawGame_Info();

ch = _getch();

if (ch == ‘p’)

{

g_start = 0;

DrawGame_Info();

break;

}

}

switch (ch)

{

case ‘w’:

EnterCriticalSection(&g_cs);

if (MyselfTanke.dir != UP)

TankAdjustUp(&MyselfTanke,UP);

else

{

TankMoeUp(&MyselfTanke);

}

LeaeCriticalSection(&g_cs);

break;

case ‘s’:

EnterCriticalSection(&g_cs);

if (MyselfTanke.dir != DOWN)

TankAdjustDown(&MyselfTanke);

else

{

TankMoeDown(&MyselfTanke);

}

LeaeCriticalSection(&g_cs);

break;

case ‘a’:

EnterCriticalSection(&g_cs);

if (MyselfTanke.dir != LEFT)

TankAdjustLeft(&MyselfTanke);

else

{

TankMoeLeft(&MyselfTanke);

}

LeaeCriticalSection(&g_cs);

break;

case ‘d’:

EnterCriticalSection(&g_cs);

if (MyselfTanke.dir != RIGHT)

TankAdjustRight(&MyselfTanke);

else

{

TankMoeRight(&MyselfTanke);

}

LeaeCriticalSection(&g_cs);

break;

case ‘j’:

if (g_self_shell_cout

{

PlaySound(TEXT(’'sound/hit.wa ‘’), NULL, SND_ASYNC | SND_NOWAIT);

psn = shot(&MyselfTanke);

g_self_shell_cout;

hThread = CreateThread(NULL, 0, ShellDispes, psn, 0, NULL);

CloseHandle(hThread);

}

break;

}

}

}

mciSendString(TEXT(’‘close music’’), NULL, 0, NULL);

while(CountOfLinkList(g_shell_list))

{

EnterCriticalSection(&g_cs);

psn = (SHELLNODE *)GetNode(g_shell_list, 0);

if (psn)

psn->shell.left = 0;

LeaeCriticalSection(&g_cs);

}

return 0;

}
感興趣的需要更多學習資料可以加郡948,954484