Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Media;
- namespace MyLittleSimpleSnake
- {
- public class SnakeForm : Form
- {
- ...
- public SnakeForm()
- {
- ...
- Timer timer = new Timer();
- timer.Interval = 1;
- timer.Tick += TimerTick;
- timer.Start();
- //if (IsOver)
- // timer.Stop();
- }
- ...
- int tickCount = 0;
- void TimerTick(object sender, EventArgs args)
- {
- if (tickCount == 0) Act();
- //KeyPreview = true; поможет ли???
- if (tickCount == maxTimeCount)
- {
- StepGame.Move();
- for (int x = 0; x < Game.MapWidth; x++)
- for (int y = 0; y < Game.MapHeight; y++)
- Game.Map[x, y] = CreatureType.Ground;
- foreach (var e in Game.Walls)
- Game.Map[e.X, e.Y] = CreatureType.Wall;
- foreach (var e in Game.Snake.snake)
- Game.Map[e.X, e.Y] = CreatureType.PartOfSnake;
- Game.Map[Game.Fruit.fruit.X, Game.Fruit.fruit.Y] = CreatureType.Fruit;
- }
- if (Game.IsOver == true)
- {
- IsOver = true;
- //MessageBox.Show("Game Over");
- this.Close();
- throw new Exception("");
- }
- tickCount++;
- if (tickCount == maxTimeCount+1) tickCount = 0;
- Invalidate();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment