public static void Main() { List <Animal> animals = new List <Animal>(); string command = Console.ReadLine(); while (command != "End") { string[] token = command.Split(); Animal animal = AnimalsCreater.CreateAnimal(token); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); string[] foodInfo = Console.ReadLine().Split(); Food food = FoodCreater.CreateFood(foodInfo); try { animal.EatFood(food); } catch (ArgumentException e) { Console.WriteLine(e.Message); } command = Console.ReadLine(); } foreach (var animal in animals) { Console.WriteLine(animal); } }
private void Awake() { audioSource = GetComponent <AudioSource>(); waitToMove = startWaitTime; body = new List <GameObject>(); foodCreater = FindObjectOfType <FoodCreater>(); }
public static void Main(string[] args) { // size of map int MaxMapWidth = 80; int MaxMapHeight = 25; Console.SetBufferSize(MaxMapWidth, MaxMapHeight); // drow frame Walls walls = new Walls(MaxMapWidth, MaxMapHeight); walls.Draw(); // drow point draw snake Point point = new Point(5, 10, '*'); Snake snake = new Snake (point, 5, Direction.RIGHT); snake.Draw (); // draw food FoodCreater foodCreator = new FoodCreater (MaxMapWidth, MaxMapHeight, '$'); Point food = foodCreator.CreateFood (); //Console.ForegroundColor = ConsoleColor.Cyan; food.Draw (); while (true) { // data de perete if (walls.IsHit (snake) || snake.IsHitTail()) break; // daca maninca if(snake.Eat(food)){ food = foodCreator.CreateFood (); food.Draw (); } else snake.Move (); Thread.Sleep (200); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey (); snake.Hadlekey (key.Key); if (key.Key == ConsoleKey.Escape) break; } } // END Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(MaxMapWidth/3 , 10); Console.WriteLine ("--=***=-- E N D --=***=--"); Console.SetCursorPosition(MaxMapWidth/3 , 12); //Thread.Sleep (300); //Console.ReadLine (); }
public GameServerMainForm() { InitializeComponent(); Food = new FoodCreater(winWidth, winHeight, new Size(10, 10)); // gamesocket GameServerSocket = new ServerSocket(IPAddress.Parse("127.0.0.1"), 40018); GameServerSocket.OnReceive += new DelagateServerReceiveMessage(DecodeMessage); this.timerUpdate.Interval = 3; }
/// <summary> /// 游戏开始 /// </summary> /// <param name="winWidth">界面宽度</param> /// <param name="winHeight">界面高度</param> /// <param name="snakeGrap">画布</param> public void GameStart(int winWidth, int winHeight, BufferedGraphics bufferGrap) { // 游戏开始时候设置 winWidth, winHeight, snakeGrap // 初始化winwidth, winheight, snakegrap this.m_bufferGrap = bufferGrap; this.m_gameGrap = bufferGrap.Graphics; this.m_winHeight = winHeight; this.m_winWidth = winWidth; // 计算snake初始点 m_snakeBeginPos = new Point(winWidth / 2 - (winWidth / 2) % 10, winHeight / 2 - (winHeight / 2) % 10); m_snake.CreateSnakeBody(m_snakeBeginPos, this.m_gameGrap); m_snake.SnakeBodyMoveSpeed = ClientGameControl.m_snakeMoveSpeed; if (this.PlayerGameMode == GameMode.OFFLINE) { // 单机模式 this.IsGameStart = true; this.IsGamePause = false; // 实例化食物类 m_food = new FoodCreater(winWidth, winHeight, this.m_gameGrap, new Size(10, 10)); m_food.CreateFood(); // 生成食物 } else if (this.PlayerGameMode == GameMode.ONLINE) { // 联机模式 // 这里不能设置IsGameStart为true, 只有收到GAME_START信号的时候才能开始游戏 // 实例化本地SnakeBody // 实例化食物类 m_food = new FoodCreater(winWidth, winHeight, this.m_gameGrap, new Size(10, 10)); } }