Exemplo n.º 1
0
        private void InitializeView( )
        {
            // Centers this window to parent
            Center();

            Title = "Snake";

            Board          = new SnakeBoard(boardWidth, boardHeight);
            Board.Position = new Point(Width / 2 - boardWidth / 2, 5);

            Board.DeathHandler += OnSnakeDeath;
            Board.EatHandler   += OnSnakeEat;

            Print(Board.Position.X, 3, "SCORE:");

            // Add Border around the board
            var border = new SadConsole.Surfaces.Basic(boardWidth + 2, boardHeight + 2);

            border.DrawBox(new Rectangle(0, 0, border.Width, border.Height), new Cell(DefaultForeground, DefaultBackground), connectedLineStyle: SurfaceBase.ConnectedLineThin);

            border.Position = new Point(-1, -1);

            // Add border to Board children so it draws later
            Board.Children.Add(border);
            Children.Add(Board);

            Score = 0;
        }
Exemplo n.º 2
0
        private void InitializeView( )
        {
            // Centers this window to parent
            Center();

            Title = "Tetris";

            // Calculate PlayArea position so its centered on X
            int playAreaX = Width / 2 - playWidth / 2;
            int playAreaY = 2;

            // Create the board
            Board          = new TetrisBoard(playWidth, playHeight);
            Board.Position = new Point(playAreaX, playAreaY);

            // Add Border around the board
            var border = new SadConsole.Surfaces.Basic(playWidth + 2, playHeight + 2);

            border.DrawBox(new Rectangle(0, 0, border.Width, border.Height), new Cell(DefaultForeground, DefaultBackground), connectedLineStyle: SurfaceBase.ConnectedLineThin);

            border.Draw(TimeSpan.Zero);
            border.Position = new Point(-1, -1);

            // Add border to Board children so it draws later
            Board.Children.Add(border);
            Children.Add(Board);
        }
Exemplo n.º 3
0
        private void MakeLayeredSurface()
        {
            layeredSurface = new Layered();

            var layer = new SadConsole.Surfaces.Basic(34, 15);

            layer.Fill(StarterProject.Theme.Gray, StarterProject.Theme.GrayDark, 0);
            layer.Print(14, 4, "Layer 0");
            layeredSurface.Add(layer);

            layer = new SadConsole.Surfaces.Basic(34, 15);
            layer.Fill(StarterProject.Theme.Green, StarterProject.Theme.GreenDark, 0);
            layer.Fill(new Rectangle(10, 4, 34 - 20, 15 - 8), Color.White, Color.Transparent, 0);
            layer.Print(14, 2, "Layer 1");
            layeredSurface.Add(layer);

            layer = new SadConsole.Surfaces.Basic(34, 15);
            layer.Fill(StarterProject.Theme.Brown, StarterProject.Theme.BrownDark, 0);
            layer.Fill(new Rectangle(5, 2, 34 - 10, 15 - 4), Color.White, Color.Transparent, 0);
            layer.Print(14, 0, "Layer 2");
            layeredSurface.Add(layer);
        }
Exemplo n.º 4
0
        public MainMenu(int Width, int Height) : base(Width, Height)
        {
            FontMaster fontMaster = SadConsole.Global.LoadFont("cp437_10_ext.font");
            Font       titleFont  = fontMaster.GetFont(Font.FontSizes.Four);

            Basic title = new SadConsole.Surfaces.Basic(20, 1);

            title.Font     = titleFont;
            title.Position = new Point(Width / 4 - "Main Menu".Length / 2, 2);
            title.Print(0, 0, "Main Menu");

            Children.Add(title);

            var tetrisButton = new SadConsole.Controls.Button(11, 3);

            tetrisButton.Text          = "Tetris";
            tetrisButton.TextAlignment = HorizontalAlignment.Center;
            tetrisButton.Position      = new Point(Width / 2 - tetrisButton.Width / 2, 10);
            tetrisButton.Theme         = new SadConsole.Themes.ButtonLinesTheme();

            Add(tetrisButton);

            tetrisButton.Click += (btn, args) =>
            {
                Program.MainMenu.Hide();
                Program.TetrisWindow.Show();
            };

            var snakeButton = new SadConsole.Controls.Button(11, 3);

            snakeButton.Position      = new Point(Width / 2 - snakeButton.Width / 2, 14);
            snakeButton.TextAlignment = HorizontalAlignment.Center;
            snakeButton.Text          = "Snake";
            snakeButton.Theme         = new SadConsole.Themes.ButtonLinesTheme();

            Add(snakeButton);

            snakeButton.Click += (btn, args) =>
            {
                Program.MainMenu.Hide();
                Program.SnakeWindow.Show();
            };

            var themeButton = new SadConsole.Controls.Button(11, 3);

            themeButton.Position      = new Point(Width / 2 - snakeButton.Width / 2, 18);
            themeButton.TextAlignment = HorizontalAlignment.Center;
            themeButton.Text          = "Theme";
            themeButton.Theme         = new SadConsole.Themes.ButtonLinesTheme();

            Add(themeButton);

            themeButton.Click += (btn, args) =>
            {
                Program.MainMenu.Hide();
                Program.ThemeEditor.Show();
            };

            var viewerButton = new SadConsole.Controls.Button(11, 3);

            viewerButton.Position      = new Point(Width / 2 - snakeButton.Width / 2, 22);
            viewerButton.TextAlignment = HorizontalAlignment.Center;
            viewerButton.Text          = "Viewer";
            viewerButton.Theme         = new SadConsole.Themes.ButtonLinesTheme();

            Add(viewerButton);

            viewerButton.Click += (btn, args) =>
            {
                Program.MainMenu.Hide();
                Program.TilesetViewer.Show();
            };

            var mapViewButton = new SadConsole.Controls.Button(11, 3);

            mapViewButton.Position      = new Point(Width / 2 - snakeButton.Width / 2, 26);
            mapViewButton.TextAlignment = HorizontalAlignment.Center;
            mapViewButton.Text          = "MapView";
            mapViewButton.Theme         = new SadConsole.Themes.ButtonLinesTheme();

            Add(mapViewButton);

            mapViewButton.Click += (btn, args) =>
            {
                Program.MainMenu.Hide();
                //Children.Add( Program.MapView );
                //Global.CurrentScreen = Program.MapView;
                Program.MapView.Show();
                Global.FocusedConsoles.Set(Program.MapView);
            };

            var themeRadioButton = new RadioButton(10, 1);

            themeRadioButton.Text      = "Light";
            themeRadioButton.Position  = new Point(60, 2);
            themeRadioButton.GroupName = "Theme";
            Add(themeRadioButton);
            themeRadioButton.IsSelectedChanged += OnThemeRadioChanged;

            themeRadioButton           = new RadioButton(10, 1);
            themeRadioButton.Text      = "Dark";
            themeRadioButton.Position  = new Point(60, 4);
            themeRadioButton.GroupName = "Theme";
            Add(themeRadioButton);
            themeRadioButton.IsSelectedChanged += OnThemeRadioChanged;
        }
Exemplo n.º 5
0
        public SerializationTests() : base(80, 23)
        {
            controlsConsole = new ControlsConsole(80, 4);

            masterView = new Console(34, 15);
            loadedView = new Console(34, 15);

            masterView.Fill(Color.White, Color.Red, 0);
            loadedView.Fill(Color.White, Color.Blue, 0);

            UseMouse = true;

            // Add the consoles to the list.
            Children.Add(controlsConsole);
            Children.Add(masterView);
            Children.Add(loadedView);

            // Setup main view
            masterView.Position = new Point(3, 6);

            // Setup sub view
            loadedView.Position = new Point(80 - 37, 6);


            // Setup controls
            controlsConsole.Position = new Point(0, 0);

            optionButtonSurface = new SadConsole.Controls.RadioButton(18, 1)
            {
                Text     = "Surface",
                Position = new Point(1, 1),
            };
            optionButtonSurface.IsSelectedChanged += OptionButton_IsSelectedChanged;
            controlsConsole.Add(optionButtonSurface);

            optionButtonView = new SadConsole.Controls.RadioButton(18, 1)
            {
                Text     = "Surface View",
                Position = new Point(1, 2)
            };
            optionButtonView.IsSelectedChanged += OptionButton_IsSelectedChanged;
            controlsConsole.Add(optionButtonView);

            optionButtonLayered = new SadConsole.Controls.RadioButton(21, 1)
            {
                Text     = "Layered Surface",
                Position = new Point(optionButtonSurface.Bounds.Right + 1, 1)
            };
            optionButtonLayered.IsSelectedChanged += OptionButton_IsSelectedChanged;
            controlsConsole.Add(optionButtonLayered);

            optionButtonAnimated = new SadConsole.Controls.RadioButton(21, 1)
            {
                Text     = "Animated Surface",
                Position = new Point(optionButtonSurface.Bounds.Right + 1, 2)
            };
            optionButtonAnimated.IsSelectedChanged += OptionButton_IsSelectedChanged;
            controlsConsole.Add(optionButtonAnimated);

            var buttonSave = new SadConsole.Controls.Button(17, 1)
            {
                Text     = "Save and Load",
                Position = new Point(controlsConsole.Width - 19, 1)
            };

            buttonSave.Click += ButtonSave_Click;
            controlsConsole.Add(buttonSave);

            basicSurface = new SadConsole.Surfaces.Basic(34, 15);

            animatedSurface = SadConsole.Surfaces.Animated.CreateStatic(34, 15, 15, 0.3d);
            viewSurface     = new Basic(1, 1);
            viewSurface.SetViewFromSurface(new Rectangle(5, 2, 34 - 10, 15 - 4), basicSurface);
            //emptySurface = (SadConsole.Surfaces.BasicSurface)loadedView.TextSurface;

            MakeBasicSurface();
            MakeLayeredSurface();
        }