Ejemplo n.º 1
0
        public override void Initialize()
        {
            // Background
            canvas = new Panel();
            canvas.Color = Color.RoyalBlue;
            canvas.Width = Game1.instance.GraphicsDevice.Viewport.Width;
            canvas.Height = Game1.instance.GraphicsDevice.Viewport.Height;

            // Title text
            title = new Label();
            title.Font = Game1.instance.titlefont;
            title.Text = "Conway's Game of Life";
            title.SizeToContents();
            title.Y = 40;
            canvas.Add(title);
            title.CenterX();

            // Menu area
            menubox = new Panel();
            menubox.Color = Color.CornflowerBlue;
            menubox.Width = 200;
            menubox.Height = 190;
            canvas.Add(menubox);
            menubox.Center();

            // Play button
            TextButton playButton = new TextButton();
            playButton.Font = Game1.instance.titlefont;
            playButton.Color = Color.RoyalBlue;
            playButton.Text = "Play";
            playButton.Width = 180;
            playButton.Height = 80;
            playButton.X = 10;
            playButton.Y = 10;

            // Exit button
            TextButton exitButton = new TextButton();
            exitButton.Font = Game1.instance.titlefont;
            exitButton.Color = Color.RoyalBlue;
            exitButton.Text = "Exit";
            exitButton.Width = 180;
            exitButton.Height = 80;
            exitButton.X = 10;
            exitButton.Y = 100;

            // Add buttons to menu box
            menubox.Add(playButton);
            menubox.Add(exitButton);

            // Button events
            playButton.OnClick += delegate { Play(); };
            exitButton.OnClick += delegate { Game1.instance.Exit(); };
        }
Ejemplo n.º 2
0
        public override void Initialize()
        {
            // Canvas for the scene's gui elements
            canvas = new Panel();
            canvas.Width = Game1.instance.GraphicsDevice.Viewport.Width;
            canvas.Height = Game1.instance.GraphicsDevice.Viewport.Height;
            canvas.Color = Color.RoyalBlue;

            // Center background for Life
            lifeBg = new Panel();
            lifeBg.Color = Color.CornflowerBlue;
            lifeBg.Width = canvas.Width - 4;
            lifeBg.Height = canvas.Height - 30 - 50 - 8;
            lifeBg.X = 2;
            lifeBg.Y = 34;
            canvas.Add(lifeBg);

            // Game of Life panel
            life = new LifeGrid();
            life.Color = Color.WhiteSmoke;
            life.CellSize = 7;
            life.SetGridSize(lifeBg.Width / life.CellSize, lifeBg.Height / life.CellSize);
            lifeBg.Add(life);
            life.Center();
            // If an area is selected, save it as a brush
            life.OnSelect += SaveBrush;

            // Menu panel
            controlmenu = new PanelList();
            controlmenu.Padding = 2;
            controlmenu.Color = Color.CornflowerBlue;
            controlmenu.Width = canvas.Width - 4;
            controlmenu.Height = 30;
            controlmenu.X = 2;
            controlmenu.Y = 2;
            canvas.Add(controlmenu);

            // Clear board button
            TextButton clear = new TextButton();
            clear.Text = "Clear";
            clear.Color = Color.RoyalBlue;
            clear.Width = 85;
            clear.Height = 26;
            clear.OnClick += delegate { life.Clear(); };
            controlmenu.Add(clear);

            // Randomize board button
            TextButton random = new TextButton();
            random.Text = "Randomize";
            random.Color = Color.RoyalBlue;
            random.Width = 85;
            random.Height = 26;
            random.OnClick += delegate { life.Random(); };
            controlmenu.Add(random);

            // Load board button
            TextButton load = new TextButton();
            load.Text = "Load";
            load.Color = Color.RoyalBlue;
            load.Width = 85;
            load.Height = 26;
            load.OnClick += delegate { life.Load(); };
            controlmenu.Add(load);

            // Save board button
            TextButton save = new TextButton();
            save.Text = "Save";
            save.Color = Color.RoyalBlue;
            save.Width = 85;
            save.Height = 26;
            save.OnClick += delegate { life.Save(); };
            controlmenu.Add(save);

            // Play button
            SpriteButton play = new SpriteButton();
            play.Load("play");
            play.Color = Color.RoyalBlue;
            play.Width = 26;
            play.Height = 26;
            play.OnClick += delegate { life.Playing = true; };
            controlmenu.Add(play);

            // Pause button
            SpriteButton pause = new SpriteButton();
            pause.Load("pause");
            pause.Color = Color.RoyalBlue;
            pause.Width = 26;
            pause.Height = 26;
            pause.OnClick += delegate { life.Playing = false; };
            controlmenu.Add(pause);

            Label fastText = new Label();
            fastText.Text = " Speed: fast ";
            fastText.SizeToContents();
            controlmenu.Add(fastText);

            // Speed slider
            Slider speed = new Slider();
            speed.Color = Color.RoyalBlue;
            speed.Width = 100;
            speed.Height = 14;
            speed.OnChange += delegate { life.Speed = Math.Max(speed.Value, 0.03); };
            controlmenu.Add(speed);

            Label slowText = new Label();
            slowText.Text = " slow  ";
            slowText.SizeToContents();
            controlmenu.Add(slowText);

            // Exit button
            TextButton exit = new TextButton();
            exit.Text = "Exit";
            exit.Color = Color.RoyalBlue;
            exit.Width = 45;
            exit.Height = 26;
            exit.OnClick += delegate { Game1.instance.ChangeScene(new MenuScene()); };
            controlmenu.Add(exit);

            // Brush menu panel
            brushmenu = new PanelList();
            brushmenu.Padding = 2;
            brushmenu.Color = Color.CornflowerBlue;
            brushmenu.Width = canvas.Width - 4;
            brushmenu.Height = 50;
            brushmenu.X = 2;
            brushmenu.Y = canvas.Height - 52;
            canvas.Add(brushmenu);

            // Brush load button
            SpriteButton loadBrush = new SpriteButton();
            loadBrush.Load("loadbrush");
            loadBrush.Color = Color.RoyalBlue;
            loadBrush.Width = 46;
            loadBrush.Height = 46;
            loadBrush.OnClick += LoadBrush;
            brushmenu.Add(loadBrush);

            // New brush button
            SpriteButton newBrush = new SpriteButton();
            newBrush.Load("savebrush");
            newBrush.Color = Color.RoyalBlue;
            newBrush.Width = 46;
            newBrush.Height = 46;
            newBrush.OnClick += delegate { life.SelectMode = life.SelectMode > 0 ? 0 : 1; };
            brushmenu.Add(newBrush);

            // Brush selection list
            brushlist = new SelectList();
            brushlist.Padding = 2;
            brushlist.Height = 50;
            brushlist.Width = brushmenu.Width - 46 * 2 - 2 * 4;
            brushlist.OnChange += delegate { life.CurrentBrush = (Brush)brushlist.selected; };
            brushmenu.Add(brushlist);

            // Default Life speed value
            speed.Value = 0.03;
            life.Speed = 0.03;
        }