예제 #1
0
        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);
        }
예제 #2
0
파일: Replay.cs 프로젝트: MartyIX/SoTh
 public LogEvent(GameObject obj, int posX, int posY, MovementDirection movementDirection, string time, bool importantEvent)
 {
     Obj = obj;
     PosX = posX;
     PosY = posY;
     Time = time;
     MovementDirection = movementDirection;
     ImportantEvent = importantEvent;
 }
예제 #3
0
        public void CalendarFirstMethod_test_6()
        {
            Calendar cal = new Calendar();
            GameObject gameObject = new GameObject();

            cal.IsEnabledAddingEvents = false;
            cal.AddEvent(2, gameObject, EventType.goDown);

            Assert.That(cal.CountOfEvents == 0);
        }
예제 #4
0
        public void CalendarFirstMethod_test_4()
        {
            Calendar cal = new Calendar();
            GameObject gameObject = new GameObject();

            cal.AddEvent(1, gameObject, EventType.goDown);

            Event ev = cal.First(2);
            Assert.That(cal.CountOfEvents == 0);
        }
예제 #5
0
        public void CalendarFirstMethod_test_3()
        {
            Calendar cal = new Calendar();
            GameObject gameObject = new GameObject();

            cal.AddEvent(2, gameObject, EventType.goDown);

            Event ev = cal.First(1);
            Assert.That(ev == null); // no event is supposed to be returned
        }
예제 #6
0
        public void CalendarFirstMethod_test_1()
        {
            Calendar cal = new Calendar();
            GameObject gameObject = new GameObject();

            cal.AddEvent(1, gameObject, EventType.goDown);

            Event ev = cal.First(2);
            Assert.That(ev != null && ev.who == gameObject && ev.when == 1);
        }
예제 #7
0
파일: Event.cs 프로젝트: MartyIX/SoTh
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ID">Identifier of the event - for debugging purposes</param>
 /// <param name="when">When to process the event</param>
 /// <param name="who">Which object should process the event</param>
 /// <param name="what">Type of event</param>
 public Event(int ID, Int64 when, GameObject who, EventType what)
 {
     this.EventID = ID;
     this.when = when;
     this.who = who;
     this.what = what;
     // useful for two player game
     this.posX = who.posX;
     this.posY = who.posY;
 }
예제 #8
0
        public void CalendarFirstMethod_test_2()
        {
            // test of: "first" method in combination with time parameter of first method
            Calendar cal = new Calendar();
            GameObject gameObject = new GameObject();

            cal.AddEvent(2, gameObject, EventType.goDown);
            cal.AddEvent(3, gameObject, EventType.goDown);

            Event ev = cal.First(2);
            Assert.That(ev != null && ev.who == gameObject && ev.when == 2);
        }
예제 #9
0
        // Public Methods (2)
        public void PrepareMovement(GameObject who, Event ev)
        {
            // This ensures that movement of Sokoban is "smoother"
            if (who.Description == "S")
            {
                ev.when = (who.model.Time > who.TimeMovementEnds) ? who.model.Time : who.TimeMovementEnds;
            }

            who.movementInProgress = true;
            who.movementNoSteps = who.Speed;
            who.movementStartTime = model.time;
            who.MakeMove((MovementDirection)ev.what);
            model.MakePlan(model.Time, who, (EventType)((int)(ev.what) + 10));
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
파일: Replay.cs 프로젝트: MartyIX/SoTh
 /// <summary>
 /// Function saves initial position of a object.
 /// </summary>
 /// <param name="obj">a GameObject</param>
 /// <param name="posX">x-coordinate on game desk (1 to maxX)</param>
 /// <param name="posY">y-coordinate on game desk (1 to maxY)</param>
 /// <param name="movementDirection">the direction the object is turned to</param>
 public void SaveInitPositions(GameObject obj, int posX, int posY, MovementDirection movementDirection)
 {
     initialPositions.Add(new LogEvent(obj, posX, posY, movementDirection, "0:00", false));
 }
예제 #13
0
파일: Replay.cs 프로젝트: MartyIX/SoTh
        // Public Methods (7)
        /// <summary>
        /// Function logs an event that happened on game desk.
        /// </summary>
        /// <param name="obj">Which GameObject</param>
        /// <param name="posX">x-coordinate on game desk</param>
        /// <param name="posY">y-coordinate on game desk</param>
        /// <param name="time">Time when event happened</param>
        /// <param name="direction">Direction of object at the time of event</param>
        /// <param name="importantEvent">If event should be displayed in listbox lbLog</param>
        public void AddEvent(GameObject obj, int posX, int posY, string time, MovementDirection direction, bool importantEvent)
        {
            if (isEnabledAddingEvents == true)
            {
                events.Add(new LogEvent(obj, posX, posY, direction, time, importantEvent));

                if (importantEvent)
                {
                    importantEvents.Add(events.Count - 1);
                    form.lbLog.Items.Add(form.lTime.Text + " | " + posX.ToString() + ", " + posY.ToString());
                }
            }
        }
예제 #14
0
파일: Event.cs 프로젝트: MartyIX/SoTh
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="when">When to process the event</param>
 /// <param name="who">Which object should process the event</param>
 /// <param name="what">Type of event</param>
 public Event(int ID, Int64 when, GameObject who, EventType what, int posX, int posY)
 {
     this.EventID = ID;
     this.when = when;
     this.who = who;
     this.what = what;
     this.posX = posX;
     this.posY = posY;
 }
예제 #15
0
파일: Event.cs 프로젝트: MartyIX/SoTh
 public bool IsIdenticalWith(Int64 when, GameObject who, EventType what)
 {
     return (this.who == who && this.when == when && this.what == what);
 }