void GoodCollision() { if (mySnake.HeadSnake.x == normfood.x && mySnake.HeadSnake.y == normfood.y) { ++score; textBlockScore.Text = score.ToString(); Random rnd = new Random(); StarVisible = rnd.Next(0, 3); if (StarVisible == 1) { Point point = NewLocation(); premfood.x = point.x; premfood.y = point.y; gridGame.Children.Add(premfood.Rectangle); premfood.Draw(); } else { gridGame.Children.Remove(premfood.Rectangle); } PartOfSnake part = mySnake.AddParts(mySnake.partsSnake.Last().x, mySnake.partsSnake.Last().y); gridGame.Children.Add(part.Rectangle); mySnake.DrawSnake(); //gridGame.Children.Remove(normfood.Rectangle); amountNormFood = rnd.Next(0, 3); Point pt = NewLocation(); normfood.x = pt.x; normfood.y = pt.y; normfood.Draw(); pt = NewLocation(); deadfood.x = pt.x; deadfood.y = pt.y; deadfood.Draw(); } if (mySnake.HeadSnake.x == premfood.x && mySnake.HeadSnake.y == premfood.y) { score += 10; textBlockScore.Text = score.ToString(); PartOfSnake part = mySnake.AddParts(mySnake.partsSnake.Last().x, mySnake.partsSnake.Last().y); gridGame.Children.Add(part.Rectangle); mySnake.DrawSnake(); gridGame.Children.Remove(premfood.Rectangle); } }
void MakeFood() { normfood = new NormalFood(10, 10); gridGame.Children.Add(normfood.Rectangle); normfood.Draw(); deadfood = new DeadFood(30, 10); gridGame.Children.Add(deadfood.Rectangle); deadfood.Draw(); premfood = new PremiumFood(40, 20); gridGame.Children.Add(premfood.Rectangle); premfood.Draw(); }
void MakeFood() { normfoodList.Add(new NormalFood(40, 35)); gridGame.Children.Add(normfoodList.ElementAt(0).Rectangle); normfoodList.ElementAt(0).Draw(); deadfood = new DeadFood(30, 10); gridGame.Children.Add(deadfood.Rectangle); deadfood.Draw(); premfood = new PremiumFood(40, 2); gridGame.Children.Add(premfood.Rectangle); premfood.Draw(); }
void GoodCollision() { foreach (NormalFood nfood in normfoodList) { if (mySnake.HeadSnake.x == nfood.x && mySnake.HeadSnake.y == nfood.y) { ++score; textBlockScore.Text = score.ToString(); Random rnd = new Random(); StarVisible = rnd.Next(0, 3); if (StarVisible == 1) { if (gridGame.Children.Contains(premfood.Rectangle)) { Point point = NewLocation(); premfood.x = point.x; premfood.y = point.y; premfood.Draw(); } else { Point point = NewLocation(); premfood.x = point.x; premfood.y = point.y; gridGame.Children.Add(premfood.Rectangle); premfood.Draw(); } } else { gridGame.Children.Remove(premfood.Rectangle); } PartOfSnake part = mySnake.AddParts(mySnake.partsSnakeList.Last().x, mySnake.partsSnakeList.Last().y); gridGame.Children.Add(part.Rectangle); mySnake.DrawSnake(); Random rand1 = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); amountNormFood = rand1.Next(1, 3); switch (amountNormFood) { case 1: if (normfoodList.Count() == 2) { normfoodList.Remove(nfood); gridGame.Children.Remove(nfood.Rectangle); Point poin = NewLocation(); normfoodList.ElementAt(0).x = poin.x; normfoodList.ElementAt(0).y = poin.y; normfoodList.ElementAt(0).Draw(); } else if (normfoodList.Count() == 1) { Point poin = NewLocation(); normfoodList.ElementAt(0).x = poin.x; normfoodList.ElementAt(0).y = poin.y; normfoodList.ElementAt(0).Draw(); } break; case 2: if (normfoodList.Count() == 1) { Point poin = NewLocation(); normfoodList.Add(new NormalFood(poin.x, poin.y)); gridGame.Children.Add(normfoodList.ElementAt(1).Rectangle); normfoodList.ElementAt(1).Draw(); poin = NewLocation(); normfoodList.ElementAt(0).x = poin.x; normfoodList.ElementAt(0).y = poin.y; normfoodList.ElementAt(0).Draw(); } else if (normfoodList.Count() == 2) { Point poin = NewLocation(); normfoodList.ElementAt(0).x = poin.x; normfoodList.ElementAt(0).y = poin.y; normfoodList.ElementAt(0).Draw(); poin = NewLocation(); normfoodList.ElementAt(1).x = poin.x; normfoodList.ElementAt(1).y = poin.y; normfoodList.ElementAt(1).Draw(); } break; } Point pt = NewLocation(); pt = NewLocation(); deadfood.x = pt.x; deadfood.y = pt.y; deadfood.Draw(); break; } } if (mySnake.HeadSnake.x == premfood.x && mySnake.HeadSnake.y == premfood.y) { score += 10; textBlockScore.Text = score.ToString(); PartOfSnake part = mySnake.AddParts(mySnake.partsSnakeList.Last().x, mySnake.partsSnakeList.Last().y); gridGame.Children.Add(part.Rectangle); mySnake.DrawSnake(); gridGame.Children.Remove(premfood.Rectangle); } }