Beispiel #1
0
        public static void Table()
        {
            string up     = ("      1       2       3");
            string one    = ("  |       |       |       |");
            string two    = ("1 |   " + first + "   |   " + second + "   |   " + third + "   |");
            string three  = ("  |       |       |       |");
            string four   = ("  |-------|-------|-------|");
            string five   = ("  |       |       |       |");
            string six    = ("2 |   " + fourth + "   |   " + fifth + "   |   " + sixth + "   |");
            string seven  = ("  |       |       |       |");
            string eigh   = ("  |-------|-------|-------|");
            string nine   = ("  |       |       |       |");
            string ten    = ("3 |   " + seventh + "   |   " + eight + "   |   " + nineth + "   |");
            string eleven = ("  |       |       |       |");
            string zero   = ("   -----------------------");

            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 11, up);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 10, zero);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 9, one);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 8, two);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 7, three);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 6, four);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 5, five);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 4, six);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 3, seven);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 2, eigh);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 1, nine);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 - 0, ten);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 1, eleven);
            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 2, zero);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            /////////////////main start
            ///

            Console.WindowHeight = 30;
            Console.WindowWidth  = 120;

            Console.CursorVisible = false;
            Console.BufferHeight  = Console.WindowHeight;
            Console.BufferWidth   = Console.WindowWidth;



            Console.Title = "TicTacToe \"Network edition\" 2.0";

            Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");

            Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");

            //Show menu
            SelectMenu();



            Console.ReadKey();
            //////////////Main end
        }
Beispiel #3
0
        public static void SelectMenu()
        {
            int index = 0;

            Display.WriteYellow(menuX, menuY, "Start");

            Display.WriteWhite(menuX, menuY + 2, "Exit");

            while (true)
            {
                ClearKeyBuffer();

                ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                if (keyInfo.Key == ConsoleKey.UpArrow)
                {
                    if (index - 1 == 0)
                    {
                        index--;
                        Console.BackgroundColor = color;
                        Display.WriteYellow(menuX, menuY, "Start");
                        Display.WriteWhite(menuX, menuY + 2, "Exit");
                        Console.BackgroundColor = color;
                    }
                }
                if (keyInfo.Key == ConsoleKey.DownArrow)
                {
                    if (index + 1 == 1)
                    {
                        index++;
                        Console.BackgroundColor = color;
                        Display.WriteWhite(menuX, menuY, "Start");
                        Display.WriteYellow(menuX, menuY + 2, "Exit");
                        Console.BackgroundColor = color;
                    }
                }
                if (keyInfo.Key == ConsoleKey.Enter)
                {
                    Console.Clear();
                    if (index == 1)
                    {
                        Chosen = StartMenuSelection.Exit;
                    }
                    if (index == 0)
                    {
                        Chosen = StartMenuSelection.Start;
                    }
                    if (Chosen == StartMenuSelection.Exit)
                    {
                        Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");
                        Display.WriteCyan(centerX - 10, centerY - 5, "Thanks for playing!");
                        Thread.Sleep(2000);
                        Environment.Exit(0);
                    }
                    else
                    {
                        Console.Clear();
                        SelectMenuHostOrClient();
                    }
                }
            }
        }
Beispiel #4
0
        public static void HostMenu()
        {
            Console.Clear(); Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");

            Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");

            Display.WriteYellow(menuX - 5, menuY + 2, "Port number: " + Port);
            Display.WriteWhite(menuX - 5, menuY + 4, "Start");
            Display.WriteWhite(menuX - 5, menuY + 8, "Back");

            int index = 0;

            while (true)
            {
                ClearKeyBuffer();

                ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                if (keyInfo.Key == ConsoleKey.UpArrow)
                {
                    if (index - 1 == 0)
                    {
                        index--;
                        Display.WriteYellow(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteWhite(menuX - 5, menuY + 4, "Start");
                        Display.WriteWhite(menuX - 5, menuY + 8, "Back");
                    }
                    if (index - 1 == 1)
                    {
                        index--;
                        Display.WriteWhite(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteYellow(menuX - 5, menuY + 4, "Start");
                        Display.WriteWhite(menuX - 5, menuY + 8, "Back");
                    }
                }
                if (keyInfo.Key == ConsoleKey.DownArrow)
                {
                    if (index + 1 == 2)
                    {
                        index++;
                        Display.WriteWhite(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteWhite(menuX - 5, menuY + 4, "Start");
                        Display.WriteYellow(menuX - 5, menuY + 8, "Back");
                    }
                    if (index + 1 == 1)
                    {
                        index++;
                        Display.WriteWhite(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteYellow(menuX - 5, menuY + 4, "Start");
                        Display.WriteWhite(menuX - 5, menuY + 8, "Back");
                    }
                }
                if (keyInfo.Key == ConsoleKey.Enter)
                {
                    if (index == 1)
                    {
                        Console.Clear();
                        Display.WriteCyan(centerX - 20, centerY - 5, "     Waiting for player to join!");

                        Display.WriteCyan(centerX - 20, centerY - 2, "       Port: " + Port);
                        string _ip = Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString();
                        Display.WriteCyan(centerX - 20, centerY - 3, "       IPv4: " + _ip);

                        HostGame hg = new HostGame();
                        hg.StartHost(Port);
                        JoinGame.exit   = false;
                        JoinGame.Winner = "";
                        Display.WriteWhite(menuX - 5, menuY + 3, "Port number: " + Port);
                        Display.WriteYellow(menuX - 5, menuY + 5, "Start");
                        Display.WriteWhite(menuX - 5, menuY + 9, "Back");
                        Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");

                        Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");
                        Game.first   = " ";
                        Game.second  = " ";
                        Game.third   = " ";
                        Game.fourth  = " ";
                        Game.fifth   = " ";
                        Game.sixth   = " ";
                        Game.seventh = " ";
                        Game.eight   = " ";
                        Game.nineth  = " ";
                    }
                    if (index == 2)
                    {
                        Console.Clear();
                        Console.Clear(); Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");

                        Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");

                        return;
                    }
                    if (index == 0)
                    {
                        Port = 0;
                        Display.WriteYellow(menuX - 5, menuY + 2, "Port number:                     ");
                        Console.SetCursorPosition(menuX + 8, menuY + 2);
                        try
                        {
                            Port = int.Parse(Console.ReadLine());
                            Display.WriteYellow(menuX - 5, menuY + 2, "Port number: " + Port);
                        }
                        catch (Exception e)
                        {
                            Display.WriteYellow(menuX - 5, menuY + 2, "Port number: " + "0                   ");
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public static void SelectMenuJoin()
        {
            Console.Clear(); Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");

            Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");

            Display.WriteYellow(menuX - 5, menuY, "IP Address: " + IP);
            Display.WriteWhite(menuX - 5, menuY + 2, "Port number: " + Port);
            Display.WriteWhite(menuX - 5, menuY + 4, "Start");
            Display.WriteWhite(menuX - 5, menuY + 8, "Back");

            int index = 0;

            while (true)
            {
                ClearKeyBuffer();

                ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                if (keyInfo.Key == ConsoleKey.UpArrow)
                {
                    if (index - 1 == 0)
                    {
                        index--;
                        Display.WriteYellow(menuX - 5, menuY, "IP Address: " + IP);
                        Display.WriteWhite(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteWhite(menuX - 5, menuY + 4, "Start");
                        Display.WriteWhite(menuX - 5, menuY + 8, "Back");
                    }
                    else if (index - 1 == 1)
                    {
                        index--;
                        Display.WriteWhite(menuX - 5, menuY, "IP Address: " + IP);
                        Display.WriteYellow(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteWhite(menuX - 5, menuY + 4, "Start");
                        Display.WriteWhite(menuX - 5, menuY + 8, "Back");
                    }
                    else if (index - 1 == 2)
                    {
                        index--;
                        Display.WriteWhite(menuX - 5, menuY, "IP Address: " + IP);
                        Display.WriteWhite(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteYellow(menuX - 5, menuY + 4, "Start");
                        Display.WriteWhite(menuX - 5, menuY + 8, "Back");
                    }
                }
                if (keyInfo.Key == ConsoleKey.DownArrow)
                {
                    if (index + 1 == 3)
                    {
                        index++;
                        Display.WriteWhite(menuX - 5, menuY, "IP Address: " + IP);
                        Display.WriteWhite(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteWhite(menuX - 5, menuY + 4, "Start");
                        Display.WriteYellow(menuX - 5, menuY + 8, "Back");
                    }
                    else if (index + 1 == 1)
                    {
                        index++;

                        Display.WriteWhite(menuX - 5, menuY, "IP Address: " + IP);
                        Display.WriteYellow(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteWhite(menuX - 5, menuY + 4, "Start");
                        Display.WriteWhite(menuX - 5, menuY + 8, "Back");
                    }
                    else if (index + 1 == 2)
                    {
                        index++;
                        Display.WriteWhite(menuX - 5, menuY, "IP Address: " + IP);
                        Display.WriteWhite(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteYellow(menuX - 5, menuY + 4, "Start");
                        Display.WriteWhite(menuX - 5, menuY + 8, "Back");
                    }
                }
                else if (keyInfo.Key == ConsoleKey.Enter)
                {
                    if (index == 1)
                    {
                        Port = 0;
                        Display.WriteYellow(menuX - 5, menuY + 2, "Port number:                     ");
                        Console.SetCursorPosition(menuX + 8, menuY + 2);
                        try
                        {
                            Port = int.Parse(Console.ReadLine());
                            Display.WriteYellow(menuX - 5, menuY + 2, "Port number: " + Port);
                        }
                        catch (Exception e)
                        {
                            Display.WriteYellow(menuX - 5, menuY + 2, "Port number: " + "0                   ");
                        }
                    }
                    if (index == 2)
                    {
                        JoinGame jg = new JoinGame();
                        jg.Network(IP, Port);

                        Game.first   = " ";
                        Game.second  = " ";
                        Game.third   = " ";
                        Game.fourth  = " ";
                        Game.fifth   = " ";
                        Game.sixth   = " ";
                        Game.seventh = " ";
                        Game.eight   = " ";
                        Game.nineth  = " ";

                        Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");

                        JoinGame.exit   = false;
                        JoinGame.txtME  = " ";
                        JoinGame.Winner = "";

                        Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");

                        Display.WriteWhite(menuX - 5, menuY, "IP Address: " + IP);
                        Display.WriteWhite(menuX - 5, menuY + 2, "Port number: " + Port);
                        Display.WriteYellow(menuX - 5, menuY + 4, "Start");
                        Display.WriteWhite(menuX - 5, menuY + 8, "Back");
                        JoinGame.exit = false;
                    }
                    if (index == 0)
                    {
                        Display.WriteWhite(menuX - 5, menuY, "IP Address:                      ");
                        Console.SetCursorPosition(menuX + 7, menuY);
                        IP = Console.ReadLine();
                        Display.WriteYellow(menuX - 5, menuY, "IP Address: " + IP);
                    }
                    if (index == 3)
                    {
                        Console.Clear();

                        Display.WriteYellow(menuX, menuY + 1, "Join");

                        Display.WriteWhite(menuX, menuY + 3, "Host");

                        Display.WriteWhite(menuX, menuY + 5, "Back");


                        Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");
                        Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");

                        break;
                    }
                }
            }
        }
Beispiel #6
0
        public static void SelectMenuHostOrClient()
        {
            Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");

            Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");


            int index = 0;

            Display.WriteYellow(menuX, menuY, "Join");

            Display.WriteWhite(menuX, menuY + 2, "Host");

            Display.WriteWhite(menuX, menuY + 4, "Back");

            while (true)
            {
                ClearKeyBuffer();

                ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                if (keyInfo.Key == ConsoleKey.UpArrow)
                {
                    if (index - 1 == 0)
                    {
                        index--;
                        Console.BackgroundColor = color;
                        Display.WriteYellow(menuX, menuY, "Join");

                        Display.WriteWhite(menuX, menuY + 2, "Host");

                        Display.WriteWhite(menuX, menuY + 4, "Back");
                        Console.BackgroundColor = color;
                    }
                    else if (index - 1 == 1)
                    {
                        index--;
                        Console.BackgroundColor = color;
                        Display.WriteWhite(menuX, menuY, "Join");

                        Display.WriteYellow(menuX, menuY + 2, "Host");

                        Display.WriteWhite(menuX, menuY + 4, "Back");
                        Console.BackgroundColor = color;
                    }
                }
                if (keyInfo.Key == ConsoleKey.DownArrow)
                {
                    if (index + 1 == 2)
                    {
                        index++;
                        Console.BackgroundColor = color;
                        Display.WriteWhite(menuX, menuY, "Join");

                        Display.WriteWhite(menuX, menuY + 2, "Host");

                        Display.WriteYellow(menuX, menuY + 4, "Back");
                        Console.BackgroundColor = color;
                    }
                    else if (index + 1 == 1)
                    {
                        index++;
                        Console.BackgroundColor = color;
                        Display.WriteWhite(menuX, menuY, "Join");

                        Display.WriteYellow(menuX, menuY + 2, "Host");

                        Display.WriteWhite(menuX, menuY + 4, "Back");
                        Console.BackgroundColor = color;
                    }
                }
                if (keyInfo.Key == ConsoleKey.Enter)
                {
                    if (index == 1)
                    {
                        if (index == 1)
                        {
                            HostMenu();
                            Console.BackgroundColor = color;
                            Display.WriteWhite(menuX, menuY, "Join");

                            Display.WriteYellow(menuX, menuY + 2, "Host");

                            Display.WriteWhite(menuX, menuY + 4, "Back");
                            Console.BackgroundColor = color;
                        }
                    }
                    if (index == 0)
                    {
                        Console.Clear();
                        Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");
                        Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");
                        Chosen2 = SecondMenuSelection.Join;
                        Console.BackgroundColor = color;
                        SelectMenuJoin();
                    }
                    if (index == 2)
                    {
                        Console.Clear();
                        Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");

                        Display.WriteGreen(Console.WindowWidth - 17, Console.WindowHeight - 1, "By Danger_boy21");
                        Chosen2 = SecondMenuSelection.Back;
                        Console.BackgroundColor = color;
                        Display.WriteYellow(menuX, menuY, "Start");
                        Display.WriteWhite(menuX, menuY + 2, "Exit");
                        break;
                    }
                }
            }
        }
Beispiel #7
0
        public static void Start()
        {
            Table();
            string cords = "";

            Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 6, "Enter cords: ");

            while (ex == true && exOff)
            {
                Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                cords = Console.ReadLine();

                if (cords == "1 1" && first == " ")
                {
                    first = "X";
                    Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                    Console.WriteLine("                    ");
                    ex             = false;
                    JoinGame.txtME = cords;
                }
                else if (cords == "1 2" && second == " ")
                {
                    second = "X"; Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                    Console.WriteLine("                    ");
                    ex = false; JoinGame.txtME = cords;
                }
                else if (cords == "1 3" && third == " ")
                {
                    third = "X"; Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                    Console.WriteLine("                    ");
                    ex = false; JoinGame.txtME = cords;
                }
                else if (cords == "2 1" && fourth == " ")
                {
                    fourth = "X"; Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                    Console.WriteLine("                    ");
                    ex = false; JoinGame.txtME = cords;
                }
                else if (cords == "2 2" && fifth == " ")
                {
                    fifth = "X"; Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                    Console.WriteLine("                    ");
                    ex = false; JoinGame.txtME = cords;
                }
                else if (cords == "2 3" && sixth == " ")
                {
                    sixth = "X"; Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                    Console.WriteLine("                    ");
                    ex = false; JoinGame.txtME = cords;
                }
                else if (cords == "3 1" && seventh == " ")
                {
                    seventh = "X"; Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                    Console.WriteLine("                    ");
                    ex = false; JoinGame.txtME = cords;
                }
                else if (cords == "3 2" && eight == " ")
                {
                    eight = "X"; Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                    Console.WriteLine("                    ");
                    ex = false; JoinGame.txtME = cords;
                }
                else if (cords == "3 3" && nineth == " ")
                {
                    nineth = "X";
                    Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                    Console.WriteLine("                    ");
                    ex = false; JoinGame.txtME = cords;
                }
                else
                {
                    Console.SetCursorPosition(Console.WindowWidth / 2 - 2, Console.WindowHeight / 2 + 6);
                    Console.WriteLine("                    ");
                }
            }
        }
        public void StartHost(int port)
        {
            TcpListener server = new TcpListener(port);
            TcpClient   client = new TcpClient();

            try
            {
                server.Start();
                int i1 = 0;
                client = server.AcceptTcpClient();
                NetworkStream str = client.GetStream();
                if (client.Connected && i1 == 0)
                {
                    Display.WriteCyan(centerX - 20, centerY - 5, "Welcome to TicTacToe Network Version!");
                    i1++;
                    Console.Clear(); Game.Table();
                }
                while (true)
                {
                    if (JoinGame.CheckIfWin("X") == true)
                    {
                        Display.WriteYellow(menuX - 10, menuY + 6, "                                                          ");
                        Display.WriteYellow(menuX, menuY + 6, "Back");
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "                        ");
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "Winner: " + JoinGame.Winner);
                        while (true)
                        {
                            Program.ClearKeyBuffer();

                            ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                            if (keyInfo.Key == ConsoleKey.Enter)
                            {
                                Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "                        ");
                                server.Stop();
                                client.Close();
                                Console.Clear();
                                return;
                            }
                        }
                    }
                    if (JoinGame.CheckIfWin("O") == true)
                    {
                        Display.WriteYellow(menuX - 10, menuY + 6, "                                                          ");
                        Display.WriteYellow(menuX, menuY + 6, "Back");
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "                        ");
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "Winner: " + JoinGame.Winner);
                        while (true)
                        {
                            Program.ClearKeyBuffer();

                            ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                            if (keyInfo.Key == ConsoleKey.Enter)
                            {
                                Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "                        ");
                                server.Stop();
                                client.Close();
                                Console.Clear();
                                return;
                            }
                        }
                    }

                    string text          = "";
                    byte[] receiveBuffer = new byte[999];
                    byte[] sendData      = new byte[999];

                    Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "                        ");
                    Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "Other player turn: ");

                    string msg;

                    str.Read(receiveBuffer, 0, receiveBuffer.Length);
                    msg = Encoding.ASCII.GetString(receiveBuffer, 0, receiveBuffer.Length);



                    if (msg.Contains("1 1"))
                    {
                        Game.first = "O";
                    }
                    if (msg.Contains("1 2"))
                    {
                        Game.second = "O";
                    }
                    if (msg.Contains("1 3"))
                    {
                        Game.third = "O";
                    }
                    if (msg.Contains("2 1"))
                    {
                        Game.fourth = "O";
                    }
                    if (msg.Contains("2 2"))
                    {
                        Game.fifth = "O";
                    }
                    if (msg.Contains("2 3"))
                    {
                        Game.sixth = "O";
                    }
                    if (msg.Contains("3 1"))
                    {
                        Game.seventh = "O";
                    }
                    if (msg.Contains("3 2"))
                    {
                        Game.eight = "O";
                    }
                    if (msg.Contains("3 3"))
                    {
                        Game.nineth = "O";
                    }


                    Game.Table();

                    for (int i = 0; i < receiveBuffer.Length; i++)
                    {
                        receiveBuffer[i] = 0;
                    }

                    if (JoinGame.CheckIfWin("X") == true)
                    {
                        Display.WriteYellow(menuX - 10, menuY + 6, "                                                          ");
                        Display.WriteYellow(menuX, menuY + 6, "Back");
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "                        ");
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "Winner: " + JoinGame.Winner);
                        while (true)
                        {
                            Program.ClearKeyBuffer();

                            ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                            if (keyInfo.Key == ConsoleKey.Enter)
                            {
                                Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "                        ");
                                server.Stop();
                                client.Close();
                                Console.Clear();
                                return;
                            }
                        }
                    }
                    if (JoinGame.CheckIfWin("O") == true)
                    {
                        Display.WriteYellow(menuX - 10, menuY + 6, "                                                          ");
                        Display.WriteYellow(menuX, menuY + 6, "Back");
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "                        ");
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "Winner: " + JoinGame.Winner);
                        Display.WriteYellow(menuX - 10, menuY + 5, "                                                 ");
                        while (true)
                        {
                            Program.ClearKeyBuffer();

                            ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                            if (keyInfo.Key == ConsoleKey.Enter)
                            {
                                Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "                        ");
                                server.Stop();
                                client.Close();
                                Console.Clear();
                                return;
                            }
                        }
                    }

                    Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "                        ");
                    Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "Your turn:");
                    Game.Start();
                    sendData = Encoding.ASCII.GetBytes(JoinGame.txtME);
                    Game.Table();
                    str.Write(sendData, 0, sendData.Length);

                    Game.ex = true;
                }
            }

            catch (SocketException e)
            {
                Console.Clear();
                Display.WriteCyan(centerX - 20, centerY - 5, "           Server already exist...");
                Display.WriteYellow(menuX - 10, menuY + 6, "                                                          ");
                Display.WriteYellow(menuX, menuY + 6, "Back");
                while (true)
                {
                    Program.ClearKeyBuffer();
                    ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                    if (keyInfo.Key == ConsoleKey.Enter)
                    {
                        Console.Clear();
                        break;;
                    }
                }
            }

            catch (Exception e)
            {
                Console.Clear();
                Display.WriteCyan(centerX - 20, centerY - 5, "           No player avaible...");
                Display.WriteYellow(menuX - 10, menuY + 6, "                                                          ");
                Display.WriteYellow(menuX, menuY + 6, "Back");
                while (true)
                {
                    Program.ClearKeyBuffer();
                    ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                    if (keyInfo.Key == ConsoleKey.Enter)
                    {
                        Console.Clear();
                        break;;
                    }
                }
                server.Stop();
                client.Close();
            }
        }
        public void Network(string ip, int port)
        {
            Console.Clear();

            try
            {
                TcpClient     client        = new TcpClient(ip, port);
                NetworkStream str           = client.GetStream();
                byte[]        receiveBuffer = new byte[999];
                Display.WriteCyan(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 6, "Enter cords: ");
                while (!exit)
                {
                    try
                    {
                        if (CheckIfWin("X") == true)
                        {
                            Display.WriteYellow(menuX - 10, menuY + 6, "                                                          ");
                            Display.WriteYellow(menuX, menuY + 6, "Back");
                            Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "                        ");
                            Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "Winner: " + Winner);
                            while (true)
                            {
                                Program.ClearKeyBuffer();

                                ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                                if (keyInfo.Key == ConsoleKey.Enter)
                                {
                                    Display.WriteYellow(menuX - 10, menuY + 7, "                                                          ");
                                    client.Close();
                                    Console.Clear();
                                    return;
                                }
                            }
                        }
                        if (CheckIfWin("O") == true)
                        {
                            Display.WriteYellow(menuX - 10, menuY + 6, "                                                          ");
                            Display.WriteYellow(menuX, menuY + 6, "Back");
                            Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "                        ");
                            Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "Winner: " + Winner);
                            while (true)
                            {
                                Program.ClearKeyBuffer();

                                ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                                if (keyInfo.Key == ConsoleKey.Enter)
                                {
                                    Display.WriteYellow(menuX - 10, menuY + 7, "                                                          ");
                                    client.Close();
                                    Console.Clear();
                                    return;
                                }
                            }
                        }
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "                        ");
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "Your turn:");
                        Game.Start();
                        Game.Table();

                        byte[] sendData = new byte[999];

                        sendData = Encoding.ASCII.GetBytes(txtME);



                        str.Write(sendData, 0, sendData.Length);


                        string msg = "";


                        bool exit = false;
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "                        ");
                        Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 4, "Other player turn: ");
                        if (CheckIfWin("X") == true)
                        {
                            Display.WriteYellow(menuX - 10, menuY + 6, "                                                          ");
                            Display.WriteYellow(menuX, menuY + 6, "Back");
                            Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "                        ");
                            Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "Winner: " + Winner);
                            while (true)
                            {
                                Program.ClearKeyBuffer();

                                ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                                if (keyInfo.Key == ConsoleKey.Enter)
                                {
                                    Display.WriteYellow(menuX - 10, menuY + 7, "                                                          ");
                                    client.Close();
                                    Console.Clear();
                                    return;
                                }
                            }
                        }
                        if (CheckIfWin("O") == true)
                        {
                            Display.WriteYellow(menuX - 10, menuY + 7, "                                                          ");
                            Display.WriteYellow(menuX, menuY + 6, "Back");
                            Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "                        ");
                            Display.WriteRed(Console.WindowWidth / 2 - 15, Console.WindowHeight / 2 + 3, "Winner: " + Winner);
                            while (true)
                            {
                                client.Close();
                                Program.ClearKeyBuffer();

                                ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                                if (keyInfo.Key == ConsoleKey.Enter)
                                {
                                    Display.WriteYellow(menuX - 10, menuY + 7, "                                                          ");
                                    Console.Clear();
                                    return;
                                }
                            }
                        }
                        while (!exit)
                        {
                            str.Read(receiveBuffer, 0, receiveBuffer.Length);
                            msg = Encoding.ASCII.GetString(receiveBuffer, 0, receiveBuffer.Length);

                            if (msg.Contains("1 1"))
                            {
                                Game.first = "O";
                            }
                            if (msg.Contains("1 2"))
                            {
                                Game.second = "O";
                            }
                            if (msg.Contains("1 3"))
                            {
                                Game.third = "O";
                            }
                            if (msg.Contains("2 1"))
                            {
                                Game.fourth = "O";
                            }
                            if (msg.Contains("2 2"))
                            {
                                Game.fifth = "O";
                            }
                            if (msg.Contains("2 3"))
                            {
                                Game.sixth = "O";
                            }
                            if (msg.Contains("3 1"))
                            {
                                Game.seventh = "O";
                            }
                            if (msg.Contains("3 2"))
                            {
                                Game.eight = "O";
                            }
                            if (msg.Contains("3 3"))
                            {
                                Game.nineth = "O";
                            }

                            Game.Table();
                            exit    = true;
                            Game.ex = true;
                        }
                    }
                    catch (Exception e)
                    {
                        client.Close();
                        str.Close();
                        Console.Clear(); Display.WriteCyan(Console.WindowWidth / 2 - 10, Console.WindowHeight / 2 - 5, "The player exit...");
                        Display.WriteYellow(Console.WindowWidth / 2 - 5, Console.WindowHeight / 2 + 8, "Back");
                        while (true)
                        {
                            ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                            if (keyInfo.Key == ConsoleKey.Enter)
                            {
                                exit = true;

                                Console.Clear();

                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Clear(); Display.WriteCyan(Console.WindowWidth / 2 - 10, Console.WindowHeight / 2 - 5, "Server not found...");
                Display.WriteYellow(Console.WindowWidth / 2 - 5, Console.WindowHeight / 2 + 8, "Back");
                while (true)
                {
                    ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                    if (keyInfo.Key == ConsoleKey.Enter)
                    {
                        exit = true;

                        Console.Clear();

                        break;
                    }
                }
            }
        }