#include<iostream>

#include<conio.h>

#include<time.h>

#include <fstream>

#include <windows.h>

using namespace std;

int job_choice(); // 직업 선택 함수

void user_skill(int jobSkill); // 직업 스킬 

void player_info(int user);

void enemy_info(int monster);


struct all

{

char *job; // 캐릭터 직업

char *name; // 몬스터이름

int hp; // 체력

int mp; // 마나

char *skill1; // 스킬1

char *skill2; // 스킬2

char *skill3; // 스킬3

};

struct all ability; // 사용자 정보

struct all tribe; // 적 정보


int main(){

// 과제 

// 대전액션 ( 구조체 )

// 내턴, 컴터 턴 돌아가면서 스킬로 상대방 데미지 주기

// 스킬은 3개 ( 내꺼 적꺼 )

// 적은 램덤 스킬사용, 플레이어는 선택

// mp가 있어서 스킬마다 소모되는 mp가 있다.

  // 자체적으로 추가 ( 직업 선택, 몬스터 랜덤 ( 3마리 ), 직업별 스킬 )

srand(time(NULL));

int player, enemy, att, enemySkill;  // 문자 선택 변수, 3가지 적, 선택할 스킬 번호, 적 스킬 번호 

char *job; // 직업을 저장할 문자 변수

player = job_choice();

if (player == 1) { job = "전사"; }

else if (player == 2) { job = "궁수"; }

else { job = "마법사"; }


cout << "당신은 직업은 " << job << " 입니다." << endl;;

cout << "당신이 사용할 스킬은 다음과 같습니다" << endl;

user_skill(player);

player_info(player);

enemy = rand() % 3;

enemy_info(enemy);

cout << "ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ" << endl;

cout << "적이 나타났습니다." << endl;

cout << "상대는 " << tribe.name << " 입니다" << endl;

do 

{

do 

{

cout << ability.job << " HP : " << ability.hp << " / MP : " << ability.mp << endl;

cout << "공격할 스킬을 선택하세요 ( 1 ~ 3 ) : ";

cin >> att;

if (att == 1) { 

cout << tribe.name << "에게 기본 공격을 가했습니다" << endl;

if (ability.job == "전사") tribe.hp -= 50; // 직업별 공격력

if (ability.job == "궁수") tribe.hp -= 70;

if (ability.job == "마법사") tribe.hp -= 100;


if (tribe.hp < 0) tribe.hp = 0;

cout << tribe.name << " HP : " << tribe.hp << " / MP : " << tribe.mp << endl;

break

}else if (att == 2 && ability.mp >= 25) { 

cout << tribe.name << "에게 " << ability.skill2 << "을 가했습니다" << endl;

ability.mp -= 25;

if (ability.mp < 0) ability.mp = 0;

if (ability.job == "전사") tribe.hp -= 100; // 직업별 공격력

if (ability.job == "궁수") tribe.hp -= 150;

if (ability.job == "마법사") tribe.hp -= 200;

if (tribe.hp < 0) tribe.hp = 0;

cout << tribe.name << " HP : " << tribe.hp << " / MP : " << tribe.mp << endl;

break

}

else if (att == 3 && ability.mp >= 50) {

cout << tribe.name << "에게 " << ability.skill3 << "을 가했습니다" << endl;

ability.mp -= 50;

if (ability.mp < 0) ability.mp = 0;

if (ability.job == "전사") tribe.hp -= 200; // 직업별 공격력

if (ability.job == "궁수") tribe.hp -= 300;

if (ability.job == "마법사") tribe.hp -= 400;


if (tribe.hp < 0) tribe.hp = 0;

cout << tribe.name << " HP : " << tribe.hp << " / MP : " << tribe.mp << endl;

break

}

} while (1);


do {

enemySkill = rand() % 3 + 1;

if (enemySkill == 1) {

cout << tribe.name << "가 " << ability.job << "에게 " << tribe.skill1 << " 공격을 가했습니다." << endl;

ability.hp -= 30;

if (ability.hp < 0) ability.hp = 0;

break;

}

else if (enemySkill == 2 && tribe.mp >= 25) {

cout << tribe.name << "가 " << ability.job << "에게 " << tribe.skill2 << " 공격을 가했습니다." << endl;

tribe.mp -= 25;

if (tribe.mp < 0) tribe.mp = 0;

ability.hp -= 50;

if (ability.hp < 0) ability.hp = 0;

break;

}

else if (enemySkill == 3 && tribe.mp >= 50) {

cout << tribe.name << "가 " << ability.job << "에게 " << tribe.skill3 << " 공격을 가했습니다." << endl;

tribe.mp -= 50;

if (tribe.mp < 0) tribe.mp = 0;

ability.hp -= 70;

if (ability.hp < 0) ability.hp = 0;

break;

}


} while (1);

if (ability.hp == 0) break;

if (tribe.hp == 0) break;


} while (ability.hp > 0 || tribe.hp > 0);


if (ability.hp == 0) {

cout << endl;

cout << "ㅡㅡ게임종료ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ" << endl;

cout << ability.job << "가 사망하였습니다. 사냥에 실패하였습니다." << endl;

cout << "ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ" << endl;

}

else if (tribe.hp == 0) {

cout << endl;

cout << "ㅡㅡ게임종료ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ" << endl;

cout << ability.job << "가 " << tribe.name << "를 잡았습니다." << endl;

cout << ability.job << " HP : " << ability.hp << " / MP : " << ability.mp << endl;

cout << "ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ" << endl;

}


return 0;

}


int job_choice() { // 직업 선택 함수

int player; // 직업을 선택할 변수

cout << "대전액션 턴제 게임" << endl;

cout << "플레이할 직업을 선택하세요 ( 1. 전사 / 2. 궁수 / 3. 마법사 ) : ";

cin >> player;

while (player != 1 && player != 2 & player != 3) {

cout << "직업 선택이 잘못됐습니다 ( 1. 전사 / 2. 궁수 / 3. 마법사 ) : ";

cin >> player;

if (player == 1 || player == 2 || player == 3) break;

}

return player;

}


void user_skill(int jobSkill)

{

if (jobSkill == 1) {

cout << "1. 기본 공격 ( 마나 소모 없음 )" << endl;

cout << "2. 대지 강타 ( 마나 25 소모 )" << endl;

cout << "3. 소용돌이 ( 마나 50 소모 )" << endl;

}

else if (jobSkill == 2) {

cout << "1. 기본 공격 ( 마나 소모 없음 )" << endl;

cout << "2. 집중 사격 ( 마나 25 소모 )" << endl;

cout << "3. 달의 섬광 ( 마나 50 소모 )" << endl;

}

else {

cout << "1. 기본 공격 ( 마나 소모 없음 )" << endl;

cout << "2. 불기둥 ( 마나 25 소모 )" << endl;

cout << "3. 불사조 ( 마나 50 소모 )" << endl;

}

}

void player_info(int user) {

if(user == 1){

ability.job = "전사";

ability.hp = 500;

ability.mp = 100;

ability.skill1 = "기본 공격";

ability.skill2 = "대지 강타";

ability.skill3 = "소용돌이";

}

else if (user == 2) {

ability.job = "궁수";

ability.hp = 450;

ability.mp = 100;

ability.skill1 = "기본 공격";

ability.skill2 = "집중 사격";

ability.skill3 = "달의 섬광";

}

else {

ability.job = "마법사";

ability.hp = 400;

ability.mp = 100;

ability.skill1 = "기본 공격";

ability.skill2 = "불기둥";

ability.skill3 = "불사조";

}

}


void enemy_info(int monster) {

if (monster == 1) {

tribe.name = "도살자";

tribe.hp = 800;

tribe.mp = 100;

tribe.skill1 = "힘줄 끊기";

tribe.skill2 = "무자비한 돌진";

tribe.skill3 = "화로구이";

}

else if (monster == 2) {

tribe.name = "누더기";

tribe.hp = 900;

tribe.mp = 100;

tribe.skill1 = "갈고리";

tribe.skill2 = "지면 강타";

tribe.skill3 = "잡아먹기";

}else{

tribe.name = "디아블로";

tribe.hp = 1000;

tribe.mp = 100;

tribe.skill1 = "암흑의 돌진";

tribe.skill2 = "압도";

tribe.skill3 = "종말";

}

}

'SGA 스터디 > C++ 코딩' 카테고리의 다른 글

슬롯머신 게임  (0) 2015.08.11
타일맵 그리기  (0) 2015.08.05
퍼즐 게임  (0) 2015.08.01
야구 게임  (0) 2015.07.31
홀짝 게임  (0) 2015.07.30

#include<iostream>

#include<conio.h>

#include<time.h>

#include <fstream>

#include <windows.h> // Sleep 쓸라고

using namespace std;

#define LEFT 75// 좌측방향키

#define RIGHT 77// 우측방향키

#define UP 72// 위쪽방향키

#define DOWN 80// 아래방향키

#define ESC 27 // ESC 키

int main(){

// 퍼즐게임

// 1 ~ 20 숫자를 가진 4x5 의 퍼즐에 숫자 1을

// 제일 우측하단에서 시작해서 방향키를 입력하면 움직이고(getch())

// 움직인 방향의 숫자와 위치를 바꾸고 벽인 방향으로 입력 시

// 움직이지 않는다.

int push, y = 3, x = 4, temp; // 누를 키값을 저장할 변수, 1의 행값 y, 열값 x, 임시 저장 변수

int puzzle[4][5] = { {18,9,14,4,7}, 

{2,8,10,5,6}, 

{15,12,3,16,19}, 

{20,11,17,13,1} };

do

{

cout << "퍼즐 게임" << endl;

printf("┌────────┐\n");

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

printf("│ ");

for (int j = 0; j < 5; j++) {

printf("%2d ", puzzle[i][j]);

}

printf("│\n");

}

printf("└────────┘\n");

push = getch();

switch (push)

{

case LEFT: // 왼쪽

if (x > 0) { // 왼쪽에 숫자가 있는 경우만 실행

temp = puzzle[y][x];

puzzle[y][x] = puzzle[y][x - 1];

puzzle[y][x - 1] = temp;

x -= 1;

}

break;

case RIGHT: // 오른쪽

if (x < 4) { // 오른쪽에 숫자가 있는 경우만 실행

temp = puzzle[y][x];

puzzle[y][x] = puzzle[y][x + 1];

puzzle[y][x + 1] = temp;

x += 1;

}

break;

case UP: // 위쪽

if (y > 0) { // 위쪽에 숫자가 있는 경우만 실행

temp = puzzle[y][x];

puzzle[y][x] = puzzle[y - 1][x];

puzzle[y - 1][x] = temp;

y -= 1;

}

break;

case DOWN: // 아래쪽

if (y < 3) { // 아래쪽에 숫자가 있는 경우만 실행

temp = puzzle[y][x];

puzzle[y][x] = puzzle[y + 1][x];

puzzle[y + 1][x] = temp;

y += 1;

}

break;

case ESC: // ESC

break;

}

system("cls");

} while (push != ESC);


return 0;

}

// ㅡㅡ 실행 화면 ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ


'SGA 스터디 > C++ 코딩' 카테고리의 다른 글

슬롯머신 게임  (0) 2015.08.11
타일맵 그리기  (0) 2015.08.05
채팅 대전액션  (0) 2015.08.04
야구 게임  (0) 2015.07.31
홀짝 게임  (0) 2015.07.30

#include<iostream>

#include<time.h>

using namespace std;

int main(){

// 기회 9번

// 컴퓨터가 중복되지 않는 랜덤 수(0~9)를 3개 뽑아서 첫번째가 0 이면 안됨

// 플레이어가 숫자 3개를 입력 하나도 맞지않으면 아웃

// 위치가 다르더라도 동일한 숫자가 나오면 볼

// 위치가 같다면 스트라이크

srand(time(NULL));

cout << "야구 게임 ~ 시작" << endl;

int baseball[3]; // 숫자를 받을 야구 배열

do{

baseball[0] = rand() % 10;

baseball[1] = rand() % 10;

baseball[2] = rand() % 10;

} while (baseball[0] == 0 || baseball[0] == baseball[1] || baseball[0] == baseball[2] || baseball[1] == baseball[2]);

cout << "? ? ?" << endl;

int ball1, ball2, ball3; // 3개의 숫자를 입력받을 변수

int strike, ball; // 스트라이크 갯수와 볼 갯수를 카운트 해줄 변수

int count = 0; // 9회 까지 운영 되며 이전에 맞출 경우 게임이 종료됨

do{

count++;

int s = 0, b = 0; // 갯수를 카운트 해주고

scanf("%d %d %d", &ball1, &ball2, &ball3);

if (baseball[0] == ball1) s += 1;

if (baseball[1] == ball2) s += 1;

if (baseball[2] == ball3) s += 1;

if (baseball[0] == ball2 || baseball[0] == ball3) b += 1;

if (baseball[1] == ball1 || baseball[1] == ball3) b += 1;

if (baseball[2] == ball1 || baseball[2] == ball2) b += 1;

strike = s;

ball = b;

cout << "스트라이크 " << strike << "\t볼 " << ball << endl;

} while (strike < 3 && count < 10);

if (strike == 3) cout << "3 스트라이크 아웃입니다. 승리하셨습니다." << endl;

else cout << "9회전 종료\t " << strike << " 스트라이크\t " << ball << " 볼을 달성하고 패배하셨습니다." << endl;

return 0;

}


'SGA 스터디 > C++ 코딩' 카테고리의 다른 글

슬롯머신 게임  (0) 2015.08.11
타일맵 그리기  (0) 2015.08.05
채팅 대전액션  (0) 2015.08.04
퍼즐 게임  (0) 2015.08.01
홀짝 게임  (0) 2015.07.30

+ Recent posts