Beispiel #1
0
        public async static Task <JsonElement> SetGamestateProperties(JsonElement element, EDGameState gameState, string commander, StarSystemChecker starSystemChecker, Func <EDGameState, object> setProperties, Action <JsonElement, Dictionary <string, JsonElement> > addStateToElement = null)
        {
            var _rdb = SharedSettings.RedisClient.GetDatabase(1);
            var elementAsDictionary = JsonSerializer.Deserialize <Dictionary <string, JsonElement> >(element.GetRawText());

            if (elementAsDictionary.TryGetValue("timestamp", out var timeStampElement))
            {
                if (!timeStampElement.TryGetDateTimeOffset(out _))
                {
                    throw new InvalidTimestampException();
                }
            }

            bool setCache = await EDSystemCache.GetSystemCache(elementAsDictionary, _rdb, starSystemChecker);

            GameStateChanger.GameStateFixer(gameState, commander, elementAsDictionary);

            var addItems = setProperties(gameState);

            var transientState = JsonDocument.Parse(JsonSerializer.Serialize(addItems)).RootElement;

            await EDSystemCache.SetSystemCache(gameState, _rdb, setCache);

            if (addStateToElement != null)
            {
                addStateToElement(transientState, elementAsDictionary);

                var json = JsonSerializer.Serialize(elementAsDictionary);
                return(JsonDocument.Parse(json).RootElement);
            }

            return(transientState);
        }
Beispiel #2
0
 private void Awake()
 {
     if (!clicked)
     {
         // clicked = true;
         gameStateChanger = GetComponent <GameStateChanger>();
     }
 }
 private void Awake()
 {
     if (!clicked)
     {
         GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("Player");
         player           = gameObjects[0];
         gameStateChanger = GetComponent <GameStateChanger>();
     }
 }
Beispiel #4
0
        public void TestOperateOnState()
        {
            var gameStateChanger = new GameStateChanger();
            var increaseNumberOfEnemiesCommand = new SerializableCommand <GameStateChanger>
                                                     (gameStateChanger, changer => changer.IncreaseNumberOfEnemies());

            increaseNumberOfEnemiesCommand.Execute();

            Assert.AreEqual(1, TestGameState.Instance.numberOfEnemies);
            Assert.AreEqual(0, TestGameState.Instance.numberOfPlayers);
        }
Beispiel #5
0
 private void Awake()
 {
     gameRules        = GetComponent <GameRules>();
     gameStateChanger = GetComponent <GameStateChanger>();
     objectPooler     = GetComponent <ObjectPooler>();
     spriteBucket     = GetComponent <SpriteBucket>();
     panelBucket      = GetComponent <PanelBucket>();
     sessionData      = GetComponent <SessionData>();
     roundCoordinator = GetComponent <RoundCoordinator>();
     roundTimer       = GetComponent <RoundTimer>();
 }
Beispiel #6
0
    private void Awake()
    {
        for (int i = 0; i < remy.transform.childCount; i++)
        {
            if (remy.transform.GetChild(i).name.Equals("Main Camera"))
            {
                camera = remy.transform.GetChild(i).gameObject;
            }
        }

        bloom            = camera.GetComponent <PostProcessVolume>().profile.GetSetting <Bloom>();
        gameStateChanger = GetComponent <GameStateChanger>();
    }
Beispiel #7
0
        public void TestSerialization()
        {
            var listOfCommands = new List <ICommand>();

            var methodGameStateChanger = new MethodGameStateChanger();
            var setPlayersAndEnemies   = TestHelper.GeneratePlayerAndEnemiesCommand();

            listOfCommands.Add(setPlayersAndEnemies);

            var gameStateChanger        = new GameStateChanger();
            var increaseNumberOfEnemies = new SerializableCommand <GameStateChanger>
                                              (gameStateChanger, changer => changer.IncreaseNumberOfEnemies());

            listOfCommands.Add(increaseNumberOfEnemies);


            byte[] bytes = new byte[0];

            using (var memoryStream = new MemoryStream())
            {
                new BinaryFormatter().Serialize(memoryStream, listOfCommands);
                bytes = memoryStream.ToArray();
            }

            var newListOfCommands = new List <ICommand>();

            using (var memoryStream = new MemoryStream(bytes, 0, bytes.Length))
            {
                memoryStream.Write(bytes, 0, bytes.Length);
                memoryStream.Position = 0;
                var data = new BinaryFormatter().Deserialize(memoryStream);
                newListOfCommands = data as List <ICommand>;
            }

            foreach (var command in newListOfCommands)
            {
                command.Execute();
            }

            Assert.AreEqual(1, TestGameState.Instance.numberOfPlayers);
            Assert.AreEqual(3, TestGameState.Instance.numberOfEnemies);
        }
Beispiel #8
0
        public void TestList()
        {
            var listOfCommands = new List <ICommand>();

            var methodGameStateChanger = new MethodGameStateChanger();
            var setPlayersAndEnemies   = TestHelper.GeneratePlayerAndEnemiesCommand();

            listOfCommands.Add(setPlayersAndEnemies);

            var gameStateChanger        = new GameStateChanger();
            var increaseNumberOfEnemies = new SerializableCommand <GameStateChanger>
                                              (gameStateChanger, changer => changer.IncreaseNumberOfEnemies());

            listOfCommands.Add(increaseNumberOfEnemies);

            foreach (var command in listOfCommands)
            {
                command.Execute();
            }

            Assert.AreEqual(1, TestGameState.Instance.numberOfPlayers);
            Assert.AreEqual(3, TestGameState.Instance.numberOfEnemies);
        }
 private void Awake()
 {
     gameStateChanger = GetComponent <GameStateChanger>();
 }
Beispiel #10
0
    /*
     * public void Update()
     * {
     *  if (Input.GetKeyDown(KeyCode.Period))
     *  {
     *      Die();
     *  }
     * }*/

    #region MonoBehaviour Messages
    private void Awake()
    {
        gameStateChanger = GetComponent <GameStateChanger>();
        remyDead         = GetComponent <RemyDead>();
    }