c語言簡單版坦克大戰(Allendraw檔案)

來源:互聯網
上載者:User

標籤:get   raw   nbu   etl   net   rand   include   setw   imap   

Allendraw.h

#include <windows.h>#define KONG 0#define USERTANKMAP 1#define ENETANKMAP 2#define BOMBMAP 3#define QINGMAP 4#define USERBULLETMAP 6#define ENETBULLETMAP 7#define HOME 8#define LIFE 9#define CAOMAP 10#define ZHANGAIMAP  11#define LONG 40#define WIDE 40#define USERTANK "■"#define ZHANGAI  "■"#define ENETANK "■"//◎●※∷#define BULLET "◎"#define CAO "※"#define TANK_DIR_UP 0#define TANK_DIR_DW 2#define TANK_DIR_LF 1#define TANK_DIR_RH 3#define TANKUP "∧"#define TANKDW "∨"#define TANKLF "<"#define TANKRH ">"extern int g_map[40][40];BOOL SetWindowInfo(char* pTitle, int nWid, int nHeight);//用於隱藏游標的函數void HideCursor();//列印邊界void my_print();void PrintChar(int Wide, int High, char*pszChar, WORD wAttr);//初始化地圖void initmap();//畫void darw();

Allendraw.c

#include "Allendraw.h"//#include <windows.h>#include<stdio.h>#include <time.h>int g_map[40][40] = { 0 };BOOL SetWindowInfo(char* pTitle, int nWid, int nHeight) {    //設定視窗標題    SetConsoleTitleA(pTitle);    // 設定視窗大小    // 因為螢幕大小不能比緩衝區大,所以先把緩衝區大小設定為足夠大    // 先擷取當前螢幕的最大值    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);    COORD cd = GetLargestConsoleWindowSize(hOut);    // 設定緩衝區最大值    if (!SetConsoleScreenBufferSize(hOut, cd)) {        printf("設定視窗緩衝區大小失敗1!\n");        return FALSE;    }    // 按要求設定視窗大小    SMALL_RECT sr = { 0,0,nWid - 1,nHeight - 1 };    if (!SetConsoleWindowInfo(hOut, 1, &sr)) {        printf("設定視窗大小失敗!\n");        return FALSE;    }    // 重新設定緩衝區大小    cd.X = nWid;    cd.Y = nHeight;    if (!SetConsoleScreenBufferSize(hOut, cd)) {        printf("設定視窗緩衝區大小失敗2!\n");        return FALSE;    }    return TRUE;}//用於隱藏游標的函數void HideCursor(){    CONSOLE_CURSOR_INFO cursor_info = { 1,0 };    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);}//列印邊界void my_print(){    for (int i = 0; i <= 40; i++) {        for (int j = 0; j <= 40; j++) {            if (i == 0 || i == 40 || j == 0 || j == 40) {                g_map[40][40] = 1;            }        }    }    for (int i = 0; i <= 40; i++) {        for (int j = 0; j <= 40; j++) {            if (g_map[i][j] == 1) {                PrintChar(i, j, "■", 0x44);            }        }    }}void PrintChar(int nPosX, int nPosY, char*pszChar, WORD wAttr) {    // 設定游標位置    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);    COORD pos = { nPosX * 2,nPosY };    SetConsoleCursorPosition(hOut, pos);    // 隱藏游標    CONSOLE_CURSOR_INFO ci;    ci.bVisible = FALSE;    ci.dwSize = 1;    SetConsoleCursorInfo(hOut, &ci);        // 設定列印符號的前景色彩背景色        SetConsoleTextAttribute(hOut, wAttr);        printf("%s", pszChar);}//初始化地圖void initmap() {    for (int i = 0; i <WIDE; i++) {        for (int j = 0; j < LONG; j++) {            if (i >= 18&& i <= 22&& j ==35) {                g_map[i][j] = HOME;                continue;            }            if ((i == 18 || i == 22) && j>35&&j<LONG -1) {                g_map[i][j] = HOME;                continue;            }            if ((i > 18 && i <22) && j>35 && j<LONG - 1) {                g_map[i][j] = LIFE;                continue;            }            if (i == 0 || i == LONG - 1 ||                j == 0 || j == WIDE - 1) {                g_map[i][j] = QINGMAP;                continue;            }            else            {                g_map[i][j] = KONG;            }        }    }    //產生草    for (int i = 0; i < 100; i++) {        int a = rand() % 39;        int b = rand() % 39;        if (g_map[a][b] == KONG) {            g_map[a][b] = CAOMAP;        }        else {            --i;        }    }    //產生障礙物    for (int i = 0; i < 20; i++) {        int a = rand() % 39;        int b = rand() % 39;        if (g_map[a][b] == KONG) {            g_map[a][b] = ZHANGAIMAP;        }        else {            --i;        }    }    //字元列印}//畫void darw(){    PrintChar(0, 0, " ", 0x44);    printf("﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍|\n");    for (int i = 0; i < LONG; i++) {        for (int j = 0; j < WIDE; j++) {            if (g_map[i][j] == QINGMAP)                PrintChar(i, j, "■", 0x44);            if (g_map[i][j] == USERTANKMAP)                PrintChar(i, j, USERTANK, 0x55);            if (g_map[i][j] == KONG)                PrintChar(i, j, " ", 0x00);            if (g_map[i][j] == HOME)                PrintChar(i, j, "■", 0x2);            if (g_map[i][j] == CAOMAP)                PrintChar(i, j, CAO, 0x2);            if (g_map[i][j] == ZHANGAIMAP)                PrintChar(i, j, ZHANGAI, 0xff);            if (g_map[i][j] == LIFE) {                if ( ((i == 19 && (j == 36 || j == 38)) || (i == 21 && (j == 36 || j == 38)) )) {                    PrintChar(i, j, "∷", 0x6);                }                else {                    PrintChar(i, j, "∷", 0x3);                }            }        }    }    printf("﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍|\n");}

c語言簡單版坦克大戰(Allendraw檔案)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.