internal void DisconnectPlayer(Player player) { if (player != null) { if (player.Ship != null) { GameHub.Say(this, player.Ship, player.Name + " disconnected."); if (player.Ship != null) player.Ship.RemovePlayer(player); } if (GetActivePlayerCount() <= 0) StopRunning(); GameServer.SaveGame(this); } }
public void SendForumMessage(string text, Player source, string sourceName = "Computer") { using (var db = new DBConnection()) { GameServer.SendMessage(db, -Id, source.AccountId, sourceName, text); } var message = new Message() { Sent = DateTime.UtcNow, Text = text, SourceId = source.AccountId, SourceName = sourceName }; GameHub.Say(this, source.Ship, message.Print(false)); }
public void Unjoin(Player player) { Players.Remove(player); SendForumMessage(player.Name + " left the game.", player); }
public Player Join(int accountId, string name, int rating) { var result = new Player() { AccountId = accountId, Name = name, Rating = rating }; Join(result); return result; }
public void Join(Player player) { player.Game = this; Players.Add(player); foreach (var invite in (from i in Invites where i.AccountId == player.AccountId select i)) { Invites.Remove(invite); break; } SendForumMessage(player.Name + " joined the game.", player); if (Players.Count >= MaxPlayers) Start(); }
public double GetScoreExpected(Player player) { double scoreExpected = 0; foreach (var otherPlayer in Players) { if (otherPlayer != player) scoreExpected += GenScoreExpected(player.Rating, otherPlayer.Rating); } scoreExpected /= CurrentPlayers - 1; return scoreExpected; }
public void EliminatePlayer(Player loser) { if (!loser.IsEliminated) { var place = (from p in Players where !p.IsEliminated select p).Count(); loser.Place = place; loser.Done = true; } if (loser.Place <= 2) End(); }
public void RemovePlayer(Player player) { if (Players.Contains(player)) { Players.Remove(player); if (player.Ship == this) player.Ship = null; } }
public void AddPlayer(Player player) { if (!Players.Contains(player)) { Players.Add(player); player.Ship = this; } }
void Initalize(int id) { game = GameServer.GetGame(id); if (game == null) { Response.RedirectPermanent("/", true); Response.End(); return; } if (LoggedIn) { player = game.GetPlayer(Account.Id); } if (player != null) { player.SessionId = Request.Cookies["ASP.Net_SessionId"].Value; } else { player = game.GetPlayer(Request.Cookies["ASP.Net_SessionId"].Value); } if (player == null) player = game.Players[0]; ViewBag.Player = player; }