private void initGame() { myLogic = new SnakeLogic(); // Инициализация логики Thread.CurrentThread.Priority = ThreadPriority.Highest; scoreLabel.SetResourceReference(DataContextProperty, "Score"); score_t = scoreLabel.Content.ToString(); scoreLabel.Content += " : " + counterScore; speedLabel.SetResourceReference(DataContextProperty, "Speed"); speed_t = speedLabel.Content.ToString(); gameStatusLabel.SetResourceReference(DataContextProperty, "Status"); status_t = gameStatusLabel.Content.ToString(); // Начальное положение змейки: for (int i = 0; i < dots; i++) { x[i] = 192 - (i * DOT_SIZE); y[i] = 144; } timer = new DispatcherTimer(); timer.Tick += MainGameLoop; timer.Start(); UpdateSpeed(); myLogic.createApple(SIZE, DOT_SIZE, x, y); // Генерация яблочка BackgroundMusic.Open(new Uri("../../Resources/MGS_Encounter.wav", UriKind.RelativeOrAbsolute)); BackgroundMusic.Play(); }
private void checkApple() { if (x[0] == myLogic.getAppleX && y[0] == myLogic.getAppleY) { AppleEaten.Play(); dots++; myLogic.createApple(SIZE, DOT_SIZE, x, y); counterScore++; // Очки за яблоко UpdateSpeed(); textbox.SetResourceReference(TagProperty, "Score"); scoreLabel.Content = textbox.Tag + " : " + counterScore; allSnake.Add(Clone(snakeDot)); allSnake[allSnake.Count - 1].Margin = new Thickness { Left = x[allSnake.Count - 1], Top = y[allSnake.Count - 1], }; } }