Пример #1
0
        //EditingBasketballPlayer Method
        public static void EditingBasketBallPlayer()
        {
            Console.ForegroundColor = ConsoleColor.Red;

            Console.WriteLine($"{"Player Type",-20} {"Player ID",10} {"Player Name",-20} {"Team Name",-20} {"Games Played",20} {"Field Goals",20} {"3-Pointers",20} {"Points",20}\n");

            foreach (var i in myList)
            {
                if (i.PlayerType == PlayerType.BasketballPlayer)
                {
                    Console.WriteLine(i);
                }
            }

            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine("\nEditing Basketball Player\n");

            Console.WriteLine("Enter ID of player you want to edit: ");
            int id;

            bool idIsNumeric = Int32.TryParse(Console.ReadLine(), out id);

            while (!idIsNumeric)
            {
                Console.WriteLine("Invalid Input.Please Try again\n");
                Console.WriteLine("Enter ID of player you want to edit: ");
                idIsNumeric = Int32.TryParse(Console.ReadLine(), out id);
            }

            if (id <= myList.Count && myList[id - 1].PlayerType == PlayerType.BasketballPlayer)
            {
                Console.Write("Enter Player's new name: ");
                string basketballPlayer = Console.ReadLine();

                while (string.IsNullOrWhiteSpace(basketballPlayer))
                {
                    Console.WriteLine("Invalid Input.Please Try again\n");
                    Console.Write("Enter Player's new name: ");
                    basketballPlayer = Console.ReadLine();
                }

                Console.Write("Enter New Team name: ");
                string basketballTeamName = Console.ReadLine();

                while (string.IsNullOrWhiteSpace(basketballTeamName))
                {
                    Console.WriteLine("Invalid Input.Please Try again\n");
                    Console.Write("Enter New Team name: ");
                    basketballTeamName = Console.ReadLine();
                }

                Console.Write("Enter Games Played: ");
                int basketballGamesPlayed;

                bool gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballGamesPlayed);
                while (!gamePlayedIsNumeric)
                {
                    Console.WriteLine("Invalid Input.Please Try again\n");
                    Console.Write("Enter Games Played: ");
                    gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballGamesPlayed);
                }

                Console.Write("Enter Field Goals: ");
                int basketballFieldGoals;

                bool fieldGoalsIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballFieldGoals);

                while (!fieldGoalsIsNumeric)
                {
                    Console.WriteLine("Invalid Input.Please Try again\n");
                    Console.Write("Enter Field Goals: ");
                    fieldGoalsIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballFieldGoals);
                }

                Console.Write("Enter 3-Pointers: ");
                int basketballThreePointers;

                bool threePointersIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballThreePointers);

                while (!threePointersIsNumeric)
                {
                    Console.WriteLine("Invalid Input.Please Try again\n");
                    Console.Write("Enter 3-Pointers: ");
                    threePointersIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballThreePointers);
                }

                myList[id - 1] = new BasketballPlayer(PlayerType.BasketballPlayer, id, basketballPlayer, basketballTeamName, basketballGamesPlayed, basketballFieldGoals, basketballThreePointers);

                Console.WriteLine("\nPlayer with ID = " + id + " updated\n");
                Console.ForegroundColor = ConsoleColor.Red;


                Console.WriteLine($"{"Player Type",-20} {"Player ID",10} {"Player Name",-20} {"Team Name",-20} {"Games Played",20} {"Field Goals",20} {"3-Pointers",20} {"Points",20}\n");

                foreach (var i in myList)
                {
                    if (i.PlayerType == PlayerType.BasketballPlayer)
                    {
                        Console.WriteLine(i);
                    }
                }
            }
            else
            {
                Console.WriteLine("Invalid Input! We dont have that id in Basketball Players Table");
                EditingBasketBallPlayer();
            }
            Console.ReadKey();
            Console.ForegroundColor = ConsoleColor.White;

            EditingPlayer();
        }
Пример #2
0
        //AddingBasketBallPlayer method
        public static void AddingBasketBallPlayer()
        {
            Console.WriteLine("\nAdding Basketball Player\n");
            Console.Write("Enter Player name: ");
            string basketballPlayer = Console.ReadLine();

            while (string.IsNullOrWhiteSpace(basketballPlayer))
            {
                Console.WriteLine("Invalid Input.Please Try again\n");
                Console.Write("Enter Player name: ");
                basketballPlayer = Console.ReadLine();
            }

            Console.Write("Enter Team name: ");
            string basketballTeamName = Console.ReadLine();

            while (string.IsNullOrWhiteSpace(basketballTeamName))
            {
                Console.WriteLine("Invalid Input.Please Try again\n");
                Console.Write("Enter Team name: ");
                basketballTeamName = Console.ReadLine();
            }

            Console.Write("Enter Games Played: ");
            int basketballGamesPlayed;

            bool gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballGamesPlayed);

            while (!gamePlayedIsNumeric)
            {
                Console.WriteLine("Invalid Input.Please Try again\n");
                Console.Write("Enter Games Played: ");
                gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballGamesPlayed);
            }

            Console.Write("Enter Field Goals: ");
            int basketballFieldGoals;

            bool fieldGoalsIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballFieldGoals);

            while (!fieldGoalsIsNumeric)
            {
                Console.WriteLine("Invalid Input.Please Try again\n");
                Console.Write("Enter Field Goals: ");
                fieldGoalsIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballFieldGoals);
            }

            Console.Write("Enter 3-Pointers: ");
            int basketballThreePointers;

            bool threePointersIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballThreePointers);

            while (!threePointersIsNumeric)
            {
                Console.WriteLine("Invalid Input.Please Try again\n");
                Console.Write("Enter 3-Pointers: ");
                threePointersIsNumeric = Int32.TryParse(Console.ReadLine(), out basketballThreePointers);
            }

            Player newBasketBallPlayer = new BasketballPlayer(PlayerType.BasketballPlayer, myList.Count + 1, basketballPlayer, basketballTeamName, basketballGamesPlayed, basketballFieldGoals, basketballThreePointers);

            myList.Add(newBasketBallPlayer);

            Console.WriteLine("\nNew Player Added.\n\nView All BasketBallPlayer: \n\n");

            Console.ForegroundColor = ConsoleColor.Red;

            Console.WriteLine($"{"Player Type",-20} {"Player ID",10} {"Player Name",-20} {"Team Name",-20} {"Games Played",20} {"Field Goals",20} {"3-Pointers",20} {"Points",20}\n");

            foreach (var i in myList)
            {
                if (i.PlayerType == PlayerType.BasketballPlayer)
                {
                    Console.WriteLine(i);
                }
            }
            Console.ReadKey();
            Console.ForegroundColor = ConsoleColor.White;

            AddingPlayer();
        }