Example #1
0
        public void FullCoordinatesTest()
        {
            var dsk = new DiscreteCoordinates(5, 4);

            Assert.AreEqual(dsk.X, 5);
            Assert.AreEqual(dsk.Y, 4);
        }
Example #2
0
        //Сделано тупо, но можно исправить, переделав список в словарь
        //Тупо - это поиск игрока по id
        public bool MoveCharacter(int playerId, DiscreteCoordinates coords)
        {
            bool ret = false;

            for (int i = 0; i < characters.Count; i++)
            {
                Character charact = characters[i];
                if (charact.PlayerId == playerId)
                {
                    DiscreteCoordinates newCoords = charact.Coordinates + coords;
                    if (CanMoveToCell(charact, newCoords))
                    {
                        charact.Move(coords);
                        int xpos = newCoords.X;
                        int ypos = newCoords.Y;
                        this[ypos, xpos].MoveIn(charact);
                        ret = true;
                        if (finishZone.IsInZone(charact.Coordinates) && FinishedPlayerId < 0)
                        {
                            FinishedPlayerId = charact.PlayerId;
                            NotifyFinish(charact.PlayerName);
                        }
                    }
                }
            }
            return(ret);
        }
Example #3
0
        public void EmptyCoordinatesTest()
        {
            var dsk = new DiscreteCoordinates();

            Assert.AreEqual(dsk.X, 0);
            Assert.AreEqual(dsk.Y, 0);
        }
Example #4
0
        public void ZoneTest()
        {
            DiscreteCoordinates coords = new DiscreteCoordinates(1, 2);
            Zone z1 = new RectangleZone(4, 5, 5, 6);
            Zone z2 = new RectangleZone(-1, 7, -3, 8);

            Assert.IsFalse(z1.IsInZone(coords));
            Assert.IsTrue(z2.IsInZone(coords));
        }
Example #5
0
        private bool CanPlaceTrapOnCell(DiscreteCoordinates coords)
        {
            bool ret = true;

            if (startZone.IsInZone(coords) || finishZone.IsInZone(coords))
            {
                ret = false;
            }
            return(ret);
        }
Example #6
0
        public bool MoveCharacter(string token, string dir)
        {
            bool ret = false;

            if (!PlayersCharacters.ContainsKey(token))
            {
                ret = false;
            }
            else
            {
                int id = PlayersCharacters[token];
                DiscreteCoordinates coords = new DiscreteCoordinates();
                switch (dir)
                {
                case "up":
                {
                    coords = new DiscreteCoordinates(0, -1);
                    break;
                }

                case "down":
                {
                    coords = new DiscreteCoordinates(0, 1);
                    break;
                }

                case "left":
                {
                    coords = new DiscreteCoordinates(-1, 0);
                    break;
                }

                case "right":
                {
                    coords = new DiscreteCoordinates(1, 0);
                    break;
                }

                default:
                {
                    break;
                }
                }
                ret = playField.MoveCharacter(id, coords);
            }
            return(ret);
        }
Example #7
0
 private bool CanMoveToCell(Character ch, DiscreteCoordinates coords)
 {
     if (!ch.CanMove())
     {
         return(false);
     }
     if ((coords.Y >= 0 && coords.Y < cells.Length) &&
         (coords.X >= 0 && coords.X < cells[0].Length))
     {
         if (!this[coords.Y, coords.X].IsPassable())
         {
             return(false);
         }
         return(true);
     }
     return(false);
 }
Example #8
0
        //Убрать возвращаемое значение, заменить его placed-ом
        //и вызвать NotifyShow в ячейке при установке(с обработкой типа - невидимые\видимые)
        public bool PlaceTrap(int playerId, Modificator trap, DiscreteCoordinates coords, out bool placed)
        {
            bool ret = false;

            placed = false;
            for (int i = 0; i < characters.Count; i++)
            {
                Character charact = characters[i];
                if (charact.PlayerId == playerId)
                {
                    if (charact.CanPlaceTrap(trap) && CanPlaceTrapOnCell(coords))
                    {
                        charact.PlaceTrap(trap);
                        placed = true;
                        this[coords.Y, coords.X].AddModificator(trap);
                        ret = true;
                    }
                }
            }
            return(ret);
        }
Example #9
0
        private static void SampleKernel(GpuShapeInfo shape, GpuSpaceInfo space, Matrix transformation, float maxDistance, bool revert)
        {
            var start = space.Bounds.Length * (blockIdx.x * blockDim.x + threadIdx.x) / blockDim.x / gridDim.x;
            var end   = space.Bounds.Length * (blockIdx.x * blockDim.x + threadIdx.x + 1) / blockDim.x / gridDim.x;

            var inversedTransformation = transformation.Inverse();

            for (int voxelIndex = start; voxelIndex < end; voxelIndex++)
            {
                var voxel = space.Voxels.Get(voxelIndex);

                var spaceCoordinates = space.Bounds.At(voxelIndex);
                var spacePosition    = spaceCoordinates.AsVertex();
                var shapePosition    = transformation * spacePosition;
                var shapeCoordinates = DiscreteCoordinates.Floor(shapePosition);

                for (int partIndex = 0; partIndex < 8; partIndex++)
                {
                    var partCoordinates       = shapeCoordinates.Move(partIndex % 2, (partIndex >> 1) % 2, (partIndex >> 2) % 2);
                    var warpedPartCoordinates = shape.Bounds.Warp(partCoordinates);

                    ref var cell     = ref shape.Voxels[shape.Bounds.Index(warpedPartCoordinates)];
                    var     distance = Vector.Between(warpedPartCoordinates.AsVertex(), cell.NearestIntersection).Length;
                    var     normal   = Vector.Between(
                        spacePosition,
                        inversedTransformation * (shapePosition + cell.Normal)
                        ).Normalize() * (revert ? -1 : 1);

                    var weight = DeviceFunction.Max(0f, 1f - distance / maxDistance);
                    var factor =
                        (1 - DeviceFunction.Abs(partCoordinates.X - shapePosition.X)) *
                        (1 - DeviceFunction.Abs(partCoordinates.Y - shapePosition.Y)) *
                        (1 - DeviceFunction.Abs(partCoordinates.Z - shapePosition.Z));

                    voxel.Weight += weight * factor;
                    voxel.Normal += normal * factor * weight;
                }

                space.Voxels.Set(voxelIndex, voxel);
            }
Example #10
0
        public bool PlaceTrap(string token, string trap, int xpos, int ypos, out bool placed)
        {
            bool ret = false;

            placed = false;
            if (!PlayersCharacters.ContainsKey(token))
            {
                ret = false;
            }
            else
            {
                int                 id     = PlayersCharacters[token];
                Modificator         modif  = Enum.Parse <Modificator>(trap);
                DiscreteCoordinates coords = new DiscreteCoordinates(xpos, ypos);
                ret = playField.PlaceTrap(id, modif, coords, out placed);
                if (modif == Modificator.Pitfall)
                {
                    ret = false;
                }
            }
            return(ret);
        }
Example #11
0
 public Cell(DiscreteCoordinates coords, Field f, CellType ct = CellType.Void)
 {
     cellType    = ct;
     coordinates = coords;
     this.f      = f;
 }
Example #12
0
 public void Move(DiscreteCoordinates coords)
 {
     this.Coordinates += coords;
 }