private void ChooseItemProperty(bool activatedByPlayer) { if (EndBattleGameMenu.PlayerFinished || EndBattleGameMenu.OpponentFinished) { return; } float possibilityToChooseShooter = 0; if (MainScript.UseShooter) { possibilityToChooseShooter = 50f * ((4f - MainScript.BattleGameCurrentShooterCounter) / 4); } float possibilityToChooseObstacle = (100f - possibilityToChooseShooter) * ((4f - MainScript.BattleGameCurrentButtonCounter) / MainScript.AllFreezer.Count); int randomNumber = Random.Range(1, 101); if (randomNumber < possibilityToChooseShooter) { if (activatedByPlayer) { GameObject.Find("Ruby").GetComponent <RubyFireAim>().EnableShooting(); MainScript.BattleGameCurrentShooterCounter++; StartCoroutine(ShowItemText("You received 3 shots!")); } else { GameObject.Find("Opponent").GetComponent <OpponentFireAim>().EnableShooting(); MainScript.BattleGameCurrentShooterCounter++; StartCoroutine(ShowItemText("Opponent received 3 shots!")); } } else if (randomNumber < possibilityToChooseObstacle + possibilityToChooseShooter) { //Generates an obstacle GameObject gameObject = Instantiate(obstacleGenerationPrefab); ObstacleGeneration obstacleGeneration = gameObject.GetComponent <ObstacleGeneration>(); if (activatedByPlayer) { obstacleGeneration.InsertObstacleOnPath((int)MainScript.BattleGameCurrentButtonCounter, !activatedByPlayer, GameObject.Find("Opponent").GetComponent <OpponentController>().CurrentNodePosition.Id); } else { obstacleGeneration.InsertObstacleOnPath((int)MainScript.BattleGameCurrentButtonCounter, !activatedByPlayer, MainScript.PlayerPath[MainScript.PlayerPath.Count - 1].Id); } MainScript.BattleGameCurrentButtonCounter++; StartCoroutine(ShowItemText("Obstacle added!")); } else { if (activatedByPlayer) { StartCoroutine(GameObject.Find("Opponent").GetComponent <OpponentController>().FreezeOpponent(10)); StartCoroutine(ShowItemText("Opponent is slowed down!")); } else { StartCoroutine(GameObject.Find("Ruby").GetComponent <RubyController>().FreezePlayer(10)); StartCoroutine(ShowItemText("You are slowed down!")); } } }
/** * <summary>Initalizes the game. Creates the maze and adds the obstacles.</summary> */ public void InitializeGame() { EnableUserInput = false; //Initializes the static variables of the game. CurrentState = 0; CurrentStepCount = 0; UpdateStepCounter(); AllNodes = new Dictionary <int, NodeController>(); AllEdges = new List <EdgeController>(); AllButtons = new List <ButtonController>(); PlayerPath = new List <NodeController>(); //Set all possible colors (at least as many as NumberOfObstacles) Colors = new List <Color> { new Color(0, 1, 0), new Color(0, 0, 1), new Color(1, 0, 0), new Color(1, 1, 0) }; //Initializes the number of states. NumberOfStates = (int)Math.Pow(2, NumberOfButtons); //Moves the player to the start point. GameObject.Find("Ruby").GetComponent <RubyController>().SetPositionAndScale(); //Generates the labyrinth GameObject gameObject = Instantiate(aldousBroderAlgorithmPrefab); AldousBroderAlgorithm a = gameObject.GetComponent <AldousBroderAlgorithm>(); a.Initialize((int)Math.Floor(1 / ScaleMazeSize * 18), (int)Math.Floor(1 / ScaleMazeSize * 10)); if (CurrentLevelCount != -1) { GarbageCollectorGameObjects.Add(gameObject); } if (!IsBattleGameMode) { //Generates all obstacles gameObject = Instantiate(obstacleGenerationPrefab); ObstacleGeneration obstacleGeneration = gameObject.GetComponent <ObstacleGeneration>(); obstacleGeneration.InsertObstacles(); if (CurrentLevelCount != -1) { GarbageCollectorGameObjects.Add(gameObject); } //Calculates the optimal path and distance. gameObject = Instantiate(modifiedDijkstraAlgorithmPrefab); ModifiedDijkstraAlgorithm dijkstra = gameObject.GetComponent <ModifiedDijkstraAlgorithm>(); if (ScaleMazeSize == 0.5f) { dijkstra.Initialize(AllNodes[0], AllNodes[719]); } else { dijkstra.Initialize(AllNodes[0], AllNodes[179]); } dijkstra.CalculateModifiedDijkstraAlgorithm(); GameObject stepCounterText = GameObject.Find("OptimalSteps"); stepCounterText.GetComponent <TextMeshProUGUI>().text = "Optimal: " + dijkstra.ShortestDistance; OptimalStepCount = dijkstra.ShortestDistance; ShortestPath = dijkstra.ShortestPath; if (CurrentLevelCount != -1) { GarbageCollectorGameObjects.Add(gameObject); } } //Creates all walls of the maze. GameObject createWallsObject = Instantiate(createWallsPrefab); CreateWalls createWallsScript = createWallsObject.GetComponent <CreateWalls>(); createWallsScript.CreateAllWalls(); if (CurrentLevelCount != -1) { GarbageCollectorGameObjects.Add(createWallsObject); } if (IsBattleGameMode) { GenerateFreezer(); GameObject.Find("Opponent").GetComponent <OpponentController>().InitializeOpponent(); } //Enables the user input. EnableUserInput = true; }