Example #1
0
        public int[][] RecuperarTabuleiro()
        {
            try
            {
                // Faz a leitura dos bytes enviados pelo cliente e converte em string
                byte[] bytes = new byte[255];
                _STREAM.Read(bytes, 0, bytes.Length);
                string temp  = new ASCIIEncoding().GetString(bytes);
                char[] chars = temp.ToCharArray();

                // Transforma os dados no formato da matriz do tabuleiro
                int[][] obj = { new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 } };
                for (int y = 0; y < 3; y++)
                {
                    for (int x = 0; x < 3; x++)
                    {
                        obj[y][x] = Int32.Parse("" + chars[(y * 3) + x]);
                    }
                }

                return(obj);
            }
            catch
            {
                throw new Exception("Conexão perdida com o oponente!");
            }
        }
Example #2
0
        public int[,] getBoard()
        {
            int[,] grid = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
            try
            {
                byte[] bytes = new byte[255];
                stream.Read(bytes, 0, bytes.Length);
                string temp       = new ASCIIEncoding().GetString(bytes);
                char[] charOfTemp = temp.ToCharArray();

                for (int y = 0; y < 3; y++)
                {
                    for (int x = 0; x < 3; x++)
                    {
                        /*
                         * Retrieve the grid with -1 replaced for 2
                         */
                        grid[y, x] = Int32.Parse("" + charOfTemp[(y * 3) + x]);
                        if (grid[y, x] == 2)
                        {
                            grid[y, x] = -1;
                        }
                    }
                }
            }
            catch (Exception ex) {
                System.Windows.Forms.MessageBox.Show("Error reading from the Network Stream !");
            }
            return(grid);
        }
Example #3
0
        public int[][] getBoard()
        {
            byte[] bytes = new byte[255];
            _STREAM.Read(bytes, 0, bytes.Length);
            string temp = new ASCIIEncoding().GetString(bytes);

            char[]  charOfTemp = temp.ToCharArray();
            int[][] obj        = { new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 } };
            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    obj[y][x] = Int32.Parse("" + charOfTemp[(y * 3) + x]);
                }
            }
            return(obj);
        }
Example #4
0
        public bool amImain()
        {
            stream = _CLIENT.GetStream(); // получаем поток
            byte[] bytes = new byte[bytesLength];

            stream.Read(bytes, 0, bytes.Length);
            string temp = new ASCIIEncoding().GetString(bytes);

            char[]  charOfTemp = temp.ToCharArray();
            int[][] obj        = { new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 } };
            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    obj[y][x] = Int32.Parse("" + charOfTemp[(y * 3) + x]);
                }
            }
            if (obj[0][0] == 1 /*1001*/)
            {
                return(true);
            }              //main
            return(false); //doesn't main
        }
Example #5
0
        public /*int[][]*/ AllData getBoard(ClientObject client)
        {
            //byte[] bytes = new byte[255];
            byte[] bytes = new byte[bytesLength];

            client.Stream.Read(bytes, 0, bytes.Length);
            string temp = new ASCIIEncoding().GetString(bytes);

            char[]  charOfTemp = temp.ToCharArray();
            int[][] obj        = { new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 } };
            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    obj[y][x] = Int32.Parse("" + charOfTemp[(y * 3) + x]);
                }
            }



            return(new AllData(obj, client.Id, client.isMain));
            //return obj;
        }
Example #6
0
        //getBoard method for client app
        public /*int[][]*/ AllData getBoard(TcpClient client)
        {
            //byte[] bytes = new byte[255];
            byte[] bytes = new byte[bytesLength];

            stream.Read(bytes, 0, bytes.Length);
            string temp = new ASCIIEncoding().GetString(bytes);

            char[]  charOfTemp = temp.ToCharArray();
            int[][] obj        = { new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 } };
            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    obj[y][x] = Int32.Parse("" + charOfTemp[(y * 3) + x]);
                }
            }

            int  clientId     = 1000;  //it does not matter what value
            bool clientIsMain = false; //it does not matter what value

            return(new AllData(obj, clientId.ToString(), clientIsMain));
            //return obj;
        }