Пример #1
0
        public BottomPanel(SnakeEngine game, Font font)
        {
            BitNoireFont = font;
            var flow = new FlowLayoutPanel();

            Controls.Add(flow);
            this.Size      = new Size(736, 90);
            this.BackColor = Color.FromArgb(30, 30, 30);
            this.Anchor    = AnchorStyles.Bottom;
            this.game      = game;
            Paint         += TitleScreen;
        }
Пример #2
0
        public PlayField(SnakeEngine gameEngine, int width, int height)
        {
            Game = gameEngine;

            DoubleBuffered = true;

            BackColor   = Color.FromArgb(30, 30, 30);
            BorderStyle = BorderStyle.None;
            Width       = width;
            Height      = height;
            InitializeComponent();

            Paint += OnPaint;
        }
Пример #3
0
 private void StartGame()
 {
     SnakeEngine = new SnakeEngine(Board);
 }
Пример #4
0
        public GameForm() : base()
        {
            Width           = playfieldWidth + borderThickness * 2;
            Height          = Width; // It's a square
            BackColor       = Color.DarkOrange;
            FormBorderStyle = FormBorderStyle.None;
            StartPosition   = FormStartPosition.CenterScreen;

            InitCustomFont();

            game = new SnakeEngine(playfieldWidth, playfieldHeight, Settings.FPS, MovesPerSecond, FoodBitmaps);
            game.GameOverEventHandler += DisplayWinner;

            timer          = new Timer();
            timer.Interval = 1000 / Settings.FPS;
            timer.Tick    += Timer_Tick;

            flow = new FlowLayoutPanel();
            flow.FlowDirection = FlowDirection.TopDown;
            flow.Location      = new Point(borderThickness - 3, borderThickness - 3);
            flow.AutoSize      = true;
            flow.BackColor     = Color.Gray;
            flow.BorderStyle   = BorderStyle.None;

            restartButton           = new Button();
            restartButton.AutoSize  = true;
            restartButton.BackColor = Color.FromArgb(30, 30, 30);
            restartButton.ForeColor = Color.White;
            restartButton.Text      = "RESTART";
            restartButton.UseCompatibleTextRendering = true;
            restartButton.Font      = new Font(pfc.Families[0], 12);
            restartButton.FlatStyle = FlatStyle.Flat;
            restartButton.FlatAppearance.BorderSize = 0;
            restartButton.Location = new Point(borderThickness * 2, Height - restartButton.Height * 2 - borderThickness);

            restartButton.Click += RestartButton_Click;

            playField = new PlayField(game, playfieldWidth, playfieldHeight);
            flow.Controls.Add(playField);

            bottomPanel = new BottomPanel(game, new Font(GameForm.pfc.Families[0], 20));
            flow.Controls.Add(bottomPanel);

            mainMenu = new MainMenu();

            Controls.Add(flow);
            Controls.Add(mainMenu);

            mainMenu.Location = new Point((Width - mainMenu.Width) / 2, (Height - mainMenu.Height) / 2);
            mainMenu.BringToFront();

            // Assign handlers for the main menu buttons.
            mainMenu.OnePlayer.Click    += OnePlayer_Click;
            mainMenu.TwoPlayers.Click   += TwoPlayers_Click;
            mainMenu.ThreePlayers.Click += ThreePlayers_Click;
            mainMenu.FourPlayers.Click  += FourPlayers_Click;
            mainMenu.ExitButton.Click   += ExitButton_Click;

            // Gets fired before the KeyDown event
            PreviewKeyDown += GameForm_PreviewKeyDown;
            KeyPreview      = true;
        }