static void Main(string[] args) { //Seinte/äärte tegemine //Windows arvuti jaoks, kui on eraldi aken, kus asju kuvatakse, macis need kordinaadid ei tööta: //Console.SetWindowSize(80,25); ja Console.SetBufferSize(80,25); Walls walls = new Walls(80, 25); walls.DrawWalls(); //ussi punktid MyPoint tail = new MyPoint(6, 5, '*'); Snake snake = new Snake(tail, 4, Direction.RIGHT); snake.DrawFigure(); FoodCatering foodCatered = new FoodCatering(80, 24, '$'); 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(200); if (Console.KeyAvailable == true) { var key = Console.ReadKey(true); snake.ReadUserKey(key.Key); } } WriteGameOver(); }
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, Direction.RIGHT); snake.DrawFigure(); FoodCatering foodCatered = new FoodCatering(80, 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(); }
static void Main(string[] args) { /* Point p1 = new Point(10, 10, '*'); * p1.Draw(); * Point p2 = new Point(10, 11, '*'); * p2.Draw(); * Point p3 = new Point(10, 12, '*'); * p3.Draw(); * Point p4 = new Point(10, 13, '*'); * p4.Draw(); * Point p5 = new Point(10, 14, '*'); * p5.Draw(); * * Point p6 = new Point(11, 10, '*'); * p6.Draw(); * Point p7 = new Point(12, 10, '*'); * p7.Draw(); * Point p8 = new Point(13, 10, '*'); * p8.Draw(); * Point p9 = new Point(14, 10, '*'); * p9.Draw(); */ /* for (int i = 5; i < 10; i++) * { * MyPoint newPoint = new MyPoint(i, 5, '*'); * newPoint.Draw(); * MyPoint newPoint2 = new MyPoint(5, i, '*'); * newPoint2.Draw(); * } */ Console.SetWindowSize(100, 30); Console.SetBufferSize(100, 30); /* HorizontalLine topLine = new HorizontalLine(0, 78, 0, '*'); * Console.ForegroundColor = ConsoleColor.Yellow; * topLine.DrawFigure(); * HorizontalLine buttomLine = new HorizontalLine(0, 78, 24, '*'); * Console.ForegroundColor = ConsoleColor.Yellow; * buttomLine.DrawFigure(); * * VerticalLine leftLine = new VerticalLine( 0, 24, 0, '*'); * Console.ForegroundColor = ConsoleColor.Blue; * leftLine.DrawFigure(); * VerticalLine rightLine = new VerticalLine(0, 24, 78, '*'); * Console.ForegroundColor = ConsoleColor.Magenta; * rightLine.DrawFigure(); */ Walls walls = new Walls(80, 25); walls.DrawWalls(); MyPoint tail = new MyPoint(6, 5, '#'); Snake snake = new Snake(tail, 4, Direction.RIGHT); snake.DrawFigure(); FoodCatering foodCatered = new FoodCatering(80, 25, '$'); Console.ForegroundColor = ConsoleColor.Red; MyPoint food = foodCatered.CaterFood(); food.Draw(); int Count = 0; while (true) { if (walls.IsHitByFigure(snake)) { break; } if (snake.Eat(food)) { food = foodCatered.CaterFood(); Console.ForegroundColor = ConsoleColor.Red; food.Draw(); Console.Beep(); Count++; } else { Console.ForegroundColor = ConsoleColor.Green; snake.MoveSnake(); } ShowScore(Count); Thread.Sleep(100 - Count * 3); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.ReadUserKey(key.Key); } } WriteGameOver(); FinalScore(Count); Console.ReadLine(); }
public static void Main(string[] args) { //Console.SetWindowSize(80, 25); //Console.SetBufferSize(80, 25); /*HorizontalLine topLine = new HorizontalLine(0, 78, 0, '*'); * topLine.DrawFigure(); * HorizontalLine bottomLine = new HorizontalLine(0, 78, 24, '*'); * bottomLine.DrawFigure(); * VerticalLine leftLine = new VerticalLine(0, 24, 0, '*'); * leftLine.DrawFigure(); * VerticalLine rightLine = new VerticalLine(0, 24, 78, '*'); * rightLine.DrawFigure(); * * HorizontalLine hrLine = new HorizontalLine(5, 10, 10, '*'); * hrLine.DrawFigure(); * VerticalLine vrLine = new VerticalLine(11, 20, 5, '*'); * vrLine.DrawFigure();*/ Console.BackgroundColor = ConsoleColor.White; Walls walls = new Walls(80, 25); walls.DrawWalls(); Bridge bridges = new Bridge(); bridges.DrawBridges(); MyPoint tail = new MyPoint(6, 5, '*'); Snake snake = new Snake(tail, 4, Direction.RIGHT); snake.DrawFigure(); Console.BackgroundColor = ConsoleColor.White; /*snake.MoveSnake(); * Thread.Sleep(100); * snake.MoveSnake(); * Thread.Sleep(100); * snake.MoveSnake(); * Thread.Sleep(100); * snake.MoveSnake();*/ FoodCatering foodCatered = new FoodCatering(78, 24, '€'); MyPoint food = foodCatered.CaterFood(); food.Draw(); while (true) { Thread.Sleep(100); if (walls.IsHitByFigure(snake)) { break; } if (walls.HitsTheObstacle(snake)) { break; } if (snake.Eat(food)) { food = foodCatered.CaterFood(); food.Draw(); } else { snake.MoveSnake(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.ReadUserKey(key.Key); /*if (key.Key == ConsoleKey.LeftArrow) * { * snake.Direction = Direction.LEFT; * } * else if (key.Key == ConsoleKey.RightArrow) * { * snake.Direction = Direction.RIGHT; * } * else if (key.Key == ConsoleKey.UpArrow) * { * snake.Direction = Direction.UP; * } * else if (key.Key == ConsoleKey.DownArrow) * { * snake.Direction = Direction.DOWN; * }*/ } } Console.Clear(); WriteGameOver(); Console.ReadLine(); }
static void Main(string[] args) { /*Point p1 = new Point(10, 10, '*'); * p1.Draw(); * * Point p2 = new Point(10, 11, '*'); * p2.Draw(); * * Point p3 = new Point(10, 12, '*'); * p3.Draw(); * * Point p4 = new Point(10, 13, '*'); * p4.Draw(); * * Point p5 = new Point(10, 14, '*'); * p5.Draw(); * * Point p6 = new Point(11, 10, '*'); * p6.Draw(); * * Point p7 = new Point(12, 10, '*'); * p7.Draw(); * * Point p8 = new Point(13, 10, '*'); * p8.Draw(); * * Point p9 = new Point(14, 10, '*'); * p9.Draw(); Esimmene võimalus*/ /*for (int i = 5; i < 10; i++) * { * Point newPoint = new Point(i, 5, '*'); * newPoint.Draw(); * Point newPoint2 = new Point(5, i, '*'); * newPoint2.Draw(); * * }Teine võimalus*/ /// Kolmas võimalus, luua eraldi klass horisontaaljoone jaoks: Console.BackgroundColor = ConsoleColor.White; ////Koos Clear () tuleb kasutada ning saab konsooli tagatausta värvida. Console.Clear(); Console.SetWindowSize(40, 26); ////sellega saab piirata konsooli akna suurust Console.SetBufferSize(40, 26); ///sellega scrolli maha, ehk piirata konsooli akna tegelikku mahutavust Console.ForegroundColor = ConsoleColor.Black; Walls walls = new Walls(26, 26); walls.DrawWalls(); ////Selle kohta tegime uue klassi Walls /*HorizontalLine topLine = new HorizontalLine(0, 24, 0, '*'); * //topLine.DrawHorizontalLine(); nüüd kasutame Figure klassi meetodit * topLine.DrawFigure(); * * VerticalLine leftVerticalLIne = new VerticalLine(0, 24, 0, '*'); * ///leftVerticalLIne.DrawVerticalLine(); nüüd kasutame Figure klassi meetodit * leftVerticalLIne.DrawFigure(); * * HorizontalLine buttonLine = new HorizontalLine(1, 24, 24, '*'); * ///buttonLine.DrawHorizontalLine(); nüüd kasutame Figure klassi meetodit * buttonLine.DrawFigure(); * * VerticalLine rightVerticalLIne = new VerticalLine(0, 24, 24, '*'); * ///rightVerticalLIne.DrawVerticalLine(); nüüd kasutame Figure klassi meetodit * rightVerticalLIne.DrawFigure();*/ Point tail = new Point(6, 5, '*'); Snake snake = new Snake(tail, 4, Direction.RIGHT); snake.DrawFigure(); FoodCatering foodCatering = new FoodCatering(26, 26, '$'); Point food = foodCatering.CaterFood(); food.Draw(); FoodCatering foodCatering2 = new FoodCatering(26, 26, '%'); Point food2 = foodCatering2.CaterFood2(); food2.Draw(); Score scoreCalculation = new Score(); /*while (true) * { * if (Console.KeyAvailable) * { * ConsoleKeyInfo key = Console.ReadKey(); * * if (key.Key == ConsoleKey.LeftArrow) * { * snake.Direction = Direction.LEFT; * } * else if (key.Key == ConsoleKey.RightArrow) * { * snake.Direction = Direction.RIGHT; * } * else if (key.Key == ConsoleKey.UpArrow) * { * snake.Direction = Direction.UP; * } * else if (key.Key == ConsoleKey.DownArrow) * { * snake.Direction = Direction.DOWN; * } * * } * * snake.MoveSnake(); * Thread.Sleep(300); ////See muudab ussi kiirust * * }See läks Snake klassi sisse meetodina readUserKey*/ int score = 0; PrintScore(); scoreCalculation.GetScore(score, 33, 1); while (true) { if (walls.IsHitByFigure(snake)) { break; } if (snake.Eat(food) || snake.Eat(food2)) { Random rnd3 = new Random(); int choise = rnd3.Next(1, 3); if (choise == 1) { food = foodCatering.CaterFood(); food.Draw(); Console.Beep(); score++; scoreCalculation.AddPoint(); } else if (choise == 2) { food2 = foodCatering2.CaterFood2(); food2.Draw(); score = score + 2; scoreCalculation.AddPoint(); } } else { snake.MoveSnake(); } Thread.Sleep(200); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.ReadUserKey(key.Key); } } WriteGameOver(score); Console.ReadLine(); }
static void Main(string[] args) { Console.SetWindowSize(110, 25); Console.SetBufferSize(110, 25); string username = GetUsername(); Console.Clear(); Walls walls = new Walls(80, 25); walls.DrawWalls(); MyPoint tail = new MyPoint(6, 20, '*'); Snake snake = new Snake(tail, 4, Direction.RIGHT); snake.DrawFigure(); FoodCatering foodCatered = new FoodCatering(80, 25, '$'); MyPoint goodFood = foodCatered.CaterFood(); goodFood.Draw(); MyPoint badFood = foodCatered.CaterFood(); Console.ForegroundColor = ConsoleColor.Red; badFood.Draw(); Console.ForegroundColor = ConsoleColor.White; int playerScore = 0; int snakeSpeed = 300; while (true) { Thread.Sleep(snakeSpeed); ShowMessage($"{username}'s score: {playerScore}", 82, 0); if (walls.IsHitByFigure(snake)) { break; } if (snake.Eat(goodFood)) { goodFood = foodCatered.CaterFood(); playerScore++; ShowMessage($"{username}'s score: {playerScore}", 82, 0); ShowMessage($"You ate some good food", 82, 1); ShowMessage($"+1 score", 82, 2); goodFood.Draw(); if (snakeSpeed > 140) { snakeSpeed -= 20; Thread.Sleep(snakeSpeed); } } else if (snake.Eat(badFood)) { badFood = foodCatered.CaterFood(); playerScore--; ShowMessage($"{username}'s score: {playerScore}", 82, 0); ShowMessage($"You ate some bad food ", 82, 1); ShowMessage($"-1 score", 82, 2); Console.ForegroundColor = ConsoleColor.Red; badFood.Draw(); Console.ForegroundColor = ConsoleColor.White; if (snakeSpeed > 140) { snakeSpeed -= 20; Thread.Sleep(snakeSpeed); } } else { snake.MoveSnake(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.ReadUserKey(key.Key); } } WriteGameOver(username, playerScore); Console.ReadLine(); }
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) { /*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 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();*/ decimal gameSpeed = 200m; Walls walls = new Walls(80, 25); walls.DrawWalls(); MyPoint tail = new MyPoint(6, 5, '*'); Snake snake = new Snake(tail, 4, Direction.RIGHT); //loome ussi snake.DrawFigure(); FoodCatering foodCatered = new FoodCatering(80, 25, '@'); //loome söögi talle MyPoint food = foodCatered.CaterFood(); food.Draw(); Console.ForegroundColor = ConsoleColor.Blue; int score = 0; while (true) { if (walls.IsHitByFigure(snake)) { Console.Beep(); break; } if (snake.Eat(food)) //kui sööb ära { food = foodCatered.CaterFood(); food.Draw(); score++; gameSpeed *= .952m; } else // kui uss pole midagi söönud, siis liigu edasi { snake.MoveSnake(); } System.Threading.Thread.Sleep(Convert.ToInt32(gameSpeed)); //vaikselt liiguks if (Console.KeyAvailable) //kui nupp oli vajutatud { ConsoleKeyInfo key = Console.ReadKey(); //loeb vajutust snake.ReadUserKey(key.Key); } } WriteGameOver(score); //teeme meetodi, et mäng on läbi /*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();*/ Console.ReadLine(); }
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) { 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();*/ }