Exemplo n.º 1
0
 public MyPoint(MyPoint _p)
 {
     x      = _p.x;
     y      = _p.y;
     symbol = _p.symbol;
 }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Menu");
            Console.WriteLine("===============================");
            Console.WriteLine("L - Working with Lines");
            Console.WriteLine("C - Working with Circles");
            Console.WriteLine("S - Working with Squars");
            Console.WriteLine("T - Working with Triangles");
            Console.WriteLine("Q - Quit");
            Console.WriteLine("===============================");
            Console.WriteLine("Enter Choice: ");
            Char answer = char.Parse(Console.ReadLine());

            while ((answer != 'q') && (answer != 'Q'))
            {
                switch (answer)
                {
                case 'L':
                case 'l':
                    Console.WriteLine("enter x value of the first point:");
                    int xLine1 = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the first point:");
                    int yLine1 = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter x value of the second point:");
                    int xLine2 = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the second point:");
                    int     yLine2 = int.Parse(Console.ReadLine());
                    MyPoint p1Line = new MyPoint(xLine1, yLine1);
                    MyPoint p2Line = new MyPoint(xLine2, yLine2);
                    Line    Line   = new Line(p1Line, p2Line);
                    Line.print_deatails();
                    break;

                case 'c':
                case 'C':
                    Console.WriteLine("enter x value of the first point of the Raduis:");
                    int x1Radius = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the first point of the Raduis:");
                    int y1Radius = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter x value of the second point of the Radius:");
                    int x2Radius = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the second point of the Radius:");
                    int     y2Radius = int.Parse(Console.ReadLine());
                    MyPoint p1Radius = new MyPoint(x1Radius, y1Radius);
                    MyPoint p2Radius = new MyPoint(x2Radius, y2Radius);
                    Line    Radius   = new Line(p1Radius, p2Radius);
                    Circle  circle   = new Circle(Radius);
                    Radius.print_deatails();
                    Console.WriteLine("the S of the circle is: {0}", circle.GetSCircle());
                    Console.WriteLine("the P of the circle is: {0}", circle.GetPCircle());
                    break;

                case 's':
                case 'S':
                    Console.WriteLine("enter x value of the left above point of the squar:");
                    int x1Squar = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the left above point of the squar:");
                    int y1Squar = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter x value of the right above point of the squar:");
                    int x2Squar = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the right above point of the squar:");
                    int y2Squar = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter x value of the right down point of the squar:");
                    int x3Squar = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the right down above point of the squar:");
                    int y3Squar = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter x value of the left down point of the squar:");
                    int x4Squar = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the left down point of the squar:");
                    int     y4Squar = int.Parse(Console.ReadLine());
                    MyPoint p1Squar = new MyPoint(x1Squar, y1Squar);
                    MyPoint p2Squar = new MyPoint(x2Squar, y2Squar);
                    MyPoint p3Squar = new MyPoint(x3Squar, y3Squar);
                    MyPoint p4Squar = new MyPoint(x4Squar, y4Squar);
                    Squar   squar   = new Squar(p1Squar, p2Squar, p3Squar, p4Squar);
                    squar.print_squar();
                    Console.WriteLine("the S of the squar: {0}", squar.SSquar());
                    Console.WriteLine("the P of the squar :{0}", squar.PSquar());
                    break;

                case 'T':
                case 't':
                    Console.WriteLine("enter x value of the first point of the Triangle:");
                    int x1Triangle = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the first point of the Triangle:");
                    int y1Triangle = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter x value of the second point of the Triangle:");
                    int x2Triangle = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the second point of the Triangle:");
                    int y2Triangle = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter x value of the third point of the Triangle:");
                    int x3Triangle = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter y value of the third point of the Triangle:");
                    int     y3Triangle = int.Parse(Console.ReadLine());
                    MyPoint p1Triangle = new MyPoint(x1Triangle, y1Triangle);
                    MyPoint p2Triangle = new MyPoint(x2Triangle, y2Triangle);
                    MyPoint p3Triangle = new MyPoint(x3Triangle, y3Triangle);
                    Tringle Triangle   = new Tringle(p1Triangle, p2Triangle, p3Triangle);
                    Triangle.print_triangle();
                    Console.WriteLine("the S of the triangle: {0}", Triangle.STriangle());
                    Console.WriteLine("the P of the triangle: {0}", Triangle.PTriangle());
                    break;

                default: Console.WriteLine("try again");
                    break;
                }
                Console.WriteLine();
                Console.WriteLine("Enter another choice: ");
                answer = char.Parse(Console.ReadLine());
            }
        }
Exemplo n.º 4
0
 public bool IsHit(MyPoint _point)
 {
     return(_point.x == x && _point.y == y);
 }
Exemplo n.º 5
0
 public bool IsHit(MyPoint point)
 {
     //kontrollime kas punktid on ühel kohal
     return(point.x == x && point.y == y);
 }
Exemplo n.º 6
0
Arquivo: Line.cs Projeto: webarak/OOP
 public Line(MyPoint p1, MyPoint p2)//בנאי
 {
     this.p1 = p1;
     this.p2 = p2;
 }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
Arquivo: Line.cs Projeto: webarak/OOP
        public double line_length(MyPoint p1, MyPoint p2)//פעולה המחזירה את אורך הישר
        {
            double length = Math.Sqrt(Math.Pow((p1.Get_X() - p2.Get_X()), 2) + Math.Pow((p1.Get_Y() - p2.Get_Y()), 2));

            return(length);
        }
Exemplo n.º 11
0
        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();*/
        }
Exemplo n.º 12
0
Arquivo: Line.cs Projeto: webarak/OOP
 public void Set_p2(MyPoint p2)//set p2
 {
     this.p2 = p2;
 }
Exemplo n.º 13
0
Arquivo: Line.cs Projeto: webarak/OOP
 public void Set_p1(MyPoint p1)//set p1
 {
     this.p1 = p1;
 }
Exemplo n.º 14
0
Arquivo: Line.cs Projeto: webarak/OOP
 public Line()//בנאי
 {
     this.p1 = new MyPoint();
     this.p2 = new MyPoint();
 }
Exemplo n.º 15
0
 public bool IsHit(MyPoint point)
 {
     return(point.x == this.x && point.y == this.y);
 }
Exemplo n.º 16
0
 public bool IsHit(MyPoint point) //kui need puktid on samad, mis koordinaadid, siis true
 {
     return(point.x == x && point.y == y);
 }
Exemplo n.º 17
0
 public double Distance(MyPoint point)
 {
     return(Distance(point.X, point.Y));
 }
Exemplo n.º 18
0
        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();
        }