c# - How to remove array element from user entered array -
hi i'm creating menu driven programme holds 3 arrays: 1 person's lastly name, 1 points scored , 1 player number. made deletemethod , deleteplayer method suppose when user enters players number delete player number, lastly name , points user entered list when utilize delete method clears entire list. not sure on on how prepare this. have maintain programme in main class.
any help appreciated please , give thanks you
static void processdelete( int32[] playernumbers, ref int32 playercount, string[] playerlastname, int32[] playerpoints) { int32[] newarray = new int32[playernumbers.length]; string[] newarray2 = new string[playerlastname.length]; int32[] newarray3 = new int32[playerpoints.length]; int index = array.indexof(playernumbers, 0); { (int = 0; < playernumbers.length; i++) playernumbers[i] = 0; } // string[] playerlastname = new string[] { null, null, null }; (int = 0; index < playerlastname.length; index++) playerlastname[i] = " "; (int = 0; < 10; i++) { //console.writeline(newarray2[i]); } (int = 0; < playerpoints.length; i++) playerpoints[i] = 0; } static void deleteplayer(int32[] playernumbers, string[] playerlastname, int32[] playerpoints, ref int32 playercount, int32 maxplayers) { int player;// player number delete int playerindex;//index of player number in array if (playercount < maxplayers) { player = getpositiveinteger("\ndelete player: please come in player's number"); playerindex = getplayerindex(player, playernumbers, playercount); if (playerindex != -1) { { console.writeline("\ndelete player: number - {0}, name - {1}, points - {2}", playernumbers[playerindex], playerlastname[playerindex], playerpoints[playerindex]); console.writeline("succesfully deleted"); console.writeline(); processdelete( playernumbers, ref playercount, playerlastname, playerpoints); } } else console.writeline("\ndelete player: player not found"); } else console.writeline("\ndelete player: roster empty"); } } }
in object-oriented language, create class capture information. allow me know if need explanation because, always, there's more 1 way this.
updated currentscore, addplayertogame() function, , incrementing playercount
class programme { static void main(string[] args) { //create firstplayer player firstplayer = new player { playerid = 1, displayname = "goober", lastname = "smith" }; // create secondplayer player secondplayer = new player { playerid = 2, displayname = "destructor", lastname = "henry" }; // create game instance game currentgame = new game(); // add together players game currentgame.addplayertogame(firstplayer); currentgame.addplayertogame(secondplayer); // player scores point secondplayer.currentscore++; // player clicks leavegame, etc. currentgame.playerleavesgame(firstplayer); } } public class player { public int playerid { get; set; } // assume same player numbers public string displayname { get; set; } public string lastname { get; set; } public int currentscore { get; set; } } public class game { private static readonly int maxplayers = 10; public game() { players = new list<player>(); } public list<player> players { get; private set; } private int _playercount = 0; public int playercount { { homecoming _playercount; } set { _playercount = value; } } /// <summary> /// tries add together player game /// </summary> /// <param name="playerthatjoinedgame"></param> /// <returns>true if player added , game wasn't full</returns> public bool addplayertogame(player playerthatjoinedgame) { if (playercount < maxplayers) { players.add(playerthatjoinedgame); playercount++; homecoming true; } else { homecoming false; } } /// <summary> /// removes player game /// </summary> /// <param name="playerthatquit">the leaving player</param> public void playerleavesgame(player playerthatquit) { // removes player game players.remove(playerthatquit); playercount--; } }
c#
No comments:
Post a Comment