Esempio n. 1
0
 public void RestartGame()
 {
     Destroy(GameManager.instance.gameObject);
     GameManager.instance = null;
     GameLogger.LogMessage("Restart called", "GameMenuController");
     GameManager.RestartGame(GameManager.customLevel);
 }
Esempio n. 2
0
    private void SetupShop()
    {
        GameLogger.LogMessage("Shop setup", "UpgradeShop");

        var upgradesIt = GameManager.instance.upgradeManager.availableUpgrades.GetEnumerator();

        for (int i = 0; i < this.buttons.Length; i++)
        {
            if (!upgradesIt.MoveNext())
            {
                this.buttons[i].gameObject.SetActive(false);
                continue;
            }

            this.buttons[i].gameObject.SetActive(true);
            var button = this.buttons[i].GetComponent <Button>();
            button.onClick.RemoveAllListeners();

            string key = upgradesIt.Current.Key;

            button.onClick.AddListener(() => {
                GameManager.instance.upgradeManager.TryToBuy(key);
                this.SetupShop();
            });

            GameLogger.LogMessage($"Item in UpgradeShop on {i} position is {key}", "UpgradeShop");

            this.buttons[i].GetComponentInChildren <Text>(true).text = $"{upgradesIt.Current.Value.Name}\r\nCost: {upgradesIt.Current.Value.Cost}";
        }
    }
Esempio n. 3
0
    private IEnumerator Start()
    {
        GameLogger.LogMessage("Loading Screen Startup", "LoadingScreen");
        yield return(null);

        AsyncOperation loading = SceneManager.LoadSceneAsync(2);

        loading.completed += (asyncOperation) => {
            GameLogger.LogMessage($"Reload of level {GameManager.instance.currentLevelNumber} complete", "LoadingScreen");
            GameManager.instance.Awake();

            if (LoadingScreen.needPlayerCopy)
            {
                GameManager.instance.playerInstance.CloneStats(LoadingScreen.playerStorage);
            }
        };

        while (!loading.isDone)
        {
            if (loading.progress < 0.9f)
            {
                float progress = Mathf.Clamp01(loading.progress / 0.9f);
                this.progressBar.value = progress;
            }

            this.progressBar.value = loading.progress;

            yield return(null);
        }
    }
Esempio n. 4
0
    public void GenerateLevel(Level level)
    {
        GameLogger.LogMessage($"Processing file {this.filePath}", "ReaderGenerator");
        var levelAsset = Resources.Load(this.filePath, typeof(TextAsset)) as TextAsset;

        try {
            if (levelAsset == null)
            {
                GameLogger.LogMessage("Opening custom level", "ReaderGenerator");
                using (var file = new BinaryReader(File.Open(this.filePath, FileMode.Open))) {
                    this.ProcessFile(file, level);
                }
            }
            else
            {
                GameLogger.LogMessage("Opening standart level", "ReaderGenerator");
                using (var file = new BinaryReader(new MemoryStream(levelAsset.bytes))) {
                    this.ProcessFile(file, level);
                }
            }
        } catch {
            GameLogger.LogError($"Incorrect input file", "ReaderGenerator");
            level.width     = Level.MinWidth;
            level.height    = Level.MinHeight;
            level.objectMap = new MapObject[level.height, level.width];
            for (int i = 0; i < level.height; i++)
            {
                for (int j = 0; j < level.width; j++)
                {
                    level.objectMap[i, j] = MapObject.Floor;
                }
            }
        }
    }
        private void GenerateNodeData()
        {
            int nodeIndex, row = 0, column = 0;

            for (int i = 0; i < m_ListOfBoxes.Count; i++)
            {
                nodeIndex = m_ListOfBoxes[i].GetBoxID();

                m_LevelNodeData.Add(nodeIndex, new GameStructs.NodeData()
                {
                    topLineID = new GameStructs.LineID {
                        ID = nodeIndex, rotation = GameEnums.ELineRotationCode.HORIZONTAL_ROTATION_CODE
                    },
                    rightLineID = new GameStructs.LineID {
                        ID = (row + (NoOfRowsOrColumns - 1) * column) + (NoOfRowsOrColumns - 1), rotation = GameEnums.ELineRotationCode.VERTICAL_ROTATION_CODE
                    },
                    bottomLineID = new GameStructs.LineID {
                        ID = nodeIndex + (NoOfRowsOrColumns - 1), rotation = GameEnums.ELineRotationCode.HORIZONTAL_ROTATION_CODE
                    },
                    leftLineID = new GameStructs.LineID {
                        ID = row + (NoOfRowsOrColumns - 1) * column, rotation = GameEnums.ELineRotationCode.VERTICAL_ROTATION_CODE
                    }
                });

                GameLogger.LogMessage(i.ToString() + " : " + "[" + m_LevelNodeData[i].topLineID.ToString() + "," + m_LevelNodeData[i].rightLineID.ToString() + "," + m_LevelNodeData[i].bottomLineID.ToString() + "," + m_LevelNodeData[i].leftLineID.ToString() + "]");

                column++;

                if (column >= NoOfRowsOrColumns - 1)
                {
                    column = 0;
                    row++;
                }
            }
        }
Esempio n. 6
0
    public void GameOver()
    {
        GameLogger.LogMessage("Game over", "GameManager");
        this.gameState = GameState.GAME_OVER;

        Time.timeScale = 0;
    }
Esempio n. 7
0
    public void SaveLevel()
    {
        try {
            using (var file = new BinaryWriter(File.Open(Utility.levelDirectory + this.levelName.text + ".bytes", FileMode.Create))) {
                file.Write((byte)'L');
                file.Write((byte)'V');
                file.Write((byte)'L');
                file.Write((byte)0);
                file.Write(EditorManager.level.width);
                file.Write(EditorManager.level.height);
                file.Write((byte)0);

                for (int i = 0; i < EditorManager.level.height; i++)
                {
                    foreach (var cell in this.map[i])
                    {
                        file.Write((int)cell.alias);
                    }
                }

                file.Write(0);
            }
        } catch (System.Exception e) {
            GameLogger.LogMessage($"Unable to save file {e.Message}", "EditorManager");
        }
    }
Esempio n. 8
0
 /// <summary>
 /// Shows the hand of <paramref name="player"/>
 /// </summary>
 /// <param name="player"></param>
 public void ShowPlayerHand(BlackPetePlayer <T> player)
 {
     foreach (string item in player.ShowPlayerCards())
     {
         GameLogger.LogMessage(item);
     }
 }
Esempio n. 9
0
    private void ProcessFile(BinaryReader file, Level level)
    {
        var bytes = System.Text.Encoding.Default.GetString(file.ReadBytes(3));

        if (bytes != "LVL")
        {
            throw new System.Exception("$Incorrect file {bytes}");
        }

        file.ReadByte();

        level.width  = file.ReadInt32();
        level.height = file.ReadInt32();

        GameLogger.LogMessage("Size: " + level.width + " " + level.height, "ReaderGenerator");
        file.ReadByte();

        level.objectMap = new MapObject[level.height, level.width];
        for (int i = 0; i < level.height; i++)
        {
            for (int j = 0; j < level.width; j++)
            {
                level.objectMap[i, j] = (MapObject)file.ReadInt32();
            }
        }
    }
Esempio n. 10
0
 public Level(IMapGenerator mapGenerator, int difficulty)
 {
     this.generator  = mapGenerator;
     this.difficulty = difficulty;
     GameLogger.LogMessage($"Current difficulty {difficulty} {this.difficulty}", "Level");
     this.LevelSetup();
 }
Esempio n. 11
0
    public void GenerateLevel(Level level)
    {
        GameLogger.LogMessage("CaveGeneration started", "CaveGenerator");

        level.width  = this.width;
        level.height = this.height;
        this.CellularAutomatonGeneration(level);
    }
Esempio n. 12
0
 private IEnumerator StartGame()
 {
     GameLogger.LogMessage("StartGame called", "GameManager");
     this.StartCoroutine(this.CheckLoading());
     this.levelManager.SetupScene(this.currentLevelNumber, GameManager.customLevel);
     this.playerInstance = MonoBehaviour.FindObjectOfType <Player>();
     yield return(new WaitForEndOfFrame());
 }
Esempio n. 13
0
 protected virtual void CheckDeath()
 {
     if (this.hp <= 0)
     {
         GameLogger.LogMessage($"Entity {this.name} died on {this.transform.position}", "Entity");
         MonoBehaviour.Destroy(this.gameObject);
         return;
     }
 }
Esempio n. 14
0
 public void ContinueGame()
 {
     GameLogger.LogMessage("Continue called", "GameMenuController");
     GameManager.instance.gameState = GameManager.GameState.PLAYING;
     GameManager.ProcessCommand(this.console.text);
     this.console.gameObject.SetActive(false);
     this.console.text = string.Empty;
     Time.timeScale    = 1.0f;
 }
Esempio n. 15
0
        public Player(string name, Color color, GameEnums.EPlayerType playerType)
        {
            m_Name        = name;
            m_PlayerType  = playerType;
            m_Score       = 0;
            m_PlayerColor = color;

            GameLogger.LogMessage(name + " Created!!");
        }
Esempio n. 16
0
    private void Awake()
    {
        GameLogger.LogMessage("Player awake", "Player");
        this.controls = new PlayerInput();
        this.controls.Player.SetCallbacks(this);
        this.currentShotCD = this.minShotCD;

        sr = this.GetComponent <SpriteRenderer>();
    }
Esempio n. 17
0
    private IEnumerator EditorShowFileDialog()
    {
        yield return(FileBrowser.WaitForLoadDialog(false, Utility.levelDirectory, "Choose level to edit", "Choose"));

        GameLogger.LogMessage("EditorBrowser: " + FileBrowser.Success + " " + FileBrowser.Result, "MenuController");
        if (FileBrowser.Success)
        {
            EditorManager.StartEditor(new ReaderGenerator(FileBrowser.Result.Replace("\\", "/")));
        }
    }
Esempio n. 18
0
 /// <summary>
 /// Checks all players at the start of the game, to see if they have any pairs
 /// </summary>
 private void PairCheckAllPlayers()
 {
     foreach (BlackPetePlayer <T> player in Players)
     {
         foreach (string pair in player.CheckForPair())
         {
             GameLogger.LogMessage(pair);
         }
     }
 }
Esempio n. 19
0
    public static void StartEditor(IMapGenerator generator)
    {
        EditorManager.level = new Level(generator, 0);

        var reloading = SceneManager.LoadSceneAsync(3);

        GameLogger.LogMessage("Editor loading started", "EditorManager");
        reloading.completed += (asyncOperation) => {
            GameLogger.LogMessage("Editor loading complete", "EditorManager");
            Time.timeScale = 1;
        };
    }
        void Start()
        {
            InitializeDimensions();
            ArrangeLines();
            ArrangeBoxes();
            GenerateNodeData();
            GenerateAffectedBoxesData();
            GenerateNeighbouringBoxesList();

            GameEventManager.TriggerLevelCreated();
            GameLogger.LogMessage("Level Created!!");
        }
Esempio n. 21
0
    public CaveGenerator(int levelWidth, int levelHeight, int seed = -1)
    {
        if (seed != -1)
        {
            Random.InitState(seed);
        }

        GameLogger.LogMessage("Random state is " + Random.state, "CaveGenerator");

        this.width  = levelWidth + Level.BorderSize * 2;
        this.height = levelHeight + Level.BorderSize * 2;
    }
Esempio n. 22
0
    private void LevelSetup()
    {
        GameLogger.LogMessage("Level setup called", "Level");
        this.generator.GenerateLevel(this);
        this.generator.SetPlayerPosition(this);
        this.generator.SetExitPosition(this);
        this.generator.PlaceOre(this, new MapObject[] { MapObject.GoldOre, MapObject.HealOre }, new int[] { 50, 20 }, new float[] { 0.25f, 0.1f });
        this.WallProc();
        this.FindObjects();

        int fightersCount  = 14;
        int suicidersCount = 19;
        int bombersCount   = 7;
        int entityCap      = this.width * this.height / 100;

        switch (this.difficulty)
        {
        case 0: {
            fightersCount  = 0;
            suicidersCount = 0;
            bombersCount   = 0;
            break;
        }

        case 1: {
            fightersCount  = 20;
            suicidersCount = 0;
            bombersCount   = 0;
            break;
        }

        case 2: {
            fightersCount  = 15;
            suicidersCount = 20;
            bombersCount   = 0;
            break;
        }

        default: {
            int coef = Mathf.Min(this.difficulty, (int)(4f * (entityCap - fightersCount - suicidersCount - bombersCount) / 5f));
            fightersCount  += coef / 2;
            suicidersCount += coef / 2;
            bombersCount   += coef / 4;
            break;
        }
        }

        GameLogger.LogMessage($"Fighters: {fightersCount} Suiciders: {suicidersCount} Bombers: {bombersCount}, Difficulty: {this.difficulty}", "Level");
        this.generator.PlaceSpawners(this, new MapObject[] { MapObject.EnemyFighterSpawner, MapObject.EnemySuiciderSpawner, MapObject.EnemyBomberSpawner }, new int[] { fightersCount, suicidersCount, bombersCount });

        this.AssetsInit();
    }
Esempio n. 23
0
 private void Update()
 {
     if (Keyboard.current.f9Key.wasPressedThisFrame)
     {
         GameManager.isDeveloperMode = true;
         GameLogger.LogMessage("Developer mode entered", "MenuController");
     }
     else if (Keyboard.current.f10Key.wasPressedThisFrame)
     {
         GameManager.isDeveloperMode = false;
         GameLogger.LogMessage("Developer mode exited", "MenuController");
     }
 }
Esempio n. 24
0
    /// <summary>
    /// Set up a scene.
    /// </summary>
    /// <param name="level"> Level id. </param>
    /// <param name="gen"> Generator for custom level. </param>
    public void SetupScene(int level, IMapGenerator gen = null)
    {
        IMapGenerator levelGenerator = gen;

        if (levelGenerator == null)
        {
            GameLogger.LogMessage("Custom generator is null", "LevelManager");
            if (level == 5)
            {
                GameLogger.LogMessage("Boss level selected", "LevelManager");
                levelGenerator = new ReaderGenerator("Levels/NewBossLevel");
            }
            else
            {
                levelGenerator = new CaveGenerator(150, 150);
            }
        }

        GameLogger.LogMessage($"Current level: {level}", "LevelManager");



        this.currentLevel = new Level(levelGenerator, level);

        this.currentLevel.AddFloorAsset(this.caveFloor, MapObject.Floor);

        this.currentLevel.AddObjectAsset(this.caveGoldOre, MapObject.GoldOre);
        this.currentLevel.AddObjectAsset(this.cavePurpleOre, MapObject.HealOre);
        this.currentLevel.AddObjectAsset(this.caveBlockage, MapObject.Blockage);

        this.currentLevel.AddObjectAsset(this.enemyFighterSpawner, MapObject.EnemyFighterSpawner);
        this.currentLevel.AddObjectAsset(this.enemyFighter, MapObject.EnemyFighter);

        this.currentLevel.AddObjectAsset(this.enemySuiciderSpawner, MapObject.EnemySuiciderSpawner);
        this.currentLevel.AddObjectAsset(this.enemySuicider, MapObject.EnemySuicider);

        this.currentLevel.AddObjectAsset(this.enemyBomberSpawner, MapObject.EnemyBomberSpawner);
        this.currentLevel.AddObjectAsset(this.enemyBomber, MapObject.EnemyBomber);

        this.currentLevel.AddObjectAsset(this.enemyBoss, MapObject.EnemyFlagman);

        this.currentLevel.AddWallAsset(this.caveWall, MapObject.Wall);
        this.currentLevel.AddWallAsset(this.caveGoldOre[0], MapObject.GoldOre);
        this.currentLevel.AddWallAsset(this.cavePurpleOre[0], MapObject.HealOre);
        this.currentLevel.AddWallAsset(this.caveBlockage[0], MapObject.Blockage);

        GameLogger.LogMessage("Assets added", "LevelManager");

        this.LevelSetup(this.currentLevel);
    }
Esempio n. 25
0
    public void OnZoom(InputAction.CallbackContext context)
    {
        float val = context.ReadValue <float>();

        if (val > 0 && Camera.main.orthographicSize > 3)
        {
            Camera.main.orthographicSize--;
        }
        else if (val < 0 && Camera.main.orthographicSize < level.height / 2 - Level.BorderSize && Camera.main.orthographicSize * Camera.main.aspect < level.width / 2 - Level.BorderSize)
        {
            Camera.main.orthographicSize++;
        }

        GameLogger.LogMessage($"Camera size is {Camera.main.orthographicSize} ", "EditorManager");
    }
Esempio n. 26
0
    public void OnTabSelect(TabButton tab)
    {
        this.selectedTab = tab;
        this.ResetTabs();
        tab.sprite.color = TabPanel.activeColor;

        int index = tab.transform.GetSiblingIndex();

        for (int i = 0; i < this.pages.Count; i++)
        {
            this.pages[i].SetActive(i == index);
        }

        GameLogger.LogMessage($"Selected tab {this.pages[index].name}", "TabPanel");
    }
Esempio n. 27
0
    public static void RestartGame(IMapGenerator generator)
    {
        GameLogger.LogMessage("Game restart", "GameManager");

        GameManager.customLevel = generator;

        if (GameManager.instance != null)
        {
            GameManager.instance.gameState          = GameState.NOT_LOADED;
            GameManager.instance.currentLevelNumber = 1;
            GameManager.instance.upgradeManager.ResetUpgrades();
            GameLogger.LogMessage("GameManager instantiated", "GameManager");
        }

        LoadingScreen.StartLoading();
    }
Esempio n. 28
0
    public void SelectBrush(MapObject brushType)
    {
        if (this.selectedBrush >= MapObject.PortalRed && this.selectedBrush <= MapObject.PortalYellow && brushType != this.selectedBrush &&
            this.portalMap[this.selectedBrush].Item1 != null && this.portalMap[this.selectedBrush].Item2 == null)
        {
            var portalPos = new Vector2Int(Mathf.RoundToInt(this.portalMap[this.selectedBrush].Item1.transform.position.x),
                                           Mathf.RoundToInt(this.portalMap[this.selectedBrush].Item1.transform.position.y));
            Destroy(this.map[portalPos.y][portalPos.x].obj);
            this.map[portalPos.y][portalPos.x].obj = Instantiate(this.brushes[MapObject.Floor], new Vector3(portalPos.x, portalPos.y, 0), Quaternion.identity);
            this.map[portalPos.y][portalPos.x].obj.transform.SetParent(this.grid.transform);
            this.map[portalPos.y][portalPos.x].alias = MapObject.Floor;
            this.portalMap[this.selectedBrush].Item1 = null;
        }

        this.selectedBrush = brushType;
        GameLogger.LogMessage($"Brush selected is {brushType}", "EditorManager");
    }
Esempio n. 29
0
    /// <summary>
    /// (DEBUG ONLY) Prints <paramref name="matrix"/> into Unity Debug stream.
    /// </summary>
    /// <param name="matrix"> Matrix to print. </param>
    /// <typeparam name="T"> Type of matrix cell. </typeparam>
    public static void PrintMatrix <T>(T[,] matrix, int width, int height)
        where T : struct
    {
        GameLogger.LogMessage("=========================", "MatrixPrint");
        for (int i = 0; i < height; i++)
        {
            string buffer = string.Empty;
            for (int j = 0; j < width; j++)
            {
                buffer += Convert.ToInt32(matrix[i, j]);
            }

            GameLogger.LogMessage(buffer, "MatrixPrint");
        }

        GameLogger.LogMessage("=========================", "MatrixPrint");
    }
Esempio n. 30
0
    public void SetupPortal(GameObject outObject, MapObject color)
    {
        this.portalOut = outObject;
        this.GetComponent <SpriteRenderer>().color = Colors[color];

        if (this.portalOut != null)
        {
            var portalComp = this.portalOut.GetComponent <Portal>();
            if (portalComp != null)
            {
                portalComp.GetComponent <SpriteRenderer>().color = Colors[color];
                portalComp.portalOut = this.gameObject;
            }
        }

        if (this.portalOut != null)
        {
            GameLogger.LogMessage($"Portal of color {color} on {this.transform.position} and {outObject.transform.position} are connected", "Portal");
        }
    }