#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