Exemplo n.º 1
0
        public bool Action(string playerName, int i, int j)
        {
            if (!State.Equals("GAME"))
            {
                return(false);
            }
            if (String.IsNullOrWhiteSpace(playerName))
            {
                return(false);
            }
            if (!Player1Name.Equals(playerName) && !Player2Name.Equals(playerName))
            {
                return(false);
            }
            if (!Turn.Equals(playerName))
            {
                return(false);
            }
            if (i < 0 || i > 2 || j < 0 || j > 2)
            {
                return(false);
            }
            if (!isEmpty(i, j))
            {
                return(false);
            }

            var sign = Player1Name.Equals(playerName) ? CROSS : ROUND;

            Field[i, j] = sign;

            if (isWin(sign))
            {
                State  = "FINISH";
                Turn   = String.Empty;
                Winner = sign == CROSS ? Player1Name : Player2Name;
            }
            else
            {
                if (isDraw())
                {
                    State = "DRAW";
                    Turn  = String.Empty;
                }
                else
                {
                    Turn = Turn.Equals(Player1Name) ? Player2Name : Player1Name;
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        //public int GetValue(int i, int j)
        //{
        //    return Field[i, j];
        //}

        public bool Join(string player2Name)
        {
            if (!isListen())
            {
                return(false);
            }
            if (String.IsNullOrWhiteSpace(player2Name))
            {
                return(false);
            }
            if (Player1Name.Equals(player2Name))
            {
                return(false);
            }

            Player2Name = player2Name;
            State       = "GAME";

            var rand = new Random(DateTime.Now.Millisecond);

            Turn = rand.Next(1000) % 2 == 0 ? Player1Name : Player2Name;

            return(true);
        }