/// <summary>
        /// New game
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNewGame_Click(object sender, EventArgs e)
        {
            //Reset game
            gameLogic = new TicTacToeLogic();

            //Reset board
            for (int row = 0; row < 3; row++)
            {
                for (int column = 0; column < 3; column++)
                {
                    Label lbl = (Label)tlpGameBoard.GetControlFromPosition(column, row);
                    lbl.Text = "";
                }
            }
            lblResult.Text = "";

            //Enable board
            tlpGameBoard.Enabled = true;
        }
        /// <summary>
        /// Start server
        /// </summary>
        private void StartServer()
        {
            try
            {
                //Declare object
                player1 = new Player("Player 1");
                gameLogic = new TicTacToeLogic();

                //Create TCPListener
                IPAddress address = IPAddress.Parse("127.0.0.1");
                listener = new TcpListener(address, PORT_NUMBER);

                //Start and listen
                listener.Start();

                socket = listener.AcceptSocket();

                //Init variables
                stream = new NetworkStream(socket);
                reader = new StreamReader(stream);
                writer = new StreamWriter(stream);
                writer.AutoFlush = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot start server. " + ex.Message);
            }
        }
 /// <summary>
 /// Start game
 /// </summary>
 private void StartGame()
 {
     player1 = new Player("Player 1");
     player2 = new Player("Player 2");
     gameLogic = new TicTacToeLogic();
     gameBoard = new TicTacToeBoard(player1, player2, gameLogic);
     //lblResult.Text = "You play first.";
     lblResult.Invoke((MethodInvoker)(() => lblResult.Text = "You play first!"));
 }
        /// <summary>
        /// New game
        /// </summary>
        private void NewGame()
        {
            //Reset game
            gameLogic = new TicTacToeLogic();

            //Reset board
            for (int row = 0; row < 3; row++)
            {
                for (int column = 0; column < 3; column++)
                {
                    Label lbl = (Label)tlpServerBoard.GetControlFromPosition(column, row);
                    lbl.Invoke((MethodInvoker)(() => lbl.Text = ""));
                }
            }
            lblResult.Invoke((MethodInvoker)(() => lblResult.Text = "You play first!"));

            //Enable board
            tlpServerBoard.Invoke((MethodInvoker)(() => tlpServerBoard.Enabled = true));
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="player1"></param>
 /// <param name="player2"></param>
 /// <param name="gameLogic"></param>
 public TicTacToeBoard(Player player1, Player player2, TicTacToeLogic gameLogic)
 {
     this.player1 = player1;
     this.player2 = player2;
     this.gameLogic = gameLogic;
 }
 /// <summary>
 /// Get symbol
 /// </summary>
 /// <param name="symbol"></param>
 /// <returns></returns>
 private string GetSymbolString(TicTacToeLogic.PlayerSymbol symbol)
 {
     switch (symbol)
     {
         case TicTacToeLogic.PlayerSymbol.X:
             return "X";
         case TicTacToeLogic.PlayerSymbol.O:
             return "O";
         default:
             return " ";
     }
 }
 /// <summary>
 /// Get symbol player
 /// </summary>
 /// <param name="symbol"></param>
 /// <returns></returns>
 private string GetSymbolPlayer(TicTacToeLogic.PlayerSymbol symbol)
 {
     switch (symbol)
     {
         case TicTacToeLogic.PlayerSymbol.X:
             return player1.GetName();
         case TicTacToeLogic.PlayerSymbol.O:
             return player2.GetName();
         default:
             return "";
     }
 }
 public System.Drawing.Color GetSymbolColor(TicTacToeLogic.PlayerSymbol symbol)
 {
     switch (symbol)
     {
         case PlayerSymbol.X:
             return System.Drawing.Color.Blue;
         case PlayerSymbol.O:
             return System.Drawing.Color.Green;
         default:
             return System.Drawing.Color.Black;
     }
 }
        /// <summary>
        /// Form load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmOnePlayer_Load(object sender, EventArgs e)
        {
            String[] users = new String[2];
            users[0] = "You";
            users[1] = "Computer";

            Random rand = new Random();
            int random_index = rand.Next(1);
            humanPlayer = new Player(users[random_index]);
            random_index = ( random_index == 1 ? 0 : 1 );
            computerPlayer = new Player(users[random_index]);
            gameLogic = new TicTacToeLogic();
            gameBoard = new TicTacToeBoard(humanPlayer, computerPlayer, gameLogic);
        }