创建播放器方法切换 [英] Create player method switching

查看:79
本文介绍了创建播放器方法切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个玩家类,我正在尝试使用我的玩家类为我的菜单驱动的玩家程序创建一个玩家。一切似乎都有效,除了我的创建玩家类正在切换为玩家编号输入的值,并显示为目标输入的值。



任何帮助将不胜感激请和谢谢



I created a player class and I am trying to use my player class to create a player for my menu driven player program. Everything seems to be working except my create player class is switching the value entered for player number with the value entered for goals when it is displayed .

Any help would be appreciated please and thanks

//Creates a player in the tables if the array is not already full and the name is not a duplicate
        static void ProcessCreate(Int32 number, String firstName, String lastName, Int32 goals,
            Int32 assists, Player[] players, ref Int32 playerCount, Int32 MAXPLAYERS)
        {
            Int32 player = 0;
            if (playerCount < MAXPLAYERS)
            {
                Console.WriteLine("\nCreate Player: please enter the player's number");
                number = Int32.Parse(Console.ReadLine());
                if (GetPlayerIndex(number, firstName, lastName, goals, assists, players, ref playerCount) == -1)
                {
                    Console.WriteLine("\nCreate Player: please enter the player's First Name");
                     firstName = Console.ReadLine();
                     Console.WriteLine("\nCreate Player: please enter the player's Last  Name");
                     lastName = Console.ReadLine();
                    Console.WriteLine("\nCreate Player: please enter the player's goals");
                    goals = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("\nCreate Player: please enter the player's assists");
                    assists = Int32.Parse(Console.ReadLine());
                    InsertPlayer(number, firstName, lastName, goals, assists, players, ref playerCount);
                    Console.WriteLine("\n{0,7}   {1,-20}{2, -20}{3,8}{4,8}{5,8}\n", "Number", "First Name", "Last Name", "Goals", " Assists", "Points");
                     // for (Int32 player = 0; player < playerCount;)
                    Console.WriteLine("{0,7}   {1,-20}{2, -20}{3,8}{4,8}{5,8}",
                  players[player].Number, players[player].FirstName, players[player].LastName,
                  players[player].Goals, players[player].Assists, players[player].Points());

             
                    Console.WriteLine();
                }
                else
                    Console.WriteLine("\nCreate Player: the player number already exists");
            }
            else
                Console.WriteLine("\nCreate Player: the player roster is already full");

        }

推荐答案

检查你的InsertPlayer方法:玩家编号应该是第一个参数,目标是第四个。我猜你已经交换了它们,或者方法是将错误的值设置到Player.Number和Player.Goals属性中。



如果有疑问,请使用调试器单步进入方法并确切检查发生了什么。
Check your InsertPlayer method: player number should be the first parameter, and goals the fourth. I'd guess that you have swapped them, or the method is setting the wrong values into the Player.Number and Player.Goals properties.

If in doubt, use the debugger to single step into the method and check exactly what is happening.


这篇关于创建播放器方法切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆