Example #1
0
        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);
            }
        }
Example #2
0
        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));
        }
Example #3
0
        public void Unjoin(Player player)
        {
            Players.Remove(player);

            SendForumMessage(player.Name + " left the game.", player);
        }
Example #4
0
 public Player Join(int accountId, string name, int rating)
 {
     var result = new Player() { AccountId = accountId, Name = name, Rating = rating };
     Join(result);
     return result;
 }
Example #5
0
        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();
        }
Example #6
0
 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;
 }
Example #7
0
        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();
        }
Example #8
0
 public void RemovePlayer(Player player)
 {
     if (Players.Contains(player))
     {
         Players.Remove(player);
         if (player.Ship == this)
             player.Ship = null;
     }
 }
Example #9
0
 public void AddPlayer(Player player)
 {
     if (!Players.Contains(player))
     {
         Players.Add(player);
         player.Ship = this;
     }
 }
Example #10
0
        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;
        }