Ejemplo n.º 1
0
        //private static void displayMap()
        //{
        //    Console.WriteLine("");
        //    for (int i = 0; i < 20; i++)
        //    {
        //        for (int j = 0; j < 20; j++)
        //        {
        //            Console.Write(theMap[i, j]);
        //        }
        //        Console.Write("\n");
        //    }
        //}
        public static void resolve(Object masg)
        {
            String themsg = (String)masg;
            //Console.WriteLine("got msg : "+themsg);
            if (themsg.Substring(0, 2).Equals("G:"))
            {
                //Console.WriteLine("---------map------");
                //displayMap();
                //Console.WriteLine("---------map------");
                //updateCoinPile();

                String[] playerMap = themsg.Substring(2, themsg.Length - 2).Split(':');

                for (int k = 0; k < playerMap.Length - 1; k++)
                {
                    String[] pMap = playerMap[k].Split(';');
                    if (pMap[0].Equals(myUserID))
                    {
                        String[] Axy = pMap[1].Split(',');
                        userLocation[0, 0] = int.Parse(Axy[0]);
                        userLocation[0, 1] = int.Parse(Axy[1]);
                        theMap[userLocation[0, 1], userLocation[0, 0]] = 'N';
                        char tempDirction = 'P';
                        if (pMap[2].Equals("0"))
                        {
                            tempDirction = 'U';
                        }
                        else if (pMap[2].Equals("1"))
                        {
                            tempDirction = 'R';
                        }
                        else if (pMap[2].Equals("2"))
                        {
                            tempDirction = 'D';
                        }
                        else if (pMap[2].Equals("3"))
                        {
                            tempDirction = 'L';
                        }
                        userDirection = tempDirction;

                        Com c = new Com();
                        if (coins.Count > 0)
                        {
                            String direction = getWhichDirection();
                            //Console.WriteLine("");
                            //for (int i = 0; i < 20; i++)
                            //{
                            //    for (int j = 0; j < 20; j++)
                            //    {
                            //        Console.Write(theSMap[i, j]);
                            //    }
                            //    Console.Write("\n");
                            //}
                            //Console.WriteLine("direction: " + direction);
                            if (!direction.Equals("None"))
                            {
                                c.sendToSever(direction);
                            }

                        }
                    }
                    else
                    {
                        for (int c = 0; c < numOfPlayers - 1; c++)
                        {
                            Player tmp = thePlayers[c];
                            if (tmp.playerID.Equals(pMap[0]))
                            {
                                String[] Axy = pMap[1].Split(',');
                                int tempx = int.Parse(Axy[0]);
                                int tempy = int.Parse(Axy[1]);
                                if (tmp.loc[0, 0] != tempx || tmp.loc[0, 1] != tempy && theMap[tempy, tempx] != 'W')
                                {
                                    char tempDirction = 'P';
                                    if (pMap[2].Equals("0"))
                                    {
                                        tempDirction = 'U';
                                    }
                                    else if (pMap[2].Equals("1"))
                                    {
                                        tempDirction = 'R';
                                    }
                                    else if (pMap[2].Equals("2"))
                                    {
                                        tempDirction = 'D';
                                    }
                                    else if (pMap[2].Equals("3"))
                                    {
                                        tempDirction = 'L';
                                    }

                                    theMap[tempy, tempx] = tempDirction;
                                    tmp.move(tempx, tempy);
                                    theMap[tmp.priloc[0, 1], tmp.priloc[0, 0]] = 'N';
                                    thePlayers[c] = tmp;
                                }
                                else
                                {
                                    char tempDirction = 'P';
                                    if (pMap[2].Equals("0"))
                                    {
                                        tempDirction = 'U';
                                    }
                                    else if (pMap[2].Equals("1"))
                                    {
                                        tempDirction = 'R';
                                    }
                                    else if (pMap[2].Equals("2"))
                                    {
                                        tempDirction = 'D';
                                    }
                                    else if (pMap[2].Equals("3"))
                                    {
                                        tempDirction = 'L';
                                    }

                                    theMap[tempy, tempx] = tempDirction;
                                }
                            }
                        }
                    }
                }
            }
            else if (themsg.Substring(0, 2).Equals("S:"))
            {
                userLocation = new int[1, 2];
                String[] playerDetails = themsg.Substring(2, themsg.Length - 2).Split(':');
                numOfPlayers = playerDetails.Length;
                thePlayers = new Player[numOfPlayers];
                int counter = 0;
                for (int i = 0; i < numOfPlayers; i++)
                {
                    String[] tempPD = playerDetails[i].Split(';');
                    if (tempPD[0].Equals(myUserID))
                    {
                        String[] xy = tempPD[1].Split(',');
                        userLocation[0, 0] = int.Parse(xy[0]);
                        userLocation[0, 1] = int.Parse(xy[1]);
                        char tempDirction = 'P';
                        if (tempPD[2].Equals("0"))
                        {
                            tempDirction = 'U';
                        }
                        else if (tempPD[2].Equals("1"))
                        {
                            tempDirction = 'R';
                        }
                        else if (tempPD[2].Equals("2"))
                        {
                            tempDirction = 'D';
                        }
                        else if (tempPD[2].Equals("3"))
                        {
                            tempDirction = 'L';
                        }
                        userDirection = tempDirction;
                    }
                    else
                    {
                        String[] xy = tempPD[1].Split(',');
                        thePlayers[counter] = new Player(tempPD[0], int.Parse(xy[0]), int.Parse(xy[1]));

                        char tempDirction = 'P';
                        if (tempPD[2].Equals("0"))
                        {
                            tempDirction = 'U';
                        }
                        else if (tempPD[2].Equals("1"))
                        {
                            tempDirction = 'R';
                        }
                        else if (tempPD[2].Equals("2"))
                        {
                            tempDirction = 'D';
                        }
                        else if (tempPD[2].Equals("3"))
                        {
                            tempDirction = 'L';
                        }
                        theMap[int.Parse(xy[1]), int.Parse(xy[0])] = tempDirction;
                        counter++;
                    }

                }
                //Console.WriteLine("x" + userLocation[0, 0] + "y" + userLocation[0, 1]);
            }
            else if (themsg.Substring(0, 2).Equals("C:"))
            {
                String coinDetails = themsg.Substring(2, themsg.Length - 4);
                String[] locltval = coinDetails.Split(':');
                String[] cloc = locltval[0].Split(',');
                String clt = locltval[1];
                String cval = locltval[2];
                CoinPile occuredPile = new CoinPile(int.Parse(cloc[1]), int.Parse(cloc[0]), int.Parse(clt), int.Parse(cval));
                theMap[int.Parse(cloc[1]), int.Parse(cloc[0])] = 'C';
                TheGame.coins.Add(occuredPile);
            }
            else if (themsg.Substring(0, 2).Equals("I:"))
            {
                initializeMap();
                String mapDetails = themsg.Substring(5, themsg.Length - 7);
                String[] brstwa = mapDetails.Split(':');
                String[] brickCor = brstwa[0].Split(';');
                String[] stoneCor = brstwa[1].Split(';');
                String[] waterCor = brstwa[2].Split(';');

                for (int i = 0; i < brickCor.Length; i++)
                {
                    String[] temp = brickCor[i].Split(',');
                    theMap[int.Parse(temp[1]), int.Parse(temp[0])] = 'B';
                }

                for (int i = 0; i < stoneCor.Length; i++)
                {
                    String[] temp = stoneCor[i].Split(',');
                    theMap[int.Parse(temp[1]), int.Parse(temp[0])] = 'S';
                }

                for (int i = 0; i < waterCor.Length; i++)
                {
                    String[] temp = waterCor[i].Split(',');
                    theMap[int.Parse(temp[1]), int.Parse(temp[0])] = 'W';
                }

                myUserID = themsg.Substring(2, 2);
                //Console.WriteLine(" ID" + myUserID);
            }
        }
Ejemplo n.º 2
0
        //private static void displayMap()
        //{
        //    Console.WriteLine("");
        //    for (int i = 0; i < 20; i++)
        //    {
        //        for (int j = 0; j < 20; j++)
        //        {
        //            Console.Write(theMap[i, j]);
        //        }
        //        Console.Write("\n");
        //    }
        //}

        public static void resolve(Object masg)
        {
            String themsg = (String)masg;

            //Console.WriteLine("got msg : "+themsg);
            if (themsg.Substring(0, 2).Equals("G:"))
            {
                //Console.WriteLine("---------map------");
                //displayMap();
                //Console.WriteLine("---------map------");
                //updateCoinPile();


                String[] playerMap = themsg.Substring(2, themsg.Length - 2).Split(':');

                for (int k = 0; k < playerMap.Length - 1; k++)
                {
                    String[] pMap = playerMap[k].Split(';');
                    if (pMap[0].Equals(myUserID))
                    {
                        String[] Axy = pMap[1].Split(',');
                        userLocation[0, 0] = int.Parse(Axy[0]);
                        userLocation[0, 1] = int.Parse(Axy[1]);
                        theMap[userLocation[0, 1], userLocation[0, 0]] = 'N';
                        char tempDirction = 'P';
                        if (pMap[2].Equals("0"))
                        {
                            tempDirction = 'U';
                        }
                        else if (pMap[2].Equals("1"))
                        {
                            tempDirction = 'R';
                        }
                        else if (pMap[2].Equals("2"))
                        {
                            tempDirction = 'D';
                        }
                        else if (pMap[2].Equals("3"))
                        {
                            tempDirction = 'L';
                        }
                        userDirection = tempDirction;

                        Com c = new Com();
                        if (coins.Count > 0)
                        {
                            String direction = getWhichDirection();
                            //Console.WriteLine("");
                            //for (int i = 0; i < 20; i++)
                            //{
                            //    for (int j = 0; j < 20; j++)
                            //    {
                            //        Console.Write(theSMap[i, j]);
                            //    }
                            //    Console.Write("\n");
                            //}
                            //Console.WriteLine("direction: " + direction);
                            if (!direction.Equals("None"))
                            {
                                c.sendToSever(direction);
                            }
                        }
                    }
                    else
                    {
                        for (int c = 0; c < numOfPlayers - 1; c++)
                        {
                            Player tmp = thePlayers[c];
                            if (tmp.playerID.Equals(pMap[0]))
                            {
                                String[] Axy   = pMap[1].Split(',');
                                int      tempx = int.Parse(Axy[0]);
                                int      tempy = int.Parse(Axy[1]);
                                if (tmp.loc[0, 0] != tempx || tmp.loc[0, 1] != tempy && theMap[tempy, tempx] != 'W')
                                {
                                    char tempDirction = 'P';
                                    if (pMap[2].Equals("0"))
                                    {
                                        tempDirction = 'U';
                                    }
                                    else if (pMap[2].Equals("1"))
                                    {
                                        tempDirction = 'R';
                                    }
                                    else if (pMap[2].Equals("2"))
                                    {
                                        tempDirction = 'D';
                                    }
                                    else if (pMap[2].Equals("3"))
                                    {
                                        tempDirction = 'L';
                                    }

                                    theMap[tempy, tempx] = tempDirction;
                                    tmp.move(tempx, tempy);
                                    theMap[tmp.priloc[0, 1], tmp.priloc[0, 0]] = 'N';
                                    thePlayers[c] = tmp;
                                }
                                else
                                {
                                    char tempDirction = 'P';
                                    if (pMap[2].Equals("0"))
                                    {
                                        tempDirction = 'U';
                                    }
                                    else if (pMap[2].Equals("1"))
                                    {
                                        tempDirction = 'R';
                                    }
                                    else if (pMap[2].Equals("2"))
                                    {
                                        tempDirction = 'D';
                                    }
                                    else if (pMap[2].Equals("3"))
                                    {
                                        tempDirction = 'L';
                                    }

                                    theMap[tempy, tempx] = tempDirction;
                                }
                            }
                        }
                    }
                }
            }
            else if (themsg.Substring(0, 2).Equals("S:"))
            {
                userLocation = new int[1, 2];
                String[] playerDetails = themsg.Substring(2, themsg.Length - 2).Split(':');
                numOfPlayers = playerDetails.Length;
                thePlayers   = new Player[numOfPlayers];
                int counter = 0;
                for (int i = 0; i < numOfPlayers; i++)
                {
                    String[] tempPD = playerDetails[i].Split(';');
                    if (tempPD[0].Equals(myUserID))
                    {
                        String[] xy = tempPD[1].Split(',');
                        userLocation[0, 0] = int.Parse(xy[0]);
                        userLocation[0, 1] = int.Parse(xy[1]);
                        char tempDirction = 'P';
                        if (tempPD[2].Equals("0"))
                        {
                            tempDirction = 'U';
                        }
                        else if (tempPD[2].Equals("1"))
                        {
                            tempDirction = 'R';
                        }
                        else if (tempPD[2].Equals("2"))
                        {
                            tempDirction = 'D';
                        }
                        else if (tempPD[2].Equals("3"))
                        {
                            tempDirction = 'L';
                        }
                        userDirection = tempDirction;
                    }
                    else
                    {
                        String[] xy = tempPD[1].Split(',');
                        thePlayers[counter] = new Player(tempPD[0], int.Parse(xy[0]), int.Parse(xy[1]));

                        char tempDirction = 'P';
                        if (tempPD[2].Equals("0"))
                        {
                            tempDirction = 'U';
                        }
                        else if (tempPD[2].Equals("1"))
                        {
                            tempDirction = 'R';
                        }
                        else if (tempPD[2].Equals("2"))
                        {
                            tempDirction = 'D';
                        }
                        else if (tempPD[2].Equals("3"))
                        {
                            tempDirction = 'L';
                        }
                        theMap[int.Parse(xy[1]), int.Parse(xy[0])] = tempDirction;
                        counter++;
                    }
                }
                //Console.WriteLine("x" + userLocation[0, 0] + "y" + userLocation[0, 1]);
            }
            else if (themsg.Substring(0, 2).Equals("C:"))
            {
                String   coinDetails = themsg.Substring(2, themsg.Length - 4);
                String[] locltval    = coinDetails.Split(':');
                String[] cloc        = locltval[0].Split(',');
                String   clt         = locltval[1];
                String   cval        = locltval[2];
                CoinPile occuredPile = new CoinPile(int.Parse(cloc[1]), int.Parse(cloc[0]), int.Parse(clt), int.Parse(cval));
                theMap[int.Parse(cloc[1]), int.Parse(cloc[0])] = 'C';
                TheGame.coins.Add(occuredPile);
            }
            else if (themsg.Substring(0, 2).Equals("I:"))
            {
                initializeMap();
                String   mapDetails = themsg.Substring(5, themsg.Length - 7);
                String[] brstwa     = mapDetails.Split(':');
                String[] brickCor   = brstwa[0].Split(';');
                String[] stoneCor   = brstwa[1].Split(';');
                String[] waterCor   = brstwa[2].Split(';');

                for (int i = 0; i < brickCor.Length; i++)
                {
                    String[] temp = brickCor[i].Split(',');
                    theMap[int.Parse(temp[1]), int.Parse(temp[0])] = 'B';
                }

                for (int i = 0; i < stoneCor.Length; i++)
                {
                    String[] temp = stoneCor[i].Split(',');
                    theMap[int.Parse(temp[1]), int.Parse(temp[0])] = 'S';
                }

                for (int i = 0; i < waterCor.Length; i++)
                {
                    String[] temp = waterCor[i].Split(',');
                    theMap[int.Parse(temp[1]), int.Parse(temp[0])] = 'W';
                }

                myUserID = themsg.Substring(2, 2);
                //Console.WriteLine(" ID" + myUserID);
            }
        }