Exemple #1
0
        public void run()
        {
            while (true)
            {
                int count1 = twodimlist.Count;
                int count2 = threedimlist.Count;

                Console.WriteLine("\n\nTwoDim Shape : " + count1);
                Console.WriteLine("ThreeDim Shape : " + count2);
                Console.WriteLine("input len and shape");
                int Len = 0;
                try
                {
                    Len = Int32.Parse(Console.ReadLine());
                }
                catch (FormatException ex1)
                {
                    Console.WriteLine(ex1.Message);
                    continue;
                }
                if (Len == 0)
                {
                    break;
                }
                string shape = Console.ReadLine();
                int num = 0;
                foreach (var i in twodimlist)
                {
                    if (i.name == shape && i.len == Len)
                    {
                        Console.WriteLine("이미 존재함");
                        num = 1;
                        break;
                    }
                }
                foreach (var i in threedimlist)
                {
                    if (i.name == shape && i.len == Len)
                    {
                        Console.WriteLine("이미 존재함");
                        num = 1;
                        break;
                    }
                }
                if (num == 1)
                {
                    continue;
                }
                if (shape == "정삼각형")
                {
                    TwoDim Triangle = new triangle();
                    Triangle.name = shape;
                    Triangle.len = Len;
                    Triangle.Calarea();
                    Triangle.Calperimeter();
                    Triangle.print(Triangle.Area, Triangle.perimeter);
                    twodimlist.Add(Triangle);
                }
                else if (shape == "정사각형")
                {
                    TwoDim Square = new square();
                    Square.name = shape;
                    Square.len = Len;
                    Square.Calarea();
                    Square.Calperimeter();
                    Square.print(Square.Area, Square.perimeter);
                    twodimlist.Add(Square);
                }
                else if (shape == "원")
                {
                    TwoDim Circle = new circle();
                    Circle.name = shape;
                    Circle.len = Len;
                    Circle.Calarea();
                    Circle.Calperimeter();
                    Circle.print(Circle.Area, Circle.perimeter);
                    twodimlist.Add(Circle);
                }
                else if (shape == "구")
                {
                    ThreeDim Sphere = new sphere();
                    Sphere.name = shape;
                    Sphere.len = Len;
                    Sphere.Calarea();
                    Sphere.Calvolume();
                    Sphere.print(Sphere.Area, Sphere.volume);
                    threedimlist.Add(Sphere);
                }
                else if (shape == "정육면체")
                {
                    ThreeDim Cube = new cube();
                    Cube.name = shape;
                    Cube.len = Len;
                    Cube.Calarea();
                    Cube.Calvolume();
                    Cube.print(Cube.Area, Cube.volume);
                    threedimlist.Add(Cube);
                }
                else
                {
                    Console.WriteLine("Wrong input");
                }
            }
        }
Exemple #2
0
 static void Main()
 {
     square sq = new square(12);
       Console.WriteLine("Area of the square = {0}",sq.area());
 }
Exemple #3
0
        static void Main(string[] args)
        {
            square myLambdaExpression = x => x * x;

            Console.WriteLine("X squared is {0}", myLambdaExpression(5));

            GreaterThan gt = (x, y) => x > y;

            Console.WriteLine("Is 6 greater than 5. {0}", gt(6, 5));

            string myLocalString = "Hello World";

            //Call the function the normal way.
            WriteToConsoleForward(myLocalString);
            WriteToConsoleBackwards(myLocalString);

            //Call the function using a delegate.
            MyFirstDelegate myFirstDelegate = new MyFirstDelegate(LambdaExpressionExample.WriteToConsoleForward);

            myFirstDelegate(myLocalString);

            //Call the fuction by passing a reference to the function.
            WriteToConsole(LambdaExpressionExample.WriteToConsoleForward, myLocalString);
            WriteToConsole(LambdaExpressionExample.WriteToConsoleBackwards, myLocalString);

            //Create an anonymous method using the local variable.
            MyAnonymousMethod forward = delegate()
            {
                Console.WriteLine(string.Format("This is my string: {0}", myLocalString));
            };

            forward();

            //Create an anonymous method with the original delegate.
            MyFirstDelegate backward = delegate(string s2)
            {
                char[] charArray = s2.ToCharArray();
                Array.Reverse(charArray);
                Console.WriteLine(string.Format("This is my string backwards: {0}", new string(charArray)));
            };

            backward(myLocalString);

            //Use a Lambda expression statement with a local variable.
            MyAnonymousMethod myFirstDelegate2 = () =>
            {
                char[] charArray = myLocalString.ToCharArray();
                Array.Reverse(charArray);
                Console.WriteLine(string.Format("This is my string backwards: {0}", new string(charArray)));
            };

            myFirstDelegate2();

            //Use a Lambda expression statement with a parameter.
            MyFirstDelegate myFirstDelegate3 = s =>
            {
                char[] charArray = s.ToCharArray();
                Array.Reverse(charArray);
                Console.WriteLine(string.Format("This is my string backwards: {0}", new string(charArray)));
            };

            myFirstDelegate3(myLocalString);

            WriteToConsole(x => Console.WriteLine("This is my string {0}", x), "Hello World");

            Console.ReadLine();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            //Age age = new Age();
            //age.Ages();

            //average av = new average();
            //av.Averages();

            //basic_calculator calculator = new basic_calculator();
            //calculator.Calculator();

            //calculate_remainder_of_division remaind = new calculate_remainder_of_division();
            //remaind.Calculate();

            //comment comments = new comment();
            //comments.CommentOut();

            //conversion con = new conversion();
            //con.Conversion();

            //draw_a_rectangle_1 rectangle = new draw_a_rectangle_1();
            //rectangle.Draw();

            //equivalent_operations equ = new equivalent_operations();
            //equ.equivalent();

            //formats_and_lines form = new formats_and_lines();
            //form.FormatLine();

            //formats fo = new formats();
            //fo.format();

            //hello_world hello = new hello_world();
            //hello.World();

            //multiple_operations mul = new multiple_operations();
            //mul.multiples();

            //multiplication_table tab = new multiplication_table();
            //tab.table();

            //multiply_using_variables use = new multiply_using_variables();
            //use.variables();

            //reading_user_input read = new reading_user_input();
            //read.reading();

            //the_division divide = new the_division();
            //divide.division();

            //the_sum add = new the_sum();
            //add.sum();

            //positive_and_negative posAndNeg = new positive_and_negative();
            //posAndNeg.PositivAndNegative();

            //multiply_if_not_zero multi = new multiply_if_not_zero();
            //multi.multi();

            //divide_if_not_zero ifDivide = new divide_if_not_zero();
            //ifDivide.divideif();

            //greatest_of_three_numbers great = new greatest_of_three_numbers();
            //great.greatestNumber();

            //repeat_until_0 repeat = new repeat_until_0();
            //repeat.repeat();

            //repeat repeats = new repeat();
            //repeats.repeats();

            //while_count counts = new while_count();
            //counts.count();

            //times_table timesTable = new times_table();
            //timesTable.times();

            //odd_numbers_descending oddNumbers = new odd_numbers_descending();
            //oddNumbers.oddNumbers();

            //sum_numbers sum = new sum_numbers();
            //sum.sum();

            //two_negatives negative = new two_negatives();
            //negative.twoNegative();

            //one_or_two_negative oneNegative = new one_or_two_negative();
            //oneNegative.oneTwoNegative();

            //multiples multi = new multiples();
            //multi.Multiple();

            //number_repeated numberRepeated = new number_repeated();
            //numberRepeated.numberRepeat();

            //password1 pass = new password1();
            //pass.passwordOne();

            //password2 passTwo = new password2();
            //passTwo.passwordTwo();

            //many_divisions many = new many_divisions();
            //many.ManyDivisions();

            //several_mutiplication_tables_do_while severalMutiplication = new several_mutiplication_tables_do_while();
            //severalMutiplication.mutiplicationTable();

            square square = new square();

            square.Square();
        }
 // References the shape object as an square
 public classA(Shape shape)
 {
     square d = (square)shape;
     d.Draw += new EventHandler(d_Draw);
 }
Exemple #6
0
    public bool IsWalkable(int _iCol, int _iRow)
    {
        square Square = GetSquare(_iCol, _iRow);

        return(Square != null && Square.GetAlive() == false);
    }
Exemple #7
0
 Some: p => CreateIterator(square, position, pieceEnum)
 );
Exemple #8
0
        private bool checkMate(square[,] squares)
        {
            //TODO
            //Fix issue where in multiplayer, pieces switch from alive to dead
            //                **Should be fixed, keep testing
            //More checkMate() optimizations might be required
            square[,] nsqrs = new square[8, 8];
            Array.Copy(squares, nsqrs, squares.Length);

            MoveBoard[,] movboard = new MoveBoard[8, 8];

            MoveBoard[,] nmovbrd = new MoveBoard[8, 8];

            Panel[,] pan = new Panel[8, 8];
            Array.Copy(game.renderer, pan, game.renderer.Length);

            Piece[] oppPieces = new Piece[16];
            Array.Copy(game.opponentPieces, oppPieces, game.opponentPieces.Length);

            //define both kings
            Piece bking = new Piece();
            Piece wking = new Piece();

            for (int a = 0; a < 8; a++)
            {
                for (int b = 0; b < 8; b++)
                {
                    if (squares[a, b].name == "bking")
                    {
                        bking.name = "bking";
                        bking.type = PTypes.king;
                        bking.x    = a;
                        bking.y    = b;
                    }
                    else if (squares[a, b].name == "wking")
                    {
                        wking.name = "wking";
                        wking.type = PTypes.king;
                        wking.x    = a;
                        wking.y    = b;
                    }
                }
            }

            bool inCheck = false;

            if (userTurn)
            {
                foreach (Piece pice in game.userPieces)
                {
                    showValidMoves(pice, nsqrs, ref movboard, ref pan);

                    Array.Copy(movboard, nmovbrd, movboard.Length);
                    Array.Copy(game.opponentPieces, oppPieces, game.opponentPieces.Length);

                    //reset background color
                    for (int a = 0; a < 8; a++)
                    {
                        for (int b = 0; b < 8; b++)
                        {
                            if (a % 2 == 0)
                            {
                                game.renderer[a, b].BackColor = (b % 2 == 0) ? Color.White : Color.Gray;
                            }
                            else
                            {
                                game.renderer[a, b].BackColor = (b % 2 == 0) ? Color.Gray : Color.White;
                            }
                        }
                    }

                    inCheck = false;
                    for (int a = 0; a < 8; a++)
                    {
                        for (int b = 0; b < 8; b++)
                        {
                            Array.Copy(nmovbrd, movboard, movboard.Length);
                            if (movboard[a, b].moveable)
                            {
                                move(pice, a, b, true, ref nsqrs, out inCheck);
                                Array.Copy(oppPieces, game.opponentPieces, game.opponentPieces.Length);
                                if (inCheck)
                                {
                                    inCheck = true;
                                }
                                else
                                {
                                    //reset background color
                                    for (int x = 0; x < 8; x++)
                                    {
                                        for (int y = 0; y < 8; y++)
                                        {
                                            if (x % 2 == 0)
                                            {
                                                game.renderer[x, y].BackColor = (y % 2 == 0) ? Color.White : Color.Gray;
                                            }
                                            else
                                            {
                                                game.renderer[x, y].BackColor = (y % 2 == 0) ? Color.Gray : Color.White;
                                            }
                                        }
                                    }
                                    Array.Copy(oppPieces, game.opponentPieces, game.opponentPieces.Length);
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (Piece pice in game.opponentPieces)
                {
                    showValidMoves(pice, nsqrs, ref movboard, ref pan);

                    inCheck = false;
                    for (int a = 0; a < 8; a++)
                    {
                        for (int b = 0; b < 8; b++)
                        {
                            if (movboard[a, b].moveable)
                            {
                                move(bking, a, b, true, ref nsqrs, out inCheck);
                                Array.Copy(oppPieces, game.opponentPieces, game.opponentPieces.Length);
                                if (inCheck)
                                {
                                    inCheck = true;
                                }
                                else
                                {
                                    //reset background color
                                    for (int x = 0; x < 8; x++)
                                    {
                                        for (int y = 0; y < 8; y++)
                                        {
                                            if (x % 2 == 0)
                                            {
                                                game.renderer[x, y].BackColor = (y % 2 == 0) ? Color.White : Color.Gray;
                                            }
                                            else
                                            {
                                                game.renderer[x, y].BackColor = (y % 2 == 0) ? Color.Gray : Color.White;
                                            }
                                        }
                                    }
                                    Array.Copy(oppPieces, game.opponentPieces, game.opponentPieces.Length);
                                    return(false);
                                }
                            }
                        }
                    }
                }
                //reset background color
                for (int x = 0; x < 8; x++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        if (x % 2 == 0)
                        {
                            game.renderer[x, y].BackColor = (y % 2 == 0) ? Color.White : Color.Gray;
                        }
                        else
                        {
                            game.renderer[x, y].BackColor = (y % 2 == 0) ? Color.Gray : Color.White;
                        }
                    }
                }
            }

            Array.Copy(oppPieces, game.opponentPieces, game.opponentPieces.Length);
            if (inCheck)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #9
0
        public void MySquareAreaTest()
        {
            square square = new square(3);

            Assert.AreEqual(9, square.Area());
        }
Exemple #10
0
        static void Main(string[] args)
        {
            bool play      = true;
            int  highScore = 0;

            //Continues until player wants to quit the game
            while (true)
            {
                //Sets up the console size and the first position of the snake
                Console.WindowHeight = 30;
                Console.WindowWidth  = 61;
                int    width  = Console.WindowWidth;
                int    height = Console.WindowHeight;
                square snake  = new square();
                snake.xpos  = 4;
                snake.ypos  = 6;
                snake.color = ConsoleColor.DarkGreen;
                int        movement = 0;
                List <int> pastx    = new List <int>();
                List <int> pasty    = new List <int>();
                pastx.Add(12);
                pastx.Add(8);
                pastx.Add(6);
                pasty.Add(5);
                pasty.Add(5);
                pasty.Add(5);
                pastx.Add(8);
                pasty.Add(8);

                //Places the food piece in a random poisiton in the console
                Random RanPos = new Random();
                int    foodx  = RanPos.Next(2, width - 2);
                if (foodx % 2 == 1)
                {
                    foodx++;
                }
                int     foody    = RanPos.Next(2, height - 2);
                int     score    = 0;
                int     point    = 10;
                int     length   = 3;
                Boolean GameOver = false;



                //Colors in the left and right side of the console
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                for (int n = 0; n < height; n++)
                {
                    Console.SetCursorPosition(0, n);
                    Console.Write("█");
                    Console.SetCursorPosition(1, n);
                    Console.Write("█");
                    Console.SetCursorPosition(width - 1, n);
                    Console.Write("█");
                    Console.SetCursorPosition(width - 2, n);
                    Console.Write("█");
                }
                //Colors in the top and bottom of the console
                for (int n = 0; n < width; n++)
                {
                    Console.SetCursorPosition(n, 0);
                    Console.Write("█");
                    Console.SetCursorPosition(n, 1);
                    Console.Write("█");
                    Console.SetCursorPosition(n, height - 1);
                    Console.Write("█");
                    Console.SetCursorPosition(n, height - 2);
                    Console.Write("█");
                }
                //Colors in the food in console
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.SetCursorPosition(foodx, foody);
                Console.Write("■");

                //Writes in the score and Highscore in console
                Console.ForegroundColor = ConsoleColor.White;
                Console.SetCursorPosition(2, height - 1);
                Console.Write("Score:");
                Console.SetCursorPosition(9, height - 1);
                Console.Write(score);
                Console.SetCursorPosition(2, 0);
                Console.Write("High Score:");
                Console.SetCursorPosition(14, 0);
                Console.Write(highScore);

                //Continues until player runs into wall or itself
                while (true)
                {
                    //Draws the head of the snake to be darkgreen
                    Console.SetCursorPosition(pastx[length], pasty[length]);
                    Console.Write(" ");
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.SetCursorPosition(pastx[0], pasty[0]);
                    Console.Write("■");

                    //Draws the rest of the snake the color green
                    for (int n = 1; n < length; n++)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.SetCursorPosition(pastx[n], pasty[n]);
                        Console.Write("■");
                    }

                    //Moves the cursor so it is less visable
                    Console.SetCursorPosition(width - 1, height - 1);

                    //Test if it hit a wall
                    if (pastx[0] == 0 || pastx[0] == width - 1 || pasty[0] == 1 || pasty[0] == height - 2)
                    {
                        GameOver = true;
                    }
                    //Test if it hits itself
                    for (int n = 1; n < length; n++)
                    {
                        if (pastx[0] == pastx[n] && pasty[0] == pasty[n])
                        {
                            GameOver = true;
                        }
                    }
                    //If gameover stop game
                    if (GameOver)
                    {
                        break;
                    }

                    //Set to read the disired derection of the snake
                    int before = movement;
                    for (int x = 0; x < 10000; x++)
                    {
                        if (Console.KeyAvailable)
                        {
                            ConsoleKeyInfo Pressed = Console.ReadKey(true);
                            if (Pressed.Key.Equals(ConsoleKey.RightArrow) && before != 2)
                            {
                                movement = 0;
                            }
                            if (Pressed.Key.Equals(ConsoleKey.UpArrow) && before != 3)
                            {
                                movement = 1;
                            }
                            if (Pressed.Key.Equals(ConsoleKey.LeftArrow) && before != 0)
                            {
                                movement = 2;
                            }
                            if (Pressed.Key.Equals(ConsoleKey.DownArrow) && before != 1)
                            {
                                movement = 3;
                            }
                        }
                    }
                    //What ever direction is decided the new position is recorded
                    if (movement == 0)
                    {
                        pastx.Insert(0, pastx[0] + 2);
                        pasty.Insert(0, pasty[0]);
                    }
                    if (movement == 1)
                    {
                        pastx.Insert(0, pastx[0]);
                        pasty.Insert(0, pasty[0] - 1);
                    }
                    if (movement == 2)
                    {
                        pastx.Insert(0, pastx[0] - 2);
                        pasty.Insert(0, pasty[0]);
                    }
                    if (movement == 3)
                    {
                        pastx.Insert(0, pastx[0]);
                        pasty.Insert(0, pasty[0] + 1);
                    }
                    //Checks if the new position is where a piece of food is. If so add 1 to the length of the snake
                    if (pastx[0] == foodx && pasty[0] == foody)
                    {
                        length++;
                        Boolean match = true;
                        //Sets and draws the new position of the food piece
                        while (match)
                        {
                            foodx = RanPos.Next(2, width - 2);
                            if (foodx % 2 == 1)
                            {
                                foodx++;
                            }

                            foody = RanPos.Next(2, height - 2);
                            int x = 0;
                            for (int n = 0; n < length; n++)
                            {
                                if (foodx == pastx[n] && foody == pasty[n])
                                {
                                    x++;
                                    break;
                                }
                            }
                            if (x == 0)
                            {
                                match = false;
                            }
                        }
                        Console.ForegroundColor = ConsoleColor.Blue;
                        Console.SetCursorPosition(foodx, foody);

                        Console.Write("■");
                        //adds 10 to the score and draws the new score total
                        score += point;
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.SetCursorPosition(8, height - 1);
                        Console.Write(score);
                    }
                }
                //If it is the first death it set the console screen to say "You got the wiggly" and play Rick Astley
                if (play)
                {
                    System.Diagnostics.Process.Start(".\\RickRoll.exe");
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.SetCursorPosition(5, 5);
                    Console.Write(" __   __                     ____           _    ");
                    Console.SetCursorPosition(5, 6);
                    Console.Write(" \\ \\ / /   ___    _   _     / ___|   ___   | |_  ");
                    Console.SetCursorPosition(5, 7);
                    Console.Write("  \\ V /   / _ \\  | | | |   | |  _   / _ \\  | __|");
                    Console.SetCursorPosition(5, 8);
                    Console.Write("   | |   | (_) | | |_| |   | |_| | | (_) | | |_   ");
                    Console.SetCursorPosition(5, 9);
                    Console.Write("   |_|    \\___/   \\__,_|    \\____|  \\___/   \\__|     ");
                    Console.SetCursorPosition(18, 10);
                    Console.Write(" _____   _   _   _____ ");
                    Console.SetCursorPosition(18, 11);
                    Console.Write("|_   _| | | | | | ____|");
                    Console.SetCursorPosition(18, 12);
                    Console.Write("  | |   | |_| | |  _|  ");
                    Console.SetCursorPosition(18, 13);
                    Console.Write("  | |   |  _  | | |___");
                    Console.SetCursorPosition(18, 14);
                    Console.Write("  |_|   |_| |_| |_____|  ");
                    Console.SetCursorPosition(6, 15);
                    Console.Write(" __        __  _                   _         ");
                    Console.SetCursorPosition(6, 16);
                    Console.Write(" \\ \\      / / (_)   __ _    __ _  | |  _   _ ");
                    Console.SetCursorPosition(6, 17);
                    Console.Write("  \\ \\ /\\ / /  | |  / _` |  / _` | | | | | | |");
                    Console.SetCursorPosition(6, 18);
                    Console.Write("   \\ V  V /   | | | (_| | | (_| | | | | |_| |");
                    Console.SetCursorPosition(6, 19);
                    Console.Write("    \\_/\\_/    |_|  \\__, |  \\__, | |_|  \\__, |");
                    Console.SetCursorPosition(6, 20);
                    Console.Write("                   |___/   |___/       |___/ ");

                    play = false;
                }
                //Playes game over symbol and prompts the person to play again or quit
                Console.ForegroundColor = ConsoleColor.White;
                Console.SetCursorPosition(22, 23);
                Console.Write("GAME OVER");
                Console.SetCursorPosition(22, 24);
                Console.Write("Play Again: Y");
                Console.ForegroundColor = ConsoleColor.White;
                Console.SetCursorPosition(22, 25);
                Console.Write("Quit: N");



                // __   __                     ____           _       _____   _   _   _____    __        __  _                   _
                // \ \ / /   ___    _   _     / ___|   ___   | |_    |_   _| | | | | | ____|   \ \      / / (_)   __ _    __ _  | |  _   _
                //  \ V /   / _ \  | | | |   | |  _   / _ \  | __|     | |   | |_| | |  _|      \ \ /\ / /  | |  / _` |  / _` | | | | | | |
                //   | |   | (_) | | |_| |   | |_| | | (_) | | |_      | |   |  _  | | |___      \ V  V /   | | | (_| | | (_| | | | | |_| |
                //   |_|    \___/   \__,_|    \____|  \___/   \__|     |_|   |_| |_| |_____|      \_/\_/    |_|  \__, |  \__, | |_|  \__, |
                //                                                                                                |___/   |___/       |___/


                Boolean end = false;
                //Reads in if the user types y or n
                while (true)
                {
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo Pressed = Console.ReadKey(true);
                        if (Pressed.Key.Equals(ConsoleKey.Y))
                        {
                            break;
                        }
                        if (Pressed.Key.Equals(ConsoleKey.N))
                        {
                            end = true;
                            break;
                        }
                    }
                }
                if (end)
                {
                    break;
                }
                //Updates highscore
                if (score > highScore)
                {
                    highScore = score;
                }
                //Clears console
                Console.Clear();
            }
        }