Пример #1
0
        /// <summary>
        /// User determines the size of the field and the number of foxes on it
        /// </summary>
        /// <returns>Program state</returns>
        public static ProgramSate GameSetUp(ref ViewTable tb, ref Table playingField)
        {
            showPeleng = false;
            go         = 0;
            bool   ch = true;
            string s  = "";
            bool   bl;

            while (ch)
            {
                s = "";
                Console.Clear();
                Console.Write("Введите размер таблички (не меньше 2 и не больше 10): ");
                s  = Console.ReadLine();
                bl = Int32.TryParse(s, out sizeOfTable);
                if (bl == false || sizeOfTable < 2 || sizeOfTable > 10)
                {
                    Console.Clear();
                    Console.WriteLine("Введите правильный размер табличики!!!");
                    Console.ReadLine();
                }
                else
                {
                    ch = false;
                }
            }

            ch = true;

            while (ch)
            {
                Console.Clear();
                Console.Write("Введите количество лис (не меньше 2): ");
                s  = Console.ReadLine();
                bl = Int32.TryParse(s, out countOfFoxes);
                if (bl == false || countOfFoxes < 2)
                {
                    Console.Clear();
                    Console.WriteLine("Введите правильное колиество лис!!!");
                    Console.ReadLine();
                }
                else
                {
                    ch = false;
                }
            }
            Console.Clear();
            tb           = new ViewTable(sizeOfTable);
            playingField = new Table(sizeOfTable, countOfFoxes);

            RandomArray(ref playingField);
            tb.DrawField(playingField);


            playingField.MoveGameCursore(0, 0, tb);
            return(ProgramSate.Game);
        }
Пример #2
0
        /// <summary>
        /// Game, move by table, shot ...
        /// </summary>
        /// <param name="tb">User Table</param>
        /// <param name="playingField">Program Table</param>
        /// <returns>Program state</returns>
        public static ProgramSate Game(ref ViewTable tb, ref Table playingField)
        {
            ProgramSate ps     = ProgramSate.Game;
            Action      action = Action.NoAction;

            Console.Clear();
            tb.DrawField(playingField);
            playingField.MoveGameCursore(0, 0, tb);

            Console.CursorVisible = true;

            if (showPeleng)
            {
                Console.Clear();
                tb.DrawField(playingField);
                go = playingField.EnterFoxes(tb);
                if (go == 2)
                {
                    ps = WinGame(ref tb, ref playingField);
                }
                else
                {
                    GameInfo(tb, playingField, go);
                    Console.CursorVisible = false;

                    action = UserActions.GetUserAction();
                }
            }
            else
            {
                action = UserActions.GetUserAction();
            }

            switch (action)
            {
            case Action.Left:
                showPeleng = false;
                playingField.MoveGameCursore(-1, 0, tb);
                break;

            case Action.Right:
                showPeleng = false;
                playingField.MoveGameCursore(1, 0, tb);
                break;

            case Action.Top:
                showPeleng = false;
                playingField.MoveGameCursore(0, -1, tb);
                break;

            case Action.Bottom:
                showPeleng = false;
                playingField.MoveGameCursore(0, 1, tb);
                break;

            case Action.Enter:
                showPeleng = !showPeleng;
                break;

            case Action.Exit:
                ps = GameExit(ref tb, ref playingField);
                break;
            }
            return(ps);
        }