Esempio n. 1
0
        /// <summary>
        /// Load ManageProfiles class
        /// </summary>
        /// <returns>loaded player</returns>
        private ManageProfiles loadProfiles(String fileName)
        {
            try
            {
                if (!File.Exists(fileName))
                {
                    throw new System.IO.FileNotFoundException();
                }
                XmlSerializer  ser            = new XmlSerializer(typeof(ManageProfiles));
                StreamReader   reader         = new StreamReader(fileName);
                ManageProfiles manageProfiles = (ManageProfiles)ser.Deserialize(reader);

                reader.Close();

                return(manageProfiles);
            }
            catch (System.IO.FileNotFoundException)
            {
                ManageProfiles result = new ManageProfiles();
                result.setProfile("-", profiles.one);
                result.profileOneExists = false;
                result.setProfile("-", profiles.two);
                result.profileTwoExists = false;
                result.setProfile("-", profiles.three);
                result.profileThreeExists = false;
                result.saveManageProfiles();
                return(result);
            }
        }
Esempio n. 2
0
        public GameState Update(RenderWindow win, float deltaTime)
        {
            gameName.Update(deltaTime);
            foreach (Button b in buttonList)
            {
                b.Update(deltaTime, win, currentScreenPosition);
            }
            UpdateButtonAlphas();
            if (stopwatch1.ElapsedMilliseconds > 200)
            {
                int index = -1;
                debugRect.Position = new Vector2f(-1000, -1000);                    // moves this out of the picture...
                if (settingNewProfile)
                {
                    List <char> charList = KeyboardInputManager.getCharInput();
                    if (newProfileName && KeyboardInputManager.getCharInput().Count > 0)
                    {
                        currentInput   = "";
                        newProfileName = false;
                    }
                    foreach (char c in charList)
                    {
                        if (currentInput.Length <= 16)
                        {
                            currentInput += c;
                        }
                    }
                    if (KeyboardInputManager.Downward(Keyboard.Key.Back))
                    {
                        if (currentInput != "")
                        {
                            currentInput = currentInput.Remove(currentInput.Length - 1);
                        }
                    }
                    UpdateSelectedProfileText(currentInput, deltaTime);
                    if ((KeyboardInputManager.IsPressed(Keyboard.Key.Escape) || Mouse.IsButtonPressed(Mouse.Button.Left)) && settingNewProfile)
                    {
                        settingNewProfile = false;
                        stopwatch.Restart();
                        UpdateActiveProfileText();
                        return(GameState.MainMenu);
                    }
                    if (KeyboardInputManager.Downward(Keyboard.Key.Return))
                    {
                        if (currentInput != "" && currentInput != "[Enter Name]" && profiles.GetProfileNames().Contains(currentInput) == false)
                        {
                            profiles.setProfile(currentInput, ProfileConstants.activeProfile);
                            settingNewProfile = false;
                            UpdateActiveProfileText();
                            return(GameState.LoadLevelState);
                        }
                        else
                        {
                            Logger.Instance.Write("ProfileName cannot be empty", Logger.level.Info);
                        }
                    }
                }
                else if (KeyboardInputManager.Downward(Keyboard.Key.Up) || KeyboardInputManager.Downward(Keyboard.Key.Down) || KeyboardInputManager.Downward(Keyboard.Key.Right) || KeyboardInputManager.Downward(Keyboard.Key.Left))
                {
                    bool soundactiv = false;
                    if (KeyboardInputManager.Downward(Keyboard.Key.Up) && currentScreenPosition.Y > 0)
                    {
                        soundactiv = true;
                        currentScreenPosition.Y -= 1;
                        if (currentScreenPosition.X == 2)
                        {
                            currentScreenPosition.X = 1;
                        }
                        else if (currentScreenPosition.X == 1 && currentScreenPosition.Y == 2)
                        {
                            currentScreenPosition.X = 0;
                        }
                    }
                    if (KeyboardInputManager.Downward(Keyboard.Key.Down) && currentScreenPosition.Y < 3)
                    {
                        soundactiv = true;
                        currentScreenPosition.Y += 1;
                        if (currentScreenPosition.Y == 3 && currentScreenPosition.X == 1)
                        {
                            currentScreenPosition.X = 2;
                        }
                    }
                    if (KeyboardInputManager.Downward(Keyboard.Key.Right) && currentScreenPosition.X < 1)
                    {
                        soundactiv = true;
                        currentScreenPosition.X += 1;
                    }
                    else if (KeyboardInputManager.Downward(Keyboard.Key.Right) && currentScreenPosition.X < 3 && currentScreenPosition.Y == 3)
                    {
                        soundactiv = true;
                        currentScreenPosition.X = 2;
                    }
                    if (KeyboardInputManager.Downward(Keyboard.Key.Left) && currentScreenPosition.X > 0)
                    {
                        soundactiv = true;
                        currentScreenPosition.X -= 1;
                    }

                    if (soundactiv)
                    {
                        MusicManager.PlaySound(AssetManager.SoundName.MenueClick);
                    }
                    else
                    {
                        MusicManager.PlaySound(AssetManager.SoundName.Wall);
                    }
                }
                else if (KeyboardInputManager.Downward(Keyboard.Key.Return))                       //Wurde die LinkeMaustaste gedrückt?
                {
                    //Console.WriteLine("Der Index in der SwitchAnweisung: " + index);
                    switch (IndexFromScreenPos())                                   //Bin mit der Maus über den Index: SwitchCaseWeg
                    {                                                               //bearbeitet das aktuelle TextFeld
                    //start
                    case 0:
                        ProfileConstants.activeProfile = MemoryMaze.profiles.one;
                        if (profiles.ProfileExists(MemoryMaze.profiles.one))
                        {
                            return(GameState.LoadLevelState);
                        }
                        else
                        {
                            currentInput      = "[Enter Name]";
                            settingNewProfile = true;
                            newProfileName    = true;
                            return(GameState.MainMenu);
                        }

                    case 3:
                        profiles.deleteProfile(MemoryMaze.profiles.one);
                        UpdateProfilePercentage();
                        break;

                    case 1:
                        ProfileConstants.activeProfile = MemoryMaze.profiles.two;
                        if (profiles.ProfileExists(MemoryMaze.profiles.two))
                        {
                            return(GameState.LoadLevelState);
                        }
                        else
                        {
                            currentInput      = "[Enter Name]";
                            settingNewProfile = true;
                            newProfileName    = true;
                            return(GameState.MainMenu);
                        }

                    case 4:
                        profiles.deleteProfile(MemoryMaze.profiles.two);
                        UpdateProfilePercentage();
                        break;

                    case 2:
                        ProfileConstants.activeProfile = MemoryMaze.profiles.three;
                        if (profiles.ProfileExists(MemoryMaze.profiles.three))
                        {
                            return(GameState.LoadLevelState);
                        }
                        else
                        {
                            currentInput      = "[Enter Name]";
                            settingNewProfile = true;
                            newProfileName    = true;
                            return(GameState.MainMenu);
                        }

                    case 5:
                        profiles.deleteProfile(MemoryMaze.profiles.three);
                        UpdateProfilePercentage();
                        break;

                    case 6: return(GameState.Tutorial);

                    case 7: return(GameState.Credits);

                    case 8:
                        profiles.saveManageProfiles();
                        return(GameState.None);

                    case 9:
                        funactivJoh = true; stopwatch.Restart();
                        break;

                    default: break;
                    }
                }
            }
            if (!settingNewProfile)
            {
                UpdateAllProfilesTexts();
            }
            UpdateMainTitle(deltaTime);

            foreach (SuperText s in superTextList)
            {
                s.Update(deltaTime);
            }
            return(GameState.MainMenu);
        }