본문 바로가기
C언어

[c언어]빙고게임[EASY]

by 코모's 2020. 4. 2.
반응형

Bingo.exe
0.04MB

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
 
#pragma warning (disable : 4996)
int Bingo[5][5] = { 0 };
int Player[5][5] = { 0 };
int AI[5][5] = { 0 };
int A_set[25] = { 0 };
int myLine = 0;
int aiLine = 0;
bool already;
int x = 0;
int count = 1;
 
void LineCheck()//빙고체크
{
    myLine = 0;
    aiLine = 0;
 
    for (int i = 0; i < 5; i++)
    {
        if (Player[0][i] == 0 && Player[1][i] == 0 && Player[2][i] == 0 && Player[3][i] == 0 && Player[4][i] == 0)
            myLine++;
        if (Player[i][0] == 0 && Player[i][1] == 0 && Player[i][2] == 0 && Player[i][3] == 0 && Player[i][4] == 0)
            myLine++;        
 
        if (AI[0][i] == 0 && AI[1][i] == 0 && AI[2][i] == 0 && AI[3][i] == 0 && AI[4][i] == 0)
            aiLine++;
        if (AI[i][0] == 0 && AI[i][1] == 0 && AI[i][2] == 0 && AI[i][3] == 0 && AI[i][4] == 0)
            aiLine++;        
    }
 
    if (Player[0][0] == 0 && Player[1][1] == 0 && Player[2][2] == 0 && Player[3][3] == 0 && Player[4][4] == 0)//대각선
        myLine++;
    if (Player[0][4] == 0 && Player[1][3] == 0 && Player[2][2] == 0 && Player[3][1] == 0 && Player[4][0] == 0)//대각선
        myLine++;
 
    if (AI[0][0] == 0 && AI[1][1] == 0 && AI[2][2] == 0 && AI[3][3] == 0 && AI[4][4] == 0)//대각선
        aiLine++;
    if (AI[0][4] == 0 && AI[1][3] == 0 && AI[2][2] == 0 && AI[3][1] == 0 && AI[4][0] == 0)//대각선
        aiLine++;
}
 
void main()
{
    srand((unsigned)time(NULL));
 
    int num = 1;
 
 
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            Bingo[i][j] = num;
            num++;
        }
    }
 
    for (int i = 0; i < 100; i++)//섞기
    {
        int randNum1 = rand() % 5;
        int randNum2 = rand() % 5;
        int randNum3 = rand() % 5;
        int randNum4 = rand() % 5;
        int temp;
        temp = Bingo[randNum1][randNum2];
        Bingo[randNum1][randNum2] = Bingo[randNum3][randNum4];
        Bingo[randNum3][randNum4] = temp;
    }
 
 
 
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
            Player[i][j] = Bingo[i][j];
    }
 
    for (int i = 0; i < 100; i++)//섞기
    {
        int randNum1 = rand() % 5;
        int randNum2 = rand() % 5;
        int randNum3 = rand() % 5;
        int randNum4 = rand() % 5;
        int temp;
        temp = Bingo[randNum1][randNum2];
        Bingo[randNum1][randNum2] = Bingo[randNum3][randNum4];
        Bingo[randNum3][randNum4] = temp;
    }
 
 
 
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
            AI[i][j] = Bingo[i][j];
    }
 
    while (true)
    {
        system("cls");
 
        printf("1. Easy\n");
        printf("2. Hard\n");
        printf("AI 모드를 선택하세요(승리조건 5빙고) : ");
        int Set = 0;
        scanf_s("%d", &Set);
        getchar();
        system("cls");
 
        if (Set < 1 || Set >2)
        {
            printf("잘못입력하셨습니다.\n");
            getchar();
            system("cls");
            continue;
        }
 
        int ply = 0;
        int ai = 0;
        char ch[] = "*";
        if (Set == 1)
        {
        start:
            printf(":::::::::::: EASY MODE ::::::::::::\n");
            printf("==============Player==============\n");
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                    printf("%d\t", Player[i][j]);
                printf("\n");
 
            }
            printf("\n");
            printf("================AI================\n");
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                    printf("%d\t", AI[i][j]);
                printf("\n");
 
            }
            printf("1 ~ 25 중 숫자를 입력하세요(0 : exit).\n ");
            printf("player의 차례입니다. :");
            scanf_s("%d", &ply);
 
            getchar();
 
            if (ply == 0)
                break;
 
            //if (ply < 0 || ply > 25)
            //{
            //   printf("잘못입력하셨습니다.\n");
            //   getchar();
            //   system("cls");
            //   //goto easy;
            //}
 
            bool em = true;
 
        
            while (true)
            {
                if (ply < 0 || ply > 25)
                {
                    printf("잘못입력하셨습니다.\n");
                    getchar();
                    system("cls");
                    goto easy;
                }                
 
                ai = (rand() % 25) + 1; //ai숫자 정하기
                if (ai == ply)
                {
                    ai = rand() % 25 + 1;
                }
                for (int j = 0; j < 25; j++)
                {
                    if (A_set[j] == ai)
                    {
                        ai = rand() % 25 + 1;
                    }
                }
 
                for (int j = 0; j < 25; j++)//중복 방지
                {
                    if (A_set[j] == ply)
                    {
                        printf("이미 선택한 숫자입니다. 다시 선택해주세요.\n");
                        printf("player의 차례입니다. :");
                        scanf_s("%d", &ply);
 
                        getchar();
                    }
                }
 
                A_set[x] = ai;
                A_set[x + 1] = ply;
 
                x = x + 2;
 
                for (int i = 0; i < 5; i++)//숫자 지우기
                {
                    for (int j = 0; j < 5; j++)
                    {
                        if (Player[i][j] == ply)
                        {
                            Player[i][j] = 0;
                        }
 
                        if (AI[i][j] == ply)
                        {
                            AI[i][j] = 0;
                        }
 
                        if (Player[i][j] == ai)
                        {
                            Player[i][j] = 0;
                        }
 
                        if (AI[i][j] == ai)
                        {
                            AI[i][j] = 0;
                        }
                    }
                }
 
 
                LineCheck();
 
 
                system("cls");
 
            easy:
                printf("Player의 선택 : %d\n", ply);
                printf("AI의 선택 : %d\n", ai);
 
                printf("\n%d번째 turn 결과 :::::::::::::::::::::::\n", count);
                printf(":::::::::::: EASY MODE ::::::::::::\n");
                printf("==============Player==============\n");
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 5; j++)
                        printf("%d\t", Player[i][j]);
                    printf("\n");
 
                }
                printf("\n");
                printf("================AI================\n");
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 5; j++)
                        printf("%d\t", AI[i][j]);
                    printf("\n");
 
                }
 
                printf("Plyaer : %d 빙고 \t AI : %d 빙고\n", myLine, aiLine);
 
                if (myLine >= 5)//승리
                {
                    printf("\nPlayer승리!");
                    getchar();
                    return;
                }
                else if (aiLine >= 5)
                {
                    printf("\nAI승리!");
                    getchar();
                    return;
                }
 
                printf("1 ~ 25 중 숫자를 입력하세요(0 : exit).\n ");
                printf("player의 차례입니다. :");
                scanf_s("%d", &ply);
                               
                getchar();
 
                count++;
 
                
 
                if (ply == 0)
                {
                    printf("잘못입력하셨습니다.\n");
                    getchar();
                    return;
                }
            }//while (true)
        }//if (Set == 1)
        else if (Set == 2)
        {
 
        }//else if (Set == 2)
    }//while(true)
 
}//main
반응형

'C언어' 카테고리의 다른 글

[c언어] 음식추천 프로그램  (0) 2020.04.02
[c언어]숫자 야구 게임  (0) 2020.04.02
[c언어] BMI측정 프로그램  (0) 2020.04.02
[c언어] 로또번호 생성기  (0) 2020.04.02
[c언어]Matrix(매트릭스)게임  (0) 2020.04.02