예제 #1
0
        private void btUndo_Click(object sender, EventArgs e)
        {
            this.player.Undo();
            if (this.lastBoxMoved != null)
            {
                Point lastBoxPosition = ((Models.Box) this.lastBoxMoved).Position;
                ((Models.Box) this.lastBoxMoved).Undo();
                Point currentBoxPosition = ((Models.Box) this.lastBoxMoved).Position;

                this.currentLevel_Rigid[currentBoxPosition.X, currentBoxPosition.Y] = this.currentLevel_Rigid[lastBoxPosition.X, lastBoxPosition.Y];
                this.currentLevel_Rigid[lastBoxPosition.X, lastBoxPosition.Y]       = new Models.BlockBase();

                this.pushes++;
                this.lastBoxMoved = null;
            }
            this.UpdateStatus();
        }
예제 #2
0
        private void LoadLevel(string[] _lineBlocks)
        {
            this.slotPositionList.Clear();
            this.boxList.Clear();
            this.panelGame.Controls.Clear();
            Models.BlockBase newBlock;
            List <Control>   slotBlocks = new List <Control>();

            char[] blocks;

            if (_lineBlocks == null)//load new level
            {
                _lineBlocks = File.ReadAllLines(System.Environment.CurrentDirectory + "\\Levels\\Level" + this.currentLevel.ToString("000") + ".txt");
                this.pushes = 0;
                this.player.ResetMovesCount();
                this.currentLevel_Rigid        = new Models.BlockBase[25, 17];
                this.lbStatusCurrentLevel.Text = this.currentLevel.ToString("00");
            }

            for (int y = 0; y < _lineBlocks.Length; y++)
            {
                blocks = _lineBlocks[y].ToCharArray();
                for (int x = 0; x < blocks.Length; x++)
                {
                    newBlock = null;
                    switch (blocks[x])
                    {
                    case '#':
                        newBlock = new Models.Wall(new Point(30 * x, 30 * y));
                        this.panelGame.Controls.Add(newBlock.Picture);
                        break;

                    case 'S':
                        newBlock = new Models.Slot(new Point(30 * x, 30 * y));
                        this.panelGame.Controls.Add(newBlock.Picture);
                        slotBlocks.Add(this.panelGame.Controls[this.panelGame.Controls.Count - 1]);
                        this.slotPositionList.Add(newBlock.Picture.Location);
                        break;

                    case 'B':
                        newBlock = new Models.Box(new Point(30 * x, 30 * y));
                        this.panelGame.Controls.Add(newBlock.Picture);
                        this.boxList.Add(newBlock);
                        break;

                    case 'X':    //box and slot
                        newBlock = new Models.Slot(new Point(30 * x, 30 * y));
                        this.panelGame.Controls.Add(newBlock.Picture);
                        slotBlocks.Add(this.panelGame.Controls[this.panelGame.Controls.Count - 1]);
                        this.slotPositionList.Add(newBlock.Picture.Location);
                        this.currentLevel_Rigid[x, y] = newBlock;

                        newBlock = new Models.Box(new Point(30 * x, 30 * y));
                        this.panelGame.Controls.Add(newBlock.Picture);
                        this.boxList.Add(newBlock);
                        break;

                    case 'Y':    //player and slot
                        newBlock = new Models.Slot(new Point(30 * x, 30 * y));
                        this.panelGame.Controls.Add(newBlock.Picture);
                        slotBlocks.Add(this.panelGame.Controls[this.panelGame.Controls.Count - 1]);
                        this.slotPositionList.Add(newBlock.Picture.Location);
                        this.currentLevel_Rigid[x, y] = newBlock;

                        newBlock = new Models.BlockBase();
                        this.player.SetStartPosition(new Point(30 * x, 30 * y));
                        this.panelGame.Controls.Add(this.player.Picture);
                        this.panelGame.Controls[this.panelGame.Controls.Count - 1].BringToFront();
                        break;

                    case 'P':
                        newBlock = new Models.BlockBase();
                        this.player.SetStartPosition(new Point(30 * x, 30 * y));
                        this.panelGame.Controls.Add(this.player.Picture);
                        this.panelGame.Controls[this.panelGame.Controls.Count - 1].BringToFront();
                        break;

                    default:
                        newBlock = new Models.BlockBase();
                        break;
                    }

                    this.currentLevel_Rigid[x, y] = newBlock;
                }
            }

            foreach (var slot in slotBlocks)
            {//just to send all 'slot' blocks to the back of the panel
                slot.SendToBack();
            }

            slotBlocks = null;
            newBlock   = null;
            blocks     = null;

            GC.Collect();
        }
예제 #3
0
        private void FormGame2_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Right:
                if (!this.currentLevel_Rigid[this.player.Position.X + 1, this.player.Position.Y].RigidBody)
                {
                    this.player.MoveRight();
                    this.lastBoxMoved = null;
                }
                else
                {    //rigid
                    if (this.currentLevel_Rigid[this.player.Position.X + 1, this.player.Position.Y].Picture.Tag.Equals("B") &&
                        !this.currentLevel_Rigid[this.player.Position.X + 2, this.player.Position.Y].RigidBody)
                    {
                        this.currentLevel_Rigid[this.player.Position.X + 1, this.player.Position.Y].MoveRight();
                        this.lastBoxMoved = this.currentLevel_Rigid[this.player.Position.X + 1, this.player.Position.Y];
                        this.currentLevel_Rigid[this.player.Position.X + 2, this.player.Position.Y] = this.currentLevel_Rigid[this.player.Position.X + 1, this.player.Position.Y];
                        this.currentLevel_Rigid[this.player.Position.X + 1, this.player.Position.Y] = new Models.BlockBase();
                        this.player.MoveRight();
                        this.pushes++;
                        this.CheckSlots();
                    }
                }
                break;

            case Keys.Left:
                if (!this.currentLevel_Rigid[this.player.Position.X - 1, this.player.Position.Y].RigidBody)
                {
                    this.player.MoveLeft();
                    this.lastBoxMoved = null;
                }
                else
                {    //rigid
                    if (this.currentLevel_Rigid[this.player.Position.X - 1, this.player.Position.Y].Picture.Tag.Equals("B") &&
                        !this.currentLevel_Rigid[this.player.Position.X - 2, this.player.Position.Y].RigidBody)
                    {
                        this.currentLevel_Rigid[this.player.Position.X - 1, this.player.Position.Y].MoveLeft();
                        this.lastBoxMoved = this.currentLevel_Rigid[this.player.Position.X - 1, this.player.Position.Y];
                        this.currentLevel_Rigid[this.player.Position.X - 2, this.player.Position.Y] = this.currentLevel_Rigid[this.player.Position.X - 1, this.player.Position.Y];
                        this.currentLevel_Rigid[this.player.Position.X - 1, this.player.Position.Y] = new Models.BlockBase();
                        this.player.MoveLeft();
                        this.pushes++;
                        this.CheckSlots();
                    }
                }
                break;

            case Keys.Up:
                if (!this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y - 1].RigidBody)
                {
                    this.player.MoveUP();
                    this.lastBoxMoved = null;
                }
                else
                {    //rigid
                    if (this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y - 1].Picture.Tag.Equals("B") &&
                        !this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y - 2].RigidBody)
                    {
                        this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y - 1].MoveUP();
                        this.lastBoxMoved = this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y - 1];
                        this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y - 2] = this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y - 1];
                        this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y - 1] = new Models.BlockBase();
                        this.player.MoveUP();
                        this.pushes++;
                        this.CheckSlots();
                    }
                }
                break;

            case Keys.Down:
                if (!this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y + 1].RigidBody)
                {
                    this.player.MoveDown();
                    this.lastBoxMoved = null;
                }
                else
                {    //rigid
                    if (this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y + 1].Picture.Tag.Equals("B") &&
                        !this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y + 2].RigidBody)
                    {
                        this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y + 1].MoveDown();
                        this.lastBoxMoved = this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y + 1];
                        this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y + 2] = this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y + 1];
                        this.currentLevel_Rigid[this.player.Position.X, this.player.Position.Y + 1] = new Models.BlockBase();
                        this.player.MoveDown();
                        this.pushes++;
                        this.CheckSlots();
                    }
                }
                break;

            default:
                break;
            }
            this.UpdateStatus();
        }