コード例 #1
0
ファイル: Logic.cs プロジェクト: ItzikEzra/MatchingGame
        public static void SetBoardSize(ref Board i_GameBoard)
        {
            bool v_validInputHeight = true;
            bool v_validInputWidth  = true;
            bool v_checkIfEquel     = true;

            GameMeseges.InputNumbers();
            v_validInputHeight = int.TryParse(Console.ReadLine(), out int choosenHeigth);
            v_validInputWidth  = int.TryParse(Console.ReadLine(), out int choosenWitdh);
            while (true)
            {
                while (!v_validInputHeight || !v_validInputWidth)
                {
                    GameMeseges.WrongInputMessege();
                    v_validInputHeight = int.TryParse(Console.ReadLine(), out choosenHeigth);
                    v_validInputWidth  = int.TryParse(Console.ReadLine(), out choosenWitdh);
                }
                v_checkIfEquel = (choosenHeigth * choosenWitdh % 2 == 0);
                if (choosenHeigth >= 4 && choosenHeigth <= 6 && choosenWitdh >= 4 && choosenWitdh <= 6 && v_checkIfEquel)
                {
                    i_GameBoard = new Board(choosenHeigth, choosenWitdh);

                    break;
                }
                else
                {
                    GameMeseges.WrongSizesMessege();
                    v_validInputHeight = int.TryParse(Console.ReadLine(), out choosenHeigth);
                    v_validInputWidth  = int.TryParse(Console.ReadLine(), out choosenWitdh);
                }
            }
        }
コード例 #2
0
        public static void GameOver()
        {
            int maxPoint = s_gameBoard.Boardheight * s_gameBoard.Boardwidth / 2;

            if (s_PlayerOne.score + s_PlayerTwo.score == maxPoint)
            {
                if (s_PlayerOne.score > s_PlayerTwo.score)
                {
                    GameMeseges.WinnerMessege(s_PlayerOne.name);
                }
                else if (s_PlayerOne.score == s_PlayerTwo.score)
                {
                    GameMeseges.ItsTieMessege();
                }
                else
                {
                    GameMeseges.WinnerMessege(s_PlayerTwo.name);
                }
                GameMeseges.PlayAgainMessege();
                string newGame = Console.ReadLine();
                {
                    if (newGame == "1")
                    {
                        Run();
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }
        }
コード例 #3
0
ファイル: Logic.cs プロジェクト: ItzikEzra/MatchingGame
        public static void SetEnemyType(ref Player i_Player)
        {
            int  typeOfPlayerChoise;
            bool v_validInput = true;

            while (true)
            {
                GameMeseges.TypeOfPlayerChoiseMwesege();
                v_validInput = int.TryParse(Console.ReadLine(), out typeOfPlayerChoise);
                while (!v_validInput)
                {
                    GameMeseges.TypeOfPlayerChoiseMwesege();
                    v_validInput = int.TryParse(Console.ReadLine(), out typeOfPlayerChoise);
                }
                if (typeOfPlayerChoise == 1)
                {
                    i_Player = new Player();
                    break;
                }
                if (typeOfPlayerChoise == 2)
                {
                    GameMeseges.GetNameMesege();
                    string playerName2 = Console.ReadLine();
                    i_Player = new Player(playerName2);
                    break;
                }
            }
        }
コード例 #4
0
ファイル: Logic.cs プロジェクト: ItzikEzra/MatchingGame
        private static void oneTurn(ref Board i_GameBoard, ref Player i_Player, ref bool v_Win, ref List <CharLocation> i_Memory)
        {
            int scoreBefore = i_Player.score;

            char[] firstChoice  = new char[2];
            char[] secondChoice = new char[2];
            int[]  tempLocation = new int[2];
            bool   foundCouple  = !true;

            DrawBoard.DrawTheBoard(i_GameBoard);
            GameMeseges.BeReady(i_Player.name);
            GameMeseges.QtoExitMessege();
            if (i_Player.isHuman)
            {
                firstChoice = inputCell(ref i_GameBoard);
                round(ref i_GameBoard, ref firstChoice);
                GameMeseges.QtoExitMessege();
                secondChoice = inputCell(ref i_GameBoard);
                round(ref i_GameBoard, ref secondChoice);
            }
            else
            {
                tempLocation   = pcRandomMove(ref i_GameBoard, ref i_Player);
                firstChoice[0] = (char)tempLocation[0];
                firstChoice[1] = (char)tempLocation[1];
                CharLocation firstPc = new CharLocation(firstChoice, i_GameBoard.GameBoard[firstChoice[1], firstChoice[0]]);
                i_Memory.Add(firstPc);
                GameMeseges.QtoExitMessege();
                System.Threading.Thread.Sleep(2000);
                smartmove(ref i_GameBoard, ref i_Memory, ref firstPc, ref foundCouple, ref secondChoice);
                if (!foundCouple)
                {
                    tempLocation    = pcRandomMove(ref i_GameBoard, ref i_Player);
                    secondChoice[0] = (char)tempLocation[0];
                    secondChoice[1] = (char)tempLocation[1];
                }
                System.Threading.Thread.Sleep(2000);
            }
            Logic.compare(ref firstChoice, ref secondChoice, ref i_GameBoard, ref i_Player);

            if (i_Player.score > scoreBefore)
            {
                v_Win = true;
            }
            else
            {
                v_Win = false;
            }
        }
コード例 #5
0
ファイル: Logic.cs プロジェクト: ItzikEzra/MatchingGame
        private static char[] inputCell(ref Board i_GameBoard)
        {
            char[] location      = new char[2];
            string inputFromUser = Console.ReadLine();

            while (true)
            {
                while (inputFromUser.Length != 2)
                {
                    if (inputFromUser == "Q")
                    {
                        Environment.Exit(0);
                    }
                    GameMeseges.WrongTemlateMessege();
                    inputFromUser = Console.ReadLine();
                }
                location = inputFromUser.ToCharArray();

                if (location.Length == 2 && char.IsUpper(location[0]) && char.IsDigit(location[1]))
                {
                    location[0] -= 'A';
                    location[1] -= '1';
                    if (inBorder(location, i_GameBoard))
                    {
                        if (i_GameBoard.GameBoardFlag[location[1], location[0]] == 0)
                        {
                            break;
                        }
                        else
                        {
                            GameMeseges.OpenCellMessege();
                        }
                    }
                    else
                    {
                        GameMeseges.NotInBorderMessege();
                    }
                }
                else
                {
                    GameMeseges.WrongTemlateMessege();
                }

                inputFromUser = Console.ReadLine();
            }
            return(location);
        }
コード例 #6
0
ファイル: Logic.cs プロジェクト: ItzikEzra/MatchingGame
        public static void TurnManager(ref Board i_GameBoard, ref Player i_PlayerOne, ref Player i_PlayerTwo, ref List <CharLocation> m_Memory)
        {
            bool v_firstPlayer  = true;
            bool v_secondPlayer = true;

            while (v_firstPlayer)
            {
                oneTurn(ref i_GameBoard, ref i_PlayerOne, ref v_firstPlayer, ref m_Memory);
                Ex02.ConsoleUtils.Screen.Clear();
                GameMeseges.Printinfo(ref i_PlayerOne, ref i_PlayerTwo);
            }

            while (v_secondPlayer)
            {
                oneTurn(ref i_GameBoard, ref i_PlayerTwo, ref v_secondPlayer, ref m_Memory);
                Ex02.ConsoleUtils.Screen.Clear();
                GameMeseges.Printinfo(ref i_PlayerOne, ref i_PlayerTwo);
            }
        }
コード例 #7
0
        public static void Run()
        {
            GameMeseges.HelloMesege();
            GameMeseges.GetNameMesege();
            string playerName = Console.ReadLine();

            s_PlayerOne = new Player(playerName);
            s_PlayerTwo = new Player();
            s_gameBoard = new Board();
            m_Memory    = new List <CharLocation>();


            Logic.SetEnemyType(ref s_PlayerTwo);
            Logic.SetBoardSize(ref s_gameBoard);
            DrawBoard.FillTable(ref s_gameBoard);

            while (true)
            {
                Logic.TurnManager(ref s_gameBoard, ref s_PlayerOne, ref s_PlayerTwo, ref m_Memory);
            }
        }