예제 #1
0
        /// <summary>
        /// Move up
        /// </summary>
        private void MoveUp(Actor actor)
        {
            int sokoPosX = actor.PosX;
            int sokoPosY = actor.PosY;

            // If soko can move to the next position
            if (levelMap[sokoPosX, sokoPosY - 1] == ItemType.Floor ||
                IsThereTarget(sokoPosX, sokoPosY - 1))
            {
                if (IsThereTarget(sokoPosX, sokoPosY - 1))
                {
                    item2 = new Item(ItemType.SokobanOnGoal, sokoPosX, sokoPosY - 1);
                }
                else if (levelMap[sokoPosX, sokoPosY - 1] == ItemType.Floor)
                {
                    item2 = new Item(ItemType.Sokoban, sokoPosX, sokoPosY - 1);
                }

                UpdateCurrentSokobanPosition(sokoPosX, sokoPosY);
                UpdateCurrentPackagePosition(sokoPosX, sokoPosY - 2, Actor.MoveDirection.Up);
                actor.Move(Actor.MoveDirection.Up);
            }
        }
예제 #2
0
        private void UpdateCurrentPackagePosition(int packagePosX, int packagePosY, Actor.MoveDirection direction)
        {
            if (IsThereTarget(packagePosX, packagePosY))
            {
                item3 = new Item(ItemType.PackageOnGoal, packagePosX, packagePosY);
            }
            else
            {
                switch (direction)
                {
                    case Actor.MoveDirection.Right:
                        if (packagePosX > target.PosX)
                        {
                            if (packagePosY < target.PosY)
                            {
                                item3 = new Item(ItemType.Package, packagePosX - 1, packagePosY + 1);
                            }
                            else
                            {
                                item3 = new Item(ItemType.Package, packagePosX - 1, packagePosY - 1);
                            }
                        }
                        else
                        {
                            item3 = new Item(ItemType.Package, packagePosX, packagePosY);
                        }
                        break;

                    case Actor.MoveDirection.Left:
                        if (packagePosX < target.PosX)
                        {
                            if (packagePosY < target.PosY)
                            {
                                item3 = new Item(ItemType.Package, packagePosX + 1, packagePosY + 1);
                            }
                            else
                            {
                                item3 = new Item(ItemType.Package, packagePosX + 1, packagePosY - 1);
                            }
                        }
                        else
                        {
                            item3 = new Item(ItemType.Package, packagePosX, packagePosY);
                        }
                        break;

                    case Actor.MoveDirection.Up:
                    case Actor.MoveDirection.Down:
                        item3 = new Item(ItemType.Package, packagePosX, packagePosY);
                        break;
                }

            }
        }
예제 #3
0
        public void SetActor(Actor actor)
        {
            lock (this)
            {
                this.actor = actor;

                item1 = new Item(ItemType.SokobanOnGoal, actor.PosX, actor.PosY);
                DrawChanges(actor.Direction);
            }
        }
예제 #4
0
        /// <summary>
        /// Move right
        /// </summary>
        private void MoveRight(Actor actor)
        {
            int sokoPosX = actor.PosX;
            int sokoPosY = actor.PosY;

            if (levelMap[sokoPosX + 1, sokoPosY] == ItemType.Floor ||
                IsThereTarget(sokoPosX + 1, sokoPosY))
            {
                if (IsThereTarget(sokoPosX + 1, sokoPosY))
                {
                    item2 = new Item(ItemType.SokobanOnGoal, sokoPosX + 1, sokoPosY);
                }
                else if (levelMap[sokoPosX + 1, sokoPosY] == ItemType.Floor)
                {
                    item2 = new Item(ItemType.Sokoban, sokoPosX + 1, sokoPosY);
                }

                UpdateCurrentSokobanPosition(sokoPosX, sokoPosY);
                UpdateCurrentPackagePosition(sokoPosX + 2, sokoPosY, Actor.MoveDirection.Right);
                actor.Move(Actor.MoveDirection.Right);
            }
        }
예제 #5
0
 /// <summary>
 /// Check in what direction we want to move and call the corresponding
 /// method.
 /// </summary>
 /// <param name="direction">Direction to move in</param>
 public void MoveActor(Actor.MoveDirection direction)
 {
     switch (direction)
     {
         case Actor.MoveDirection.Up:
             MoveUp(actor);
             break;
         case Actor.MoveDirection.Down:
             MoveDown(actor);
             break;
         case Actor.MoveDirection.Right:
             MoveRight(actor);
             break;
         case Actor.MoveDirection.Left:
             MoveLeft(actor);
             break;
     }
 }
예제 #6
0
        /// <summary>
        /// Depending on the 'item character' in the XML for the level set we
        /// need to display an image on the screen. This is what happens here.
        /// We also take into account the direction Sokoban is moving in,
        /// because we want him to face to the left when he is moving left.
        /// </summary>
        /// <param name="itemType">Level item</param>
        /// <param name="direction">Sokoban direction</param>
        /// <returns>The image to be displayed on screen</returns>
        public Image GetLevelImage(ItemType itemType, Actor.MoveDirection direction)
        {
            Image image;

            if (itemType == ItemType.Wall)
                image = ImgWall;
            else if (itemType == ItemType.Floor)
                image = ImgFloor;
            else if (itemType == ItemType.Package)
                image = ImgPackage;
            else if (itemType == ItemType.Goal)
                image = ImgGoal;
            else if (itemType == ItemType.Sokoban)
            {
                if (direction == Actor.MoveDirection.Up)
                    image = ImgSokoUp;
                else if (direction == Actor.MoveDirection.Down)
                    image = ImgSokoDown;
                else if (direction == Actor.MoveDirection.Right)
                    image = ImgSokoRight;
                else
                    image = ImgSokoLeft;
            }
            else if (itemType == ItemType.PackageOnGoal)
                image = ImgPackageGoal;
            else if (itemType == ItemType.SokobanOnGoal)
            {
                if (direction == Actor.MoveDirection.Up)
                    image = ImgSokoUpGoal;
                else if (direction == Actor.MoveDirection.Down)
                    image = ImgSokoDownGoal;
                else if (direction == Actor.MoveDirection.Right)
                    image = ImgSokoRightGoal;
                else
                    image = ImgSokoLeftGoal;
            }
            else
                image = ImgSpace;

            return image;
        }
예제 #7
0
        /// <summary>
        /// When Sokoban moves or pushes we only draws these changes instead of
        /// redrawing the whole level again. Great performance improvement.
        /// </summary>
        /// <returns>The 'level' image that will be drawn to screen</returns>
        public void DrawChanges(Actor.MoveDirection direction)
        {
            if (item1 != null)
            {
                Image image1 = GetLevelImage(item1.ItemType, direction);
                g.DrawImage(image1, item1.XPos * ITEM_SIZE,
                    item1.YPos * ITEM_SIZE, ITEM_SIZE, ITEM_SIZE);
            }

            if (item2 != null)
            {
                Image image2 = GetLevelImage(item2.ItemType, direction);
                g.DrawImage(image2, item2.XPos * ITEM_SIZE,
                    item2.YPos * ITEM_SIZE, ITEM_SIZE, ITEM_SIZE);
            }

            if (item3 != null)
            {
                Image image3 = GetLevelImage(item3.ItemType, direction);
                g.DrawImage(image3, item3.XPos * ITEM_SIZE,
                    item3.YPos * ITEM_SIZE, ITEM_SIZE, ITEM_SIZE);
            }
        }
 public static void Serialize(HlaEncodingWriter writer, Actor.MoveDirection val)
 {
     writer.WriteHLAinteger32BE((int)val);
 }
예제 #9
0
 public void UpdateUI(Actor.MoveDirection direction)
 {
     // InvokeRequired required compares the thread ID of the
     // calling thread to the thread ID of the creating thread.
     // If these threads are different, it returns true.
     if (this.screen.InvokeRequired)
     {
         this.direction = direction;
         DrawChangesDelegate d = new DrawChangesDelegate(_UpdateUI);
         Invoke(d);
     }
     else
     {
         _UpdateUI();
     }
 }