Beispiel #1
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        public SnakeForm()
        {
            var topLayout = new Panel
            {
                Dock   = DockStyle.Top,
                Margin = new Padding(4),
                Size   = new Size(284, 32)
            };

            var bottomLayout = new TableLayoutPanel
            {
                Dock        = DockStyle.Fill,
                RowCount    = SnakeConfig.RowCount,
                ColumnCount = SnakeConfig.ColumnCount
            };

            SuspendLayout();
            topLayout.SuspendLayout();
            topLayout.Controls.Add(_label2);

            topLayout.Controls.Add(new Label
            {
                AutoSize  = true,
                Dock      = DockStyle.Left,
                Font      = new Font("Consolas", 12F, FontStyle.Bold, GraphicsUnit.Point, 0),
                ForeColor = Color.White,
                Location  = new Point(0, 0),
                Margin    = new Padding(0),
                Padding   = new Padding(4, 6, 4, 4),
                Size      = new Size(62, 29),
                Text      = "SCORE",
                TextAlign = ContentAlignment.MiddleLeft
            });

            BackColor  = Color.Black;
            ClientSize = new Size(284, 261);
            Controls.Add(bottomLayout);
            Controls.Add(topLayout);
            Text             = "SNAAAAAKE";
            _snakeController = new SnakeController(bottomLayout);
            ClientSize       = new Size(SnakeConfig.ColumnCount * SnakeConfig.CellSize, SnakeConfig.CellSize + SnakeConfig.RowCount * SnakeConfig.CellSize);
            KeyDown         += (sender, eventArgs) => _snakeController.Move(eventArgs.KeyCode);
            _timer.Tick     += Tick;
            _timer.Start();
            topLayout.ResumeLayout(false);
            topLayout.PerformLayout();
            ResumeLayout(false);
        }
Beispiel #2
0
 /// <summary>
 /// </summary>
 /// <param name="snakeController"></param>
 public Snake(SnakeController snakeController)
 {
     _snakeController = snakeController;
     _segment         = new SnakeSegment(_snakeController.CellAt(new Position2D(4, 5)), new Position2D(4, 5));
     _body.Enqueue(_segment);
 }