static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Initialize the states directory Datastore.CreateGeneralStateDirectory(); // Initialize the scores directory Datastore.CreateScoresDirectory(); // Creates the application's game manager Application.Run(new StartForm(new GameManager())); }
/// <summary> /// Ends the current simulation and opens leaderboard /// </summary> /// <returns> True if the user's simulation meets the criteria to end the game and false otherwise </returns> public bool GameOver() { // Calculate the score given the current state of the grid int gridScore = CalculateScore(); // A game over occurs if the grid score is 0 or the score has been stable for the next generations bool gameOver = gridScore == 0 || currentState.isScoreStable(gridScore); // Check if a game over occurs if (gameOver) { // Save this user's highest score Datastore.AddScore(Username, HighestConcurrentScore); return(true); } // Otherwise, the game continues return(false); }
/// <summary> /// Display the highest recorded concurrent scores /// </summary> private void DisplayScores() { // Get all the scores List <KeyValuePair <string, int> > allScores = Datastore.GetAllHighestConcurrentScores(); // Sort the scores in descending order, and only select the top 5 var sortedScores = (from score in allScores orderby score.Value descending select score).Take(5); // Display the scores int curScoreLabel = 0; foreach (var score in sortedScores) { // Go to the next score label while populating the text of this one scoreLabels[curScoreLabel++].Text = $"{ score.Key }: { score.Value }"; } }
/// <summary> /// Loads a state with the given name /// </summary> /// <param name="name"></param> public void SaveState(string name) { Datastore.SaveState(currentState, name); }
/// <summary> /// Loads the current state /// </summary> /// <param name="statePath"></param> public void LoadState(string statePath) { Datastore.LoadState(currentState, statePath); }