예제 #1
0
        public UserPlay(ScoreList scores)
        {
            int choice;

            mode = 0;  // 사용자 모드로 설정
            map  = new int[9] {
                -1, -1, -1, -1, -1, -1, -1, -1, -1
            };
            ChoicePlayer(scores);
            DecideTurn();
            while (true)
            {
                Console.Clear();
                PrintGameScreen();
                while (true)
                {
                    // 현재 입력된 키를 읽고 맞는지 체크한다.
                    char _input = Console.ReadKey().KeyChar;
                    if (_input < '1' || _input > '9')
                    {
                        Console.Clear();
                        Console.WriteLine("\n\t\t\tAlert : 1 ~ 9번 중 선택하세요");
                        PrintGameScreen();
                        continue;
                    }
                    else
                    {
                        choice = int.Parse(_input + "");
                        if (map[choice - 1] != -1)  // 이미 놓여진 자리라면
                        {
                            continue;
                        }
                        map[choice - 1] = turn;
                        if (turn == 0)
                        {
                            turn = 1;
                        }
                        else
                        {
                            turn = 0;
                        }
                        break;
                    }
                }
                win = CheckGame();
                if (win != -1)
                {
                    Console.Clear();
                    ConsoleUI.GotoLine(4);
                    ConsoleUI.DynamicPrint('#');
                    Console.WriteLine("  " + nickname[win] + "가 이겼습니다.");
                    scores.Update(nickname[win], true);
                    if (win == 0)
                    {
                        scores.Update(nickname[1], false);
                    }
                    else
                    {
                        scores.Update(nickname[0], false);
                    }
                    break;
                }
                else
                {
                    int iter;
                    for (iter = 0; iter < map.Length; iter++)
                    {
                        if (map[iter] == -1)
                        {
                            break;
                        }
                    }
                    if (iter == map.Length)
                    {
                        Console.Clear();
                        ConsoleUI.GotoLine(4);
                        ConsoleUI.DynamicPrint('#');
                        Console.WriteLine("  무승부입니다.");
                        for (int k = 0; k < 2; k++)  // 무승부이므로 둘 다 승이 아님
                        {
                            scores.Update(nickname[k], false);
                        }
                        break;
                    }
                }
            }
        }
예제 #2
0
        public int NormalGame()    // 보통 모드
        {
            int    choice;
            Random rand = new Random();

            DecideTurn();  // 사용자와 컴퓨터 턴을 결정한다.

            while (true)
            {
                PrintGameScreen();  // 게임 화면 출력

                // 컴퓨터가 아직 놓이지 않은 자리에 놓는다
                if (turn == 1)
                {  // 컴퓨터 차례이면
                    while (true)
                    {
                        choice = PositionDecision();  // 컴퓨터가 위치를 찍는다
                        if (map[choice - 1] == -1)
                        {
                            break;
                        }
                    }
                    map[choice - 1] = 1;
                    turn            = 0;
                }
                else
                {  // 사용자 차례이면
                    while (true)
                    {
                        // 현재 입력된 키를 읽고 맞는지 체크한다.
                        char _input = Console.ReadKey().KeyChar;
                        if (_input < '1' || _input > '9')
                        {
                            Console.Clear();
                            Console.WriteLine("\n\t\t\tAlert : 1 ~ 9번 중 선택하세요");
                            PrintGameScreen();
                            continue;
                        }
                        else
                        {
                            choice = int.Parse(_input + "");
                            if (map[choice - 1] != -1)
                            {
                                continue;
                            }
                            map[choice - 1] = 0;
                            Console.WriteLine();
                            break;
                        }
                    }
                    turn = 1;
                }
                Console.Clear();
                win = CheckGame();
                if (win != -1)
                {
                    ConsoleUI.GotoLine(4);
                    ConsoleUI.DynamicPrint('#');
                    if (win == 1)
                    {
                        Console.WriteLine("  컴퓨터가 이겼습니다.");
                    }
                    else
                    {
                        Console.WriteLine("  {0}가 이겼습니다.", nickname[0]);
                    }
                    break;
                }
                else
                {
                    int iter;
                    for (iter = 0; iter < map.Length; iter++)  // 무승부 여부를 판단한다
                    {
                        if (map[iter] == -1)
                        {
                            break;
                        }
                    }
                    if (iter == map.Length)
                    {
                        ConsoleUI.GotoLine(4);
                        ConsoleUI.DynamicPrint('#');
                        Console.WriteLine("  무승부입니다.");
                        return(0);
                    }
                }
            }
            return(win);
        }