예제 #1
0
 public Snapshot getSnapshot(Client client)
 {
     return null;
 }
예제 #2
0
 public static Client fromStringToStats(string initData)
 {
     Client client;
     try
     {
         XmlDocument doc = new XmlDocument();
         doc.LoadXml(Regex.Replace(initData, @"\p{C}+", ""));
         XmlElement root = doc.DocumentElement;
         int playerId = Int32.Parse(root.SelectSingleNode("id").InnerText);
         int ore = Int32.Parse(root.SelectSingleNode("ore").InnerText);
         XmlNode initxy = root.SelectSingleNode("InitXY");
         int key   = Int32.Parse(initxy.SelectSingleNode("x").InnerText);
         int value = Int32.Parse(initxy.SelectSingleNode("y").InnerText);
         KeyValuePair<int, int> position = new KeyValuePair<int, int>(key, value);
         client = new Client(playerId);
         //client.Player.setInitialParams(position, ore, null);
         return client;
     }
     catch (Exception e)
     {
         client = new Client();
         return client;
     }
 }
예제 #3
0
        private void clientTurn(Client client)
        {
            while (client.isConnected && !stop)
            {
                this.sendMessage(SERVER_GAME_LOOP, "Client " + client.id + ":");
                client.Player.startTurn();
                string snapshot = sim.getSnapshot(client).ToString();
                try
                {
                    this.sendMessage(SERVER_GAME_LOOP, "Sending turn data");
                    if (saving)
                        client.sendString(snapshot);
                }
                catch (Exception e)
                {

                    this.sendMessage(SERVER_GAME_LOOP, "Error while sending data");
                    client.isConnected = false;
                }

                string action = "";
                try
                {
                    this.sendMessage(SERVER_GAME_LOOP, "Recieving command");
                    if (saving)
                    {
                        action = client.recieveString();
                        saveData(action);
                    }
                    else
                    {
                        action = loadData();
                    }
                    this.sendMessage(SERVER_GAME_LOOP, "Command recieved");
                }
                catch (Exception e)
                {
                    this.sendMessage(SERVER_GAME_LOOP, "Error while recieving data");
                    client.isConnected = false;
                }
                try
                {
                    Command toExecute = Factory.fromStringToCommand(action);
                    if (toExecute.PlayerId == client.id)
                    {
                        this.sendMessage(SERVER_GAME_LOOP, "Command sent to simulator");
                        sim.executeCommand(toExecute);
                    }
                    else
                    {
                        this.sendMessage(SERVER_GAME_LOOP, "Invalid command");
                    }
                }
                catch (Exception e)
                {
                    this.sendMessage(SERVER_GAME_LOOP, "Error while executing data");
                }
                finally
                {
                    client.Player.endTurn();
                }
                switch (sim.getResult())
                {
                    case 0:
                        break;
                    case 1:
                        break;
                    default:
                        stop = true;
                        break;
                }
                this.sendMessage(SERVER_GAME_LOOP, "Turn completed");
            }
        }