コード例 #1
0
        protected void Execute(string input, string expectedOutput, DateTime dateTimeUtc)
        {
            var outputBuilder = new StringBuilder();

            using (var inputReader = new StringReader(input))
                using (var outputWriter = new StringWriter(outputBuilder))
                {
                    Domain.Execute(inputReader, outputWriter, dateTimeUtc);
                }
            var output = outputBuilder.ToString();

            if (output != expectedOutput)
            {
                var expectedOutput2 = expectedOutput + Environment.NewLine;
                if (output == expectedOutput2)
                {
                    expectedOutput = expectedOutput2;
                }
            }
            output.ShouldEqual(expectedOutput);
        }
コード例 #2
0
        void FixedUpdate()
        {
            foreach (var req in pendingRequests)
            {
                Debug.Log("sending request " + req.GetType().Name);
            }

            var responses = current.Execute(pendingRequests);

            pendingRequests.Clear();

            foreach (var e in responses)
            {
                Debug.Log("receive response " + e.GetType().Name);

                if (e is ResponseGameStart || e is ResponseFullState)
                {
                    state = State.Playing;
                    ClearGameState();
                    LoadStartGameScene();
                }
                else if (e is ResponseGameStatus)
                {
                    var resp = e as ResponseGameStatus;
                    if (resp.status == ResponseGameStatus.GameStatus.Idle)
                    {
                        Debug.Log("Receive game status. Game is idling. Request  new game");
                        pendingRequests.Add(new RequestStartNewGame());
                        state = State.Idle;
                    }
                    else
                    {
                        Debug.Log("Receive game status. Game is in progress. Request full state");
                        pendingRequests.Add(new RequestFullState());
                        state = State.Playing;
                    }
                }
                else if (e is ResponseSpawn)
                {
                    var ev = e as ResponseSpawn;
                    Debug.Log($"Receive new spawn of prefab {ev.prefab} with id {ev.id} at {ev.position}");

                    GameObject obj;
                    if (ev.prefab == FfiResponses.PrefabKind.Player)
                    {
                        obj = Instantiate(playerPrefab);
                    }
                    else
                    {
                        throw new System.NotImplementedException();
                    }

                    DomainRef.Add(obj, new RefId(ev.id));
                    obj.transform.position = ev.position;
                }
                else if (e is ResponsePos)
                {
                    var ev = e as ResponsePos;
                    Debug.Log($"Receive new position for {ev.id} at {ev.position}");

                    var obj = GetDomainObjById(new RefId(ev.id));
                    obj.transform.position = ev.position;
                }
                else
                {
                    throw new System.NotImplementedException($"Unsupported server response {e.GetType()}");
                }
            }
        }