Пример #1
0
        public GameModel DeepCopy()
        {
            //model.Init(Model.ScoresGained);
            var dataCopy = new MyCell[YSize][];//copy of game field for AI mod

            for (int i = 0; i < YSize; i++)
            {
                dataCopy[i] = new MyCell[XSize];
                for (int j = 0; j < XSize; j++)
                {
                    dataCopy[i][j] = new MyCell(Data[i][j].TypeOfCell);
                }
            }
            var entitiesCopy = new Dictionary <Vector, MovingEntity>();

            foreach (var entity in MovingEntities)
            {
                entitiesCopy.Add(entity.Key, entity.Value.ShallowCopy());
            }
            var modelCopy = new GameModel(Level)
            {
                Data = dataCopy, ScoresNeed = ScoresNeed, MovingEntities = entitiesCopy
            };

            modelCopy.Init(ScoresGained);
            return(modelCopy);
        }
Пример #2
0
        /// <summary>
        /// Этот метод для изменения размера поля
        /// </summary>
        /// <param name="cellTemplate"></param>
        public void Fill(MyCell cellTemplate)
        {
            if (cellTemplate.TypeOfCell == CellType.Murphy)
            {
                Height = _rows;
                Width  = _cells;
                return;
            }
            int cellSet = Width;
            int rowsSet = Height;

            if (_cells < cellSet)
            {
                for (int i = 0; i < _rows; i++)
                {
                    for (int j = Data[i].Count - 1; j >= _cells; j--)
                    {
                        Data[i].Remove(Data[i][j]);
                    }
                }
                return;
            }

            if (_rows < rowsSet)
            {
                for (int i = rowsSet - 1; i >= _rows; i--)
                {
                    Data.Remove(Data[i]);
                }
                return;
            }

            if (_rows > rowsSet)
            {
                for (int i = 0; i < _rows - rowsSet; i++)
                {
                    Data.Add(new ObservableCollection <MyCell>());
                    for (int j = 0; j < cellSet; j++)
                    {
                        Data[Height - 1].Add(new MyCell(cellTemplate.TypeOfCell));
                    }
                }
                return;
            }

            if (_cells > cellSet)
            {
                for (int i = 0; i < rowsSet; i++)
                {
                    for (int j = 0; j < _cells - cellSet; j++)
                    {
                        Data[i].Add(new MyCell(cellTemplate.TypeOfCell));
                    }
                }
            }
            CookiesCount();
        }
Пример #3
0
 public ConstructViewModel()
 {
     //ButtonsOpacity = new ObservableCollection<MyDouble>();
     //for (int i = 0; i < 6; i++)
     //    ButtonsOpacity.Add(new MyDouble(0.6));//начальные значения прозрачности кнопок
     //ButtonsOpacity[0].Value = 9.5;//выбрана по умочанию
     //WinSizedCommand = new Command(WinSized);
     //ResizeWinChgCommand = new Command(WinResMode);
     ChangeTypeCommand  = new Command(ChangeTemplate);
     MouseCommand       = new Command(OnMouseEvent);
     SerializeCommand   = new Command(Serialize);
     DeserializeCommand = new Command(Deserialize);
     PlayCommand        = new Command(StrWin);
     CellTemplate       = new MyCell(CellType.None);
     AvilableLvl        = new List <string>();
     LvlGet();
     Model = new ConstructModel(Level);
 }
Пример #4
0
 public override void Moved()
 {
     if (!MovedCommon())
     {
         return;
     }
     if (Pushing)
     {
         Pushing = false;
     }
     if (rollCell != null)
     {
         rollCell.ToBeFilled = false;
         rollCell            = null;
     }
     AddUpperEntities();
     Loc = NextLoc;
     Loc.Get(Model.Data).TypeOfCell = OperatedCell;
 }
Пример #5
0
 public ConstructViewModel()
 {
     _upField           = new GridLength(30);
     _leftField         = new GridLength(30);
     DragCommand        = new Command(DragField);
     ChangeTypeCommand  = new Command(ChangeTemplate);
     MouseCommand       = new Command(OnMouseEvent);
     SerializeCommand   = new Command(Serialize);
     DeserializeCommand = new Command(Deserialize);
     PlayCommand        = new Command(StrWin);
     CellTemplate       = new MyCell(CellType.None);
     AvilableLvl        = MainMenuParameters.Levels;
     ScoresRequired     = "0";
     Model = new EditorModel(Level);
     Level = MainMenuParameters.DefaultLevel ?? AvilableLvl[MainMenuParameters.LevelNumb];
     Deserialize(null);
     _fieldHeight = new GridLength(Model.YSize * 30);
     _fieldWidth  = new GridLength(Model.XSize * 30);
 }
Пример #6
0
 public abstract string Moving(Vector direct, out MyCell cell, MoveType typeOfMoving);
Пример #7
0
 private bool IsCellAccessible(MyCell cell)
 {
     return(cell != null && (cell.TypeOfCell == CellType.None || cell.TypeOfCell == CellType.Murphy) &&
            !cell.ToBeFilled);
 }
Пример #8
0
 public override string Moving(Vector direct, out MyCell cell, MoveType typeOfMoving)
 {
     cell = null;
     return("");
 }
Пример #9
0
 private bool CheckRolling(MyCell targCell, MyCell passCell)
 {
     return(targCell != null && !targCell.ToBeFilled && !passCell.ToBeFilled &&
            targCell.TypeOfCell.Equals(CellType.None) &&
            passCell.TypeOfCell == CellType.None);
 }
Пример #10
0
        public override string Moving(Vector direct, out MyCell cell, MoveType typeOfMoving)
        {
            Vector newLoc = Loc + direct;

            cell = newLoc.Get(Model.Data);

            if (cell != null)
            {
                switch (cell.TypeOfCell)
                {
                case CellType.Cookie:
                case CellType.Ball:
                    if (typeOfMoving != MoveType.Rolling)
                    {
                        break;
                    }
                    MovingEntity downBallEntity;
                    if (Model.MovingEntities.TryGetValue(newLoc, out downBallEntity) && !downBallEntity.Loc.Equals(downBallEntity.NextLoc))
                    {
                        break;
                    }
                    Vector nl = newLoc + Vector.Left;
                    cell = nl.Get(Model.Data);
                    var passCell = (Loc + Vector.Left).Get(Model.Data);
                    if (CheckRolling(cell, passCell))
                    {
                        NextLoc             = nl;
                        cell.ToBeFilled     = true;
                        passCell.ToBeFilled = true;
                        rollCell            = passCell;
                        return("DL");
                    }
                    nl       = newLoc + Vector.Right;
                    passCell = (Loc + Vector.Right).Get(Model.Data);
                    cell     = nl.Get(Model.Data);
                    if (CheckRolling(cell, passCell))
                    {
                        NextLoc             = nl;
                        cell.ToBeFilled     = true;
                        passCell.ToBeFilled = true;
                        rollCell            = passCell;
                        return("DR");
                    }
                    break;

                case CellType.Murphy:
                    if (IsFalling)
                    {
                        Model.GameFinishing(false);
                    }
                    break;

                case CellType.Scissors:
                    Model.MovingEntities[newLoc].Explode(true);
                    break;

                case CellType.None:
                    NextLoc         = newLoc;
                    cell.ToBeFilled = true;
                    return("D");
                }
            }
            NextLoc = Loc;
            return("");
        }
Пример #11
0
        public override string Moving(Vector direct, out MyCell cell, MoveType typeOfMoving)
        {
            Vector newLoc = Loc + direct;

            cell = newLoc.Get(Model.Data);
            MovingEntity targetEnt;
            var          isTargetFalling = Model.MovingEntities.TryGetValue(newLoc, out targetEnt) && targetEnt.IsFalling;

            if (cell != null && !cell.ToBeFilled && !isTargetFalling)
            {
                if (cell.TypeOfCell == CellType.Cookie) //пcounting cookies
                {
                    Model.ScoresGained++;
                }
                switch (cell.TypeOfCell)
                {
                case CellType.Exit:
                    if (Model.AllScoresCollected)
                    {
                        Model.GameFinishing(true);
                    }
                    break;

                case CellType.Ball:
                case CellType.Cookie:
                case CellType.None:
                case CellType.Grass:
                    NextLoc = newLoc;
                    var isBall = cell.TypeOfCell == CellType.Ball;
                    if (direct.Equals(Vector.Left))
                    {
                        if (isBall)
                        {
                            //if not than create such a ball
                            if (Model.PushedBall == null || !Model.PushedBall.Loc.Equals(newLoc))
                            {
                                Model.PushedBall = new Ball(Model, newLoc);
                            }
                            //if can not be mooved yet
                            if (!Model.PushedBall.CheckPushing(Vector.Left))
                            {
                                break;
                            }
                        }
                        Loc.Get(Model.Data).TypeOfMurphy = DirectionType.Left;
                        Model.GridScrollingHorisontal    = -1;  //field rolling direction set
                        return("L");
                    }
                    if (direct.Equals(Vector.Right))
                    {
                        if (isBall)
                        {
                            //if no pushed ball than create
                            if (Model.PushedBall == null || !Model.PushedBall.Loc.Equals(newLoc))
                            {
                                Model.PushedBall = new Ball(Model, newLoc);
                            }
                            //if can not moove the ball
                            if (!Model.PushedBall.CheckPushing(Vector.Right))
                            {
                                break;
                            }
                        }
                        Loc.Get(Model.Data).TypeOfMurphy = DirectionType.Right;
                        Model.GridScrollingHorisontal    = 1;
                        return("R");
                    }
                    if (isBall)
                    {
                        break;
                    }
                    if (direct.Equals(Vector.Up))
                    {
                        Loc.Get(Model.Data).TypeOfMurphy = DirectionType.Up;
                        Model.GridScrollingVertical      = -1;
                        return("U");
                    }
                    if (direct.Equals(Vector.Down))
                    {
                        Loc.Get(Model.Data).TypeOfMurphy = DirectionType.Down; // change Murphy picture
                        Model.GridScrollingVertical      = 1;
                        return("D");                                           //animation property value changing
                    }
                    break;
                }
            }
            Model.Murphy.Loc.Get(Model.Data).TypeOfMurphy = DirectionType.None;
            NextLoc = Loc;
            return("");
        }