Пример #1
0
        /// <summary>
        /// Player makes a move
        /// </summary>
        /// <param name="player">current player (which will make a move)</param>
        /// <returns>status.player1Win or status.player2Win or status.notFinished</returns>
        private status NewStep(IPlayer player)
        {
            // numberOfStep increases every players' move
            // For example: after player1 made a move, numberOfStep will be 2
            // But we still need 1.txt (instead of 2.txt) from player2
            int stepOfPlayer = (int)Math.Ceiling(this.numberOfStep / 2.0);
            int newStep = player.Step(stepOfPlayer);
            bool IsValid = this.field.ChangeCell(newStep, player.xORo);
            if (!IsValid)
                return status.invalidStep;

            string newFile;
            if (player == this.player1)
                newFile = this.player2.Path + this.player1.xORo + (stepOfPlayer) + ".txt";
            else
                newFile = this.player1.Path + this.player2.xORo + (stepOfPlayer) + ".txt";

            StreamWriter file = new StreamWriter(newFile);
            file.WriteLine(Convert.ToString(newStep));
            file.Close();

            this.panel.Refresh();
            this.label.Refresh();

            // check status of the game every step
            return CheckStatus(newStep);
        }