예제 #1
0
        //Delete the previous level's data
        private static void DeletePreviousArray()
        {
            if (player != null)
            {
                player.ClearSubscriptions();
                player.Dispose();
            }
            currentLevelSurfaceArray = null;
            currentLevelCaveArray    = null;
            objectives     = null;
            itemsToCollect = null;
            moveNumber     = 0;
            gameOver       = false;
            returnHome     = false;

            player = null;
            relic  = null;
        }
예제 #2
0
        //Generate the level specified by levelNumber
        public static void GenerateLevel(int levelNumber)
        {
            //Clear data
            DeletePreviousArray();
            //Get new level data
            LevelContainerClass.levelInfo levelInfo = LevelContainerClass.extractLevelInfo(levelNumber);
            //Load Help Window
            levelInfoWindow = new LevelInfoWindow();

            //Get level rankings
            gold   = levelInfo.gold;
            silver = levelInfo.silver;
            bronze = levelInfo.bronze;
            //Update help window
            levelInfoWindow.lblMedalsList.Text = "Gold: " + gold.ToString() + "\nSilver: " + silver.ToString() + "\nBronze: " + bronze.ToString();
            //Reset the medal status icon
            if (Program.formRef != null)
            {
                Program.formRef.naPicMedalIcon.Image = global::TileGamePrototype.Properties.Resources.GoldMedal;
            }


            //Get list of objectives
            objectives = levelInfo.objectives;
            //Get list of items to collect
            itemsToCollect = levelInfo.itemsToCollect;
            //Check level robustness
            if (objectives.Contains(ObjectiveTypes.CollectItem) && itemsToCollect == null)
            {
                Console.WriteLine("Invalid Objectives Provided");
                return;
            }

            //Set variable used when checking if the player has to return to the village
            if (objectives.Contains(ObjectiveTypes.ReturnHome))
            {
                returnHome = true;
            }

            //////Update the help window with objective requirements
            string objectivesList = "";

            //Loop every objective. Not most efficient but convinient for getting the total count of any given objective. Enums are short so low cost
            foreach (ObjectiveTypes objective in Enum.GetValues(typeof(ObjectiveTypes)))
            {
                //Calculates the number of times that objective appears
                int count = ObjectiveOperators.getObjectiveOccurances(objectives, objective);
                //Check it is required
                if (count > 0)
                {
                    //List items that you need to find
                    if (objective == ObjectiveTypes.CollectItem)
                    {
                        objectivesList += "Collect Items: (" + ObjectiveOperators.getItemsToCollectString() + "), ";
                    }
                    //Ignore count for returning home
                    else if (objective == ObjectiveTypes.ReturnHome)
                    {
                        objectivesList += objective.ToString() + ", ";
                    }
                    //Else list how many times that objective is required
                    else
                    {
                        objectivesList += objective.ToString() + " x" + count.ToString() + ", ";
                    }
                }
            }
            objectivesList = objectivesList.Remove(objectivesList.Length - 2); // remove the last comma
            //Update help window
            levelInfoWindow.lblObjeciveList.Text     = objectivesList;
            levelInfoWindow.lblobjRemainingList.Text = objectivesList;

            //Get Relic for current level
            relic = levelInfo.relic;

            //Update help window
            if (objectives.Contains(ObjectiveTypes.ObtainRelic))
            {
                //Check level robustness
                if (relic == null)
                {
                    return;
                }
                //Show the relic info box in the help window
                levelInfoWindow.lblRelicInfoList.Text = relic.info;
                levelInfoWindow.lblRelicInfoList.Show();
                levelInfoWindow.lblRelicInfoTitle.Show();
            }


            //////Generate level using level builder
            currentLevelSurfaceArray = levelBuilder.buildLevelSurface(levelInfo);

            //Caves were going to be added, code accomadating their addition exists but will rarely be used (such as Zones etc.). Not worth removing at present.

            /*if (levelInfo.containsCave)
             * {
             *  currentLevelCaveArray = levelBuilder.buildLevelCave(levelInfo);
             * }*/

            //Give animals paths for moving. This is buggy and does not support multiple animals moving and they can walk on water :-P
            if (levelInfo.paths != null)
            {
                //Loops through every path provided
                foreach (KeyValuePair <System.Drawing.Point, int[]> entry in levelInfo.paths)
                {
                    System.Drawing.Point location = entry.Key;
                    int[] path = entry.Value;
                    Tile  tile = currentLevelSurfaceArray[location.X, location.Y];
                    //Checks if it is an animal and sets up its paths
                    if (tile.isLiving && !tile.isPlayer)
                    {
                        tile.setupPath(path);
                    }
                }
            }

            //Adds every animal to event
            foreach (Tile tile in currentLevelSurfaceArray)
            {
                if (tile.isLiving && !tile.isPlayer)
                {
                    player.playerMove += new Action(tile.playerAction);
                }
            }

            /*foreach (Tile tile in currentLevelCaveArray)
             * {
             *  if (tile.isLiving && !tile.isPlayer)
             *  {
             *      player.playerMove += new Action(tile.playerAction);
             *  }
             * }*/

            //Adds animal movement handler to the move event
            player.playerMove += new Action(AnimalMovementHandler.handleAllRequests);
            //Add move counter to move event
            player.playerMove += new Action(moveCounter);
            //Add objective checking function to move event
            player.playerMove += new Action(checkLevelComplete);
            //Add check for if the player is recently deceased to move event
            player.playerMove += new Action(checkPlayerStatus);
            //Add restart level to death event
            player.playerDeath += new Action(restartLevel);
        }