Пример #1
0
        // פעולה המציגה את המסך למשתמש
        public override void Show()
        {
            try
            {
                base.Show();                                                                    // ניקיון המסך והצגת הכותרת
                Task <ActionTypeDTO> actionTypeTask = UIMain.api.GetActionTypeAsync("Playing"); // בניית אוביקט הפעולה
                Console.WriteLine("May take a few seconds...");
                actionTypeTask.Wait();
                ActionTypeDTO actionType = actionTypeTask.Result;

                Task <List <ActionDTO> > actionListTask = UIMain.api.GetActionsListAsync(actionType);
                Console.WriteLine("May take a few seconds...");
                actionTypeTask.Wait();
                List <ActionDTO> actionList = actionListTask.Result;

                List <object> listActions = actionList.ToList <object>();            // קבלת הפעולות שניתן לבצע על החיה לתוך רשימה
                ObjectsList   objList     = new ObjectsList("Actions", listActions); // בניית טבלת פעולות שניתן לבצע על החיה
                objList.Show();                                                      // הצגת הפעולות שניתן לבצע לחיה למשתמש
                Console.WriteLine();

                // קליטה מהמשתמש את הפעולה אותה הוא רוצה לבצע לחיה
                Console.WriteLine("Choose what do you want to play with your tamagotchi: ");
                int       id     = int.Parse(Console.ReadLine());
                ActionDTO action = actionList.Where(p => p.ActionId == id).FirstOrDefault();

                // מסננת קלט לבדוק שבאמת חזרה פעולה
                while (action == null)
                {
                    Console.WriteLine("The id is invalid! Please type again: ");
                    id     = int.Parse(Console.ReadLine());
                    action = actionList.Where(p => p.ActionId == id).FirstOrDefault();
                }

                Task <bool> playTask = UIMain.api.PlayWithAnimalAsync(action);
                Console.WriteLine("Your animal is playing, please wait a few seconds...");
                playTask.Wait();
                bool play = playTask.Result;

                if (play)
                {
                    Console.WriteLine("Action managed successfully!");
                }
                else
                {
                    Console.WriteLine("OOps, something went wrong...");
                }
                Console.ReadKey();
            }

            catch (Exception e)
            {
                Console.WriteLine($"Fail with error: {e.Message}!");
            }
        }
        // פעולה המציגה את המסך למשתמש
        public override void Show()
        {
            base.Show();
            ObjectView showPlayer = new ObjectView("", UIMain.CurrentPlayer);

            showPlayer.Show();
            Console.WriteLine("Press A to see Player Animals or other key to go back!");
            char c = Console.ReadKey().KeyChar;

            if (c == 'a' || c == 'A')
            {
                Console.WriteLine();
                //Read first the animals of the player
                Task <List <AnimalDTO> > t = UIMain.api.GetPlayerAnimalsAsync();
                Console.WriteLine("Reading player animals...");
                t.Wait();
                List <AnimalDTO> list = t.Result;
                if (list != null)
                {
                    //Create list to be displayed on screen
                    //Format the desired fields to be shown! (screen is not wide enough to show all)

                    List <Object> animals = list.ToList <Object>();
                    ObjectsList   oList   = new ObjectsList("Animals", animals);
                    oList.Show();
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("Animals could not be read!");
                }
                Console.WriteLine();


                Console.ReadKey();
            }
        }