Ejemplo n.º 1
0
        private void DoAction(Actions action)
        {
            switch (action)
            {
            case Actions.Down:
                model.Action(Model.Directions.Down);
                break;

            case Actions.Up:
                model.Action(Model.Directions.Up);
                break;

            case Actions.Left:
                model.Action(Model.Directions.Left);
                break;

            case Actions.Right:
                model.Action(Model.Directions.Right);
                break;

            case Actions.Exit:
                this.isNotExitCommandRecived = false;
                break;

            case Actions.Restart:
                RestartGame();
                break;
            }
        }
Ejemplo n.º 2
0
        public void KeyPressed(Actions action)
        {
            if (this.GameState == GameStates.Running || this.GameState == GameStates.Continued)
            {
                switch (action)
                {
                case Actions.Down:
                    this.model.Action(Model.Directions.Down);
                    break;

                case Actions.Up:
                    this.model.Action(Model.Directions.Up);
                    break;

                case Actions.Left:
                    model.Action(Model.Directions.Left);
                    break;

                case Actions.Right:
                    this.model.Action(Model.Directions.Right);
                    break;
                }
                UpdateValues();
                IsFail();
                if (this.GameState == GameStates.Running)
                {
                    IsWin();
                }
            }
        }
Ejemplo n.º 3
0
        public void ActionTest_Right_WithMerges_ScoresUpdated()
        {
            Model model = new Model(3);

            int[,] fieldData = { { 2, 4, 0 }, { 2, 4, 0 }, { 0, 0, 0 } };
            model.ForTestsOnly_Field.ForTestsOnly_FieldArray = fieldData;
            model.Action(Model.Directions.Right);
            Assert.AreEqual(12, model.Score);
        }
Ejemplo n.º 4
0
        public void ActionTest_Right_WithoutMoves()
        {
            Model model = new Model(3);

            int[,] fieldData = { { 0, 0, 64 }, { 0, 4, 2 }, { 2, 8, 4 } };
            model.ForTestsOnly_Field.ForTestsOnly_FieldArray = fieldData;
            model.Action(Model.Directions.Right);
            Assert.IsTrue(IsFieldArraysEqual(fieldData, model.ForTestsOnly_Field.ForTestsOnly_FieldArray));
        }
Ejemplo n.º 5
0
        public void ActionTest_Right_NewTileNotGeneratedIfTilesNotMoved()
        {
            Model model = new Model(3);

            int[,] fieldData = { { 0, 0, 0 }, { 0, 0, 0 }, { 2, 2, 0 } };
            model.ForTestsOnly_Field.ForTestsOnly_FieldArray = fieldData;
            model.Action(Model.Directions.Right);
            Assert.IsTrue(IsFieldArraysEqual(fieldData, model.ForTestsOnly_Field.ForTestsOnly_FieldArray));
        }
Ejemplo n.º 6
0
        public void ActionTest_Left_WithoutMoves()
        {
            Model model = new Model(3);

            int[,] fieldData = { { 64, 8, 4 }, { 0, 4, 8 }, { 0, 16, 0 } };
            model.ForTestsOnly_Field.ForTestsOnly_FieldArray = fieldData;
            model.Action(Model.Directions.Left);
            Assert.IsTrue(IsFieldArraysEqual(fieldData, model.ForTestsOnly_Field.ForTestsOnly_FieldArray));
        }
Ejemplo n.º 7
0
        public void ActionTest_Up_WithoutMoves()
        {
            Model model = new Model(3);

            int[,] fieldData = { { 64, 0, 0 }, { 4, 2, 0 }, { 2, 8, 4 } };
            model.ForTestsOnly_Field.ForTestsOnly_FieldArray = fieldData;
            model.Action(Model.Directions.Up);
            Assert.IsTrue(IsFieldArraysEqual(fieldData, model.ForTestsOnly_Field.ForTestsOnly_FieldArray));
        }
Ejemplo n.º 8
0
        public void ActionTest_Right_WithTwoMerges()
        {
            Model model = new Model(4);

            int[,] fieldData = { { 2, 4, 0, 0 }, { 2, 4, 0, 0 }, { 2, 8, 0, 0 }, { 2, 8, 0, 0 } };
            model.ForTestsOnly_Field.ForTestsOnly_FieldArray = fieldData;
            model.Action(Model.Directions.Right);
            model.ForTestsOnly_Field.Set(model.LastGeneratedTileCoords, 0);
            int[,] expected = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 4, 8, 0, 0 }, { 4, 16, 0, 0 } };
            Assert.IsTrue(IsFieldArraysEqual(expected, model.ForTestsOnly_Field.ForTestsOnly_FieldArray));
        }
Ejemplo n.º 9
0
        public void ActionTest_Right_NewTileGeneratedIfTilesMoved()
        {
            Model model = new Model(3);

            int[,] fieldData = { { 2, 0, 0 }, { 0, 2, 0 }, { 0, 0, 0 } };
            model.ForTestsOnly_Field.ForTestsOnly_FieldArray = fieldData;
            model.Action(Model.Directions.Right);
            int newTileValue = model.Get(model.LastGeneratedTileCoords);

            Assert.IsTrue(newTileValue == 2 || newTileValue == 4);
        }
Ejemplo n.º 10
0
        public void ActionTest_Left_WithMerges()
        {
            Model model = new Model(3);

            int[,] fieldData = { { 64, 2, 4 }, { 0, 2, 2 }, { 64, 4, 2 } };
            model.ForTestsOnly_Field.ForTestsOnly_FieldArray = fieldData;
            model.Action(Model.Directions.Left);
            model.ForTestsOnly_Field.Set(model.LastGeneratedTileCoords, 0);
            int[,] expected = { { 128, 4, 4 }, { 0, 4, 4 }, { 0, 0, 0 } };
            Assert.IsTrue(IsFieldArraysEqual(expected, model.ForTestsOnly_Field.ForTestsOnly_FieldArray));
        }
Ejemplo n.º 11
0
        public void UserAction(Actions action)
        {
            switch (action)
            {
            case Actions.Down:
                this.model.Action(Model.Directions.Down);
                break;

            case Actions.Up:
                this.model.Action(Model.Directions.Up);
                break;

            case Actions.Left:
                model.Action(Model.Directions.Left);
                break;

            case Actions.Right:
                this.model.Action(Model.Directions.Right);
                break;
            }
            UpdateValues();
            UpdateScore();
        }
Ejemplo n.º 12
0
        private View SetupItemButton(TextItem ti)
        {
            //Forms9Patch.Frame itemFrame = new Forms9Patch.Frame()
            Frame itemFrame = new Frame()
            {
                CornerRadius      = 10,
                BackgroundColor   = _style.BackgroundColor,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HasShadow         = true,
            };

            Label itemLabel = null;

            if (_style.Height > 0)
            {
                itemFrame.HeightRequest = _style.Height;
                itemLabel = new AutoFontSizeLabel();
            }
            else if (_style.FontSize > 0)
            {
                itemLabel = new Label()
                {
                    FontSize = _style.FontSize
                };
            }
            else
            {
                itemLabel = new Label()
                {
                    FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label))
                };
            }

            itemLabel.Text = ti.Text;
            //FontAttributes = FontAttributes.Bold,
            //FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
            //FontSize = fontSize < 0 ? Configuration.Theme.MediumFontSize : fontSize,
            itemLabel.TextColor               = _style.TextColor;
            itemLabel.VerticalTextAlignment   = TextAlignment.Center;
            itemLabel.HorizontalTextAlignment = TextAlignment.Center;
            itemLabel.HorizontalOptions       = LayoutOptions.FillAndExpand;
            itemLabel.VerticalOptions         = LayoutOptions.FillAndExpand;

            itemFrame.Content = itemLabel;

            //var effect = Effect.Resolve("PositiveThinking.ViewShadowEffect");

            //itemFrame.Effects.Add(new ShadowEffect
            //{
            //    Radius = 2,
            //    Color = Color.Red,
            //    DistanceX = 2,
            //    DistanceY = 2
            //});

            buttons.Add(ti.Text, itemFrame);
            labels.Add(ti.Text, itemLabel);

            if (_model.Action != null)
            {
                itemFrame.AddTapRecognizer((s, e) => { ToggleItem(ti); _model.Action(ti); });
            }

            if (_model.MultiSelect)
            {
                itemFrame.AddTapRecognizer((s, e) => { ToggleItem(ti); });
            }

            return(itemFrame);
        }
Ejemplo n.º 13
0
 private void ExecuteAction()
 {
     _model.Action();
 }