Exemple #1
0
        public void continueGame()
        {
            StreamReader saveFile = new StreamReader("bananas.txt");
            string line;
            Level currentReadLevel = null;
            string tempLine = "";
            int px = 0, py = 0;
            string loadLevel = "";
            while ((line = saveFile.ReadLine()) != null)
            {
                tempLine = line.Substring(2, line.Length - 2);
                string[] args = tempLine.Split('|');
                //complete
                if (line[0] == 'L')
                {
                    currentReadLevel = stringToLevel[tempLine];
                }
                if (line[0] == 'I')
                {
                    currentReadLevel.removeLevelItem(tempLine);
                }
                if (line[0] == 'P')
                {
                    //Add player at location
                    px = Int32.Parse(args[0]);
                    py = Int32.Parse(args[1]);
                }
                if (line[0] == 'N')
                {
                    int itemX = Int32.Parse(args[1]);
                    int itemY = Int32.Parse(args[2]);
                    switch (args[0])
                    {
                        case "BatteryGooI":
                            inventory.setInventoryItem(new BatteryGooI(), itemX, itemY);
                            break;
                        case "KnifeI":
                            inventory.setInventoryItem(new KnifeI(), itemX, itemY);
                            break;
                        case "DiaryI":
                            inventory.setInventoryItem(new DiaryI(), itemX, itemY);
                            break;
                        case "LampI":
                            LampI lamp = new LampI();
                            if (args[3].Equals("T"))
                            {
                                lamp.setBatteries(true);
                            }
                            inventory.setInventoryItem(lamp, itemX, itemY);
                            break;
                        case "RopeI":
                            inventory.setInventoryItem(new RopeI(), itemX, itemY);
                            break;
                        case "RoseI":
                            inventory.setInventoryItem(new RoseI(), itemX, itemY);
                            break;
                        case "ScrollI":
                            inventory.setInventoryItem(new ScrollI(args[3], args[4]), itemX, itemY);
                            break;
                    }
                }
                if (line[0] == 'S')
                {
                    aboutScreen.addSeenObject(tempLine);
                }
                //complete
                if (line[0] == 'F')
                {
                    bool platformComplete = (args[1].Equals("T"));

                    findPlatformGivenString(args[0]).setItemOnPlatform(platformComplete);
                }
                if (line[0] == 'C')
                {
                    loadLevel = tempLine;
                }
            }
            LevelTile lv = new LevelTile(0, 0, "blackBlock", "blackBlock", loadLevel, new Point(px, py));
            saveFile.Close();
            gameState = "play";

            setLevel(lv);
        }
Exemple #2
0
 protected override void Initialize()
 {
     exitButton2Position = new Vector2((GraphicsDevice.Viewport.Width / 2) + 160, 400);
     restartButtonPosition = new Vector2((GraphicsDevice.Viewport.Width / 2) + 160, 400);
     base.Initialize();
     //width = Window.ClientBounds.Width;
     //height = Window.ClientBounds.Height;
     fadeDirection = false;
     blackScreenAlpha = 0;
     currentLevelString = "hub";
     lastEnteredLevelTile = new LevelTile(0, 0, "blackBlock", "blackBlock", "hubLevel", new Point(13 * 32, 25 * 32));
     hubLevelTile = new LevelTile(0, 0, "blackBlock", "blackBlock", "hubLevel", new Point(13 * 32, 25 * 32));
     showInventory = false;
     AllowAccessibilityShortcutKeys(false);
     AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);
 }
Exemple #3
0
        public void setLevel(LevelTile level)
        {
            player.setLocked(false);
            backUpInventory = inventory.getItemsCopy();

            lastEnteredLevelTile = level;
            Console.WriteLine(level.getLevel());
            currentLevelString = level.getLevel();
            //Eventually turn level strings into global constants
            if (currentLevel != null)
            {
                currentLevel.unloadLevel();
            }

            if (currentLevelString.Equals("hubLevel"))
            {
                currentLevel = hubLevel;
            }
            else if (currentLevelString.Equals("houseLevel"))
            {
                currentLevel = houseLevel;
            }
            else if (currentLevelString.Equals("schoolLevel"))
            {
                currentLevel = schoolLevel;
            }
            else if (currentLevelString.Equals("gate1Level"))
            {
                currentLevel = gate1Level;
            }
            else if (currentLevelString.Equals("gate2Level"))
            {
                currentLevel = gate2Level;
            }
            else if (currentLevelString.Equals("complex1Level"))
            {
                currentLevel = complex1Level;
            }
            else if (currentLevelString.Equals("ghostTestLevel"))
            {
                currentLevel = ghostTestLevel;
            }
            else if (currentLevelString.Equals("laserTestLevel"))
            {
                currentLevel = laserTestLevel;
            }
            else if (currentLevelString.Equals("laserIntroLevel"))
            {
                currentLevel = laserIntroLevel;
            }
            else if (currentLevelString.Equals("marshEnterLevel"))
            {
                currentLevel = marshEnterLevel;
            }
            else if (currentLevelString.Equals("marsh1Level"))
            {
                currentLevel = marsh1Level;
            }
            else if (currentLevelString.Equals("marsh2Level"))
            {
                currentLevel = marsh2Level;
            }
            else if (currentLevelString.Equals("marshFinalLevel"))
            {
                currentLevel = marshFinalLevel;
            }
            creatures.Add(player);
            currentLevel.loadLevel();

            backUpItems = (ArrayList)(currentLevel.getLevelItems()).Clone();

            currentLevel.setPlayerStart(level.getPlayerStart());
            //add level transfer tiles from current level to the array list of tiles
            levelTiles.Clear();
            tiles.AddRange(currentLevel.getLevelTiles());
            levelTiles.AddRange(currentLevel.getLevelTiles());
            player.setX(currentLevel.getPlayerStartingX());
            player.setY(currentLevel.getPlayerStartingY());
            //set flag for dirt particles
            if (!currentLevel.getIndoors())
            {
                player.setTracks(true);
            }
            else
            {
                player.setTracks(false);
            }

            cam.setBounds(currentLevel.getMapSizeX(), currentLevel.getMapSizeY());
            cam.changeRoom();
            cam.update();
            if (level.getLevel().Equals("hubLevel"))
                loadBackupPlatforms();
            saveGame(level);
            syncStates();
        }
Exemple #4
0
        //For each game state
        public void startUpdate()
        {
            newKeyBoardState = Keyboard.GetState();
            if (titleScreenPhase == 0)
            {
                MouseState mouseState = Mouse.GetState();
                int mouseX, mouseY;

                Point p = convertCursorLocation(mouseState);
                mouseX = p.X;
                mouseY = p.Y;

                startScreen.checkButtonHovers();
                startScreen.checkButtonClicks();
                //if we set state to start from a button
                /*
                if (mouseState.LeftButton == ButtonState.Pressed)
                {

                    Rectangle startButtonRect = new Rectangle((int)startButtonPosition.X,
                                        (int)startButtonPosition.Y, 160, 64);
                    Rectangle exitButtonRect = new Rectangle((int)exitButtonPosition.X,
                                        (int)exitButtonPosition.Y, 160, 64);

                    if (startButtonRect.Contains(new Vector2(mouseX, mouseY)))
                    {
                        titleScreenPhase++;
                        screenDisplayed = Textures.textures["controls1"];
                    }

                    else if (exitButtonRect.Contains(new Vector2(mouseX, mouseY)))
                    {
                        Exit();
                    }
                }
                 * */
            }
            if (titleScreenPhase == 1)
            {
                if ((newKeyBoardState.IsKeyDown(Keys.LeftShift) && oldKeyBoardState != null && !oldKeyBoardState.IsKeyDown(Keys.LeftShift))
                || (newKeyBoardState.IsKeyDown(Keys.RightShift) && oldKeyBoardState != null && !oldKeyBoardState.IsKeyDown(Keys.RightShift)))
                {
                    screenDisplayed = Textures.textures["controls2"];
                    titleScreenPhase++;
                    oldKeyBoardState = newKeyBoardState;
                }
            }
            if (titleScreenPhase == 2)
            {
                if ((newKeyBoardState.IsKeyDown(Keys.LeftShift) && oldKeyBoardState != null && !oldKeyBoardState.IsKeyDown(Keys.LeftShift))
                || (newKeyBoardState.IsKeyDown(Keys.RightShift) && oldKeyBoardState != null && !oldKeyBoardState.IsKeyDown(Keys.RightShift))){
                    screenDisplayed = Textures.textures["hourglassinstruction"];
                    titleScreenPhase++;
                    oldKeyBoardState = newKeyBoardState;
                }
            }
            if (titleScreenPhase == 3)
            {
                if ((newKeyBoardState.IsKeyDown(Keys.LeftShift) && oldKeyBoardState != null && !oldKeyBoardState.IsKeyDown(Keys.LeftShift))||
                    (newKeyBoardState.IsKeyDown(Keys.RightShift) && oldKeyBoardState != null && !oldKeyBoardState.IsKeyDown(Keys.RightShift)))
                {
                    if(!beginningExpositionShown)
                    {
                        setState("textbox", "beginningExposition");
                        beginningExpositionShown = true;
                    }
                    else
                    {
                        gameState = "play";
                    }

                    LevelTile lv = new LevelTile(0, 0, "blackBlock", "blackBlock", "hubLevel", new Point(13 * 32, 25 * 32));
                    saveGame(lv);
                    //screenDisplayed = Textures.textures["inventorytutorial"];
                }
            }
            if (newKeyBoardState.IsKeyUp(Keys.LeftShift) && newKeyBoardState.IsKeyUp(Keys.RightShift))
            {
                oldKeyBoardState = new KeyboardState();
            }
        }
Exemple #5
0
        public void saveGame(LevelTile level)
        {
            StreamWriter saveFile = new StreamWriter("bananas.txt");

            //Remove specified items from particular levels
            foreach (Level l in levels)
            {
                saveFile.WriteLine("L:" + levelToString[l]);

                string[] itemStrings = l.getRemovedLevelItems();

                for (int x = 0; x < itemStrings.Length; x++)
                {
                    saveFile.WriteLine("I:" + itemStrings[x]);
                }

                foreach (Platform p in platforms)
                {
                    string str = "F:" + p.GetType().Name;
                    if (((Platform)p).isItemOnPlatform())
                    {
                        str += "|T";
                    }
                    else
                    {
                        str += "|F";
                    }
                }
            }

            //Load which objects have been seen and which haven't
            ArrayList seenObjects = aboutScreen.getSeenObjects();
            for (int x = 0; x < seenObjects.Count; x++)
            {
                saveFile.WriteLine("S:" + seenObjects[x]);
            }

            //Load the inventory
            for (int x = 0; x < backUpInventory.GetLength(0); x++)
            {
                for (int y = 0; y < backUpInventory.GetLength(1); y++)
                {
                    if (backUpInventory[x, y] == null) continue;

                    string str = backUpInventory[x, y].GetType().Name;
                    str += "|" + x + "|" + y;

                    if (backUpInventory[x, y] is ScrollI)
                    {
                        str += "|" + ((ScrollI)backUpInventory[x, y]).getGoodItemTip() + "|" + ((ScrollI)backUpInventory[x, y]).getBadItemTip();
                    }
                    else if (backUpInventory[x, y] is LampI)
                    {
                        if (((LampI)backUpInventory[x, y]).hasBatteries())
                        {
                            str += "|T";
                        }
                        else
                        {
                            str += "|F";
                        }
                    }
                    saveFile.WriteLine("N:" + str);
                }
            }

            saveFile.WriteLine(levelToString[currentLevel]);

            saveFile.WriteLine("P:" + level.getPlayerStart().X + "|" + level.getPlayerStart().Y);

            saveFile.WriteLine("C:" + levelToString[currentLevel]);

            // if (level.Equals("hubLevel"))
            // {
            foreach (Platform p in platforms)
            {
                string str = "F:"+p.GetType().Name;
                if (((Platform)p).isItemOnPlatform())
                {
                    str += "|T";
                }
                else
                {
                    str += "|F";
                }
                saveFile.WriteLine(str);
            }
            //  }

            saveFile.Close();
        }