new MainMenu (); item = new MenuItem ("& Файл");. MenuItems.Add (item);
// Add the menu entries to the "File" menu.MenuItems.Add (new MenuItem ("& Вихід", new EventHandler (Exit))); = new MenuItem (" & Рівень ");. MenuItems.Add (item);
// Add the menu entries to the "File" menu.MenuItems.Add (new MenuItem ("Швидше", new EventHandler (LevelUp)));. MenuItems.Add (new MenuItem ( "повільні", new EventHandler (LevelDown)));
// Create a new Menu = new MenuItem ("& Допомога");. MenuItems.Add (item);
// Add the menu entries to the "Help" menu.MenuItems.Add (new MenuItem ("& Про проект", new EventHandler (OnAbout)));
// Attach the menu to the window = menu;. ClientSize = new System.Drawing.Size (640, 480);. FormBorderStyle = FormBorderStyle.FixedSingle;. Name = "SnakeCSharpWindow";. Text = "SnakeCSharp";. Paint + = new PaintEventHandler (SnakeCSharpWindow_Paint);. KeyDown + = new KeyEventHandler (SnakeCSharpWindow_KeyDown);. Tick + = new EventHandler (t_Tick);. Start ();. AddFirst (new Dir (10, 10));. Player = player;
}
void LevelUp (object sender, EventArgs ev)
{(bonus <5)
{. Interval - = 20; + = 1;
}
}
void LevelDown (object sender, EventArgs ev)
{(bonus> 1)
{. Interval + = 20; - = 1;
}
}
void OnAbout (object sender, EventArgs ev)
{
about = new AboutBox1 ();. ShowDialog (); = null;
}
SnakeCSharpWindow_KeyDown (object sender, KeyEventArgs e)// Change direction
{(e.KeyCode == Keys.Left) {dir = new Dir (-10, 0);} (e.KeyCode == Keys.Right) {dir = new Dir (10, 0);} (e.KeyCode == Keys.Up) {dir = new Dir (0, -10);} (e.KeyCode == Keys.Down) {dir = new Dir (0, 10);} ( e.KeyCode == Keys.Escape) {this.Close ();}
}
SnakeCSharpWindow_Paint (object sender, PaintEventArgs e)
{. Graphics.DrawRectangle (new Pen (Color.Red, 3), 0, 0, 640, 480);. Graphics.FillRectangle (apple.Color, apple.Coordinates.X, apple. Coordinates.Y, 10, 10);. Graphics.DrawString (points.ToString (), new Font ("Arial", 30), new SolidBrush (Color.Orange), new PointF (540, 10));. Graphics . DrawString ("Рівень:" + bonus.ToString (), new Font ("Arial", 20), new SolidBrush (Color.DarkBlue), new PointF (10, 10)); (points> = ( bonus * 200)) {LevelUp (sender, e);} i = 0; point = 1; (m) {point = 3;} (Dir cur in snake)// Draw snake and check self collision
{. Graphics.FillRectangle (Brushes.Black, cur.point.X, cur.point.Y, 10, 10); (i! = 0 && snake.First.Value. point.X ==...