#include <iostream>

#include <Windows.h>

#include <random>

#include <time.h>

#include "Console.h"

//#include "enemy.h"

//#include "player.h"

#define ENEMY_COUNT 10

#define PLAYER_LIFE 1

using namespace std;


typedef struct enemy{

int x, y;

char name = 'e';

char blank = ' ';

}enemy;


typedef struct player{

int x= 40, y= 19;

char name = 'p';

int life = PLAYER_LIFE;

}player;


typedef struct player_shoot{

int x, y;

char name = '.';

};


typedef struct enemy_shoot{

int x, y;

int flag = 0;

char name = '*';

};


void enemy_shoot_initial();

void enemy_shoot_move();

int move_flag = 0;

int shoot_flag = 0;

int _gameover = 1;

void enemy_initial();

void enemy_move();

void player_shoot_initial();

void player_shoot_move();

void player_shoot_check();


enemy e;

player p;

player_shoot p_s;

enemy_shoot e_s[10];

enemy e_member[ENEMY_COUNT];


int main()

{

enemy_initial();

while (_gameover)

{

Initial();

for (int i = 0; i < 10; i++){

MoveCursor(e_member[i].x, e_member[i].y);

cout << e_member[i].name;

}

enemy_move();

MoveCursor(p.x, p.y);

cout << p.name;

MoveCursor(p_s.x, p_s.y);

if (GetAsyncKeyState(VK_CONTROL)){

player_shoot_initial();

}

cout << p_s.name;

if (GetAsyncKeyState(VK_UP)){ p.y -= 1; }

if (GetAsyncKeyState(VK_DOWN)){ p.y += 1; }

if (GetAsyncKeyState(VK_LEFT)){ p.x -= 1; }

if (GetAsyncKeyState(VK_RIGHT)){ p.x += 1; }


enemy_shoot_initial();

enemy_shoot_move();

player_shoot_move();

player_shoot_check();

ClearScreen();

}

cout << "gameover";

}


void enemy_move()

{

if (move_flag == 0){

for (int i = 0; i < 10; i++)

{

e_member[i].x += 1;

}

if (e_member[9].x == 80)

move_flag = 1;

}

if (move_flag == 1){

for (int i = 0; i < 10; i++)

{

e_member[i].x -= 1;

}

if (e_member[0].x == 2)

move_flag = 0;

}

}

void enemy_initial()

{

for (int i = 0; i < 10; i++)

{

e_member[i].x = 20 + (i*2) ;

e_member[i].y = 5;

e_member[i].name = 'e';

}

}


void player_shoot_initial()

{

p_s.x = p.x;

p_s.y = p.y;

}

void player_shoot_move()

{

p_s.y -= 1;

}



void player_shoot_check()

{

for (int i = 0; i < 10; i++){

if (p_s.x == e_member[i].x && p_s.y == e_member[i].y)

e_member[i].name = e_member[i].blank;

}

}



void enemy_shoot_initial()

{

int select;

srand(time(NULL));

select = rand() % 10;

e_s[select].flag = 1;

e_s[select].x = e_member[select].x;

e_s[select].y = e_member[select].y;

}

void enemy_shoot_move()

{

for (int i = 0; i < 10; i++)

{

if (e_s[i].flag == 1)

{

MoveCursor(e_s[i].x, e_s[i].y);

cout << e_s[i].name;

e_s[i].y += 1;

if (e_s[i].y == 22 )

{

e_s[i].name = ' ';

e_s[i].y = 0;

e_s[i].flag = 0;

}

if ((p.x == e_s[i].x && p.y == e_s[i].y))

{

p.life -= 1;

if (p.life == 0){

_gameover = 0;

}

}

}

}

}


구조체로 구현한 Invader 게임입니다. 버퍼를 따로 생성하지 않아 끊기는 현상이 있는데, 버퍼를 구현해서 끊기지 않도록 해야겠습니다.



'Programing > C++' 카테고리의 다른 글

-> , * 연산자 오버로딩  (0) 2015.09.02
간단한 오버라이딩  (0) 2015.09.02
구조체로 구현한 Invader  (0) 2015.06.09
클래스 template  (0) 2015.04.27
함수 Template  (0) 2015.04.27
이차원 동적 배열 입력 받아 생성하기  (0) 2015.02.10
Posted by thread1525

댓글을 달아 주세요


블로그 이미지
1525번 thread 입니다.
thread1525

공지사항

Yesterday9
Today1
Total6,171

달력

 « |  » 2019.10
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

최근에 달린 댓글

최근에 받은 트랙백

글 보관함