public void NMP_1() { NetworkMessageProtocol nmp = new NetworkMessageProtocol(); Queue<Event> queue = new Queue<Event>(); byte[] messageToSent = new byte[1200]; int messageLen; int iterationNo; Int64 actualSimulationTime; GameObject gameObject = new GameObject(); nmp.EventWasRead += new d_SimulationEventHandler(this.NMP_1_OnEventWasRead); actualSimulationTime = 22; iterationNo = 10; NMP_1_receivedEvents = 0; // generate a few events for (int i = 0; i < iterationNo; i++) { queue.Enqueue(new Event(i, i, gameObject, EventType.none)); } // Prepare events in queue for sending; result is in "messageToRead" nmp.EncodeEvents(ref queue, ref messageToSent, out messageLen, actualSimulationTime); // Reading nmp.DecodeData(messageToSent, messageLen); Debug.Write("\nRESULT: " +NMP_1_receivedEvents.ToString() + " is equal to " + iterationNo.ToString() + " ? \n\n"); Assert.That(NMP_1_receivedEvents == iterationNo); }
public void NMP_2() { NetworkMessageProtocol nmp = new NetworkMessageProtocol(); Queue<Event> queue = new Queue<Event>(); byte[] messageToSent = new byte[1200]; int messageLen; GameObject gameObject = new GameObject(); nmp.NetworkTimeChanged += new d_NetworkTimeChanged(NMP_2_OnNetworkTimeChanged); queue.Enqueue(new Event(1, 1, gameObject, EventType.none)); // Prepare events in queue for sending; result is in "messageToRead" nmp.EncodeEvents(ref queue, ref messageToSent, out messageLen, NMP_2_SentTime); // Reading nmp.DecodeData(messageToSent, messageLen); }
public void NMP_3() { NetworkMessageProtocol nmp = new NetworkMessageProtocol(); Queue<Event> queue = new Queue<Event>(); byte[] messageToSent = new byte[1200]; int messageLen; GameObject gameObject = new GameObject(); nmp.EventWasRead += new d_SimulationEventHandler(NMP_3_OnEventWasRead); queue.Enqueue(new Event(NMP_3_eventID, NMP_3_when, NMP_3_gameObject, NMP_3_eventType, NMP_3_posX, NMP_3_posY)); // Prepare events in queue for sending; result is in "messageToRead" nmp.EncodeEvents(ref queue, ref messageToSent, out messageLen, NMP_2_SentTime); // Reading nmp.DecodeData(messageToSent, messageLen); Debug.Write("\nRESULT #2: " + NMP_3_receivedEvents.ToString() + " should be 1. \n\n"); Assert.That(NMP_3_receivedEvents == 1); }
/// <summary> /// Class Player creates gamedesk /// </summary> public SecondPlayer(GameDeskView form, int posX, int posY) : base(form, posX, posY) { this.form = form; eventBuffer = new Queue<Event>(); playerType = PlayerType.NotDecided; messageToSend = new byte[1200]; receivedMessage = new byte[1200]; nmp = new NetworkMessageProtocol(); nmp.NetworkTimeChanged += new d_NetworkTimeChanged(SynchronizeWithNetworkTime); nmp.EventWasRead += new d_SimulationEventHandler(OnEventWasRead); nmp.PlayerFinishedRound += new d_PlayerFinishedRound(ReceivedVictoryMessage); }