Пример #1
0
        public static void AssignAssassinId(int gameId)
        {
            Random        random      = new Random();
            var           db          = new AssassinContext();
            List <Player> playerList  = db.players.Where(p => p.game_id == gameId).ToList();
            int           playerCount = playerList.Count;

            foreach (Player player in playerList)
            {
                while (player.assassin_id == 0)
                {
                    int randomNumber = random.Next(1, playerCount + 1);
                    int count        = 0;
                    foreach (Player checkPlayer in playerList)
                    {
                        if (randomNumber == checkPlayer.assassin_id)
                        {
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        player.assassin_id = randomNumber;
                    }
                }
            }
            db.SaveChanges();
        }
Пример #2
0
        public Player MostSockKills()
        {
            var    db            = new AssassinContext();
            Player mostSockKills = db.players.OrderByDescending(p => p.sock_score).First();

            return(mostSockKills);
        }
Пример #3
0
        public static List <Player> GetAll(int gameId)
        {
            var           db         = new AssassinContext();
            List <Player> playerList = db.players.Where(p => p.game_id == gameId).ToList();

            return(playerList);
        }
Пример #4
0
        public Player LastAlive()
        {
            var    db        = new AssassinContext();
            Player lastAlive = db.players.Where(p => p.is_alive == 1 && p.game_id == this.id).FirstOrDefault();

            return(lastAlive);
        }
Пример #5
0
        public string TargetPlayerInfo(int gameId)
        {
            var    db               = new AssassinContext();
            Player targetPlayer     = db.players.Where(p => p.assassin_id == this.target_id && p.game_id == gameId).FirstOrDefault();
            string targetPlayerName = targetPlayer.name;

            return(targetPlayerName);
        }
Пример #6
0
        public Player FirstDead()
        {
            var      db                     = new AssassinContext();
            DateTime comparison             = new DateTime(1, 1, 1, 0, 0, 0);
            Contract firstCompletedContract = db.contracts.Where(c => c.contract_end != comparison && c.game_id == this.id).OrderBy(c => c.contract_end).First();
            int      firstTarget            = firstCompletedContract.target_id;
            Player   firstDead              = db.players.Where(p => p.assassin_id == firstTarget && p.game_id == this.id).FirstOrDefault();

            return(firstDead);
        }
Пример #7
0
        public Dictionary <string, object> MostKills()
        {
            var    db        = new AssassinContext();
            Player mostKills = db.players.OrderByDescending(p => p.spoon_score + p.sock_score).First();
            int    total     = mostKills.spoon_score + mostKills.sock_score;
            Dictionary <string, object> thisDictionary = new Dictionary <string, object> {
                { "player", mostKills }, { "total", total }
            };

            return(thisDictionary);
        }
Пример #8
0
        public static int IsGameOver(int gameId, int assassinId, int targetId)
        {
            var db           = new AssassinContext();
            var selectedGame = db.games.Find(gameId);

            if (assassinId == targetId)
            {
                selectedGame.is_end   = 1;
                selectedGame.is_start = 0;
                // selectedGame.AssignDeathDay();
            }
            db.SaveChanges();
            return(selectedGame.is_end);
        }
Пример #9
0
        public List <Player> DailyStats()
        {
            var             db                = new AssassinContext();
            DateTime        today             = DateTime.Today;
            List <Contract> contractsToday    = db.contracts.Where(c => c.is_fulfilled == 1 && c.contract_end.Date == today && c.game_id == this.id).ToList();
            List <Player>   playerDeathsToday = new List <Player> {
            };

            foreach (Contract contract in contractsToday)
            {
                Player targetPlayer = db.players.Where(p => p.assassin_id == contract.target_id && p.game_id == this.id).FirstOrDefault();
                playerDeathsToday.Add(targetPlayer);
            }
            return(playerDeathsToday);
        }
Пример #10
0
        public void CloseContract(int contractId, int playerId, string weapon)
        {
            var db = new AssassinContext();
            var selectedContract = db.contracts.Find(contractId);

            selectedContract.weapon       = weapon;
            selectedContract.contract_end = DateTime.Now;
            selectedContract.is_fulfilled = 1;
            var selectedPlayer = db.players.Find(playerId);

            if (weapon == "sock")
            {
                selectedPlayer.sock_score++;
            }
            else if (weapon == "spoon")
            {
                selectedPlayer.spoon_score++;
            }
            db.SaveChanges();
        }
Пример #11
0
        public void KillTarget(int contractId)
        {
            var      db = new AssassinContext();
            var      completedContract = db.contracts.Find(contractId);
            int      newAssassin       = completedContract.assassin_id;
            int      newGameId         = completedContract.game_id;
            Contract deadContract      = db.contracts.Where(c => c.assassin_id == completedContract.target_id && c.is_fulfilled == 0).FirstOrDefault();
            int      newTarget         = deadContract.target_id;
            var      nowDeadPlayer     = db.players.Where(p => p.assassin_id == completedContract.target_id).FirstOrDefault();

            nowDeadPlayer.is_alive = 0;
            if (IsGameOver(newGameId, newAssassin, newTarget) != 1)
            {
                DateTime nullDateTime = new DateTime(1, 1, 1, 0, 0, 0);
                Contract newContract  = new Contract {
                    game_id = newGameId, assassin_id = newAssassin, target_id = newTarget, contract_start = DateTime.Today, contract_end = nullDateTime, is_fulfilled = 0
                };
                db.contracts.Add(newContract);
            }
            db.SaveChanges();
        }
Пример #12
0
        public void BeginGame()
        {
            var  db       = new AssassinContext();
            Game thisGame = db.games.Find(this.id);

            thisGame.is_start = 1;
            DateTime      nullDateTime = new DateTime(1, 1, 1, 0, 0, 0);
            List <Player> playerList   = Player.GetAll(thisGame.id);

            foreach (Player player in playerList)
            {
                Contract firstContract = new Contract {
                    game_id = thisGame.id, assassin_id = player.assassin_id, target_id = (player.assassin_id + 1), contract_start = DateTime.Today, contract_end = nullDateTime, is_fulfilled = 0
                };
                if (firstContract.target_id > playerList.Count)
                {
                    firstContract.target_id = 1;
                }
                db.contracts.Add(firstContract);
            }
            db.SaveChanges();
        }