Wacky_rubia

Untitled

Mar 23rd, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. using System.Media;
  9.  
  10. namespace MyLittleSimpleSnake
  11. {
  12.  
  13. public class SnakeForm : Form
  14. {
  15. ...
  16. public SnakeForm()
  17. {
  18. ...
  19. Timer timer = new Timer();
  20. timer.Interval = 1;
  21. timer.Tick += TimerTick;
  22. timer.Start();
  23. //if (IsOver)
  24. // timer.Stop();
  25. }
  26.  
  27. ...
  28. int tickCount = 0;
  29.  
  30. void TimerTick(object sender, EventArgs args)
  31. {
  32. if (tickCount == 0) Act();
  33. //KeyPreview = true; поможет ли???
  34. if (tickCount == maxTimeCount)
  35. {
  36. StepGame.Move();
  37. for (int x = 0; x < Game.MapWidth; x++)
  38. for (int y = 0; y < Game.MapHeight; y++)
  39. Game.Map[x, y] = CreatureType.Ground;
  40. foreach (var e in Game.Walls)
  41. Game.Map[e.X, e.Y] = CreatureType.Wall;
  42. foreach (var e in Game.Snake.snake)
  43. Game.Map[e.X, e.Y] = CreatureType.PartOfSnake;
  44. Game.Map[Game.Fruit.fruit.X, Game.Fruit.fruit.Y] = CreatureType.Fruit;
  45. }
  46. if (Game.IsOver == true)
  47. {
  48. IsOver = true;
  49. //MessageBox.Show("Game Over");
  50. this.Close();
  51. throw new Exception("");
  52. }
  53. tickCount++;
  54. if (tickCount == maxTimeCount+1) tickCount = 0;
  55. Invalidate();
  56. }
  57.  
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment