Esempio n. 1
0
        public void TargetSetGame(
            NetworkConnection target,
            string labyrinth,
            Algorithms.Id algo,
            int round)
        {
            controls.RecordedSteps.Value = new int[0];

            Client.Instance.LabyrinthData.Value = JsonUtility.FromJson <Labyrinths.Labyrinth>(labyrinth);

            // Destroy old labyrinth
            if (Client.Instance.Labyrinth.Value != null)
            {
                Destroy(Client.Instance.Labyrinth.Value.gameObject);
                Client.Instance.Labyrinth.Value = null;
            }

            Labyrinths.Labyrinth data = JsonUtility.FromJson <Labyrinths.Labyrinth>(labyrinth);

            Client.Instance.Labyrinth.Value =
                Labyrinths.Resources.Instance
                .GetLabyrinthObject(Client.Instance.LabyrinthData.Value)
                .Create(Client.Instance.LabyrinthData.Value);

            Client.Instance.Algorithm.Set(Algorithms.Resources.Instance.GetAlgorithm(algo));

            gameManager.IsLevelCompleted.Value = false;

            gameManager.Level.Value = round;

            Client.Instance.State.Set(ClientGameState.Playing);
        }
Esempio n. 2
0
        public void StartNextLevel(
            ILabyrinth labyrinth,
            Algorithms.Id algorithmId)
        {
            currentLevel = new Level
            {
                Number    = NextLevelNumber,
                Labyrinth = labyrinth,
                Algorithm = Algorithms.Resources.Instance.GetAlgorithm(algorithmId)
            };

            levels.Add(currentLevel);

            SQLiteUtilities.InsertLevel(
                SQLiteUtilities.GetNextLevelID(),
                currentLevel.Number,
                Id,
                labyrinth.Id
                );

            baseAlgorithmId = algorithmId;

            for (int i = 0; i < PlayerList.instance.list.Count; i++)
            {
                Player player = PlayerList.instance.GetPlayerWithId(i);

                switch (player.ServerPlayerGameState)
                {
                case ClientGameState.Ready:
                case ClientGameState.PlayingTutorial:
                case ClientGameState.Playing:
                case ClientGameState.ViewingGlobalReplay:
                case ClientGameState.ViewingLocalReplay:
                case ClientGameState.WaitingForNextLevel:

                    Debug.Log(player);

                    player.serverAlgorithm = baseAlgorithmId;

                    player.serverLabyrinthId = currentLevel.Labyrinth.Id;

                    AssignCourse(player);

                    player.TargetSetGame(
                        player.connectionToClient,
                        currentLevel.Labyrinth.Json,
                        player.serverAlgorithm,
                        currentLevel.Number);

                    break;
                }
            }

            Server.Instance.State.Set(LevelState);
        }
        public void OnAlgorithmChanged(Algorithms.Id algorithm)
        {
            MoveIndex = MoveIndex < MoveCount ? MoveIndex : MoveCount - 1;
            algorithmSequence.Algorithm = algorithm;
            OnAlgorithmChangedHandler?.Invoke();

            // TODO fix this is not clean
            // We should lose the callback ref everytinme
            algorithmSequence.OnMoveIndexChangedHandler += algorithmSelection.OnAlgorithmMoveIndexChanged;
            algorithmSequence.OnMoveIndexChangedHandler?.Invoke(algorithmSequence.MoveIndex);

            //if (algorithmSequence.OnChangedHandler != null)
            //    algorithmSequence.OnChangedHandler -= OnAlgorithmChanged;

            //algorithmSequence.OnChangedHandler += OnAlgorithmChanged;
            //algorithmSequence.OnMoveIndexChangedHandler?.Invoke(algorithmSequence.MoveIndex);
        }
Esempio n. 4
0
        void GenerateVisualForAlgorithm(Algorithms.Id algorithm)
        {
            algorithmStepsPosition = Client.Instance.Algorithm.Value.GetAlgorithmSteps(Client.Instance.LabyrinthData.Value);

            Debug.Log("algorithmStepsPosition Count : " + algorithmStepsPosition.Count);

            for (int i = 0; i < algorithmStepsPosition.Count; i++)
            {
                Debug.Log("algorithmStepsPosition #" + i + " : " + algorithmStepsPosition[i].x + " , " + algorithmStepsPosition[i].y + " , " + algorithmStepsPosition[i].Color);

                GameObject obj = Instantiate(sphere, GetWorldPosition(algorithmStepsPosition[i].x, algorithmStepsPosition[i].y), Quaternion.identity, gameObject.transform);
                Algorithms.FloorPainter floorPainter = Client.Instance.Labyrinth.Value.GetTile(algorithmStepsPosition[i].x, algorithmStepsPosition[i].y).GetComponentInChildren <Algorithms.FloorPainter>();

                if (floorPainter != null)
                {
                    floorPainter.PaintFloorWithColor(algorithmStepsPosition[i].Color);
                }

                objectList.Add(obj);
            }
        }
Esempio n. 5
0
        public void TargetSetGameWithSteps(
            NetworkConnection target,
            int[] steps,
            string labyrinth,
            Algorithms.Id algo,
            int round,
            bool isTutorial)
        {
            controls.RecordedSteps.Value = steps;

            Client.Instance.LabyrinthData.Value = JsonUtility.FromJson <Labyrinths.Labyrinth>(labyrinth);

            Client.Instance.Labyrinth.Value = Labyrinths.Resources.Instance
                                              .GetLabyrinthObject(Client.Instance.LabyrinthData.Value)
                                              .Create(Client.Instance.LabyrinthData.Value);

            Client.Instance.Algorithm.Set(Algorithms.Resources.Instance.GetAlgorithm(algo));

            gameManager.IsLevelCompleted.Value = false;

            gameManager.Level.Value = round;

            Client.Instance.State.Value = isTutorial ? ClientGameState.PlayingTutorial : ClientGameState.Playing;
        }