private static IGameObject CheckCollision(List <IGameObject> field, IRound obj, Position newCentre, out bool isCollision)
 {
     foreach (var gameObj in field)
     {
         if (gameObj.UniqueId != (obj as IGameObject).UniqueId)
         {
             if (gameObj.Type == ObjectType.Block ||
                 gameObj.Type == ObjectType.Bullet ||
                 gameObj.Type == ObjectType.Player)
             {
                 var diff = Mathematics.Distance(newCentre, gameObj.Centre) - gameObj.MaxSize - obj.Radius;
                 if (diff < 0)
                 {
                     if (gameObj.Type == ObjectType.Block)
                     {
                         if (PreciseСalculationCollision(gameObj as Block, obj, newCentre))
                         {
                             isCollision = true;
                             return(gameObj);
                         }
                         isCollision = false;
                         return(null);
                     }
                     isCollision = true;
                     return(gameObj);
                 }
             }
         }
     }
     isCollision = false;
     return(null);
 }
Exemple #2
0
        private void TallyScores(IRound round)
        {
            var winner = round.GetWinner();
            var team   = RuleHelpers.GetTeam(winner);

            _teamScores[team] += round.GetWinnersPoints();
        }
Exemple #3
0
        public static BitmapSource DrawRoundStart(BitmapSource baseImage, IRound round, int roundNum)
        {
            Action <DrawingContext, double> drawAction = (drawingContext, annotationScale) =>
            {
                var image    = round.GetRoundTemplateImage();
                var faceRect = new Rect(0, 0, baseImage.Width, baseImage.Height);
                //faceRect.Inflate(6 * annotationScale, 6 * annotationScale);

                drawingContext.DrawImage(image, faceRect);

                FormattedText targetText = new FormattedText(round.GetRoundImageText(),
                                                             CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface, 30, Brushes.White);

                var targetPoint = new System.Windows.Point(70, 160);
                drawingContext.DrawText(targetText, targetPoint);

                FormattedText roundNmberText = new FormattedText(roundNum.ToString(),
                                                                 CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface, 40, Brushes.White);

                var roundNumberPoint = new System.Windows.Point(200, 16);
                drawingContext.DrawText(roundNmberText, roundNumberPoint);
            };

            return(DrawOverlay(baseImage, drawAction));
        }
        public void ValidateRound(IRound round)
        {
            var teamExceptions   = new List <SelfChoiceException <ITeam> >();
            var playerExceptions = new List <SelfChoiceException <IMafiaPlayer> >();

            foreach (var action in round.Actions)
            {
                if (action.Team.Participants.Contains(action.TargetPlayer))
                {
                    teamExceptions.Add(new SelfChoiceException <ITeam>(action.Team));
                }
            }

            foreach (var vote in round.Votes)
            {
                if (vote.SourcePlayer == vote.TargetPlayer)
                {
                    playerExceptions.Add(new SelfChoiceException <IMafiaPlayer>(vote.SourcePlayer));
                }
            }

            var exceptions = teamExceptions.Cast <Exception>().Concat(playerExceptions).ToList();

            if (exceptions.Any())
            {
                throw new RoundException(exceptions);
            }
        }
 public void Run(IRound round, ICommand command)
 {
     if (command?.SquarePosition != null && round != null)
     {
         round.RunActionOnBoard(command);
     }
 }
Exemple #6
0
 public SerializableRound(IRound round)
 {
     Id = round.Id;
     Word = round.Word;
     ImpostersGuess = round.ImpostersGuess;
     IsComplete = round.IsComplete;
     AllOptions = round.AllOptions?.ToList();
     Participants = round.Participants?.Select(p => new SerializableRoundParticipant(p))?.ToList();
 }
        private void Start()
        {
            IRound manager = (IRound)_manager;

            manager.Round().RoundSetup  += OnRoundSetup;
            manager.Round().RoundStart  += OnRoundStart;
            manager.Round().RoundEnd    += OnRoundEnd;
            manager.Round().RoundFinish += OnRoundFinish;
        }
Exemple #8
0
 public BattlefieldViewModel(IRound round)
 {
     BattlefieldHeight = 1000;
     BattlefieldWidth  = 1000;
     Bots = new ObservableCollection <BattlefieldBotViewModel>();
     foreach (var bot in round.Bots)
     {
         Bots.Add(new BattlefieldBotViewModel(bot, BattlefieldWidth, BattlefieldHeight, round.Battlefield));
     }
 }
Exemple #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="player1">The first player.</param>
 /// <param name="player2">The second player.</param>
 /// <param name="map">The map for this game.</param>
 /// <param name="maxRounds">The maximum number of rounds that can be played.</param>
 public Game(IPlayer player1, IPlayer player2, IMap map, int maxRounds)
 {
     this.player1 = player1;
     this.player2 = player2;
     this.map = map;
     this.maxRounds = maxRounds;
     this.currentRound = 1;
     this.currentPlayer = player1;
     this.round = new Round(this, currentPlayer);
 }
Exemple #10
0
 /// <summary>
 /// Constructor for the deserialization.
 /// </summary>
 /// <param name="info">Information for the serialization.</param>
 /// <param name="context">The context for the serialization.</param>
 public Game(SerializationInfo info, StreamingContext context)
 {
     this.player1 = (IPlayer)info.GetValue("Player1", typeof(IPlayer));
     this.player2 = (IPlayer)info.GetValue("Player2", typeof(IPlayer));
     this.map = (IMap)info.GetValue("Map", typeof(IMap));
     this.maxRounds = (int)info.GetValue("MaxRounds", typeof(int));
     this.currentRound = (int)info.GetValue("CurrentRound", typeof(int));
     this.currentPlayer = (IPlayer)info.GetValue("CurrentPlayer", typeof(IPlayer));
     this.round = new Round(this, currentPlayer);
 }
Exemple #11
0
        public IEnumerator <IRound <T, U> > GetEnumerator()
        {
            yield return(_groupRound);

            for (int i = 1; i < Count; i++)
            {
                _groupRound = _groupRound.Next();
                yield return(_groupRound);
            }
        }
Exemple #12
0
 private static void BuildPairings(IRound round, int entryCount)
 {
     for (int i = 0; i < entryCount / 2; i++)
     {
         round.Matchups.Add(new Matchup()
         {
             MatchupId      = i,
             MatchupEntries = new List <IMatchupEntry>()
         });
     }
 }
Exemple #13
0
        public void Order(IRound round)
        {
            round.ListContestants.Sort((x, y) => x.Score.CompareTo(y.Score));

            Console.WriteLine("Order of jumpers: ");

            for (var i = 0; i < round.ListContestants.Count; i++)
            {
                Console.WriteLine("{0}. {1} ({2} scored)", i + 1, round.ListContestants[i].Name, round.ListContestants[i].Score);
            }
        }
Exemple #14
0
 public GameRunner(IOverallScoreCalculator overallScoreCalculator, Func <string, IComputerPlayer> computerPlayerFactory, IRound round, IConfiguration configuration, IInputOutputWrapper inputOutputWrapper, IComputerPlayerViewModelHelper computerPlayerViewModelHelper, IGameMoveViewModelHelper gameMoveViewModelHelper)
 {
     _overallScoreCalculator = overallScoreCalculator;
     _computerPlayerFactory  = computerPlayerFactory;
     _round                         = round;
     _configuration                 = configuration;
     _inputOutputWrapper            = inputOutputWrapper;
     _computerPlayerViewModelHelper = computerPlayerViewModelHelper;
     _gameMoveViewModelHelper       = gameMoveViewModelHelper;
     _normalPlayer                  = new NormalPlayer();
 }
Exemple #15
0
 public void SetUpPlayerRound()
 {
     if (this.playerOrder != null)
     {
         this.currentRound = new Round(playerOrder.GoToNextPlayer(), this.TimePerPlayer, this);
     }
     else
     {
         throw new NullReferenceException("Player order is null");
     }
 }
Exemple #16
0
        public IRoundResult PlayNextRound(IRound round)
        {
            _rounds.Add(round);

            RemoveKilledAndExcluded();

            var result = Rules.GetCurrentResult(this);

            _roundRefresher.Refresh();

            return(result);
        }
        public IRound CreateRounder(int companyId)
        {
            IRound rounder = null;

            switch (companyId)
            {
            default:
                rounder = new DefaultIntegralRound();
                break;
            }
            return(rounder);
        }
        public static IRound Create(IRound entity, MySqlConnection dbConn)
        {
            string query = "INSERT INTO Rounds (tournament_id, round_num) VALUES (@id, @round)";
            Dictionary <string, string> param = new Dictionary <string, string>();

            param.Add("@id", entity.TournamentId.ToString());
            param.Add("@round", entity.RoundNum.ToString());

            var resultsPK = DatabaseHelper.GetNonQueryCount(query, dbConn, param);

            entity.RoundId = resultsPK;
            return(entity);
        }
Exemple #19
0
        private string GetBattlefieldText(IRound round)
        {
            var sb = new StringBuilder();

            foreach (var bot in round.Bots)
            {
                sb.AppendLine(
                    $"{bot.Name,-30} " +
                    $"[X: {bot.Position.X,2}, Y: {bot.Position.Y,2}]");
            }

            return(sb.ToString());
        }
        public void Process(IRound round)
        {
            var orderedEffects = round.Actions.OrderBy(i => i.Team.Priority).Select(i => i.Team.Effect.EffectName);

            foreach (var effect in orderedEffects)
            {
                var processors = _processors.Where(p => p.ProcessEffectName == effect);

                foreach (var processor in processors)
                {
                    processor.Process(round);
                }
            }
        }
 private void CreateRoundLinks(IRound round, List <ITournamentEntry> tournamentEntries)
 {
     round.Matchups.ForEach(x => x.RoundId = round.RoundId);
     foreach (var matchup in round.Matchups)
     {
         matchup.MatchupId = MatchupsTable.Create(matchup, dbConn).MatchupId;
         matchup.MatchupEntries.ForEach(x => x.MatchupId = matchup.MatchupId);
         foreach (var matchupEntry in matchup.MatchupEntries)
         {
             matchupEntry.TournamentEntryId = tournamentEntries.Find(x => x.TeamId == matchupEntry.TheTeam.TeamId).TournamentEntryId;
             matchupEntry.MatchupEntryId    = MatchupEntriesTable.Create(matchupEntry, dbConn).MatchupEntryId;
         }
     }
 }
Exemple #22
0
        public IRound AddScoresToRound(IRound round)
        {
            if (round == null)
            {
                throw new ArgumentNullException(nameof(round));
            }

            var imposter               = round.Imposter;
            var imposterId             = round.Imposter.Player.Id;
            var isImposterGuessCorrect = round.IsImpostersGuessCorrect;

            foreach (var nonImposter in round.Participants.Where(p => !p.IsImposter))
            {
                var accuserGuessedCorrectly = nonImposter.Accusation.PlayerId == imposterId;
                var wager = nonImposter.Accusation.Wager;

                // Normal player gets 1 team point if they find the imposter.
                if (round.WasImposterFound)
                {
                    nonImposter.ScoredPoints += 1;
                }

                if (accuserGuessedCorrectly)
                {
                    // Normal player gets their wager if they guess correctly.
                    nonImposter.ScoredPoints += nonImposter.Accusation.Wager;
                }
                else if (isImposterGuessCorrect && isImposterGuessCorrect)
                {
                    // Imposter gets wager if player guesses incorrectly and the imposter guesses the word.
                    imposter.ScoredPoints += wager;
                }
            }

            // Imposter gets 1 point if they are not identified.
            if (!round.WasImposterFound)
            {
                imposter.ScoredPoints += 1;
            }

            // Imposter gets 1 bonus point if they guess the word.
            if (isImposterGuessCorrect)
            {
                imposter.ScoredPoints += 1;
            }

            return(round);
        }
        public static IRound Delete(IRound entity, MySqlConnection dbConn)
        {
            string query = "DELETE FROM Rounds WHERE round_id = @id";
            Dictionary <string, string> param = new Dictionary <string, string>();

            param.Add("@id", entity.RoundId.ToString());

            var result = DatabaseHelper.GetNonQueryCount(query, dbConn, param);

            if (result != 0)
            {
                return(entity);
            }

            return(null);
        }
        public void Create(int groupId, IRound <int, Matchup <int> > groupRound, DateTime date)
        {
            GroupRound dbGroupRound = new GroupRound
            {
                GroupId   = groupId,
                EventDate = date
            };

            _leagueContext.GroupRounds.Add(dbGroupRound);
            _leagueContext.SaveChanges();

            foreach (Matchup <int> matchup in groupRound)
            {
                _matchService.CreateMatch(dbGroupRound.Id, matchup.FirstPlayer, matchup.SecondPlayer);
            }
        }
Exemple #25
0
        public void Start(IList <Player> players, Player dealer)
        {
            _notifier.GameStartedWith(players.Select(p => p.Name).ToList());

            Deck.Regroup();
            Deck.Shuffle();


            _notifier.DeckShuffled();

            OrderPlayers(players, dealer);
            ResetPlayersState();

            _currentRound = _rounds[0];
            StartRound();
        }
Exemple #26
0
        public override void Process(IRound round)
        {
            var actions = round.Actions.Where(i => i.Team.Effect.EffectName == ProcessEffectName).ToList();

            foreach (var action in actions)
            {
                if (!action.TargetPlayer.State.Effects.ContainsEffect(ActionEffectConstants.Healed) ||
                    !action.TargetPlayer.State.Effects.ContainsEffect(ActionEffectConstants.F****d))
                {
                    continue;
                }

                action.Team.Effect.IsNeutralized = true;
                RaiseNeutralized(action.Team, action.TargetPlayer);
            }
        }
        private static bool PreciseСalculationCollision(Block block, IRound obj, Position newCentre)
        {
            var location = FindRelativeLocation(block, newCentre);

            if (location == Location.Inside)
            {
                return(true);
            }

            if (location == Location.Top || location == Location.Bottom)
            {
                var diff = Math.Abs(block.Centre.Y - newCentre.Y) - obj.Radius - block.Height / 2;
                return(diff < 0);
            }
            else if (location == Location.MiddleLeft || location == Location.MiddleRight)
            {
                var diff = Math.Abs(block.Centre.X - newCentre.X) - obj.Radius - block.Width / 2;
                return(diff < 0);
            }
            else if (location == Location.TopLeft)
            {
                var cornerPos = new Position(block.Centre.X - block.Width / 2, block.Centre.Y - block.Height / 2);
                var diff      = Mathematics.Distance(cornerPos, newCentre) - obj.Radius;
                return(diff < 0);
            }
            else if (location == Location.TopRight)
            {
                var cornerPos = new Position(block.Centre.X + block.Width / 2, block.Centre.Y - block.Height / 2);
                var diff      = Mathematics.Distance(cornerPos, newCentre) - obj.Radius;
                return(diff < 0);
            }
            else if (location == Location.BottomRight)
            {
                var cornerPos = new Position(block.Centre.X + block.Width / 2, block.Centre.Y + block.Height / 2);
                var diff      = Mathematics.Distance(cornerPos, newCentre) - obj.Radius;
                return(diff < 0);
            }
            else if (location == Location.BottomLeft)
            {
                var cornerPos = new Position(block.Centre.X - block.Width / 2, block.Centre.Y + block.Height / 2);
                var diff      = Mathematics.Distance(cornerPos, newCentre) - obj.Radius;
                return(diff < 0);
            }
            return(false);
        }
        public static IRound Update(IRound entity, MySqlConnection dbConn)
        {
            string query = "UPDATE Rounds SET tournament_id = @tId, round_num = @roundNum WHERE round_id = @id";
            Dictionary <string, string> param = new Dictionary <string, string>();

            param.Add("@tId", entity.TournamentId.ToString());
            param.Add("@roundNum", entity.RoundNum.ToString());
            param.Add("@id", entity.RoundId.ToString());

            var result = DatabaseHelper.GetNonQueryCount(query, dbConn, param);

            if (result != 0)
            {
                return(entity);
            }

            return(null);
        }
Exemple #29
0
        private void nextRound()
        {
            if (this.round == null)
            {
                roundNumber = 1;
            }
            else
            {
                roundNumber++;
            }

            this.sound = SoundProvider.Round(roundNumber);
            this.sound.Play();
            round = getRandomRound();
            scoringSystem.CreateNewRound();
            this.gameState            = GameState.RoundBegin;
            this.currentTimerTask     = TimeSpan.FromSeconds(6);
            this.currentTimeTaskStart = DateTime.Now;
        }
Exemple #30
0
        private void Update()
        {
            Update(Game.Match);
            IRound round = Game.Match.Round;

            ViewModel.BattlefieldWidth  = round.Battlefield.Width;
            ViewModel.BattlefieldHeight = round.Battlefield.Height;

            var sb = new StringBuilder();

            ViewModel.BotStates.Clear();
            foreach (var bot in Game.Match.Round.Bots)
            {
                sb.AppendLine(bot.Action);
                sb.AppendLine(DisplayBot(bot));
                ViewModel.BattlefieldViewModel.Update(bot);
                ViewModel.BotStates.Add(new BotStateViewModel(bot));
            }
            ViewModel.TurnText        = sb.ToString();
            ViewModel.BattlefieldText = GetBattlefieldText(Game.Match.Round);
        }
Exemple #31
0
        public static ImageSource DrawTime(string showTime, bool drawIndicator, IRound round)
        {
            if (lastBitmap == null)
            {
                return(lastBitmap);
            }
            DrawingVisual visual = new DrawingVisual();



            DrawingContext drawingContext = visual.RenderOpen();

            FormattedText ft = new FormattedText(showTime,
                                                 CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface,
                                                 50, Brushes.White);

            drawingContext.DrawImage(lastBitmap, new Rect(0, 0, lastBitmap.Width, lastBitmap.Height));

            drawingContext.DrawText(ft, new Point(550, 0));

            if (drawIndicator)
            {
                drawingContext.DrawImage(round.GetRoundIndicator(), new Rect(20, 20, 100, 100));

                FormattedText targetText = new FormattedText(round.GetRoundImageText(),
                                                             CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface,
                                                             20, Brushes.White);

                drawingContext.DrawText(targetText, new Point(55, 75));
            }
            drawingContext.Close();

            RenderTargetBitmap outputBitmap = new RenderTargetBitmap(
                (int)lastBitmap.Width, (int)lastBitmap.Height,
                0, 0, PixelFormats.Pbgra32);

            outputBitmap.Render(visual);

            return(outputBitmap);
        }
Exemple #32
0
        public void Scores(IRound round)
        {
            var random      = new Random();
            var judgePoints = new List <int>();

            Console.WriteLine("Round results:");

            foreach (var t in round.ListContestants)
            {
                var jumpLength = random.Next(60, 121);

                for (var i = 0; i < 5; i++)
                {
                    judgePoints.Add(random.Next(10, 21));
                }

                Console.WriteLine("{0}  length: {1}  judge votes: {2}, {3}, {4}, {5}, {6}", t.Name, jumpLength, judgePoints[0], judgePoints[1], judgePoints[2], judgePoints[3], judgePoints[4]);

                judgePoints.Sort();
                t.Score += jumpLength + judgePoints[1] + judgePoints[2] + judgePoints[3];
            }
        }
Exemple #33
0
        /// <summary>
        /// Ends the current round and start the next one.
        /// </summary>
        public void EndRound()
        {
            Dictionary<IUnit, IPoint> units = map.GetUnits(this.currentPlayer);
            // Resets the movements points for each unit
            // and computes the points:
            foreach(IUnit unit in units.Keys) {
                ITile tile = this.map.GetTile(units[unit]);
                ITile[] neighbours = this.GetNeighbours(units[unit]);
                this.currentPlayer.AddPoints(unit.GetPoints(tile, neighbours));
                unit.ResetMovementPoints();
            }

            // Updates the current player:
            if(this.currentPlayer == this.player1) {
                this.currentPlayer = this.player2;
            } else {
                this.currentPlayer = player1;
                this.currentRound++;
            }

            // Updates round.
            this.round = new Round(this, this.currentPlayer);
        }