Exemplo n.º 1
0
 public void RegisterTower(TowerController tower, int x, int y)
 {
     if (playGrid == null)
     {
         playGrid = new PlayGridLoc[gridRows, gridCols];
     }
     playGrid[x, y] = new PlayGridLoc(tower, LaserDirection.NONE, PlayerTeam.Nobody);
 }
Exemplo n.º 2
0
    public void TowerCaptured(TowerController tower, PlayerTeam team)
    {
        Debug.Log("Tower " + tower + "captured! " + tower.gridRow + "/" + tower.gridCol + " by " + team.ToString());
        PlayGridLoc loc = playGrid[tower.gridRow, tower.gridCol];

        loc.team = team;
        tower.OnCapture(team);
        RecalculateGrid();
    }
Exemplo n.º 3
0
    public void RotateTower(TowerController tower, LaserDirection direction)
    {
        PlayGridLoc loc = playGrid[tower.gridRow, tower.gridCol];

        if (loc.direction == direction)
        {
            return;                                     // Nothing to do. Skip recalculation.
        }
        loc.direction = direction;
        RecalculateGrid();
    }
Exemplo n.º 4
0
 private void UpdateTowerRenders(bool[,,] state)
 {
     for (int i = 0; i < gridRows; i++)
     {
         for (int j = 0; j < gridCols; j++)
         {
             PlayGridLoc loc = playGrid[i, j];
             loc.tower.UpdateLasers(state[i, j, 0], state[i, j, 1], loc.direction);
         }
     }
 }
Exemplo n.º 5
0
    // Returns bool[row,col] = laser on/off, calls EndOfGame if someone wins.
    private bool[,] TraceRouteThroughGrid(PlayerTeam team)
    {
        int row, col;

        if (team == PlayerTeam.Red)
        {
            row = activeEmitterRed;
            col = 0;
        }
        else
        {
            row = activeEmitterBlue;
            col = gridCols - 1;
        }

        // Red and Blue active bools for each tower
        bool[,] laserStates = new bool[gridRows, gridCols];
        // Loop detection - store towers we've "seen"
        bool[,] seenTowers = new bool[gridRows, gridCols];

        while (true)
        {
            if (row < 0 || row >= gridRows)
            {
                Debug.Log("Trace went off play grid - bailing.");
                break;
            }

            if (col < 0)
            {
                if (team == PlayerTeam.Blue)
                {
                    EndOfGame(PlayerTeam.Blue);
                }
                else
                {
                    Debug.Log("Red team hit own emitter - bailing.");
                }
                break;
            }

            if (col >= gridCols)
            {
                if (team == PlayerTeam.Red)
                {
                    EndOfGame(PlayerTeam.Red);
                }
                else
                {
                    Debug.Log("Blue team hit own emitter - bailing.");
                }
                break;
            }

            if (seenTowers[row, col])
            {
                Debug.Log("Loop detected in TraceRouteThroughGrid - bailing.");
                break;                 // Avoid infinite loop.
            }

            seenTowers[row, col] = true;
            PlayGridLoc loc = playGrid[row, col];
            Debug.Log("TRACE: " + team.ToString() + " " + row + "/" + col + " " + loc.direction.ToString());
            if (loc.direction == LaserDirection.NONE)
            {
                break;
            }
            laserStates[row, col] = true;

            switch (loc.direction)
            {
            case LaserDirection.UP:
                row -= 1;
                break;

            case LaserDirection.RIGHT:
                col += 1;
                break;

            case LaserDirection.DOWN:
                row += 1;
                break;

            case LaserDirection.LEFT:
                col -= 1;
                break;

            default:
                throw new ArgumentOutOfRangeException();                         // Should be impossible.
            }
        }

        return(laserStates);
    }
Exemplo n.º 6
0
    public PlayerTeam GetTowerOwner(TowerController tower)
    {
        PlayGridLoc loc = playGrid[tower.gridRow, tower.gridCol];

        return(loc.team);
    }