コード例 #1
0
ファイル: GameService.cs プロジェクト: Juraj04/POT_Pexeso
        public void SendInvitation(string hostNick, string opponentNick, CardTypes cards)
        {
            if (!AllPlayers.ContainsKey(opponentNick) || AllPlayers[opponentNick].Playing)
            {
                return;
            }
            if (AllPlayers[hostNick].Playing) //if he already plays (could happen)
            {
                return;
            }

            _gameId++;
            if (AllPlayers[opponentNick].Client.ReceiveInvitation(_gameId, cards, hostNick))
            {
                if (AllPlayers[hostNick].Playing) //if he already plays (could happen as well)
                {
                    return;
                }
                var game = new CurrentGame(AllPlayers[hostNick], AllPlayers[opponentNick], cards, _gameId);
                CurrentGames.Add(_gameId, game);
                var area = CreateRandomArea(cards);
                game.Host.Playing     = true;
                game.Opponent.Playing = true;
                game.Host.Client.StartGame(_gameId, area, opponentNick, true);
                game.Opponent.Client.StartGame(_gameId, area, hostNick, false);
                game.Start(ForceFinishGame);
                return;
            }
            _gameId--;
        }
コード例 #2
0
ファイル: GameService.cs プロジェクト: Juraj04/POT_Pexeso
 public void JoinLobby(string nickName)
 {
     if (!AllPlayers.ContainsKey(nickName))
     {
         AllPlayers.Add(nickName, new ConnectedPlayer(ClientCallback, nickName));
     }
 }
コード例 #3
0
        public static void GenerateFrags(DemoParser parser)
        {
            Dictionary <string, Player> AllPlayers = new Dictionary <string, Player>();
            List <Death> deaths       = new List <Death>();
            var          outputStream = new StreamWriter("round.txt");

            float timeBeginningRound = 0f;

            parser.ParseHeader();

            string   mapName = parser.Map;
            Map_JSON map     = new Map_JSON();

            // Get information from the assoiated JSON file.
            try {
                map = JsonConvert.DeserializeObject <Map_JSON>(File.ReadAllText("Maps_json/" + mapName + ".json"));
            } catch (FileNotFoundException) {
                Console.WriteLine("File was not found {0}", mapName);
                System.Environment.Exit(1);
            }

            int numberCT = 5;
            int numberT  = 5;

            outputStream.WriteLine(parser.Map);

            // Make a print on round-start so you can see the actual frags per round.
            parser.RoundStart += (sender, e) => {
                timeBeginningRound = parser.CurrentTime;
                outputStream.WriteLine("Round {0}", parser.CTScore + parser.TScore);
                // Console.WriteLine("New Round, Current Score: T {0} : {1} CT", parser.TScore, parser.CTScore);

                numberCT = 5;
                numberT  = 5;

                AllPlayers = new Dictionary <string, Player>();
                deaths     = new List <Death>();

                //foreach (var player in parser.PlayingParticipants) {
                //    AllPlayers.Add(player.Name, new Player(player.Name, player.Position, player.Position,
                //        player.ActiveWeapon.AmmoInMagazine, player.ActiveWeapon.Weapon));
                //}
            };

            parser.PlayerKilled += (sender, e) => {
                if (e.Killer == null)
                {
                    // The player has murdered himself (falling / own nade / ...)
                    Console.WriteLine("<World><0><None>");
                }
                else
                {
                    Console.Write("<{0}><{1}> killed ", e.Killer.Name, ShortTeam(e.Killer.Team));
                }

                if (e.Assister == null)
                {
                    // nothing
                }
                else
                {
                    Console.Write(" + <{0}><{1}> assist ", e.Assister.Name, ShortTeam(e.Assister.Team));
                }

                Console.Write(" [{0}]", e.Weapon.Weapon);

                if (e.Headshot)
                {
                    Console.Write("[HS]");
                }

                if (e.PenetratedObjects > 0)
                {
                    Console.Write("[Wall]");
                }

                Console.Write(" ");

                Console.Write(" <{0}><{1}>", e.Victim.Name, ShortTeam(e.Victim.Team));
                Console.Write(" Weapon {0} Ammo in Magazine {1} {2}", e.Victim.ActiveWeapon.Weapon,
                              e.Victim.ActiveWeapon.AmmoInMagazine.ToString(),
                              e.Victim.ActiveWeapon.AmmoInMagazine == WeaponInfo.WeaponAmmoMagazine(e.Victim.ActiveWeapon.Weapon) ?
                              "Ammo Max" : "");

                if (BackStabbing(e))
                {
                    Console.Write("  Not Looking player");
                }
                else
                {
                    Console.Write("  LookingPlayer");
                }

                if (e.Victim.Team == Team.CounterTerrorist)
                {
                    numberCT--;
                }
                else
                {
                    numberT--;
                }

                Console.WriteLine();
                WriteToFileDeadPlayers(outputStream, AllPlayers[e.Victim.Name]);
                deaths.Add(new Death(GetPositionMiniMap(e.Victim.Position, map.pos_x, map.pos_y, map.scale), e.Victim.Team));
            };

            parser.RoundEnd += (sender, e) => {
                Console.WriteLine("NumberCT alive " + numberCT.ToString() + " Number T alive " + numberT.ToString());
                Console.WriteLine();

                GenerateHeatMaps.GenerateMap(deaths, parser.CTScore + parser.TScore);
            };

            parser.TickDone += (sender, e) => {
                float currentTime = parser.CurrentTime - timeBeginningRound;

                // Updated every frame
                foreach (var player in parser.PlayingParticipants)
                {
                    // We multiply it by the time of one tick
                    // Since the velocity is given in
                    // ingame-units per second
                    // Console.WriteLine("{0} {1}", player.Name, player.Position);
                    if (AllPlayers.ContainsKey(player.Name))
                    {
                        Player current = AllPlayers[player.Name];
                        //if (player.IsAlive) {
                        //    current.Update(player.Position, player.ActiveWeapon.AmmoInMagazine);
                        //}
                    }
                    else
                    {
                        AllPlayers.Add(player.Name, new Player(player.Name, player.Position, player.Position,
                                                               player.ActiveWeapon.AmmoInMagazine, player.ActiveWeapon.Weapon, player.Team,
                                                               (player.Team == Team.CounterTerrorist) ? parser.CTClanName : parser.TClanName));
                    }
                }
            };

            parser.ParseToEnd();
            outputStream.Close();
        }