Пример #1
0
        private WhatsUp MovePlayer(Point dir, bool undoMove)
        {
            CellsChanged.Clear();
            WhatsUp result = WhatsUp.Nothing;
            Action  act    = new Action();

            CellsChanged.Add(new Point(playerHx, playerVy));
            if (CanPlayerMove(dir))
            {
                playerHx += dir.X;
                playerVy += dir.Y;
                CellsChanged.Add(new Point(playerHx, playerVy));
                act.PlayerMove = dir;

                steps++;
                result = WhatsUp.Step;
            }
            else
            {
                if (CanPushObject(dir))
                {
                    result = MoveObjectRelative(dir);

                    CellsChanged.Add(new Point(playerHx, playerVy));
                    playerHx += dir.X;
                    playerVy += dir.Y;
                    CellsChanged.Add(new Point(playerHx, playerVy));
                    act.PlayerMove       = dir;
                    act.IsBarrelMovedToo = true;

                    steps++;
                }
            }

            if (!undoMove && !act.IsEmpty)
            {
                history.Push(act);
            }

            if (dir.X != 0)
            {
                playerDir.X = dir.X;
            }

            if (dir.Y != 0)
            {
                playerDir.Y = dir.Y;
            }

            if (inPlace == Map.Plates ||
                inPlace == Map.Barrels)
            {
                result = WhatsUp.Win;
                G.I.Win();
            }

            return(result);
        }
Пример #2
0
        private WhatsUp MoveObjectAbsolute(Point from, Point to)
        {
            WhatsUp result = WhatsUp.Move;

            movements++;

            int fromHx = from.X;
            int fromVy = from.Y;

            Cell cfrom = cells[fromHx, fromVy];

            if (cfrom != Cell.BarrelOnPlate)
            {
                cells[fromHx, fromVy] = Cell.Empty;
            }
            else
            {
                cfrom = Cell.Barrel;
                cells[fromHx, fromVy] = Cell.Plate;
                inPlace--;
            }

            int toHx = to.X;
            int toVy = to.Y;

            if (cells[toHx, toVy] != Cell.Plate)
            {
                cells[toHx, toVy] = cfrom;
            }
            else
            {
                cells[toHx, toVy] = Cell.BarrelOnPlate;
                inPlace++;
                result = WhatsUp.InPlace;
            }

            CellsChanged.Add(new Point(fromHx, fromVy));
            CellsChanged.Add(new Point(toHx, toVy));

            return(result);
        }
Пример #3
0
        private void Do_Keys(KeyEventArgs e)
        {
            Point dir = Point.Empty;

            switch (e.KeyCode)
            {
            case Keys.Escape:
                if (!G.I.IsSplashLevel)
                {
                    Show_SelectLevelForm();
                }
                break;

            case Keys.Up:
            case Keys.W:
                dir.Y = -1;
                break;

            case Keys.Down:
            case Keys.S:
                dir.Y = 1;
                break;

            case Keys.Left:
            case Keys.A:
                dir.X = -1;
                break;

            case Keys.Right:
            case Keys.D:
                dir.X = 1;
                break;

            case Keys.Oemplus:
                if (e.Control)
                {
                    cellSizePx++;
                    Update_GameField();
                }
                break;

            case Keys.OemMinus:
                if (e.Control && cellSizePx > 10)
                {
                    cellSizePx--;
                    Update_GameField();
                }
                break;

            case Keys.Add:
                cellSizePx++;
                Update_GameField();
                break;

            case Keys.Subtract:
                if (cellSizePx > 10)
                {
                    cellSizePx--;
                    Update_GameField();
                }
                break;

            case Keys.Back:
                G.I.Logic.Undo();
                G.I.View.Update();
                Invalidate();
                break;

            case Keys.F5:
                RestartLevel(G.I.Logic.Map);
                break;
            } // switch (e.KeyCode)

            if (dir.X != 0 || dir.Y != 0)
            {
                WhatsUp whatsup = G.I.Logic.MovePlayer(dir);

                G.I.View.Update();
                Invalidate();

                switch (whatsup)
                {
                case WhatsUp.Win:
                    if (G.I.IsSplashLevel)
                    {
                        Show_SelectLevelForm();
                    }
                    else
                    {
                        Show_LevelDone();
                    }
                    break;

                case WhatsUp.Nothing:
                    if (G.I.Logic.PlayerHx > 38)
                    {
                        Close();
                    }
                    break;
                } // switch(whatsup)
            }     // if (dir.X != 0 || dir.Y != 0)
        }         // Do_Keys()