static void Receiver_OnMessageReceived(object sender, MessageEventArgs e) { string message = e.message.Trim(); int messageLength = e.message.Length; string receivedCommand = message.Substring(messageLength - 4); string movement = receivedCommand.Substring(1); char pistol = receivedCommand[0]; Console.WriteLine("received command: " + movement + " from pistol " + pistol); switch (pistol) { case '1': greenCar.SendCommand(movement); break; case '2': redCar.SendCommand(movement); break; default: Console.WriteLine("unrecognized pistol: " + pistol); break; } }
static void Finish_OnMessageReceived(object sender, MessageEventArgs e) { string[] message = e.message.Split(' '); if (OnMessageReceivedFinish != null) { OnMessageReceivedFinish(new object(), new MessageEventArgs(message.Last())); } }
private static void Receiver_OnMessageReceived(object sender, MessageEventArgs e) { string message = e.message.Trim(); int messageLength = e.message.Length; string receivedCommand = message.Substring(messageLength - 4); string movement = string.Join("",receivedCommand.Substring(1).Take(2).ToArray()); char pistol = receivedCommand[0]; Console.WriteLine("received command: " + movement + " from pistol " + pistol); switch (pistol) { case '1': MessageReceivedPistol1(movement); break; case '2': MessageReceivedPistol2(movement); break; default: Console.WriteLine("unrecognized pistol: " + pistol); break; } }
static void receiver_OnCommandSend(object sender, MessageEventArgs e) { Console.WriteLine(e.ToString()); }
static void Finish_OnMessageReceived(object sender, MessageEventArgs e) { Console.WriteLine(e.message + " heeft gewonnen!"); }