static void Main(string[] args) { Console.SetWindowSize(100, 55); Console.SetBufferSize(100, 55); Walls walls = new Walls(80, 25); walls.DrawWalls(); MyPoint tail = new MyPoint(6, 5, '*'); Snake snake = new Snake(tail, 4, Color.GreenYellow, Direction.RIGHT); //added a color snake.DrawFigure(); Console.WriteLine("Try to find some food for the snake"); //telling to search for food FoodCatering foodCatered = new FoodCatering(80, 25, '$'); MyPoint food = foodCatered.CaterFood(); food.Draw(); while (true) { if (walls.IsHitByFigure(snake)) { for (int i = 0; i >= 3; i++) //if the worm hits the wall, 2 beeps { Console.Beep(); snake.color = Color.Red; //changing the snake's color to red } Console.BackgroundColor = ConsoleColor.DarkMagenta; //changing the console color on impact Console.WriteLine($" {snake.name} hit the wall"); break; } if (snake.Eat(food)) { food = foodCatered.CaterFood(); food.Draw(); Console.Beep(); // if the worm eats, console makes 1 beep Random fiftyPercent = new System.Random(); //bool like; fiftyPercent.Next(1, 2); Console.WriteLine(fiftyPercent.Equals(1) ? $"{snake.name} likes the food" : $"{snake.name} hates the food"); //determining wheter the snake likes the food Console.WriteLine(fiftyPercent.Equals(1) ? snake.color = Color.Azure : snake.color = Color.Purple); //changig colors dependent on the reaction to food } else { snake.MoveSnake(); } Thread.Sleep(300); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.ReadUserKey(key.Key); } } WriteGameOver(); Console.ReadLine(); }
static void Main(string[] args) { Console.SetWindowSize(80, 25); Console.SetBufferSize(80, 25); //märkide arv, mis sinna mahub Walls walls = new Walls(80, 25); walls.DrawWalls(); /*HorizontalLine upLine = new HorizontalLine(0, 78, 0, '*'); * upLine.DrawFigure(); * HorizontalLine downLine = new HorizontalLine(0, 78, 24, '*'); * downLine.DrawFigure(); * VerticalLine leftLine = new VerticalLine(0, 24, 0, '*'); * leftLine.DrawFigure(); * VerticalLine rightLine = new VerticalLine(0, 24, 78, '*'); * rightLine.DrawFigure();*/ MyPoint tail = new MyPoint(6, 5, '*'); Snake snake = new Snake(tail, 4, Direction.RIGHT); snake.DrawFigure(); //TOIDU SERVEERIMINE FoodCatering foodCatered = new FoodCatering(50, 25, '$'); MyPoint food = foodCatered.CaterFood(); food.Draw(); while (true) { if (walls.IsHitByFigure(snake)) { break; } if (snake.Eat(food)) { food = foodCatered.CaterFood(); food.Draw(); } else { snake.MoveSnake(); } Thread.Sleep(300); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.ReadUserKey(key.Key); } } WriteGameOver(); Console.ReadLine(); /*snake.MoveSnake(); * Thread.Sleep(100); * snake.MoveSnake(); * Thread.Sleep(100); * snake.MoveSnake(); * Thread.Sleep(100); * snake.MoveSnake();*/ /*HorizontalLine hrLine = new HorizontalLine(5, 10, 10, '*'); * hrLine.DrawHorizontalLine(); * * VerticalLine vrLine = new VerticalLine(11, 20, 5, '*'); * vrLine.DrawVerticalLine();*/ /*Console.BackgroundColor = ConsoleColor.White; * Console.Clear(); * * for (int i = 5; i < 10; i++) * { * MyPoint newPoint = new MyPoint(i, 5, '*'); * newPoint.Draw(); * MyPoint newPoint2 = new MyPoint(5, i, '#'); * newPoint2.Draw(); * }*/ /*Point p1 = new Point(10, 10, '*'); * p1.Draw(); * * Point p2 = new Point(11, 10, '*'); * p2.Draw(); * * Point p3 = new Point(12, 10, '*'); * p3.Draw(); * * Point p4 = new Point(13, 10, '*'); * p4.Draw(); * * Point p5 = new Point(14, 10, '*'); * p5.Draw(); * * Point p6 = new Point(15, 10, '*'); * p6.Draw();*/ }
static void Main(string[] args) { Start: Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.White; Console.SetWindowSize(95, 25); Console.SetBufferSize(95, 25); Walls walls = new Walls(80, 25); walls.DrawWalls(); int x1Offset = 81; int y1Offset = 1; Console.SetCursorPosition(x1Offset, y1Offset++); ShowMessage("POINTS:", x1Offset, y1Offset++); MyPoint tail = new MyPoint(6, 5, Convert.ToChar("\u2588")); Snake snake = new Snake(tail, 4, Direction.RIGHT); snake.DrawFigure(); FoodCatering foodCatered = new FoodCatering(80, 25, '$'); MyPoint food = foodCatered.CaterFood(); food.Draw(); int points = 1; while (true) { if (walls.IsHitByFigure(snake)) { Console.Beep(); break; } if (snake.Eat(food)) { Console.Beep(); food = foodCatered.CaterFood(); int x11ffset = 89; int y11ffset = 2; Console.SetCursorPosition(x11ffset, y11ffset++); Console.WriteLine($"{points}", x11ffset, y11ffset++); points++; food.Draw(); } else { snake.MoveSnake(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.ReadUserKey(key.Key); } } WriteGameOver(); int xxOffset = 52; int yyOffset = 10; Console.SetCursorPosition(xxOffset, yyOffset++); string userAnswer = Console.ReadLine(); if (userAnswer == "y") { Console.Clear(); goto Start; } else { int xOffset = 35; int yOffset = 8; Console.SetCursorPosition(xOffset, yOffset++); Console.Clear(); ShowMessage("BYE!", xOffset, yOffset++); } Console.ReadLine(); }
static void Main(string[] args) { /*Point p1 = new Point(5, 5, '*'); * p1.Draw(); * * Point p2 = new Point(6, 5, '*'); * p2.Draw(); * * Point p3 = new Point(7, 5, '*'); * p3.Draw(); * Point p4 = new Point(8, 5, '*'); * p4.Draw(); * Point p5 = new Point(9, 5, '*'); * p5.Draw(); * Console.ReadLine();*/ /*for(int i =5; i<10; i++) * { * MyPoint newPoint = new MyPoint(i, 5, '*'); * newPoint.Draw(); * MyPoint newPoint2 = new MyPoint(5, i, '#'); * newPoint2.Draw(); * } //list, mille sees on objektid, objekt klassis point*/ //Console.SetWindowSize(80, 25); ei tööta //Console.SetBufferSize(80, 25); /*HorizontalLines hrLine = new HorizontalLines(5,10, 10,'*'); * hrLine.DrawHorizontlLine(); * * VerticalLine vrLine = new VerticalLine(11, 20, 5, '#'); * vrLine.DrawVerticallLine(); * * HorizontalLines hrLine2 = new HorizontalLines(10, 15, 10, '*'); * hrLine2.DrawHorizontlLine(); * * VerticalLine vrLine2 = new VerticalLine(10, 15, 10, '#'); * vrLine2.DrawVerticallLine();*/ /*HorizontalLines topLine = new HorizontalLines(0, 78, 0, '*'); * topLine.DrawFigure(); * * HorizontalLines bottomLine = new HorizontalLines(0, 78, 24, '*'); * bottomLine.DrawFigure(); * * VerticalLine leftLine = new VerticalLine(0, 24, 0, '*'); * leftLine.DrawFigure(); * * VerticalLine rightLine = new VerticalLine(0, 24, 78, '*'); * rightLine.DrawFigure();*/ timer.Start(); Console.BackgroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.Blue; Console.Clear(); Walls walls = new Walls(80, 25); walls.DrawWalls(); MyPoint tail = new MyPoint(6, 5, '*'); Snake snake = new Snake(tail, 4, Direction.RIGHT); snake.DrawFigure(); //toidu serveerimine /*FoodCatering foodCatered = new FoodCatering(80, 25, '$'); * MyPoint food = foodCatered.CaterFood(); * food.Draw();*/ FoodCatering goodFood = new FoodCatering(80, 25, '€'); MyPoint goodF = goodFood.CaterGoodFood(); Console.ForegroundColor = ConsoleColor.Green; goodF.Draw(); FoodCatering badFood = new FoodCatering(80, 25, '@'); MyPoint badF = badFood.CaterBadFood(); Console.ForegroundColor = ConsoleColor.DarkRed; badF.Draw(); int scorePoints = 0; while (true) { if (walls.IsHitByFigure(snake)) { Console.Beep(); break; } if (snake.EatGoodFood(goodF)) { goodF = goodFood.CaterGoodFood(); Console.ForegroundColor = ConsoleColor.Green; scorePoints += 2; goodF.Draw(); badF.Draw(); } else if (snake.EatBadFood(badF)) { badF = badFood.CaterBadFood(); Console.ForegroundColor = ConsoleColor.DarkRed; scorePoints--; badF.Draw(); goodF.Draw(); } else { Console.ForegroundColor = ConsoleColor.Blue; snake.MoveSnake(); } Thread.Sleep(200); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); // loeb klahvi nuppu snake.ReadUserKey(key.Key); } } WriteGameOver(scorePoints); Console.ReadLine(); }