/// <summary> /// Determines the most played Hero of the last play session /// </summary> /// <param Name="oldStats">Playtime of each hero before the Timer elapsed</param> /// <param Name="newStats">Playtime of each hero after the Timer elapsed</param> /// <returns>A Tuple with the Name of the most played Hero, and a string presenting the change in playtime</returns> private Tuple <string, string> getSessionMostPlayed(Playtime oldStats, Playtime newStats) { var New = newStats.merge(); var Old = oldStats.merge(); var difference = new Dictionary <string, double>(); foreach (string key in Old.Keys) { difference.Add(key, New[key] - Old[key]); } var sortedList = (from entry in difference orderby entry.Value descending select entry).ToList(); string leaderboard = ""; for (int i = 0; i < 5; i++) { if (sortedList[i].Value > 0.005) { leaderboard += $"{sortedList[i].Key}: {Math.Round(New[sortedList[i].Key], 2)}hrs (+{Math.Round(sortedList[i].Value, 2)})\n"; } else { break; } } if (difference[sortedList[0].Key] > 0.005) { return(Tuple.Create(sortedList[0].Key, leaderboard)); } return(Tuple.Create("CannotFetchArcade", "CannotFetchArcade")); }
private static Tuple <string, string> getMostPlayed(Playtime stats) { var playtime = stats.merge(); var sortedList = (from entry in playtime orderby entry.Value descending select entry).ToList(); string leaderboard = ""; for (int i = 0; i < 5; i++) { if (sortedList[i].Value > 0.005) { leaderboard += $"{sortedList[i].Key}: {Math.Round(playtime[sortedList[i].Key], 2)}hrs\n"; } else { break; } } if (playtime[sortedList[0].Key] > 0.005) { return(Tuple.Create(sortedList[0].Key, leaderboard)); } return(Tuple.Create("CannotFetchArcade", "CannotFetchArcade")); }
public async Task <ActionResult <Pet> > CreatePlaytimeForPet(int id, Playtime playtime) // | | // | Player deserialized from JSON from the body // | // Pet ID comes from the URL { // First, lets find the pet (by using the ID) var pet = await _context.Pets.FindAsync(id); // If the pet doesn't exist: return a 404 Not found. if (pet == null) { // Return a `404` response to the client indicating we could not find a pet with this id return(NotFound()); } // Associate the playtime to the given pet. playtime.PetId = pet.Id; // needs to add +5 to happiness lvl pet.HappinessLevel += 5; // needs to add +3 to hunger lvl pet.HungerLevel += 3; // Add the playtime to the database _context.Playtimes.Add(playtime); await _context.SaveChangesAsync(); // Return the new playtime to the response of the API return(Ok(playtime)); }
public async Task <ActionResult <Playtime> > CreatePlaytime(int id, Playtime newPlaytime) // | | // | Player deserialized from JSON from the body // | // GameNight ID comes from the URL { // First, lets find the game night (by using the ID) var pet = await _context.Pets.FindAsync(id); // If the game doesn't exist: return a 404 Not found. if (pet == null || pet.IsDead == true) { // Return a `404` response to the client indicating we could not find a game night with this id return(NotFound()); } // Associate the player to the given game night. newPlaytime.PetId = pet.Id; newPlaytime.When = DateTime.Now; pet.HappinessLevel += 5; pet.HungerLevel += 3; pet.LastInteractedWithDate = DateTime.Now; // Add the player to the database _context.Playtimes.Add(newPlaytime); await _context.SaveChangesAsync(); // Return the new player to the response of the API return(Ok(newPlaytime)); }
public async Task <ActionResult <Playtime> > PlaytimeForPet(int id) { var pet = await _context.Pets.FindAsync(id); if (pet == null) { return(NotFound()); } var deathDate = DateTime.Now; if ((deathDate - pet.LastInteractedWithDate).TotalDays > 3) { pet.IsDead = true; await _context.SaveChangesAsync(); return(Ok(new { Message = "Your pet is dead" })); } else { pet.LastInteractedWithDate = DateTime.Now; Playtime playtimes = new Playtime(); playtimes.PetId = pet.Id; playtimes.When = DateTime.Now; pet.HappinessLevel += 5; pet.HungerLevel += 3; _context.Playtimes.Add(playtimes); await _context.SaveChangesAsync(); return(Ok(playtimes)); } }
public async Task <ActionResult <Playtime> > CreatePlaytimeForPets(int id) { var pet = await _context.Pets.FindAsync(id); if (pet == null) { // Return a `404` response to the client indicating we could not find a game with this id return(NotFound()); } // Associate the player to the given game. pet.HappinessLevel += 5; pet.HungerLevel += 3; var playtime = new Playtime(); playtime.When = DateTime.Now; playtime.PetId = pet.Id; // Add the player to the database _context.Playtimes.Add(playtime); await _context.SaveChangesAsync(); // Return the new player to the response of the API return(Ok(playtime)); }
public async Task <ActionResult <Playtime> > CreatePlaytimeForPet(int id, Playtime playtime) { // First, lets find the Pet (by using the ID) var pet = await _context.Pets.FindAsync(id); // If the pet doesn't exist: return a 404 Not found. if (pet == null) { return(NotFound()); } // Associate the playtime to the given pet. playtime.PetId = pet.Id; // Set playtime to current time. playtime.When = DateTime.Now; // Add the playtime to the database _context.Playtimes.Add(playtime); // Add five to pet happiness level. pet.HappinessLevel += 5; // Add three to pet hunger level. pet.HungerLevel += 3; // Adventure mode: Update LastInteractedWithDate pet.LastInteractedWithDate = DateTime.Now; await _context.SaveChangesAsync(); // Return the new playtime to the response of the API. return(Ok(playtime)); }
//Update session timer in UI private void updatePlaytimeUI_Tick(object sender, EventArgs e) { if (SessionPlaytime.Elapsed.TotalMinutes == 1) { this.Invoke(new Action(() => SessionLenght.Text = $"Current Session: {SessionPlaytime.Elapsed.TotalMinutes} minute")); } else { this.Invoke(new Action(() => SessionLenght.Text = $"Current Session: {SessionPlaytime.Elapsed.TotalMinutes} minutes")); } //As this timer updates every minute, playtime in file gets updated also Playtime.AddPlaytime(CurrentGame, TimeSpan.FromMinutes(1)); Console.WriteLine($"Updating UI with TimerTimer: {SessionPlaytime.Elapsed.TotalMinutes} minutes, adding 1 minute to file"); }
public async Task <ActionResult <Pet> > PostPlayPetByIdAsync(int petId, Playtime playtime) { var pet = await _context.Pets.FindAsync(petId); if (pet == null) { return(NotFound()); } playtime.When = DateTime.Now; playtime.PetId = pet.PetId; _context.Playtimes.Add(playtime); pet.HappinessLevel += 5; pet.HungerLevel += 3; await _context.SaveChangesAsync(); return(Ok(pet)); }
public async Task <ActionResult <Playtime> > AddPlayingTime(int id, Playtime playtime) { var pet = await _context.Pets.FindAsync(id); if (pet == null) { return(NotFound()); } playtime.PetId = pet.Id; pet.HappinessLevel += 5; pet.HungerLevel += 3; // playtime.When = DateTime.Now; _context.Playtimes.Add(playtime); await _context.SaveChangesAsync(); return(Ok(playtime)); }
public async Task <ActionResult <Playtime> > PostPlaytime(int id) { var playingPet = await _context.Pets.FindAsync(id); if (playingPet.IsDead) { return(Ok("Your Tamagotchi has perished...")); } Playtime playtime = new Playtime(); playtime.PetId = id; playingPet.HungerLevel += 3; playingPet.HappinessLevel += 5; await _context.Playtimes.AddAsync(playtime); try { // Try to save these changes. await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { // Ooops, looks like there was an error, so check to see if the record we were // updating no longer exists. if (!PetExists(id)) { // If the record we tried to update was already deleted by someone else, // return a `404` not found return(NotFound()); } else { // Otherwise throw the error back, which will cause the request to fail // and generate an error to the client. throw; } } // Return a copy of the updated data return(Ok(playtime)); }
public async Task <ActionResult <Playtime> > CreatePlaytimeForPet(int id, Playtime playtime) { // Find the pet in the database using `FindAsync` to look it up by id var pet = await _context.Pets.FindAsync(id); // If we didn't find anything, we receive a `null` in return if (pet == null) { // Return a `404` response to the client indicating we could not find a pet with this id return(NotFound()); } playtime.PetId = pet.Id; pet.HungerLevel += 5; pet.HappinessLevel += 3; // Indicate to the database context we want to add this new record _context.PlayTimes.Add(playtime); await _context.SaveChangesAsync(); return(Ok(playtime)); }
public async Task <ActionResult <Playtime> > CreatePlaytimeForPet(int id, Playtime playtime) { // Find the pet by ID var pet = await _context.Pets.FindAsync(id); // If the pet doesn't exist, return 404 if (pet == null) { return(NotFound()); } // Associate the playtime to the pet playtime.PetId = pet.Id; // Adjust levels for pet pet.HappinessLevel += 5; pet.HungerLevel += 3; // Add the playtime to the database _context.Playtimes.Add(playtime); await _context.SaveChangesAsync(); // return the new playtime to the response of the API return(Ok(playtime)); }
private void Start() { _pt = FindObjectOfType <Playtime>(); _pt.TimeAnnouncer += IncreaseSpawnRate; ZombieList = new List <GameObject>(); }
public void SavePlaytime() { Playtime p = new Playtime(new TimeSpan(0, 35, 56)); s1.Save(p); s1.Flush(); }
private void Start() { time = GameObject.Find("Playtime_Text").GetComponent <Text>(); _pt = FindObjectOfType <Playtime>(); _pt.TimeAnnouncer += SetTimeText; }