Exemple #1
0
 protected void Prize_OnLocationChanged(object sender, PointF e)
 {
     if (IsLevelStarted && !IsLevelPaused && sender is IPrize <TBoard> )
     {
         IPrize <TBoard> prize = (IPrize <TBoard>)sender;
         if (prizeFallList.IndexOf(prize) >= 0)
         {
             RectangleF prizeRect = new RectangleF(prize.Left + Left, prize.Top + Top, prize.Width, prize.Height);
             if (prizeRect.IntersectsWith(Plank.GetRectangleF()))
             {
                 prizeActiveList.Add(prize);
                 prize.Active(ParentBoard);
                 prizeFallList.Remove(prize);
                 if (bricksLeft <= 0 && prizeFallList.Count == 0)
                 {
                     FinishLevel();
                 }
             }
             else if (prize.Top > Plank.Bottom)
             {
                 prizeFallList.Remove(prize);
                 ResetPrizeEvents(prize);
                 ChangeSumOfPrizeFellEachPrize(prize.Tag, -1);
                 if (bricksLeft <= 0 && prizeFallList.Count == 0)
                 {
                     FinishLevel();
                 }
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Remove prize by index
        /// </summary>
        /// <param name="index"></param>
        public void RemovePrize(int index)
        {
            IPrize <TBoard> prize = prizeList[index];

            prizeList.RemoveAt(index);
            OnPrizeRemoved(prize);
        }
 public void RemovePrize(IPrize prize)
 {
     if (Prizes.Contains(prize))
     {
         Prizes.Remove(prize);
         _drawer.Remove(prize);
     }
 }
Exemple #4
0
 private void RestartPrizeEvents(IPrize <TBoard> prize)
 {
     if (prize != null)
     {
         prize.LocationChanged += Prize_OnLocationChanged;
         prize.FinishedActive  += Prize_FinishedActive;
     }
 }
Exemple #5
0
 protected void Prize_FinishedActive(object sender, EventArgs e)
 {
     if (IsLevelStarted && !IsLevelPaused && sender is IPrize <TBoard> )
     {
         IPrize <TBoard> prize = (IPrize <TBoard>)sender;
         ResetPrizeEvents(prize);
         prizeActiveList.Remove(prize);
         ChangeSumOfPrizeFellEachPrize(prize.Tag, -1);
     }
 }
Exemple #6
0
        public void TestValidatePrize_EmptyInput()
        {
            //Arrange
            PrizeController prizeController = new PrizeController();

            //Act
            IPrize valid = prizeController.ValidatePrize("", "");

            //Assert
            Assert.IsNull(valid);
        }
Exemple #7
0
        public void TestValidatePrize_Numbers_Spaces_Symbols()
        {
            //Arrange
            PrizeController prizeController = new PrizeController();
            String          name            = "Test-Prize-Name 123456789 &%$#@.";
            String          inPercentage    = "12%";

            //Act
            IPrize valid = prizeController.ValidatePrize(name, inPercentage);

            //Assert
            Assert.IsNotNull(valid);
        }
Exemple #8
0
        public void TestValidatePrize_DefaultInput()
        {
            //Arrange
            PrizeController prizeController = new PrizeController();
            String          name            = "Champion, runner-up, etc...";
            String          inPercentage    = "ex) .25, .5, .33, etc...";

            //Act
            IPrize valid = prizeController.ValidatePrize(name, inPercentage);

            //Assert
            Assert.IsNull(valid);
        }
Exemple #9
0
        public void TestValidatePrize_NoPercentSignDoubleAndSpaces()
        {
            //Arrange
            PrizeController prizeController = new PrizeController();
            String          name            = "Test-Prize-Name";
            String          inPercentage    = "10.99 ";

            //Act
            IPrize valid = prizeController.ValidatePrize(name, inPercentage);

            //Assert
            Assert.IsNotNull(valid);
        }
Exemple #10
0
        public void TestValidatePrize_PrizeNameWithNumbersAndSpaces()
        {
            //Arrange
            PrizeController prizeController = new PrizeController();
            String          name            = "Test Prize Name 123456789";
            String          inPercentage    = "12%";

            //Act
            IPrize valid = prizeController.ValidatePrize(name, inPercentage);

            //Assert
            Assert.IsNotNull(valid);
        }
Exemple #11
0
        public void TestValidatePrize_PercentWithCharacters()
        {
            //Arrange
            PrizeController prizeController = new PrizeController();
            String          name            = "Test-Prize-Name";
            String          inPercentage    = "12xxxx%";

            //Act
            IPrize valid = prizeController.ValidatePrize(name, inPercentage);

            //Assert
            Assert.IsNull(valid);
        }
Exemple #12
0
        public void TestValidatePrize_DoublePercent()
        {
            //Arrange
            PrizeController prizeController = new PrizeController();
            String          name            = "Test-Prize-Name";
            String          inPercentage    = "12.55%";

            //Act
            IPrize valid = prizeController.ValidatePrize(name, inPercentage);

            //Assert
            Assert.IsNotNull(valid);
        }
Exemple #13
0
        public void TestValidatePrize_DoublePercentAbove100() //Should we allow over 100% Input?
        {
            //Arrange
            PrizeController prizeController = new PrizeController();
            String          name            = "Test-Prize-Name";
            String          inPercentage    = "120.55%";

            //Act
            IPrize valid = prizeController.ValidatePrize(name, inPercentage);

            //Assert
            Assert.IsNull(valid);
        }
Exemple #14
0
        public void TestValidatePrize_NullInput()
        {
            //Arrange
            PrizeController prizeController = new PrizeController();
            String          name            = null;
            String          inPercentage    = null;

            //Act
            IPrize valid = prizeController.ValidatePrize(name, inPercentage);

            //Assert
            Assert.IsNull(valid);
        }
        public static IPrize Create(IPrize entity, MySqlConnection dbConn)
        {
            string query = "INSERT INTO Prizes (prize_name, prize_amount, prize_percent) VALUES (@name, @amount, @percent)";
            Dictionary <string, string> param = new Dictionary <string, string>();

            param.Add("@name", entity.PrizeName);
            param.Add("@amount", entity.PrizeAmount.ToString());
            param.Add("@percent", entity.PrizePercent.ToString());

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

            entity.PrizeId = resultsPK;
            return(entity);
        }
        public static IPrize Delete(IPrize entity, MySqlConnection dbConn)
        {
            string query = "DELETE FROM Prizes WHERE prize_id = @id";
            Dictionary <string, string> param = new Dictionary <string, string>();

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

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

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

            return(null);
        }
        public static IPrize Update(IPrize entity, MySqlConnection dbConn)
        {
            string query = "UPDATE Prizes SET prize_name = @name, prize_amount = @amount, prize_percent = @percent WHERE prize_id = @id";
            Dictionary <string, string> param = new Dictionary <string, string>();

            param.Add("@name", entity.PrizeName.ToString());
            param.Add("@amount", entity.PrizeAmount.ToString());
            param.Add("@percent", entity.PrizePercent.ToString());
            param.Add("@id", entity.PrizeId.ToString());

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

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

            return(null);
        }
        private void Add_Prize_Click(object sender, RoutedEventArgs e)
        {
            object selectedItem  = prizeDataGrid.SelectedItem;
            IPrize selectedPrize = (IPrize)selectedItem;

            if (placeComboBox.SelectedItem == null)
            {
                errorMessages.Text = "Must select a place";
                return;
            }

            var selectedPlace       = placeComboBox.SelectedItem;
            int selectedPlaceNumber = (int)selectedPlace;

            decimal percentTotal = prizesInTournament.Sum(x => x.PrizePercent);

            //validate that prize doesn't already exist
            errorMessages.Text = "";
            if (prizesInTournament.Any(x => x.PlaceNumber == selectedPlaceNumber))
            {
                errorMessages.Text = "There is already a prize for the selected place.";
                return;
            }

            if (percentTotal + selectedPrize.PrizePercent > 1)
            {
                errorMessages.Text = "Total prize percent exceeds 100%";
                return;
            }

            prizesInTournament.Add(new Prize()
            {
                PrizeId      = selectedPrize.PrizeId,
                PrizeName    = selectedPrize.PrizeName,
                PrizeAmount  = selectedPrize.PrizeAmount,
                PrizePercent = selectedPrize.PrizePercent,
                PlaceNumber  = selectedPlaceNumber
            });
            prizesListBox.ItemsSource = prizesInTournament;
            prizesListBox.Items.Refresh();
        }
Exemple #19
0
        public IPrize ValidatePrize(String inName, String inPerc)
        {
            if (inName == null || inPerc == null)
            {
                return(null);
            }

            if (!isValidName(inName))
            {
                return(null);
            }

            if (!isValidPercent(inPerc))
            {
                return(null);
            }

            IPrize prize = buildPrize(inName, inPerc);

            return(prize);
        }
        private void createPrizeBtn_Click(object sender, RoutedEventArgs e)
        {
            IPrize prize = prizeController.ValidatePrize(placeNameTxtBox.Text, prizeAmtTxtBox.Text);

            if (prize != null)
            {
                //Creates a new prize with valid information
                IPrize newPrize = source.createPrize(prize);
                readPrizes();
                List <IPrize> prizesInTournment = tournament.prizesInTournament;
                List <IPrize> allPrizes         = tournament.prizes;
                allPrizes.Add(newPrize);/*
                                         * tournament.prizeComboBox.ItemsSource = allPrizes;
                                         * tournament.prizesListBox.ItemsSource = prizesInTournment;
                                         * tournament.prizeComboBox.Items.Refresh();
                                         * tournament.prizesListBox.Items.Refresh();*/
                errorMsgLbl.Visibility = Visibility.Hidden;
            }
            else
            {
                errorMsgLbl.Visibility = Visibility.Visible;
            }
        }
Exemple #21
0
        public void GeneratePrize(RectangleF rect)
        {
            Random rnd = new Random();

            if (PrizePrecent > 0)
            {
                double number = rnd.NextDouble();
                if (number <= PrizePrecent)
                {
                    List <IPrize <TBoard> > prizeCanFallList = CheckIfHavePrizeThatCanFell();
                    if (prizeCanFallList.Count > 0)
                    {
                        int             indexOfPrize = rnd.Next(0, prizeCanFallList.Count);
                        IPrize <TBoard> prize        = (IPrize <TBoard>)prizeCanFallList[indexOfPrize].Clone();
                        prizeFallList.Add(prize);
                        prize.Location = new PointF(rect.X + (rect.Width - prize.Width) / 2, rect.Bottom);
                        prize.StartMove(Direction.Bottom);
                        ChangeSumOfPrizeFellEachPrize(prize.Tag, 1);
                        RestartPrizeEvents(prize);
                        OnPrizeGenerated(prize);
                    }
                }
            }
        }
 public IPrize createPrize(IPrize prize)
 {
     return(PrizesTable.Create(prize, dbConn));
 }
Exemple #23
0
 /// <summary>
 /// Raise the PrizeFall event
 /// </summary>
 /// <param name="prize"></param>
 protected virtual void OnPrizeFall(IPrize <TBoard> prize)
 {
     PrizeFall?.Invoke(this, prize);
 }
Exemple #24
0
 /// <summary>
 /// Raise the PrizeGenerated event
 /// </summary>
 /// <param name="prize"></param>
 protected virtual void OnPrizeGenerated(IPrize <TBoard> prize)
 {
     PrizeGenerated?.Invoke(this, prize);
 }
Exemple #25
0
 private void Lvl_PrizeGenerated(object sender, IPrize <Board> e)
 {
 }
Exemple #26
0
 public PrizeBlock(IGameConfiguration configuration, Size size, ComponentManager componentManager, IPrize prize) : base(configuration, size)
 {
     _componentManager = componentManager;
     Prize             = prize;
 }
Exemple #27
0
 public Door(IPrize prize)
 {
     Prize = prize;
 }
 public bool Collides(IPrize prize)
 {
     return(base.Collides(_spaceShip, prize));
 }
 public void AddPrize(IPrize prize)
 {
     Prizes.Add(prize);
     _drawer.Add(prize, _resourceRepository.GetTextureByType(prize.GetType()));
 }