Пример #1
0
        private Position GetMaxPosition(Position original, Index2d size, int modifier)
        {
            var xMin = GetCheckedIndex(original.Start.X - modifier, size.X);
            var xMax = GetCheckedIndex(original.End.X + modifier, size.X);
            var yMin = GetCheckedIndex(original.Start.Y - modifier, size.Y);
            var yMax = GetCheckedIndex(original.End.Y + modifier, size.Y);

            return(xMin, yMin, xMax, yMax);
        }
Пример #2
0
 // todo: virtual indexes -> vectors
 public Position(Index2d center, IEnumerable <Index2d> indexes)
 {
     Center = center;
     if (indexes == null)
     {
         Indexes = new[] { center };
     }
     else
     {
         // to remove duplicates.
         // probably should do it only for debug
         Indexes = new HashSet <Index2d>(indexes.Union(new[] { Center })).ToArray();
     }
 }
Пример #3
0
        private IEnumerable <Position> GetPossiblePositions(Index2d fieldSize, Position currentPosition)
        {
            var maxStartPosition = GetMaxPosition(
                new Position(
                    currentPosition.Start.X,
                    currentPosition.Start.Y,
                    currentPosition.End.X - Size + 1,
                    currentPosition.End.Y - Size + 1),
                fieldSize,
                Speed);
            var indexes = maxStartPosition.GetIndexes().ToList();

            return(RandomSort(indexes)
                   .Select(i => new Position(i, new Index2d(i.X + Size - 1, i.Y + Size - 1))));
        }
Пример #4
0
        private Field CreateField(Index2d size, int creatureCount, int speed, int vision, int maxHealth)
        {
            var field = new Field(size);
            var rand  = new Random();

            for (int i = 0; i < creatureCount; i++)
            {
                var creature = new Ex1Creature(speed, vision, maxHealth);
                int x, y;
                do
                {
                    x = rand.Next(0, size.X);
                    y = rand.Next(0, size.Y);
                }while (!field.AddEntity(creature, (x, y, x + creature.Size - 1, y + creature.Size - 1)));
            }
            return(field);
        }
Пример #5
0
        private Index2d indexOf(char c, char[,] array)
        {
            Index2d index = new Index2d();

            index.Column = index.Row = -1;

            for (short i = 0; i < mSize.Row; i++)
            {
                for (short j = 0; j < mSize.Column; j++)
                {
                    if (array[i, j] == c)
                    {
                        index.Row    = i;
                        index.Column = j;
                        return(index);
                    }
                }
            }

            return(index);
        }
Пример #6
0
        public bool areAdjacent(char c1, char c2)
        {
            Index2d index1 = indexOf(c1, mChars), index2 = indexOf(c2, mChars);

            if (index1.Column == -1 || index1.Row == -1)
            {
                index1 = indexOf(c1, mAltChars);
            }
            if (index2.Column == -1 || index2.Row == -1)
            {
                index2 = indexOf(c2, mAltChars);
            }

            // We will assume that both characters were found at this point

            bool  sameKey = (index1.Column == index2.Column) && (index1.Row == index2.Row);
            short diffCol = abs(index1.Column, index2.Column);
            short diffRow = abs(index1.Row, index2.Row);

            return(diffCol <= 1 && diffRow <= 1);
        }
Пример #7
0
 private Index2d GetCheckedIndex(Index2d index, Index2d maxIndex)
 {
     return(new Index2d(GetCheckedIndex(index.X, maxIndex.X), GetCheckedIndex(index.Y, maxIndex.Y)));
 }
Пример #8
0
 public static Index2dAssertion Should(this Index2d instance) => new Index2dAssertion(instance);
Пример #9
0
 public static void Check_ArgumentOutOfRange(Index2d index, Index2d maxValue, string paramName)
 {
     Check_ArgumentOutOfRange(index.X, maxValue.X, paramName);
     Check_ArgumentOutOfRange(index.Y, maxValue.Y, paramName);
 }
Пример #10
0
        public Position Move(Index2d center)
        {
            Position this_ = this;

            return(new Position(center, Indexes.Select(i => i + center - this_.Center)));
        }
Пример #11
0
 public Position(Index2d center, params Index2d[] indexes) : this(center, (IEnumerable <Index2d>)indexes)
 {
 }