#include "pch.h"
#include <iostream>
#include <conio.h>
#include <stdlib.h>;
#include <time.h>;
int rand_X()
{
int Rand_X = rand() % 49;
return Rand_X;
}
int rand_Y()
{
int Rand_Y = rand() % 15;
return Rand_Y;
}
int main()
{
int MapSizeY = 20;
int MapSizeX = 52;
int KillCount = 0;
int MonsterCount = 3;
int FrameCount = 0;
int BoomCount = 0;
bool Boom = false;
int BoomX = 0;
int BoomY = 0;
int PlayerX = 25;
int PlayerY = 18;
int MonsterX_1 = 10;
int MonsterX_2 = 28;
int MonsterX_3 = 42;
int MonsterY_1 = 3;
int MonsterY_2 = 5;
int MonsterY_3 = 7;
char ArrPixel[20][52];
memset((void*)ArrPixel, '*', sizeof(char) * MapSizeY * MapSizeX);
for (int y = 0; y < 20; y++)
{
ArrPixel[y][50] = '\n';
ArrPixel[y][51] = 0;
}
ArrPixel[MonsterY_1][MonsterX_1] = 'M';
ArrPixel[MonsterY_2][MonsterX_2] = 'M';
ArrPixel[MonsterY_2][MonsterX_3] = 'M';
while (true)
{
system("cls");
ArrPixel[PlayerY][PlayerX] = '@';
for (int y = 0; y < MapSizeY; y++)
{
printf_s(ArrPixel[y]);
}
printf_s("---------------------------------------------------- \n");
printf_s("MONSTER : %d KILL : %d \n",MonsterCount ,KillCount);
printf_s("-----------------------조작법----------------------- \n");
printf_s("이동 : W A S D \n");
printf_s("총알 : K \n");
printf_s("폭탄 : B \n");
printf_s("몬스터가 있는곳으로는 이동할 수 없습니다.\n");
printf_s("폭탄이 터지는 동안 폭탄을 재사용 할 수 없습니다.\n");
printf_s("승리 : 20 Kill\n");
printf_s("패배 : 20 MONSTER\n");
printf_s("---------------------------------------------------- \n");
if (Boom == true)
{
BoomCount += 1;
}
if (BoomCount == 1)
{
if (ArrPixel[BoomY][BoomX - 1] == 'M'
|| ArrPixel[BoomY][BoomX + 1] == 'M'
|| ArrPixel[BoomY + 1][BoomX] == 'M'
|| ArrPixel[BoomY - 1][BoomX] == 'M')
{
KillCount += 1;
MonsterCount -= 1;
}
ArrPixel[BoomY][BoomX - 1] = 'B';
ArrPixel[BoomY][BoomX + 1] = 'B';
ArrPixel[BoomY + 1][BoomX] = 'B';
ArrPixel[BoomY - 1][BoomX] = 'B';
}
else if (BoomCount == 2)
{
if (ArrPixel[BoomY][BoomX - 2] == 'M'
|| ArrPixel[BoomY][BoomX + 2] == 'M'
|| ArrPixel[BoomY + 2][BoomX] == 'M'
|| ArrPixel[BoomY - 2][BoomX] == 'M')
{
KillCount += 1;
MonsterCount -= 1;
}
ArrPixel[BoomY][BoomX - 2] = 'B';
ArrPixel[BoomY][BoomX + 2] = 'B';
ArrPixel[BoomY + 2][BoomX] = 'B';
ArrPixel[BoomY - 2][BoomX] = 'B';
}
else if (BoomCount == 3)
{
if (ArrPixel[BoomY][BoomX - 3] == 'M'
|| ArrPixel[BoomY][BoomX + 3] == 'M'
|| ArrPixel[BoomY + 3][BoomX] == 'M'
|| ArrPixel[BoomY - 3][BoomX] == 'M')
{
KillCount += 1;
MonsterCount -= 1;
}
ArrPixel[BoomY][BoomX - 3] = 'B';
ArrPixel[BoomY][BoomX + 3] = 'B';
ArrPixel[BoomY + 3][BoomX] = 'B';
ArrPixel[BoomY - 3][BoomX] = 'B';
}
else if (BoomCount == 4)
{
if (ArrPixel[BoomY][BoomX - 4] == 'M'
|| ArrPixel[BoomY][BoomX + 4] == 'M'
|| ArrPixel[BoomY + 4][BoomX] == 'M'
|| ArrPixel[BoomY - 4][BoomX] == 'M')
{
KillCount += 1;
}
ArrPixel[BoomY][BoomX - 4] = 'B';
ArrPixel[BoomY][BoomX + 4] = 'B';
ArrPixel[BoomY + 4][BoomX] = 'B';
ArrPixel[BoomY - 4][BoomX] = 'B';
}
else if (BoomCount == 5)
{
for (int i = -4; i < 5; i++)
{
ArrPixel[BoomY + i][BoomX] = '*';
ArrPixel[BoomY][BoomX + i] = '*';
}
Boom = false;
BoomCount = 0;
}
if (KillCount == 20)
{
printf_s("Game Clear......");
break;
}
if (MonsterCount == 20)
{
printf_s("Game Over......");
break;
}
for (int i = 0; i < MapSizeY; i++)
{
for (int j = 0; j < MapSizeX; j++)
{
if (ArrPixel[i][j] == '^')
{
ArrPixel[i][j] = '*';
if (ArrPixel[i - 1][j] == 'M')
{
ArrPixel[i - 1][j] = '*';
KillCount += 1;
MonsterCount -= 1;
}
else
{
if (i - 1 > 0)
{
ArrPixel[i - 1][j] = '^';
}
}
}
}
}
switch (_getch())
{
case 'a':
case 'A':
if (PlayerX != 0 && ArrPixel[PlayerY][PlayerX - 1] != 'M')
{
ArrPixel[PlayerY][PlayerX] = '*';
ArrPixel[PlayerY][PlayerX - 1] = '@';
PlayerX -= 1;
}
break;
case 'd':
case 'D':
if (PlayerX != (MapSizeX -3) && ArrPixel[PlayerY][PlayerX + 1] != 'M')
{
ArrPixel[PlayerY][PlayerX] = '*';
ArrPixel[PlayerY][PlayerX + 1] = '@';
PlayerX += 1;
}
break;
case 'w':
case 'W':
if (PlayerY != 0 && ArrPixel[PlayerY - 1][PlayerX] != 'M')
{
ArrPixel[PlayerY][PlayerX] = '*';
ArrPixel[PlayerY - 1][PlayerX] = '@';
PlayerY -= 1;
}
break;
case 's':
case 'S':
if (PlayerY != (MapSizeY -1) && ArrPixel[PlayerY + 1][PlayerX] != 'M')
{
ArrPixel[PlayerY][PlayerX] = '*';
ArrPixel[PlayerY + 1][PlayerX] = '@';
PlayerY += 1;
}
break;
case 'r':
case 'R':
break;
case 'k':
case 'K':
if (ArrPixel[PlayerY - 1][PlayerX] == 'M')
{
KillCount += 1;
MonsterCount -= 1;
}
ArrPixel[PlayerY - 1][PlayerX] = '^';
break;
case 'b':
case 'B':
if (Boom == false
&& PlayerY -3 -4 > -1
&& PlayerY -3 +4 < 20
&& PlayerX -4 > -1
&& PlayerX +4 < 50)
{
if (ArrPixel[PlayerY - 3][PlayerX] == 'M')
{
KillCount += 1;
MonsterCount -= 1;
}
Boom = true;
ArrPixel[PlayerY - 3][PlayerX] = 'B';
BoomY = PlayerY - 3;
BoomX = PlayerX;
break;
}
}
FrameCount += 1;
if (FrameCount % 10 == 0)
{
ArrPixel[rand_Y()][rand_X()] = 'M';
MonsterCount += 1;
}
}
}
간단한 소스입니다 과제에 사용하시면 F...
'게임 프로그래밍 > C++ 게임' 카테고리의 다른 글
자체엔진 2D포트폴리오 스타듀밸리 모작 (0) | 2020.03.02 |
---|---|
C++ 콘솔RPG게임[클래스사용, 간단..] (0) | 2019.01.23 |
C++ 콘솔슈팅게임[클래스사용, 간단..] (0) | 2019.01.23 |