C language design Battle City (unfinished)

// Tankedaizhan
 // 0, prompt interface
 // 1, frame
 // 2, the specified position to show their tanks
 @ 3, with the tank's own direction key to move
 // getasynkeustae
 // Sleep (milliseconds)
 // reduce flicker
 // not blinking SetConsoleCursorPosition
 // . 4, the display position of the enemy tanks designated
 @ 5, enemy tanks themselves move
 // 6, enemy tanks automatically rounds
 // 7, own tank, press the spacebar rounds
 // 8 , set your own BOSS
 // 9, set up barriers
 // 10, died judgment 
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h> 
#include <stdlib.h> 
#include <conio.h> 
#include<windows.h>
#include<string.h>


#define BACK_WIDE 22
#define BACK_HIGHT 22

unsigned char g_arrBackGround[BACK_HIGHT][BACK_WIDE] = {
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 1},
    {1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    {1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    {1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    {1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    {1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    {1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    {1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    {1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    {1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    {1, 0, 0, 0, 0, 0, 0, 2, 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, 1, 1, 1, 1, 1 , 1 , 1 , 1 , 1 , 1 } 
}; 
// own tank coordinate 
unsigned char   g_OurPosX = . 7 ; 
unsigned char   g_OurPosY = 20 is ; 

unsigned char   g_ourPosTempX = . 7 ; 
unsigned char   g_ourPosTempY = 20 is ; 


// prompts interface 
void StartIU ();
 // press any key to start the game 
void StartGame ();
 // Clear display console 
voidClearIU ();
 // display a border 
void ShowBackGround ();
 // own tanks move 
void TanKeRun ();
 // location update to the new tank background 
void TanKePosUpdateBack ();
 // record the coordinates tank 
void RemberTanKePos ( );
 // empty tank old coordinate 
void ClearTanKeOldPos ();
 int main () 
{ 
    // prompts interface 
    StartIU (); 
    StartGame (); 
    ClearIU (); 
    ShowBackGround (); 
    the while ( . 1 ) 
    { 
        TanKeRun (); 
        // TanKePosUpdateBack (); 
        ClearIU ();
        ShowBackGround ();
    } 
    System ( " PAUSE " );
     return  0 ; 
} 
void StartIU () 
{ 
    the printf ( " \ n-\ n-\ n-\ T \ T \ T" Welcome tankedaizhan "\ n- " ); 
    the printf ( " \ T \ t \ t "WSAD control the movement of tanks" \ the n- " );     
    printf ( " \ t \ t \ t "blank send bullets," \ the n- " ); 
    printf ( " \ t \ t \ t "press any key to start the game." \ n- " ); 
} 
void StartGame () 
{ 
    _getch (); // not read the blocking 

} 
voidClearIU ()  
{
    System ( " CLS " ); 
} 
// own keys to move the tank 
void TanKeRun () 
{ 
    char cKetDis = _getch ();
     IF ( ' W ' == cKetDis || ' W is ' == cKetDis) // on 
    { 
        g_OurPosY - ; 
    } 
    IF ( ' S ' == cKetDis || ' S ' == cKetDis) // the 
    { 
        g_OurPosY ++ ;
    }
     IF( ' A ' == cKetDis || ' A ' == cKetDis) // left 
    { 
        g_OurPosX - ; 
    } 
    IF ( ' D ' == cKetDis || ' D ' == cKetDis) // Right 
    { 
        g_OurPosX ++ ; 
    } 
    IF (!! g_ourPosTempX = g_OurPosX || g_ourPosTempY = g_OurPosY) 
    { 
        TanKePosUpdateBack (); 
    } 

} 
// will be updated to the new tank background 
void TanKePosUpdateBack ()
{ 
    G_arrBackGround [g_OurPosY] [g_OurPosX] = 2 ; 
    ClearTanKeOldPos (); 
    RemberTanKePos (); 

} 
// record the coordinates tank 
void RemberTanKePos () 
{ 
    g_ourPosTempX = g_OurPosX; 
    g_ourPosTempY = g_OurPosY; 
} 
// empty tank old coordinate 
void ClearTanKeOldPos () 
{ 
    g_arrBackGround [g_ourPosTempY] [g_ourPosTempX] = 0 ; 
} 
void ShowBackGround () 
{ 
    int I, J; 
    unsigned char strAllBack [ 1024] = { 0 };
    for (i = 0; i <BACK_HIGHT; i++)
    {
        for (j = 0; j < BACK_WIDE; j++)
        {
            switch (g_arrBackGround[i][j])
            {
            case 0://空格
                /*printf(" ");*/
                strcat(strAllBack," ");
                break;
            case 1://边框
                /*printf("#");*/
                strcat(strAllBack, "#");
                break;
            case 2://己方坦克
                /*printf("土");*/
                strcat(strAllBack, "F");
                break;
            }
        }
        strcat(strAllBack, "\n");
    }
    printf("%s",strAllBack);
}

 

Guess you like

Origin www.cnblogs.com/doker/p/11076994.html