Apple.cs
上传用户:cljx11
上传日期:2022-08-09
资源大小:49k
文件大小:1k
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- namespace Snake_v2
- {
- class Apple
- {
- private static Random rd = new Random();
- private static int _x = -1, _y = -1;
- public static void NewApple()
- {
- while (SnakeMap.Map[_x = rd.Next(0, 35), _y = rd.Next(0, 15)] != 0) //在地图上随机产生一个苹果坐标,如果将要产生的坐标是蛇的身体,则重新产生
- {
- Thread.Sleep(10);
- }
- SnakeMap.Map[_x, _y] = -1;
- }
- public static int GetAppleX()
- {
- return _x;
- }
- public static int GetAppleY()
- {
- return _y;
- }
- }
- }