Esempio n. 1
0
            //Builds the surface
            public Tile[,] buildLevelSurface(LevelContainerClass.levelInfo levelInformation)
            {
                //Create array to add tiles to
                Tile[,] controlArray;
                controlArray = new Tile[levelInformation.width, levelInformation.height];
                int caveIndex = 0;                                                                                                           // No longer used
                int tileSize  = Math.Min(Program.formWidth, Program.formHeight) / Math.Max(levelInformation.width, levelInformation.height); //Set the tiles to be the size of the smallest dimension of the space it is in divided by the longest side of level

                //Loop every tile
                for (int x = 0; x < levelInformation.width; x++)
                {
                    for (int y = 0; y < levelInformation.height; y++)
                    {
                        //Handle player seperately
                        if (levelInformation.surface[x, y] == TileTypes.Player)
                        {
                            //Assume player is on grass
                            controlArray[x, y] = TileOperators.extractControlFromType(TileTypes.Grass, Zone.Surface);

                            //Create the player
                            player = new Player(TileTypes.Grass);
                            player.hiddenControl = controlArray[x, y];
                            player.BringToFront();

                            //Sets the playersdetails
                            TileOperators.setTileDetails(player, tileSize, 0, 0);
                            //Override the players location
                            player.Location = new System.Drawing.Point(0, 0);
                        }
                        else
                        {
                            //Extract the tile at this location
                            controlArray[x, y] = TileOperators.extractControlFromType(levelInformation.surface[x, y], Zone.Surface);
                            //Set cave ID - Not used
                            if (levelInformation.surface[x, y] == TileTypes.Cave)
                            {
                                Cave cave = (Cave)controlArray[x, y];
                                cave.SetId(levelInformation.surfaceCaveId[caveIndex]);
                                caveIndex++;
                            }
                        }
                        //Set details of the tile at current location
                        TileOperators.setTileDetails(controlArray[x, y], tileSize, x, y);
                    }
                }
                //Return initialised level
                return(controlArray);
            }
Esempio n. 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);
        }