예제 #1
0
 /// <summary>
 /// Adds the exit.
 /// </summary>
 /// <param name='intObj'>
 /// Int object.
 /// </param>
 /// <param name='exit'>
 /// Exit.
 /// </param>
 /// <param name='newRoomPos'>
 /// New room position. so the position the player will be in once they enter the new room
 /// </param>
 public void AddExit(InteractableObject intObj,Vector2 newRoomPos, string exit)
 {
     intObj.SetIsExit(true,newRoomPos,exit);
     obj_InteractableObjects.Add(intObj);
     str_Exits.Add(exit);
 }
예제 #2
0
 public void AddObject(InteractableObject intObj)
 {
     obj_InteractableObjects.Add(intObj);
 }
        /// <summary>
        /// Loads the level.
        /// </summary>
        /// <returns>
        /// The level.
        /// </returns>
        /// <param name='Levelname'>
        /// Levelname.
        /// </param>
        public Level LoadLevel(String Levelname)
        {
            // the actual level that will be returned
            Level ret;

            int NumberOfLines = 0;
            string line;

            string ImageSrc;
            int numberOfObject = 0;
            int numberOfCharacters = 0;

            bool ObjectsRead = false;
            bool CharactersRead = false;
            System.IO.StreamReader file= null ;
            // Read the file and display it line by line.
            try{
             file = new System.IO.StreamReader(LevelDirectory+Levelname+".txt");
            }
            catch ( Exception e)
            {
                Console.Out.WriteLine(e);
            };

            ret = new Level();
            while((line = file.ReadLine()) != null)
            {
                if(NumberOfLines ==0)
                {
                    ImageSrc = line;
                    ret.SetImage(ImageSrc);
                    line = file.ReadLine();

                    if(line == "SNOW")
                    {
                        ret.LevelEmitter = new SnowEmitter(0,1920,1200,1000,10);
                        ret.LevelEmitter.Initialise(0,0);
                    }
                    else if(line == "NULL")
                    {
                        ret.LevelEmitter = new Emitter(0,0,0,0);
                        ret.LevelEmitter.Initialise(0,0);
                    }

                }
                if(NumberOfLines ==1)
                {
                    /// number of exits
                    numberOfObject = Convert.ToInt32(line);
                    for(int l =0;l<numberOfObject; l ++)
                    {
                        // temporary data that will be used to add objects to the level
                        string tempFileName;
                        Vector2 tempPosition;
                        InteractableObject tempObject;

                        // reads in data for object position etc
                        tempFileName = file.ReadLine();
                        NumberOfLines++;

                        // position
                        line = file.ReadLine();
                        string[] Positions = line.Split(','); // get postition from file
                        tempPosition = new Vector2(Convert.ToInt32(Positions[0]),Convert.ToInt32(Positions[1]));
                        NumberOfLines++;

                        tempObject = new InteractableObject(tempFileName);
                        tempObject.Position = tempPosition;

                        //if this object is an exit
                        line = file.ReadLine();

                        if(line=="true")
                        {
                            //read in what it exits to (file)
                            string tempExit = file.ReadLine();
                            NumberOfLines++;
                            //where ther position is in the next level when they exit
                            // position
                            line = file.ReadLine();
                            string[] exitsPositionStr = line.Split(','); // get postition from file
                            Vector2 exitPosition = new Vector2(Convert.ToInt32(exitsPositionStr[0]),Convert.ToInt32(exitsPositionStr[1]));
                            NumberOfLines++;

                            ret.AddExit(tempObject,exitPosition,tempExit);

                        }
                        // if not load in th action associated
                        // use the enum from the interactable object class
                        else
                        {

                            line = file.ReadLine();
                            NumberOfLines++;

                            /// sets the action to corresponding string in the file
                            ///  i may actually have to list all of them
                            if( line == InteractableObject.Action.EquipShiv.ToString())
                            {
                                tempObject.act_Action = InteractableObject.Action.EquipShiv;
                            }

                            ret.AddObject(tempObject);
                        }
                    }
                    ObjectsRead = true;
                }

                // read in number of characters
                if (ObjectsRead)
                {
                    line = file.ReadLine();
                    NumberOfLines++;

                    numberOfCharacters = Convert.ToInt32(line);
                    for(int l =0;l<numberOfCharacters; l ++)
                    {
                        string tempCharName;
                        Vector2 tempPosition;
                        AI tempChar;

                        // now read in who is in the level
                        line = file.ReadLine();
                        tempCharName = line;

                        // read in the position
                        line = file.ReadLine();
                        string[] Positions = line.Split(','); // get postition from file
                        tempPosition = new Vector2(Convert.ToInt32(Positions[0]),Convert.ToInt32(Positions[1]));
                        NumberOfLines++;

                        // now we use the character file to read in the character data
                        tempChar = LoadCharacter(tempCharName);
                        //tempChar = new AI(tempCharName

                        tempChar.Position = tempPosition;
                        tempChar.Name = tempCharName;
                        ret.AddCharacter(tempChar);

                    }

                    CharactersRead = true;
                }
                // now read all the actions
                if(CharactersRead)
                {
                    line = file.ReadLine();
                    int numOfAction = Convert.ToInt32(line);
                    for(int num = 0; num < numOfAction; num++)
                    {
                        line = file.ReadLine();
                        Level.Action tempAction;

                        int tempCharStat = 0;
                        int tempGameProg= 0;
                        float tempTime = 0.0f;
                        string tempCharName = "";
                        string tempProgStatName = "";
                        Vector2 tempPosition=new Vector2(0,0);
                        Level.Action.TypeOfCharStat enumTypeCharStat = Level.Action.TypeOfCharStat.NONE;
                        Level.Action.TypeOfGameStat enumTypeGameStat = Level.Action.TypeOfGameStat.NONE;

                        //types of action and reaction/affected party
                        Level.Action.TypeOfAction tempTypeOfAction = Level.Action.TypeOfAction.REMOVE;
                        bool tempEqual = false;
                        bool tempGreater= false;
                        bool tempLess= false;
                        string Affected;

                        string[] strFullAction = line.Split(';');
                        string[] strFirstLine = strFullAction[0].Split(',');
                        string[] strThirdLine = strFullAction[2].Split(',');
                        string[] strForthLine = strFullAction[3].Split(',');

                        if( strFirstLine[0] == "CHARSTAT")
                        {
                            // who's stat
                            tempCharName = strFirstLine[1];

                            // what type of stat
                            if(Level.Action.TypeOfCharStat.NONE.ToString() == strFirstLine[2])
                            {
                                enumTypeCharStat = Level.Action.TypeOfCharStat.NONE;
                                tempCharStat = Convert.ToInt32(strFirstLine[3]);
                            }
                            if(Level.Action.TypeOfCharStat.PLAYERDIS.ToString() == strFirstLine[2])
                            {
                                enumTypeCharStat = Level.Action.TypeOfCharStat.PLAYERDIS;
                                tempCharStat = Convert.ToInt32(strFirstLine[3]);
                            }
                            if(strFirstLine[4] == "<")
                                tempLess = true;
                            else if (strFirstLine[4] == ">")
                                tempGreater=true;
                            else if (strFirstLine[4] == "=")
                                tempEqual = true;

                        }
                        else if(strFirstLine[0] == "PROGSTAT")
                        {
                            // who's stat
                            tempProgStatName = strFirstLine[1];

                            // what type of stat
                            if(Level.Action.TypeOfGameStat.CRIPPLE.ToString() == tempProgStatName)
                            {
                                enumTypeGameStat = Level.Action.TypeOfGameStat.CRIPPLE;
                                tempGameProg = Convert.ToInt32(strFirstLine[2]);
                            }
                            if(Level.Action.TypeOfGameStat.FOODTRUCK.ToString() == tempProgStatName)
                            {
                                enumTypeGameStat = Level.Action.TypeOfGameStat.FOODTRUCK;
                                tempGameProg = Convert.ToInt32(strFirstLine[2]);
                            }
                            if(Level.Action.TypeOfGameStat.INSANE.ToString() == tempProgStatName)
                            {
                                enumTypeGameStat = Level.Action.TypeOfGameStat.INSANE;
                                tempGameProg = Convert.ToInt32(strFirstLine[2]);
                            }
                            if(Level.Action.TypeOfGameStat.TUNNEL.ToString() == tempProgStatName)
                            {
                                enumTypeGameStat = Level.Action.TypeOfGameStat.TUNNEL;
                                tempGameProg = Convert.ToInt32(strFirstLine[2]);
                            }
                            if(Level.Action.TypeOfGameStat.SLAYER.ToString() == tempProgStatName)
                            {
                                enumTypeGameStat = Level.Action.TypeOfGameStat.SLAYER;
                                tempGameProg = Convert.ToInt32(strFirstLine[2]);
                            }
                            if(Level.Action.TypeOfGameStat.SUICIDE.ToString() == tempProgStatName)
                            {
                                enumTypeGameStat = Level.Action.TypeOfGameStat.SUICIDE;
                                tempGameProg = Convert.ToInt32(strFirstLine[2]);
                            }

                            if(strFirstLine[3] == "<")
                                tempLess = true;
                            else if (strFirstLine[3] == ">")
                                tempGreater=true;
                            else if (strFirstLine[3] == "=")
                                tempEqual = true;
                        }
                        // the time
                        tempTime =(float)(Convert.ToDouble(strFullAction[1]));

                        // Action / reaction stuff

                        if(strThirdLine[0] ==Level.Action.TypeOfAction.CHANGEROOM.ToString())
                        {
                            tempTypeOfAction = Level.Action.TypeOfAction.CHANGEROOM;
                        }
                        if(strThirdLine[0] ==Level.Action.TypeOfAction.REMOVE.ToString())
                        {
                            tempTypeOfAction = Level.Action.TypeOfAction.REMOVE;
                        }
                        if(strThirdLine[0] ==Level.Action.TypeOfAction.SPAWN.ToString())
                        {
                            tempTypeOfAction = Level.Action.TypeOfAction.SPAWN;
                        }
                        if(strThirdLine[0] ==Level.Action.TypeOfAction.CHANGEOUTFIT.ToString())
                        {
                            tempTypeOfAction = Level.Action.TypeOfAction.CHANGEOUTFIT;
                        }
                        if(strThirdLine[0] ==Level.Action.TypeOfAction.QUIT.ToString())
                        {
                            tempTypeOfAction = Level.Action.TypeOfAction.QUIT;
                        }
                        Affected =strThirdLine[1];

                        // the new given position
                        tempPosition = new Vector2(Convert.ToInt32( strForthLine[0]),Convert.ToInt32( strForthLine[1]));
                        // set up now using the data
                        tempAction = new Level.Action(tempCharStat,tempGameProg,tempCharName,enumTypeCharStat,enumTypeGameStat);
                        tempAction.SetupAction(tempTypeOfAction,tempEqual,tempLess,tempGreater,tempTime,Affected,tempPosition);

                        // add it to the list
                        ret.AddAction(tempAction);
                    }
                }

                Console.WriteLine (line);
                NumberOfLines++;
            }

            // close your file!
            file.Close();
            file = null;
            Console.WriteLine("Total number of lines : " + NumberOfLines);
            return ret;
        }