Esempio n. 1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.fragment_select_game, container, false);

            root = view.FindViewById <ViewGroup>(Resource.Id.root);

            var label = view.FindViewById <TextView>(Resource.Id.text);

            label.Text = GameSet.Name;

            root.SetBackgroundColor(Android.Graphics.Color.ParseColor(GameSet.Color));

            grid = view.FindViewById <SquareGridLayout>(Resource.Id.grid);

            int gameCount = GameSet.GameCount;
            var cols      = (int)Math.Sqrt(gameCount);
            var rows      = (int)(gameCount / cols);

            if ((cols * rows) < gameCount)
            {
                rows++;
            }

            grid.ColumnCount = cols;
            grid.RowCount    = rows;
            grid.RemoveAllViews();

            for (int i = 0; i < GameSet.GameCount; i++)
            {
                int row = i / grid.ColumnCount;
                int col = i % grid.ColumnCount;

                var gameDefinition = GameSet.Games[i];
                var highScore      = GameData.Current.GetGameHighScore(gameDefinition);

                if (string.IsNullOrWhiteSpace(gameDefinition.Name))
                {
                    gameDefinition.Name = (i + 1).ToString();
                }

                var squareWidget = new SquareWidget(Context);
                squareWidget.GameDefinition = gameDefinition;
                squareWidget.Text           = gameDefinition.Name;
                //squareWidget.IsSelected = false;
                squareWidget.ShowBackground = highScore == null;

                var layoutParams = new GridLayout.LayoutParams(
                    GridLayout.InvokeSpec(row, 1f),      // Row
                    GridLayout.InvokeSpec(col, 1f));     // Col
                grid.AddView(squareWidget, layoutParams);

                squareWidget.Click += SquareView_Click;
            }

            return(view);
        }
Esempio n. 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            colorPalette = new List <Color>
            {
                new Color(ApplicationContext.GetColor(Resource.Color.yellow_300)),
                new Color(ApplicationContext.GetColor(Resource.Color.orange_700)),
                new Color(ApplicationContext.GetColor(Resource.Color.deeporange_300)),
                new Color(ApplicationContext.GetColor(Resource.Color.green_700)),
                new Color(ApplicationContext.GetColor(Resource.Color.lightgreen)),
                new Color(ApplicationContext.GetColor(Resource.Color.blue_700)),
                new Color(ApplicationContext.GetColor(Resource.Color.lightblue)),
                new Color(ApplicationContext.GetColor(Resource.Color.teal_700)),
                new Color(ApplicationContext.GetColor(Resource.Color.purple)),
                new Color(ApplicationContext.GetColor(Resource.Color.purple_900)),
            };
            //trainingColorPallet = new List<Color>
            //{
            //    new Color( ApplicationContext.GetColor(Resource.Color.yellow_300)),
            //    new Color( ApplicationContext.GetColor(Resource.Color.deeporange_300)),
            //};


            SetContentView(Resource.Layout.activity_play);

            GameDefinition gameDefinition = null;
            var            json           = Intent.GetStringExtra(GAMESTARTDATA);
            var            startData      = json.FromJson <GameStartData>();

            if (startData != null)
            {
                gameDefinition = GameManager.GetGameDefinition(startData);
            }

            if (gameDefinition == null)
            {
                Finish();
            }

            if (gameDefinition.Width <= 4)
            {
                textSize = Resources.GetDimension(Resource.Dimension.cell4_font_size);
            }
            else if (gameDefinition.Width == 5)
            {
                textSize = Resources.GetDimension(Resource.Dimension.cell5_font_size);
            }
            else if (gameDefinition.Width == 6)
            {
                textSize = Resources.GetDimension(Resource.Dimension.cell6_font_size);
            }
            else if (gameDefinition.Width == 7)
            {
                textSize = Resources.GetDimension(Resource.Dimension.cell7_font_size);
            }
            else if (gameDefinition.Width == 8)
            {
                textSize = Resources.GetDimension(Resource.Dimension.cell8_font_size);
            }
            else if (gameDefinition.Width == 9)
            {
                textSize = Resources.GetDimension(Resource.Dimension.cell9_font_size);
            }
            else
            {
                textSize = Resources.GetDimension(Resource.Dimension.cell10_font_size);
            }

            root = FindViewById <ViewGroup>(Resource.Id.root);
            root.SetBackgroundColor(Android.Graphics.Color.ParseColor(gameDefinition.GameSet.Color));

            topLabel = FindViewById <TextView>(Resource.Id.text);
            if (!string.IsNullOrWhiteSpace(gameDefinition.Instructions))
            {
                topLabel.Text = gameDefinition.Instructions;
            }
            else
            {
                topLabel.Text = gameDefinition.DisplayLevel;
            }

            winText = FindViewById <TextView>(Resource.Id.win_text);
            winText.SetTypeface(FontManager.IconFont, TypefaceStyle.Normal);
            winText.Text = "\uE8dc";

            if (gameDefinition.GameSet.Palette != null)
            {
                var colors = new List <Color>();
                foreach (var colorStr in gameDefinition.GameSet.Palette)
                {
                    var color = Android.Graphics.Color.ParseColor(colorStr);
                    colors.Add(color);
                }
                colorPalette = colors;
            }

            frame = FindViewById <FrameLayout>(Resource.Id.frame);
            grid  = FindViewById <SquareGridLayout>(Resource.Id.grid);

            grid.RowCount    = gameDefinition.Height;
            grid.ColumnCount = gameDefinition.Width;

            gameOverFrame = FindViewById <FrameLayout>(Resource.Id.gameover_frame);
            nextButton    = FindViewById <Button>(Resource.Id.next);
            nextButton.SetBackgroundColor(Android.Graphics.Color.ParseColor(gameDefinition.GameSet.Color));
            nextButton.Click += (s, e) => { NextGame(); };
            nextButton.SetTypeface(FontManager.IconFont, TypefaceStyle.Normal);
            nextButton.Text = "\uE037";

            refreshButton        = FindViewById <ImageButton>(Resource.Id.refresh);
            refreshButton.Click += (s, e) => { ResetGame(); };

            undoButton        = FindViewById <ImageButton>(Resource.Id.undo);
            undoButton.Click += (s, e) => { Undo(); };

            runner = new GameRunner(this);
            runner.SetGameDefinition(gameDefinition);
            BuildGrid(300);
            runner.StartGame();

            grid.Touch += Grid_Touch;
        }