示例#1
0
    /// <summary>
    /// Adds the new signsInARow and removes the ones which overlap
    /// </summary>
    private void NewSignPlaced(EvaluationField[,] field, IntVector2 where, out List <PlaceData> placed, out List <PlaceData> removed)
    {
        Cell.CellOcc     currentType = field[where.x, where.y].type;
        List <PlaceData> _placed     = new List <PlaceData>();
        List <PlaceData> _removed    = new List <PlaceData>();

        // Check how many signs there are in a row that contains the where sign
        for (int i = 0; i < checkDirections.GetLength(0); i++)
        {
            int        count = 1;
            IntVector2 endOne = new IntVector2(where), endTwo = new IntVector2(where);

            // Go through the checkdirection direction
            for (int j = 1; j < Grid.WIN_CONDITION; j++)
            {
                int examineX = where.x + checkDirections[i, 0] * j;
                int examineY = where.y + checkDirections[i, 1] * j;

                // We are in bounds
                //if (examineX >= 0 && examineX < field.GetLength(0) && examineY >= 0 && examineY < field.GetLength(1)) {
                // It is the same sign
                if (field[examineX, examineY].type == currentType)
                {
                    count++;
                    endOne = new IntVector2(examineX, examineY);
                }
                else
                {
                    break;
                }
            }

            // Go through the opposite of checkdirection direction
            for (int j = 1; j < Grid.WIN_CONDITION; j++)
            {
                int examineX = where.x + -checkDirections[i, 0] * j;
                int examineY = where.y + -checkDirections[i, 1] * j;

                // We are in bounds
                //if (examineX >= 0 && examineX < field.GetLength(0) && examineY >= 0 && examineY < field.GetLength(1)) {
                // It is the same sign
                if (field[examineX, examineY].type == currentType)
                {
                    count++;
                    endTwo = new IntVector2(examineX, examineY);
                }
                else
                {
                    break;
                }
            }

            if (count < 2)
            {
                continue;
            }
            // Now we have the endpoints of this checkdirection in endpoint one and endpoint two
            // We also have if there are blocks at the end if there is not then the block variables are null
            SignInARow signsInARow = new SignInARow(endOne, endTwo, currentType);
            IntVector2 end1 = signsInARow.From - signsInARow.Steepness, end2 = signsInARow.To + signsInARow.Steepness;
            signsInARow.SetEndEvaluationFields(field[end1.x, end1.y], field[end2.x, end2.y]);

            SignInARow removedSignInARow = null;
            field[where.x, where.y].AddSignInARow(signsInARow, out removedSignInARow);

            _placed.Add(new PlaceData(new IntVector2(where), signsInARow));
            if (removedSignInARow != null)
            {
                _removed.Add(new PlaceData(new IntVector2(where), removedSignInARow));
            }
        }

        placed = _placed; removed = _removed;
    }