C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[71348] 심심해서 한번 만들어 봤습니다. 참고하세요.
NeverWash [neverwash] 3253 읽음    2014-05-21 16:31
#include <iostream>
#include <string.h>
#include <time.h>
using namespace std;

#define max_n    50
#define blank    '_'

char input[max_n];
char answer[max_n];
int err_count = 0;

char dictionary[][max_n] = {"Rose", "Audio", "Bible", "Earth", "Movie", "Space", "Good", "Enterprise", "University", "Tomorrow",
"Professor", "Parent", "Korea", "Basketball", "Computer", "Programming", "C++_rule_the_world!!", "Amazing", "Apple", "Marathon"};

void display(int stage)
{
    switch (stage)
    {
    case 99:
        cout << "----------- GAME  START -----------\n";
        break;
    case 0:
        cout << "        \n";
        break;
    case 1:
        cout << "        \n";
        cout << "        \n";
        cout << "        \n";
        cout << "        \n";
        cout << "        \n";
        cout << "        \n";
        cout << "        \n";
        cout << " -+---- \n";
        break;
    case 2:
        cout << "        \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << " -+---- \n";
        break;
    case 3:
        cout << "  +---  \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << " -+---- \n";
        break;
    case 4:
        cout << "  +---  \n";
        cout << "  |  |  \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << " -+---- \n";
        break;
    case 5:
        cout << "  +---  \n";
        cout << "  |  |  \n";
        cout << "  |  o  \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << " -+---- \n";
        break;
    case 6:
        cout << "  +---  \n";
        cout << "  |  |  \n";
        cout << "  |  o  \n";
        cout << "  |  |  \n";
        cout << "  |  |  \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << " -+---- \n";
        break;
    case 7:
        cout << "  +---  \n";
        cout << "  |  |  \n";
        cout << "  |  o  \n";
        cout << "  | -|  \n";
        cout << "  |  |  \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << " -+---- \n";
        break;
    case 8:
        cout << "  +---  \n";
        cout << "  |  |  \n";
        cout << "  |  o  \n";
        cout << "  | -|- \n";
        cout << "  |  |  \n";
        cout << "  |     \n";
        cout << "  |     \n";
        cout << " -+---- \n";
        break;
    case 9:
        cout << "  +---  \n";
        cout << "  |  |  \n";
        cout << "  |  o  \n";
        cout << "  | -|- \n";
        cout << "  |  |  \n";
        cout << "  | /   \n";
        cout << "  |     \n";
        cout << " -+---- \n";
        break;
    case 10:
        cout << "  +---  \n";
        cout << "  |  |  \n";
        cout << "  |  o  \n";
        cout << "  | -|- \n";
        cout << "  |  |  \n";
        cout << "  | //  \n";
        cout << "  |     \n";
        cout << " -+---- \n";
        break;
    }
    cout << "ANSWER: ";
    for (int i = 0; i < strlen(answer); ++i) cout << input[i];
    cout << endl;
}

void init()
{
    err_count = 0;
    srand(time(NULL));
    sprintf(answer, "%s\0", dictionary[rand()%20]);
    memset(input, blank, max_n * sizeof(char));
    display(99);
}

int main()
{
    init();
    while (true)
    {
        cout << "Input alpa: ";
        char c;
        cin >> c;
   
        c = tolower(c);
        int match_count = 0;
        for (int i = 0; i < strlen(answer); ++i)
        {
            if (input[i] == blank && tolower(answer[i]) == tolower(c))
            {
                input[i] = answer[i];
                ++match_count;
            }
        }

        if (match_count == 0) ++err_count;
        else cout << match_count << (match_count == 1 ? "match!" : "matches!!") << endl;
        display(err_count);

        if (!strncmp(input, answer, strlen(answer)))
        {
            cout << "Success!!" << endl;
            cout << "More Game?(y/n): " << endl;
            char c;
            cin >> c;

            if (tolower(c) == 'n') exit(0);
            init();
        }

        if (err_count == 10)
        {
            cout << "Failed!!" << endl;
            cout << "Continue?(y/n): ";
            char c;
            cin >> c;

            if (tolower(c) == 'n') exit(0);
            init();
        }
    }
}

+ -

관련 글 리스트
71328 과제를 하는데 어디서 막힌건지 도저히 모르겠습니다 포뇨우 3149 2014/05/18
71344     Re:과제를 하는데 어디서 막힌건지 도저히 모르겠습니다 NeverWash 3072 2014/05/21
71348         심심해서 한번 만들어 봤습니다. 참고하세요. NeverWash 3253 2014/05/21
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.