开发者

C++ Fantasy Football Draft Program - Adding Players to Teams

I am working on making a C++ program that will simulate a fantasy football draft.. I have used a linked list to create a list of team names, for each person participating in the draft. Now, I would like to know which way I should go about adding the players a team drafts to their respective team. I have the football players in a read 开发者_StackOverflow社区in file and can figure out how to let them choose which, but cannot figure out how to store them on their respective team.

Any help appreciated Thanks in advance


Well, you ought to have a Team class; the Team class ought to have a container to hold player names (another linked list, let's say). The list you have now should hold Teams rather than Strings.

Eventually the list of player names will probably be upgraded to a list of Player objects -- yet another class you'll want to define.

I know this is vague, but does it help?


It seems like you just need to understand the basic C++ containers a bit better.

One way might be to simply remove the player from a list or array of all players in the league, and add it to the fantasy player's list or array of players.

class Player; // ...

class FantasyPlayer
{
public:
  std::vector< Player > picks; // array of my picks
};

std::vector< Player >         all_players;     // all available picks
std::vector< FantastyPlayer > fantasy_players; // all pickers

int iPicked = ...; // index of picked player in all_players
int iPicker = ...; // index of fantasy player currently picking

// add picked player to this fantasy player's pick list
fantasy_players[iPicker].picks.push_back(all_players[iPicked]);

// remove picked player from available players list
all_players.erase(iPicked);

Another, maybe easier, way to handle it might be to reference the "pickers" directly from the players themselves.

class FantasyPlayer; // ...

class Player
{
public:
  Player() : owner(0) { /* empty */ }
  FantastyPlayer* owner; // pointer to fantasy player who picked me
};

std::vector< Player >         all_players;     // all available picks
std::vector< FantastyPlayer > fantasy_players; // all pickers


int iPicked = ...; // index of picked player in all_players
int iPicker = ...; // index of fantasy player currently picking

// create link between a player and its picker
all_players[iPicked].owner = &(fantasy_players[iPicker]);

This code is all intentionally brief and incomplete, but maybe it'll get you started in the right direction. Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜