示例#1
0
文件: Sokoban.cs 项目: MartyIX/SoTh
 /// <summary>
 /// Constructor
 /// </summary>
 public Sokoban(View.GameDeskView form, Player player, int objectID, string description,
                   int pozX, int pozY, MovementDirection direction, EventType InitialEvent, int speed)
     : base(form, player, objectID, description, pozX, pozY, direction, InitialEvent, speed)
 {
     isDeathAnimationStarted = false;
     sokobanState = SokobanState.alive;
     stepsNo = 0;
 }
示例#2
0
        static void Main(string[] args)
        {
            int[,] availableMatrix =
            {
                {4,0,0,0},
                {1,2,0,1},
                {0,0,0,8},
                {0,2,4,1}
            };
            SokobanState initState = new SokobanState(availableMatrix);
            HashSet<SokobanState> stateSet = new HashSet<SokobanState>();
            Queue<SokobanState> stateQueue = new Queue<SokobanState>();
            stateSet.Add(initState);
            stateQueue.Enqueue(initState);

            while (stateQueue.Count > 0)
            {
                SokobanState currentState = stateQueue.Dequeue();

                if (currentState.IsSolved())
                {
                    System.Console.WriteLine("GOAL!");
                    break;
                }

                HashSet<SokobanState> expandStateSet = currentState.moveAll();
                foreach (SokobanState expandState in expandStateSet)
                {
                    if (stateSet.Add(expandState))
                    {
                        stateQueue.Enqueue(expandState);
                    }
                }
            }
            System.Console.ReadKey();
        }
示例#3
0
文件: Sokoban.cs 项目: MartyIX/SoTh
 public void ShowDeath()
 {
     sokobanState = SokobanState.dead;
 }
示例#4
0
文件: Sokoban.cs 项目: MartyIX/SoTh
        /// <summary>
        /// XNA drawing
        /// </summary>
        public override void Draw()
        {
            if (isDeathAnimationStarted == true)
                {
                    currentFrame++;
                }
                else
                {
                    if (sokobanState == SokobanState.alive)
                    {
                        currentFrame = 1;
                    }
                    else
                    {
                        currentFrame = 30;
                    }
                }

                // stop animation
                if (currentFrame > numberOfFrames)
                {
                    isDeathAnimationStarted = false;
                    sokobanState = SokobanState.dead;
                }

                SpriteElement frame = deathSpriteSheet.Sprites["dead_" + currentFrame.ToString().PadLeft(4, '0')];

                // looping frames
                //deathAnimationCurrentFrame = (deathAnimationCurrentFrame + 1 > deathAnimationFrames) ? 1 : deathAnimationCurrentFrame + 1;

                if (this.direction == MovementDirection.goLeft)
                {
                    spriteEffect = SpriteEffects.FlipHorizontally;
                }
                else
                {
                    spriteEffect = SpriteEffects.None;
                }

                if (movementInProgress == false)
                {

                    spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
                    spriteBatch.Draw(deathSpriteSheet.Texture,
                                     new Rectangle(1 + (this.posX - 1) * form.squareSize + Convert.ToInt32((form.squareSize - texture.Width) / 2),
                                                   1 + (this.posY - 1) * form.squareSize + Convert.ToInt32((form.squareSize - texture.Height) / 2),
                                                   frame.Rect.Width, frame.Rect.Height),
                                     frame.Rect, Color.White, 0f, new Vector2(0f, 0f), spriteEffect, 0f);
                    spriteBatch.End();
                }
                else
                {
                    if (movementCurrentFrame == 0)
                    {
                        movementCurrentFrame = 3;
                    }
                    else if (movementCurrentFrame == 3)
                    {
                        movementCurrentFrame = 5;
                    }
                    else if (movementCurrentFrame == 5)
                    {
                        movementCurrentFrame = 11;
                    }
                    else if (movementCurrentFrame == 11)
                    {
                        movementCurrentFrame = 3;
                    }

                    SpriteElement mov_frame = movementSpriteSheet.Sprites["sokobanMovement_" + (movementCurrentFrame % 6).ToString()];

                    double ratio = ((double)(this.model.time - movementStartTime) / (double)movementNoSteps);

                    if (ratio >= 1)
                    {
                        ratio = 1f;
                        movementInProgress = false;
                    }

                    int addDistance = Convert.ToInt32(Math.Round(form.squareSize * ratio));

                    spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
                    spriteBatch.Draw(movementSpriteSheet.Texture,
                                     new Rectangle(1 + (this.lastPosX - 1) * form.squareSize + Convert.ToInt32((form.squareSize - texture.Width) / 2) + (posX - lastPosX) * addDistance,
                                                   1 + (this.lastPosY - 1) * form.squareSize + Convert.ToInt32((form.squareSize - texture.Height) / 2) + (posY - lastPosY) * addDistance,
                                                   mov_frame.Rect.Width, mov_frame.Rect.Height),
                                     mov_frame.Rect, Color.White, 0f, new Vector2(0f, 0f), spriteEffect, 0f);

                    spriteBatch.End();
                }
        }