示例#1
0
        void DeleteCell(int col, int row, int points)
        {
            var bonus = Grid[col, row] as BonusCell;

            if (bonus == null || bonus.IsEmpty)
            {
                if (Grid[col, row] == null)
                {
                    return;
                }
                Grid[col, row] = null;
                InvokeCellDeleted(col, row, points);
                // Move all cells above downwards
                MoveDown(col, row);
                MovedDown.Invoke(null, new EventArgs());
            }
            else
            {
                if (!bonus.IsNew && !bonus.IsDetonated)
                {
                    bonus.IsDetonated = true;
                    ActivatedBonus.Invoke(null, new Tuple <int, int>(bonus.Col, bonus.Row));
                }
            }
        }
示例#2
0
        /// <summary>
        /// Activates a bonus for a user and a service
        /// </summary>
        /// <param name="userId">User id</param>
        /// <param name="activateBonusDto">Model for activating the bonus with a Service Id and a Promocode</param>
        /// <returns></returns>
        public async Task ActivateBonusAsync(Guid userId, ActivateBonusDto activateBonusDto)
        {
            var activatedBonus = new ActivatedBonus
            {
                UserId    = userId,
                ServiceId = activateBonusDto.ServiceId
            };

            await _servicesRepository.ActivateBonusAsync(activatedBonus);
        }
示例#3
0
        public void Detonate()
        {
            bool success = false;

            var bonusesToDetonate = new List <BonusCell>();

            foreach (var cell in Grid)
            {
                if (cell is BonusCell bonus)
                {
                    if (bonus.IsDetonated)
                    {
                        bonusesToDetonate.Add(bonus);
                    }
                }
            }

            foreach (var bonus in bonusesToDetonate)
            {
                bonus.IsEmpty = true;
                success       = true;
                var bonusMatch = bonus.Action(Grid);
                foreach (var dead in bonusMatch)
                {
                    if (dead != null)
                    {
                        var deadBonus = dead as BonusCell;
                        if (deadBonus == null || deadBonus.IsEmpty || dead.Col == bonus.Col && dead.Row == bonus.Row)
                        {
                            DeleteCell(dead.Col, dead.Row, dead.Points);
                        }
                        else if (!deadBonus.IsDetonated)
                        {
                            deadBonus.IsDetonated = true;
                            ActivatedBonus.Invoke(null, new Tuple <int, int>(deadBonus.Col, deadBonus.Row));
                        }
                    }
                }
            }
            if (!success)
            {
                NoMoreMatches.Invoke(null, new EventArgs());
            }
        }
示例#4
0
 public async Task ActivateBonusAsync(ActivatedBonus activatedBonus)
 {
     _context.Add(activatedBonus);
     await _context.SaveChangesAsync();
 }