示例#1
0
 public static void LoadScores()
 {
     if (File.Exists(Resources.scoresFilePath))
     {
         StreamReader input = new StreamReader(Resources.scoresFilePath);
         String       line;
         String[]     tokens;
         try
         {
             while ((line = input.ReadLine()) != null && (tokens = Regex.Split(line, @"\s+")).Length == 5)
             {
                 Score score = new Score(tokens[0], Int32.Parse(tokens[1]), Int32.Parse(tokens[2]), Boolean.Parse(tokens[3]), TimeSpan.Parse(tokens[4]));
                 Scores.Add(score);
                 if (score.AlgorithmName == "Human")
                 {
                     HumanScores.Add(score);
                 }
                 else
                 {
                     ComputerScores.Add(score);
                     if (score.AlgorithmName == "SA")
                     {
                         SAScores.Add(score);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             throw (ex);
         }
         finally
         {
             input.Close();
         }
     }
     else
     {
         File.Create(Resources.scoresFilePath);
     }
 }
示例#2
0
        public static void Update(GameTime gameTime, Game1 game, GameState gameState)
        {
            if (prevGameTime == null)
            {
                prevGameTime = new GameTime(gameTime.TotalGameTime, gameTime.ElapsedGameTime);
            }

            if (nodeGrid.Length == 0)
            {
                LoadMap();
            }

            switch (gameState)
            {
            case GameState.MANUAL_MODE:
                if (!gameOver)
                {
                    if (!humanStopWatch.IsRunning)
                    {
                        humanStopWatch.Start();
                    }
                    ManualMode(gameTime);
                }
                else if (gameOver && humanStopWatch.IsRunning)
                {
                    humanStopWatch.Stop();
                    Score humanScore = new Score("Human", humanPathNumberOfNodes, collectedDiamonds, collectedDiamonds == goals.Count, humanStopWatch.Elapsed);
                    Scores.Add(humanScore);
                    HumanScores.Add(humanScore);
                    humanStopWatch.Reset();
                }
                break;

            case GameState.ASTAR_MODE:
                if (path == null)
                {
                    Score score;
                    path = SolveAStar(out score);
                    ComputerScores.Add(score);
                    Scores.Add(score);
                }
                if (!gameOver)
                {
                    MovePlayerFromPath(gameTime);
                }
                break;

            case GameState.IDDFS_MODE:
                if (multiPath == null)
                {
                    Score score;
                    multiPath = SolveIDDFS(out score);
                    ComputerScores.Add(score);
                    Scores.Add(score);
                }
                if (!gameOver)
                {
                    MovePlayerFrom2DPath(gameTime);
                }
                break;

            case GameState.CSP_MODE:
                if (path == null)
                {
                    Score score;
                    path = SolveCSP(out score);
                    ComputerScores.Add(score);
                    Scores.Add(score);
                }
                if (!gameOver)
                {
                    MovePlayerFromPath(gameTime);
                }
                break;

            case GameState.SA_MODE:
                if (path == null)
                {
                    Score score;
                    path = SolveSA(out score);
                    ComputerScores.Add(score);
                    Scores.Add(score);
                    SAScores.Add(score);
                }
                if (!gameOver)
                {
                    MovePlayerFromPath(gameTime);
                }
                break;
            }

            if (gameOver)
            {
                Resources.backgroundMusicInstance.Stop();
            }

            MouseState mouseState = Mouse.GetState();

            if (mouseState.X < backButtonPosition.X || mouseState.Y < backButtonPosition.Y || mouseState.X > backButtonPosition.X + Resources.buttonBackground.Width || mouseState.Y > backButtonPosition.Y + Resources.buttonBackground.Height)
            {
                backHover = false;
            }
            else
            {
                backHover = true;
                if (mouseState.LeftButton == ButtonState.Released && prevMouseState.LeftButton == ButtonState.Pressed)
                {
                    game.gameState = GameState.MAIN_MENU;
                    Resources.backgroundMusicInstance.Stop();
                    if (humanStopWatch.IsRunning)
                    {
                        humanStopWatch.Stop();
                        Score humanScore = new Score("Human", humanPathNumberOfNodes, collectedDiamonds, collectedDiamonds == goals.Count, humanStopWatch.Elapsed);
                        Scores.Add(humanScore);
                        HumanScores.Add(humanScore);
                        humanStopWatch.Reset();
                    }
                    Reset();
                }
            }

            if (game.gameState != GameState.MAIN_MENU && game.gameState != GameState.SCORES)
            {
                prevMouseState = mouseState;
            }
        }