Exemplo n.º 1
0
        private void MoveItem(Guid guid, EntityMoveDirection dir)
        {
            var ef   = new EntityFactory(RegistryContext);
            var item = ef.LoadEntity(guid);

            item.Move(dir);
        }
Exemplo n.º 2
0
        /*public void InsertIntoMap(char[,] map)
         * {
         *  //Player appearance always has only one character.
         *  map[XPosition, YPosition] = Appearance[0];
         * }
         * public void InsertIntoMap(char[,] map, int xPosition, int yPosition)
         * {
         *  //Player appearance always has only one character.
         *  map[xPosition, yPosition] = Appearance[0];
         * }*/
        public void Move(EntityMoveDirection moveDirection)
        {
            int previousX = XPosition;
            int previousY = YPosition;

            switch (moveDirection)
            {
            case EntityMoveDirection.Up:
                YPosition++;
                Appearance = "^";
                break;

            case EntityMoveDirection.Down:
                YPosition--;
                Appearance = "v";
                break;

            case EntityMoveDirection.Left:
                XPosition--;
                Appearance = "<";
                break;

            case EntityMoveDirection.Right:
                XPosition++;
                Appearance = ">";
                break;

            default:
                throw new ArgumentException("Unexpected movement direction.");
            }
            OnEntityPositionChanged(previousX, previousY);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Moves the entity up among its siblings.
        /// </summary>
        /// <remarks>
        /// Moves the entity up among its siblings by decreasing its <see cref="Number" /> property.
        /// All siblings are reorganized to keep the values of <b>Numbers</b> contigous.
        /// </remarks>
        public void Move(EntityMoveDirection direction)
        {
            string sql;

            if (direction == EntityMoveDirection.Up)
            {
                sql = "spMoveUpEntity";
            }
            else
            {
                sql = "spMoveDownEntity";
            }

            CheckConcurrency();

            using (SqlCommand cmd = Context.CreateStoredProcedureCommand(sql))
            {
                AppendBasicParameters(cmd);
                cmd.Parameters.Add("RETVAL", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;

                cmd.ExecuteNonQuery();

                var retval = (int)cmd.Parameters["RETVAL"].Value;

                if (retval >= 0)
                {
                    this.number = retval;
                }
            }

            Context.LogEvent(new Jhu.Graywulf.Logging.Event("Jhu.Graywulf.Registry.Entity.Move", this.guid));
        }
Exemplo n.º 4
0
        private PointInt GetOffset(EntityMoveDirection direction)
        {
            switch (direction)
            {
            case EntityMoveDirection.Right:
                return(new PointInt(1, 0));

            case EntityMoveDirection.Up:
                return(new PointInt(0, 1));

            case EntityMoveDirection.Left:
                return(new PointInt(-1, 0));

            case EntityMoveDirection.Down:
                return(new PointInt(0, -1));

            default:
                return(new PointInt(0, 0));
            }
        }
        /// <summary>
        /// Detects collision for objects that are of size 1x1 and move one field at a time.
        /// </summary>
        /// <returns>Whether the Entity can move or not</returns>
        /// <param name="map">Map in which the entity is contained.</param>
        /// <param name="movementDirection">Direction to which the entity is going to move to.</param>
        /// <param name="xPosition">X coordinate of the entity</param>
        /// <param name="yPosition">Y coordinate of the entity</param>
        public static bool DetectCollision1X1(Map map, EntityMoveDirection movementDirection, int xPosition, int yPosition)
        {
            foreach (MapTemplate mt in map.MapTemplates)
            {
                switch (movementDirection)
                {
                //First the collision detector checks whether the player is about to move out of the map,
                case EntityMoveDirection.Up:
                    if (yPosition + 1 == mt.MapHeight || mt.Layout[xPosition, mt.MapHeight - yPosition - 2] != ' ')
                    {
                        return(false);
                    }
                    break;

                case EntityMoveDirection.Down:
                    if (yPosition == 0 || mt.Layout[xPosition, mt.MapHeight - yPosition] != ' ')
                    {
                        return(false);
                    }
                    break;

                case EntityMoveDirection.Left:
                    if (xPosition == 0 || mt.Layout[xPosition - 1, mt.MapHeight - yPosition - 1] != ' ')
                    {
                        return(false);
                    }
                    break;

                case EntityMoveDirection.Right:
                    if (xPosition + 1 == mt.MapWidth || mt.Layout[xPosition + 1, mt.MapHeight - yPosition - 1] != ' ')
                    {
                        return(false);
                    }
                    break;
                }
            }
            return(true);
        }
Exemplo n.º 6
0
        private void MoveItem(Guid guid, EntityMoveDirection dir)
        {
            var ef = new EntityFactory(RegistryContext);
            var item = ef.LoadEntity(guid);

            item.Move(dir);
        }