コード例 #1
0
        /// <summary>
        /// Checks if someone won
        /// </summary>
        public void CheckGameState()
        {
            if (winner == IdentifyWinner.NULL)
            {
                //if there is empty spots game continues else game is over
                foreach (var spot in spotValues)
                {
                    if (spot == Game.SpotState.empty)
                    {
                        GameState = true;
                        break;
                    }
                    else
                    {
                        GameState = false;
                    }
                }

                //if there is no empty spots and winner is null -> it's draw
                if (GameState != true)
                {
                    winner = IdentifyWinner.draw;
                }
            }
        }
コード例 #2
0
 public GameLogic()
 {
     winSegments = new short[3] {
         0, 0, 0
     };
     tileValues = new BoxState[maxSize];
     winner     = new IdentifyWinner();
 }
コード例 #3
0
 /// <summary>
 /// Game constructor
 /// </summary>
 public Game()
 {
     winSegments = new short[3] {
         0, 0, 0
     };
     spotValues      = new SpotState[9];
     winner          = new IdentifyWinner();
     foundWinPattern = false;
     PlayerTurn      = true;
     GameState       = true;
 }
コード例 #4
0
 public TicTac()
 {
     this.winSegments = new short[3] {
         0, 0, 0
     };
     this.tileValues   = new BoxState[9];
     this.winner       = new IdentifyWinner();
     this.foundPattern = false;
     this.PlayerState  = true;
     this.GameState    = true;
 }
コード例 #5
0
        public void DefaultTileInit()
        {
            for (int i = 0; i < maxSize; ++i)
            {
                tileValues[i] = BoxState.free;
            }

            winner           = IdentifyWinner.NULL;
            FoundPattern     = false;
            FirstPlayerState = true;
            GameState        = true;
        }
コード例 #6
0
 /// <summary>
 /// initialize board with all empty spots
 /// </summary>
 public void InitialBoard()
 {
     //all empty spots
     for (int i = 0; i < maxSize; ++i)
     {
         spotValues[i] = SpotState.empty;
     }
     //first turn is player's turn
     winner          = IdentifyWinner.NULL;
     foundWinPattern = false;
     PlayerTurn      = true;
     GameState       = true;
 }
コード例 #7
0
        /// <summary>
        /// Get winner of game
        /// </summary>
        /// <param name="tempstate"></param>
        public void GetWinner(SpotState spotstate)
        {
            if (GameState != false)
            {
                GetWin(spotstate);

                if (foundWinPattern)
                {
                    if (spotstate == SpotState.X)
                    {
                        winner = IdentifyWinner.player;
                    }

                    else if (spotstate == SpotState.O)
                    {
                        winner = IdentifyWinner.computer;
                    }
                }

                CheckGameState();
            }
        }
コード例 #8
0
        public void GetWinner(BoxState tempstate)
        {
            if (this.GameState != false)
            {
                Getwin(tempstate);

                if (FoundPattern)
                {
                    if (tempstate == BoxState.cross)
                    {
                        winner = IdentifyWinner.player1;
                    }

                    else if (tempstate == BoxState.zero)
                    {
                        winner = IdentifyWinner.player2;
                    }
                }

                CheckGameState();
            }
        } ///
コード例 #9
0
        public void getWinner(BoxState tempstate)
        {
            if (this.GameState != false)
            {
                getwin(tempstate);

                if (foundPattern)
                {
                    if (tempstate == BoxState.cross)
                    {
                        winner = IdentifyWinner.player;
                    }

                    else if (tempstate == BoxState.zero)
                    {
                        winner = IdentifyWinner.computer;
                    }
                }

                this.checkGameState();
            }
        }
コード例 #10
0
        public void CheckGameState()
        {
            if (this.winner == IdentifyWinner.NULL)
            {
                foreach (var tile in this.tileValues)
                {
                    if (tile == BoxState.free)
                    {
                        this.GameState = true;
                        break;
                    }
                    else
                    {
                        this.GameState = false;
                    }
                }

                if (this.GameState != true)
                {
                    winner = IdentifyWinner.stalemate;
                }
            }
        }
コード例 #11
0
 public void IdentifyWinnerSub()
 {
     IdentifyWinner.Invoke();
 }