예제 #1
0
        private void checkIfDestroyedThree(int id, TakenBy takenBy)
        {
            var linesWhereFieldIdBelongs = possibleThrees.Where(t => t.Contains(id));
            var fieldsToRemove           = new List <Field>();

            foreach (var line in linesWhereFieldIdBelongs)
            {
                //all have to belongs to three
                if (!line.All(field => fields.FirstOrDefault(f => f.Id == field).BelongsToThree))
                {
                    continue;
                }

                //two have to belongs to one player, one should be second player
                if (!(line.Where(l => getAssigment(l) == takenBy).Count() == 2 && line.Where(l => getAssigment(l) == TakenBy.Nobody).Count() == 1))
                {
                    continue;
                }

                //not deleteing assigment to three here because field could belong to two threes before move
                foreach (var it in line)
                {
                    fieldsToRemove.Add(fields.FirstOrDefault(f => f.Id == it));
                }
            }

            foreach (var f in fieldsToRemove)
            {
                f.BelongsToThree = false;
            }
        }
예제 #2
0
        public void AssignBallTo(int id, TakenBy takenBy)
        {
            checkAndIncrementRound(takenBy);

            fields.Find(f => f.Id == id).TakenBy = takenBy;

            if (takenBy == TakenBy.Nobody)
            {
                return;
            }
            checkIfCreatedThree(id, takenBy);
        }
예제 #3
0
 private void checkAndIncrementRound(TakenBy takenBy)
 {
     if (firstStageRound == Setting.NumberOfPlayerBall)
     {
         IsFirstStage = false;
         ActionName   = "Moving ball";
     }
     else
     {
         if (isPlayerStarting && takenBy == TakenBy.Player)
         {
             firstStageRound++;
         }
         else if (!isPlayerStarting && takenBy == TakenBy.Computer)
         {
             firstStageRound++;
         }
     }
 }
예제 #4
0
        private void checkIfCreatedThree(int id, TakenBy takenBy)
        {
            var linesWhereFieldIdBelongs = possibleThrees.Where(t => t.Contains(id));
            var handleActionOfMakedThree = false;

            foreach (var line in linesWhereFieldIdBelongs)
            {
                if (!line.All(field => getAssigment(field) == takenBy))
                {
                    continue;
                }
                foreach (var field in fields)
                {
                    if (!line.Contains(field.Id))
                    {
                        continue;
                    }

                    field.BelongsToThree = true;

                    if (!handleActionOfMakedThree)
                    {
                        if (takenBy == TakenBy.Player)
                        {
                            PlayerCanTakeComputerBall = true;
                            ActionName = "Take ball";
                            PlayerPoints++;
                        }
                        else if (takenBy == TakenBy.Computer)
                        {
                            ActionName = "Taking ball";
                            ComputerPoints++;
                        }

                        handleActionOfMakedThree = true;
                    }
                }
            }
        }
예제 #5
0
 private IEnumerable <int> getIdsTakenBy(TakenBy takenBy)
 {
     return(fields.Where(f => f.TakenBy == takenBy).Select(i => i.Id));
 }
예제 #6
0
 public bool IsTaker(string userName)
 {
     return(!string.IsNullOrEmpty(TakenBy) && TakenBy.ToLower() == userName.ToLower());
 }