Ejemplo n.º 1
0
        private void AnimalEnclosureChanged(object sender, EnclosureChangedEventArgs e)
        {
            var animal = (Animal)sender;

            Phaser(interop =>
            {
                var animalSpriteName = SpriteName.Create("animal", animal.Name);
                var animalSprite     = interop.Sprite(animalSpriteName);

                if (e.EnclosureName == null)
                {
                    if (animalSprite.Exists())
                    {
                        interop.RemoveSprite(animalSpriteName);
                    }
                }
                else
                {
                    var animalPosition = AnimalPositions[animal.EnclosureName];

                    if (animalSprite.Exists())
                    {
                        animalSprite.Move(animalPosition.X, animalPosition.Y);
                    }
                    else
                    {
                        interop.AddSprite(animalSpriteName, $"animals/{animal.Name}/top",
                                          animalPosition.X, animalPosition.Y, options => options
                                          .OnPointerUp(nameof(Animal_PointerUp)));
                    }
                }
            });
        }
        public override void Create()
        {
            Phaser(interop =>
            {
                interop
                .AddSprite("sprBackground", "backgrounds/animal-management", 640, 512)
                .AddSprite("sprBack", "misc/board", 180, 60)
                .AddSprite("btnBack", "misc/back", 165, 95, options => options
                           .OnPointerUp(nameof(btnBack_PointerUp)));

                for (var i = 0; i < State.Animals.Count; i++)
                {
                    var animal    = State.Animals[i];
                    var xPosition = (i + 1) * 250;

                    interop.AddSprite(SpriteName.Create("btnAnimalPhoto", animal.Name), $"animals/{animal.Name}/photo",
                                      xPosition + 50, 350, options => options
                                      .OnPointerUpAsync(nameof(btnAnimalPhoto_PointerUp)));

                    if (animal.OwnerName != StateManager.PlayerName)
                    {
                        interop.AddSprite(SpriteName.Create("sprLock", animal.Name), "misc/lock",
                                          xPosition + 143, 467);
                    }

                    var label = animal.OwnerName != null ? animal.Name : animal.Price.ToString();

                    interop.AddText(SpriteName.Create("txtPhoto", animal.Name),
                                    xPosition + 50, 430, label, options => options
                                    .WithOrigin(0.5, 0.5));
                }
            });
        }
        private void AnimalPurchaseFailed(object sender, EventArgs e)
        {
            var animal = (Animal)sender;

            Phaser(interop => interop
                   .ShakeCamera()
                   .Text(SpriteName.Create("txtPhoto", animal.Name))
                   .Value(animal.Price.ToString()));
        }
Ejemplo n.º 4
0
        private void AddAnimalSprite(Animal animal)
        {
            Phaser(interop =>
            {
                var animalSpriteName = SpriteName.Create("animal", animal.Name);
                var animalPosition   = AnimalPositions[animal.EnclosureName];

                interop
                .AddSprite(animalSpriteName, $"animals/{animal.Name}/top",
                           animalPosition.X, animalPosition.Y, options => options
                           .OnPointerUp(nameof(Animal_PointerUp)));
            });
        }
        private void AnimalOwnerChanged(object sender, OwnerChangedEventArgs e)
        {
            var animal = (Animal)sender;

            var lockSpriteName = SpriteName.Create("sprLock", animal.Name);

            Phaser(interop =>
            {
                if (interop.Sprite(lockSpriteName).Exists())
                {
                    interop.RemoveSprite(lockSpriteName);
                }

                interop.Text(SpriteName.Create("txtPhoto", animal.Name))
                .Value(animal.Name);
            });
        }
        public async Task btnAnimalPhoto_PointerUp(SpritePointerEventArgs args)
        {
            var animalName = SpriteName.ExtractId(args.SpriteName);
            var animal     = StateManager.State.FindAnimal(animalName);

            if (animal.OwnerName == null)
            {
                Phaser(interop => interop
                       .Text(SpriteName.Create("txtPhoto", animal.Name))
                       .Value("purchasing..."));

                await _apiClient.PurchaseAnimalAsync(State.GameName, animalName, PlayerName);
            }
            else if (animal.OwnerName == StateManager.PlayerName)
            {
                await _apiClient.MoveAnimalAsync(State.GameName, animalName, State.SelectedEnclosureName);

                Phaser(interop => interop.SwitchToScene(RanchScene.Name));
            }
            else
            {
                Phaser(interop => interop.ShakeCamera());
            }
        }