private static void RestartAGame(PacketHeader header, Connection connection, string message) { string clientIp = GetIp(connection.ToString()); int clientPort = GetPort(connection.ToString()); Console.WriteLine(connection.ToString() + " --> " + message); Plateau p = FindPlayer(clientIp, clientPort); p.Cards = new Deck(); p.Player.Cards = p.Cards.getCards(5); p.Player2 = new IA(); p.Player2.Cards = p.Cards.getCards(5); string cards = JsonConvert.SerializeObject(p.Player.Cards); string res = JsonConvert.SerializeObject(new Message() { Content = cards }); NetworkComms.SendObject("Start Turn", clientIp, clientPort, res); }
private static Plateau FindPlayer(string ip, int port) { foreach (Plateau p in parties) { if (p.Player.Ip == ip && p.Player.Port == port) { return(p); } } Plateau plateau = new Plateau() { Player = new Player() { Ip = ip, Port = port }, Player2 = new IA(), Cards = new Deck() }; parties.Add(plateau); return(plateau); }
private static void ChangeCardRequest(PacketHeader header, Connection connection, string message) { string clientIp = GetIp(connection.ToString()); int clientPort = GetPort(connection.ToString()); Console.WriteLine(connection.ToString() + " --> " + message); Message msg = JsonConvert.DeserializeObject <Message>(message); Plateau p = JsonConvert.DeserializeObject <Plateau>(msg.Content); Plateau pFind = FindPlayer(clientIp, clientPort); if (p != pFind) { pFind = p; } Message msgRes = new Message() { Content = JsonConvert.SerializeObject(p.Player.Cards) }; string res = JsonConvert.SerializeObject(msgRes); NetworkComms.SendObject("Card Changed", p.Player.Ip, p.Player.Port, res); }
private static void PlayerTurn(PacketHeader header, Connection connection, string message) { string clientIp = GetIp(connection.ToString()); int clientPort = GetPort(connection.ToString()); Console.WriteLine(connection.ToString() + " --> " + message); Message msg = JsonConvert.DeserializeObject <Message>(message); Plateau plateau = JsonConvert.DeserializeObject <Plateau>(msg.Content); for (int i = 0; i < parties.Count; i++) { if (parties[i].Player.Ip == clientIp && parties[i].Player.Port == clientPort) { parties[i] = plateau; } } string res = JsonConvert.SerializeObject(new Message() { Content = "OK" }); NetworkComms.SendObject("Play", clientIp, clientPort, res); }