Пример #1
0
 private void OnAppearing()
 {
     Fruits.Clear();
     Fruits.Add("Strawberry");
     Fruits.Add("Apple");
     Fruits.Add("Banana");
     Fruits.Add("Orange");
 }
        private void ExecuteClearCommand()
        {
            Planets = new ObservableCollection <string>();
            DataAccess db = new DataAccess();

            db.ClearAllUserCreatedRows();
            clearDataGrids();
            updateRows();
            FruitsSelectedItem  = null;
            PlanetsSelectedItem = null;

            Fruits.Clear();
            Planets.Clear();
            populateComboBoxes();
        }
        private void OnAppearing()
        {
            Fruits.Clear();
            Fruits.Add("Apple");
            Fruits.Add("Orange");
            Fruits.Add("Banana");
            Fruits.Add("Pineapple");
            Fruits.Add("Pear");
            Fruits.Add("Grapes");

            //**DEBUG HERE**
            //HERE THE POSITION = 0 BUT VISUALLY THE CAROUSEL DIFFERS.
            var position = FruitPosition;

            //**DEBUG HERE**
            //ON FIRST INSTANCE SELECTEDFRUIT IS NULL. IT SHOULD BE
            //SET TO APPLE. ON SUBSEQUANT RUNS IT REMAINS APPLE BUT
            //VISUALLY THE CAROUSEL DIFFERS.
            var selectedFruit = CurrentFruit;
        }
Пример #4
0
        public void GenerateFruits()
        {
            foreach (Fruit fruit in Fruits)
            {
                if (!(GameMap.MapUnits[fruit.UnitPosition.Row, fruit.UnitPosition.Column] is Snake))
                {
                    GameMap.RemoveUnit(fruit.UnitPosition);
                }
            }
            Fruits.Clear();

            Random random = new Random();
            int    aux    = random.Next(100);

            if (aux < 60) // place one fruit
            {
                bool canPut = false;
                while (!canPut)
                {
                    Random rdRow     = new Random();
                    Random rdColumn  = new Random();
                    int    auxRow    = rdRow.Next(GameMap.NumberOfRows);
                    int    auxColumn = rdColumn.Next(GameMap.NumberOfColumns);
                    if (GameMap.MapUnits[auxRow, auxColumn] == null &&
                        (((auxRow - SnakeParts[0].UnitPosition.Row) < -2) || ((auxRow - SnakeParts[0].UnitPosition.Row) > 2) ||
                         ((auxColumn - SnakeParts[0].UnitPosition.Column) < -2) || ((auxColumn - SnakeParts[0].UnitPosition.Column) > 2)))
                    {
                        GameMap.AddUnit(new Fruit(new Position(auxRow, auxColumn)));
                        Fruits.Add(new Fruit(new Position(auxRow, auxColumn)));
                        canPut = true;
                    }
                }
            }
            else // place two fruits
            {
                bool canPut = false;
                while (!canPut)
                {
                    Random rdRow1     = new Random();
                    Random rdColumn1  = new Random();
                    Random rdRow2     = new Random();
                    Random rdColumn2  = new Random();
                    int    auxRow1    = rdRow1.Next(GameMap.NumberOfRows);
                    int    auxColumn1 = rdColumn1.Next(GameMap.NumberOfColumns);
                    int    auxRow2    = rdRow2.Next(GameMap.NumberOfRows);
                    int    auxColumn2 = rdColumn2.Next(GameMap.NumberOfColumns);
                    if ((auxRow1 != auxRow2 || auxColumn1 != auxColumn2) &&
                        GameMap.MapUnits[auxRow1, auxColumn1] == null && GameMap.MapUnits[auxRow2, auxColumn2] == null &&
                        (((auxRow1 - SnakeParts[0].UnitPosition.Row) < -2) || ((auxRow1 - SnakeParts[0].UnitPosition.Row) > 2) ||
                         ((auxColumn1 - SnakeParts[0].UnitPosition.Column) < -2) || ((auxColumn1 - SnakeParts[0].UnitPosition.Column) > 2)) &&
                        (((auxRow2 - SnakeParts[0].UnitPosition.Row) < -2) || ((auxRow2 - SnakeParts[0].UnitPosition.Row) > 2) ||
                         ((auxColumn2 - SnakeParts[0].UnitPosition.Column) < -2) || ((auxColumn2 - SnakeParts[0].UnitPosition.Column) > 2)))
                    {
                        GameMap.AddUnit(new Fruit(new Position(auxRow1, auxColumn1)));
                        Fruits.Add(new Fruit(new Position(auxRow1, auxColumn1)));
                        GameMap.AddUnit(new Fruit(new Position(auxRow2, auxColumn2)));
                        Fruits.Add(new Fruit(new Position(auxRow2, auxColumn2)));
                        canPut = true;
                    }
                }
            }
        }