示例#1
0
    /// <summary>
    /// Test the selected row in debug.
    /// </summary>
    public IEnumerator StartRowTest(int playerIndex, int startingRow)
    {
        if (!runningDebugTest)
        {
            RestartGame();                             // Restart the game board.
            runningDebugTest   = true;                 // In the debug editor, we do not want to start a test while another test is active.
            currentTurn        = players[playerIndex]; // The first player to select a tile will be the player specified in the debug editor.
            currentPlayerIndex = playerIndex;
            Debug.Log("Starting Row Test");
            int currentColumn = 0;                                  // Current column in the row we are testing. We want to insert a tile here.
            while (mainGrid.GetMoveNumber() < GameGridSize * 2 - 1) // After (GameGridSize * 2) - 1, the game should be over.
            {
                if (currentTurn == players[playerIndex])            // If the current player selected is the player we want to win, we should place a tile in the row we specified.
                {
                    mainGrid.Debug_InsertTile(startingRow, currentColumn++);
                }
                else                                    // If it is the other players turn, select a random tile to set. Make sure the tile is not in the row we specified.
                {
                    int randomRow    = (int)Random.Range(0, GameGridSize);
                    int randomColumn = (int)Random.Range(0, GameGridSize);

                    while (randomRow == startingRow || mainGrid.IsTileInitialized(randomRow, randomColumn)) // If we happen to randomly choose the row we specified, find another row to select.
                    {
                        randomRow = (int)Random.Range(0, GameGridSize - 1);
                        yield return(new WaitForEndOfFrame());                                               // Yield the CoRoutine so we don't hold up the rest of the game.
                    }

                    mainGrid.Debug_InsertTile(randomRow, randomColumn);                                     // Finally, insert the tile we found.
                }
                yield return(new WaitForSeconds(.5f));
            }
            Debug.Log("Test Ended");
            runningDebugTest = false;
        }
        yield return(null);
    }