C-language simple version tank war (allendraw file)

Source: Internet
Author: User

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) {//Set window caption Setconsoletitlea (ptitle);    Set the window size//Because the screen size can not be larger than the buffer, so the buffer size is set to large enough//first get the maximum value of the current screen HANDLE HOut = GetStdHandle (Std_output_handle);    COORD cd = Getlargestconsolewindowsize (HOut); Sets the maximum buffer value if (! Setconsolescreenbuffersize (HOut, CD)) {printf ("Set window buffer size failed 1!        \ n ");    return FALSE;    }//Set window size as required Small_rect sr = {0,0,nwid-1,nheight-1}; if (! Setconsolewindowinfo (HOut, 1, &AMP;SR)) {printf ("Setting window size failed!")        \ n ");    return FALSE; }//Reset the buffer size CD.    X = Nwid; Cd.    Y = nheight; if (! Setconsolescreenbuffersize (HOut, CD)) {printf ("Set window buffer size failed 2!        \ n ");    return FALSE; } return TRUE;    function to hide cursor void hidecursor () {Console_cursor_info cursor_info = {1,0}; Setconsolecursorinfo (GetStdHandle (std_output_handle), &cursor_info);}  Print boundary void My_print () {for (int i = 0; I <=, i++) {for (int j = 0; J <=; J + +) {if (i = = 0 | | i = = 40 | | j = = 0 | |            j = = max) {g_map[40][40] = 1;  }}} for (int i = 0; I <=, i++) {for (int j = 0; J <=; J + +) {if (G_map[i][j]            = = 1) {Printchar (I, J, "", 0x44); }}}}void Printchar (int nposx, int nposy, Char*pszchar, WORD wattr) {//Set cursor position HANDLE HOut = Getstdhandl    E (Std_output_handle);    COORD pos = {NPOSX * 2,nposy};    SetConsoleCursorPosition (HOut, POS);    Hide Cursor Console_cursor_info ci;    ci.bvisible = FALSE;    Ci.dwsize = 1;        Setconsolecursorinfo (HOut, &AMP;CI);        Sets the foreground color background color of the print symbol Setconsoletextattribute (hOut, wattr); printf ("%s", Pszchar);} Initialize map 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 = = | | i = =) && j>35&&j<long-1) {g_map[i][j] = HOME;            Continue  if ((i > && 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;        }}}//Generate grass for (int i = 0; i < i++) {int a = rand ()% 39;        int b = rand ()% 39;        if (g_map[a][b] = = KONG) {G_map[a][b] = Caomap;        } else {-I.;        }}//Create an obstacle for (int i = 0; i <; i++) {int a = rand ()% 39;        int b = rand ()% 39; if (g_map[a][b] = = KONG) {G_map[a][b] = Zhangaimap;        } else {-I.;    }}//character print}//draw 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 = = && (j = = | | j = = 38)) | | (i = = && (j = = | | j = = 38)))) {Printchar (I, J, "I",0x6);                } else {Printchar (i, J, "0x3"); }}}} printf ("﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍|\n");}

C language Simple version tank war (allendraw file)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.