Makes a bunch of players and adds them to teams

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












I have a lot of code (probably about 1/2 of all of my 891 lines) dedicated to just making players and teams.

Here's the code that makes the players and teams:



private void makeTeams() 
toPlay = maps.get(random.nextInt(maps.size())); // I have a method that I shortened to make maps

pName = toPlay.islands().get(you).getTeam().players.get(0).getName();

// red's players
ArrayList<Player> redPlayers = new ArrayList<>();

if(toPlay.allPlayers().size() == 8) // making players for solo
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
redPlayers.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// what color the team is
ColorOfTeam cotred = new ColorOfTeam(Color.red);

// the team
Team red = new Team(redPlayers, cotred);

// adding the team
teams.add(red);

// blue's players
ArrayList<Player> bluePlayers = new ArrayList<>();

if(toPlay.allPlayers().size() == 7) // making players
// making player

Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
// adding players

bluePlayers.add(toAdd);
// removing the player

toPlay.allPlayers().remove(toAdd);
// what color the team is

ColorOfTeam cotblue = new ColorOfTeam(Color.blue);
// the team

Team blue = new Team(bluePlayers, cotblue);
// adding the team

teams.add(blue);

// red's players
ArrayList<Player> greenPlayers = new ArrayList<>();

if(toPlay.allPlayers().size() == 6) // making players for solo
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
greenPlayers.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// what color the team is
ColorOfTeam cotgreen = new ColorOfTeam(Color.green);

// the team
Team green = new Team(greenPlayers, cotgreen);

// adding the team
teams.add(green);

// blue's players
ArrayList<Player> yellPlayers = new ArrayList<>();

if(toPlay.allPlayers().size() == 5) // making players
// making player

Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
// adding players

yellPlayers.add(toAdd);
// removing the player

toPlay.allPlayers().remove(toAdd);
// what color the team is

ColorOfTeam cotyell = new ColorOfTeam(Color.yellow);
// the team

Team yell = new Team(yellPlayers, cotyell);
// adding the team

teams.add(yell);

// aqua's players
ArrayList<Player> aquaPlayers = new ArrayList<>();

if(toPlay.allPlayers().size() == 4) // making players for solo
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
aquaPlayers.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// what color the team is
ColorOfTeam cotaqua = new ColorOfTeam(Color.cyan);

// the team
Team aqua = new Team(aquaPlayers, cotaqua);

// adding the team
teams.add(aqua);

// white's players
ArrayList<Player> whitePlayers = new ArrayList<>();

if(toPlay.allPlayers().size() == 3) // making players
// making player

Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
// adding players

whitePlayers.add(toAdd);
// removing the player

toPlay.allPlayers().remove(toAdd);
// what color the team is

ColorOfTeam cotwhite = new ColorOfTeam(Color.lightGray);
// the team

Team white = new Team(whitePlayers, cotwhite);
// adding the team

teams.add(white);

// pink's players
ArrayList<Player> pinkPlayers = new ArrayList<>();

if(toPlay.allPlayers().size() == 2) // making players for solo
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
pinkPlayers.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// what color the team is
ColorOfTeam cotpink = new ColorOfTeam(Color.magenta);

// the team
Team pink = new Team(pinkPlayers, cotpink);

// adding the team
teams.add(pink);

// gray's players
ArrayList<Player> grayPlayers = new ArrayList<>();

if(toPlay.allPlayers().size() == 1) // making players
// making player

Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
// adding players

grayPlayers.add(toAdd);
// removing the player

toPlay.allPlayers().remove(toAdd);
// what color the team is

ColorOfTeam cotgray = new ColorOfTeam(Color.gray);
// the team

Team gray = new Team(grayPlayers, cotgray);
// adding the team

teams.add(gray);

// red's players
ArrayList<Player> redPlayersrd = new ArrayList<>();

if(toPlay.allPlayers().size() == 16)
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
redPlayersrd.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// making player
Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
redPlayersrd.add(toAdd2);

// removing the player
toPlay.allPlayers().remove(toAdd2);

// what color the team is
ColorOfTeam cotredRD = new ColorOfTeam(Color.red);

// the team
Team redRD = new Team(redPlayersrd, cotredRD);

// adding the team
teams.add(redRD);

// red's players
ArrayList<Player> bPlayersrd = new ArrayList<>();

if(toPlay.allPlayers().size() == 14)
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
bPlayersrd.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// making player
Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
bPlayersrd.add(toAdd2);

// removing the player
toPlay.allPlayers().remove(toAdd2);

// what color the team is
ColorOfTeam cotbRD = new ColorOfTeam(Color.blue);

// the team
Team bRD = new Team(bPlayersrd, cotbRD);

// adding the team
teams.add(bRD);
// red's players
ArrayList<Player> gPlayersrd = new ArrayList<>();

if(toPlay.allPlayers().size() == 12)
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
gPlayersrd.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// making player
Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
gPlayersrd.add(toAdd2);

// removing the player
toPlay.allPlayers().remove(toAdd2);

// what color the team is
ColorOfTeam cotgRD = new ColorOfTeam(Color.green);

// the team
Team gRD = new Team(gPlayersrd, cotgRD);

// adding the team
teams.add(gRD);

// red's players
ArrayList<Player> yPlayersrd = new ArrayList<>();

if(toPlay.allPlayers().size() == 10)
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
yPlayersrd.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// making player
Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
yPlayersrd.add(toAdd2);

// removing the player
toPlay.allPlayers().remove(toAdd2);

// what color the team is
ColorOfTeam cotyRD = new ColorOfTeam(Color.yellow);

// the team
Team yRD = new Team(yPlayersrd, cotyRD);

// adding the team
teams.add(yRD);
// red's players
ArrayList<Player> aquPlayersrd = new ArrayList<>();

if(toPlay.allPlayers().size() == 8)
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
aquPlayersrd.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// making player
Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
redPlayersrd.add(toAdd2);

// removing the player
toPlay.allPlayers().remove(toAdd2);

// what color the team is
ColorOfTeam cotaquRD = new ColorOfTeam(Color.cyan);

// the team
Team aquRD = new Team(aquPlayersrd, cotaquRD);

// adding the team
teams.add(aquRD);

// red's players
ArrayList<Player> wPlayersrd = new ArrayList<>();

if(toPlay.allPlayers().size() == 6)
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
wPlayersrd.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// making player
Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
wPlayersrd.add(toAdd2);

// removing the player
toPlay.allPlayers().remove(toAdd2);

// what color the team is
ColorOfTeam cotwRD = new ColorOfTeam(Color.white);

// the team
Team wRD = new Team(wPlayersrd, cotwRD);

// adding the team
teams.add(wRD);

// red's players
ArrayList<Player> pPlayersrd = new ArrayList<>();

if(toPlay.allPlayers().size() == 4)
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
pPlayersrd.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// making player
Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
pPlayersrd.add(toAdd2);

// removing the player
toPlay.allPlayers().remove(toAdd2);

// what color the team is
ColorOfTeam cotpRD = new ColorOfTeam(Color.magenta);

// the team
Team pRD = new Team(pPlayersrd, cotpRD);

// adding the team
teams.add(pRD);

// red's players
ArrayList<Player> graPlayersrd = new ArrayList<>();

if(toPlay.allPlayers().size() == 2)
// making player
Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
graPlayersrd.add(toAdd);

// removing the player
toPlay.allPlayers().remove(toAdd);

// making player
Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

// adding players
graPlayersrd.add(toAdd2);

// removing the player
toPlay.allPlayers().remove(toAdd2);

// what color the team is
ColorOfTeam cotgraRD = new ColorOfTeam(Color.gray);

// the team
Team graRD = new Team(graPlayersrd, cotgraRD);

// adding the team
teams.add(graRD);

System.out.println("The map is " + toPlay.getName() + '-' + toPlay.maxPlayerAm());
int u = random.nextInt(teams.size()-1);
youAreOn = teams.get(u);
System.out.println("You are on team " + youAreOn.getName());
for(int i=0; i<youAreOn.getPlayers().size(); i++)
System.out.print("The players are " + youAreOn.getPlayers().get(i).getName());




As you can see, this is very lengthy (I calculated that it takes up 438 lines of code), being lengthy because I wrote this before I got good at using for and while loops. My question is: can anyone find a way to shorten this? It got out of hand and is now hard to shorten for me. I've looked at it, and can't find a way to shorten it.

The main reason I wanted to shorten it is so that it runs faster: I have a run() method that counts the ticks and frames of every second; the ticks and frames should be 60, because that's what I set my fps to, but they're always 0.







share|improve this question

























    up vote
    0
    down vote

    favorite












    I have a lot of code (probably about 1/2 of all of my 891 lines) dedicated to just making players and teams.

    Here's the code that makes the players and teams:



    private void makeTeams() 
    toPlay = maps.get(random.nextInt(maps.size())); // I have a method that I shortened to make maps

    pName = toPlay.islands().get(you).getTeam().players.get(0).getName();

    // red's players
    ArrayList<Player> redPlayers = new ArrayList<>();

    if(toPlay.allPlayers().size() == 8) // making players for solo
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    redPlayers.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // what color the team is
    ColorOfTeam cotred = new ColorOfTeam(Color.red);

    // the team
    Team red = new Team(redPlayers, cotred);

    // adding the team
    teams.add(red);

    // blue's players
    ArrayList<Player> bluePlayers = new ArrayList<>();

    if(toPlay.allPlayers().size() == 7) // making players
    // making player

    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
    // adding players

    bluePlayers.add(toAdd);
    // removing the player

    toPlay.allPlayers().remove(toAdd);
    // what color the team is

    ColorOfTeam cotblue = new ColorOfTeam(Color.blue);
    // the team

    Team blue = new Team(bluePlayers, cotblue);
    // adding the team

    teams.add(blue);

    // red's players
    ArrayList<Player> greenPlayers = new ArrayList<>();

    if(toPlay.allPlayers().size() == 6) // making players for solo
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    greenPlayers.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // what color the team is
    ColorOfTeam cotgreen = new ColorOfTeam(Color.green);

    // the team
    Team green = new Team(greenPlayers, cotgreen);

    // adding the team
    teams.add(green);

    // blue's players
    ArrayList<Player> yellPlayers = new ArrayList<>();

    if(toPlay.allPlayers().size() == 5) // making players
    // making player

    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
    // adding players

    yellPlayers.add(toAdd);
    // removing the player

    toPlay.allPlayers().remove(toAdd);
    // what color the team is

    ColorOfTeam cotyell = new ColorOfTeam(Color.yellow);
    // the team

    Team yell = new Team(yellPlayers, cotyell);
    // adding the team

    teams.add(yell);

    // aqua's players
    ArrayList<Player> aquaPlayers = new ArrayList<>();

    if(toPlay.allPlayers().size() == 4) // making players for solo
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    aquaPlayers.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // what color the team is
    ColorOfTeam cotaqua = new ColorOfTeam(Color.cyan);

    // the team
    Team aqua = new Team(aquaPlayers, cotaqua);

    // adding the team
    teams.add(aqua);

    // white's players
    ArrayList<Player> whitePlayers = new ArrayList<>();

    if(toPlay.allPlayers().size() == 3) // making players
    // making player

    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
    // adding players

    whitePlayers.add(toAdd);
    // removing the player

    toPlay.allPlayers().remove(toAdd);
    // what color the team is

    ColorOfTeam cotwhite = new ColorOfTeam(Color.lightGray);
    // the team

    Team white = new Team(whitePlayers, cotwhite);
    // adding the team

    teams.add(white);

    // pink's players
    ArrayList<Player> pinkPlayers = new ArrayList<>();

    if(toPlay.allPlayers().size() == 2) // making players for solo
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    pinkPlayers.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // what color the team is
    ColorOfTeam cotpink = new ColorOfTeam(Color.magenta);

    // the team
    Team pink = new Team(pinkPlayers, cotpink);

    // adding the team
    teams.add(pink);

    // gray's players
    ArrayList<Player> grayPlayers = new ArrayList<>();

    if(toPlay.allPlayers().size() == 1) // making players
    // making player

    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
    // adding players

    grayPlayers.add(toAdd);
    // removing the player

    toPlay.allPlayers().remove(toAdd);
    // what color the team is

    ColorOfTeam cotgray = new ColorOfTeam(Color.gray);
    // the team

    Team gray = new Team(grayPlayers, cotgray);
    // adding the team

    teams.add(gray);

    // red's players
    ArrayList<Player> redPlayersrd = new ArrayList<>();

    if(toPlay.allPlayers().size() == 16)
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    redPlayersrd.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // making player
    Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    redPlayersrd.add(toAdd2);

    // removing the player
    toPlay.allPlayers().remove(toAdd2);

    // what color the team is
    ColorOfTeam cotredRD = new ColorOfTeam(Color.red);

    // the team
    Team redRD = new Team(redPlayersrd, cotredRD);

    // adding the team
    teams.add(redRD);

    // red's players
    ArrayList<Player> bPlayersrd = new ArrayList<>();

    if(toPlay.allPlayers().size() == 14)
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    bPlayersrd.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // making player
    Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    bPlayersrd.add(toAdd2);

    // removing the player
    toPlay.allPlayers().remove(toAdd2);

    // what color the team is
    ColorOfTeam cotbRD = new ColorOfTeam(Color.blue);

    // the team
    Team bRD = new Team(bPlayersrd, cotbRD);

    // adding the team
    teams.add(bRD);
    // red's players
    ArrayList<Player> gPlayersrd = new ArrayList<>();

    if(toPlay.allPlayers().size() == 12)
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    gPlayersrd.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // making player
    Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    gPlayersrd.add(toAdd2);

    // removing the player
    toPlay.allPlayers().remove(toAdd2);

    // what color the team is
    ColorOfTeam cotgRD = new ColorOfTeam(Color.green);

    // the team
    Team gRD = new Team(gPlayersrd, cotgRD);

    // adding the team
    teams.add(gRD);

    // red's players
    ArrayList<Player> yPlayersrd = new ArrayList<>();

    if(toPlay.allPlayers().size() == 10)
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    yPlayersrd.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // making player
    Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    yPlayersrd.add(toAdd2);

    // removing the player
    toPlay.allPlayers().remove(toAdd2);

    // what color the team is
    ColorOfTeam cotyRD = new ColorOfTeam(Color.yellow);

    // the team
    Team yRD = new Team(yPlayersrd, cotyRD);

    // adding the team
    teams.add(yRD);
    // red's players
    ArrayList<Player> aquPlayersrd = new ArrayList<>();

    if(toPlay.allPlayers().size() == 8)
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    aquPlayersrd.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // making player
    Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    redPlayersrd.add(toAdd2);

    // removing the player
    toPlay.allPlayers().remove(toAdd2);

    // what color the team is
    ColorOfTeam cotaquRD = new ColorOfTeam(Color.cyan);

    // the team
    Team aquRD = new Team(aquPlayersrd, cotaquRD);

    // adding the team
    teams.add(aquRD);

    // red's players
    ArrayList<Player> wPlayersrd = new ArrayList<>();

    if(toPlay.allPlayers().size() == 6)
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    wPlayersrd.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // making player
    Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    wPlayersrd.add(toAdd2);

    // removing the player
    toPlay.allPlayers().remove(toAdd2);

    // what color the team is
    ColorOfTeam cotwRD = new ColorOfTeam(Color.white);

    // the team
    Team wRD = new Team(wPlayersrd, cotwRD);

    // adding the team
    teams.add(wRD);

    // red's players
    ArrayList<Player> pPlayersrd = new ArrayList<>();

    if(toPlay.allPlayers().size() == 4)
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    pPlayersrd.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // making player
    Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    pPlayersrd.add(toAdd2);

    // removing the player
    toPlay.allPlayers().remove(toAdd2);

    // what color the team is
    ColorOfTeam cotpRD = new ColorOfTeam(Color.magenta);

    // the team
    Team pRD = new Team(pPlayersrd, cotpRD);

    // adding the team
    teams.add(pRD);

    // red's players
    ArrayList<Player> graPlayersrd = new ArrayList<>();

    if(toPlay.allPlayers().size() == 2)
    // making player
    Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    graPlayersrd.add(toAdd);

    // removing the player
    toPlay.allPlayers().remove(toAdd);

    // making player
    Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

    // adding players
    graPlayersrd.add(toAdd2);

    // removing the player
    toPlay.allPlayers().remove(toAdd2);

    // what color the team is
    ColorOfTeam cotgraRD = new ColorOfTeam(Color.gray);

    // the team
    Team graRD = new Team(graPlayersrd, cotgraRD);

    // adding the team
    teams.add(graRD);

    System.out.println("The map is " + toPlay.getName() + '-' + toPlay.maxPlayerAm());
    int u = random.nextInt(teams.size()-1);
    youAreOn = teams.get(u);
    System.out.println("You are on team " + youAreOn.getName());
    for(int i=0; i<youAreOn.getPlayers().size(); i++)
    System.out.print("The players are " + youAreOn.getPlayers().get(i).getName());




    As you can see, this is very lengthy (I calculated that it takes up 438 lines of code), being lengthy because I wrote this before I got good at using for and while loops. My question is: can anyone find a way to shorten this? It got out of hand and is now hard to shorten for me. I've looked at it, and can't find a way to shorten it.

    The main reason I wanted to shorten it is so that it runs faster: I have a run() method that counts the ticks and frames of every second; the ticks and frames should be 60, because that's what I set my fps to, but they're always 0.







    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a lot of code (probably about 1/2 of all of my 891 lines) dedicated to just making players and teams.

      Here's the code that makes the players and teams:



      private void makeTeams() 
      toPlay = maps.get(random.nextInt(maps.size())); // I have a method that I shortened to make maps

      pName = toPlay.islands().get(you).getTeam().players.get(0).getName();

      // red's players
      ArrayList<Player> redPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 8) // making players for solo
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      redPlayers.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // what color the team is
      ColorOfTeam cotred = new ColorOfTeam(Color.red);

      // the team
      Team red = new Team(redPlayers, cotred);

      // adding the team
      teams.add(red);

      // blue's players
      ArrayList<Player> bluePlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 7) // making players
      // making player

      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
      // adding players

      bluePlayers.add(toAdd);
      // removing the player

      toPlay.allPlayers().remove(toAdd);
      // what color the team is

      ColorOfTeam cotblue = new ColorOfTeam(Color.blue);
      // the team

      Team blue = new Team(bluePlayers, cotblue);
      // adding the team

      teams.add(blue);

      // red's players
      ArrayList<Player> greenPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 6) // making players for solo
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      greenPlayers.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // what color the team is
      ColorOfTeam cotgreen = new ColorOfTeam(Color.green);

      // the team
      Team green = new Team(greenPlayers, cotgreen);

      // adding the team
      teams.add(green);

      // blue's players
      ArrayList<Player> yellPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 5) // making players
      // making player

      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
      // adding players

      yellPlayers.add(toAdd);
      // removing the player

      toPlay.allPlayers().remove(toAdd);
      // what color the team is

      ColorOfTeam cotyell = new ColorOfTeam(Color.yellow);
      // the team

      Team yell = new Team(yellPlayers, cotyell);
      // adding the team

      teams.add(yell);

      // aqua's players
      ArrayList<Player> aquaPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 4) // making players for solo
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      aquaPlayers.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // what color the team is
      ColorOfTeam cotaqua = new ColorOfTeam(Color.cyan);

      // the team
      Team aqua = new Team(aquaPlayers, cotaqua);

      // adding the team
      teams.add(aqua);

      // white's players
      ArrayList<Player> whitePlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 3) // making players
      // making player

      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
      // adding players

      whitePlayers.add(toAdd);
      // removing the player

      toPlay.allPlayers().remove(toAdd);
      // what color the team is

      ColorOfTeam cotwhite = new ColorOfTeam(Color.lightGray);
      // the team

      Team white = new Team(whitePlayers, cotwhite);
      // adding the team

      teams.add(white);

      // pink's players
      ArrayList<Player> pinkPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 2) // making players for solo
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      pinkPlayers.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // what color the team is
      ColorOfTeam cotpink = new ColorOfTeam(Color.magenta);

      // the team
      Team pink = new Team(pinkPlayers, cotpink);

      // adding the team
      teams.add(pink);

      // gray's players
      ArrayList<Player> grayPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 1) // making players
      // making player

      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
      // adding players

      grayPlayers.add(toAdd);
      // removing the player

      toPlay.allPlayers().remove(toAdd);
      // what color the team is

      ColorOfTeam cotgray = new ColorOfTeam(Color.gray);
      // the team

      Team gray = new Team(grayPlayers, cotgray);
      // adding the team

      teams.add(gray);

      // red's players
      ArrayList<Player> redPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 16)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      redPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      redPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotredRD = new ColorOfTeam(Color.red);

      // the team
      Team redRD = new Team(redPlayersrd, cotredRD);

      // adding the team
      teams.add(redRD);

      // red's players
      ArrayList<Player> bPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 14)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      bPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      bPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotbRD = new ColorOfTeam(Color.blue);

      // the team
      Team bRD = new Team(bPlayersrd, cotbRD);

      // adding the team
      teams.add(bRD);
      // red's players
      ArrayList<Player> gPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 12)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      gPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      gPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotgRD = new ColorOfTeam(Color.green);

      // the team
      Team gRD = new Team(gPlayersrd, cotgRD);

      // adding the team
      teams.add(gRD);

      // red's players
      ArrayList<Player> yPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 10)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      yPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      yPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotyRD = new ColorOfTeam(Color.yellow);

      // the team
      Team yRD = new Team(yPlayersrd, cotyRD);

      // adding the team
      teams.add(yRD);
      // red's players
      ArrayList<Player> aquPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 8)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      aquPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      redPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotaquRD = new ColorOfTeam(Color.cyan);

      // the team
      Team aquRD = new Team(aquPlayersrd, cotaquRD);

      // adding the team
      teams.add(aquRD);

      // red's players
      ArrayList<Player> wPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 6)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      wPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      wPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotwRD = new ColorOfTeam(Color.white);

      // the team
      Team wRD = new Team(wPlayersrd, cotwRD);

      // adding the team
      teams.add(wRD);

      // red's players
      ArrayList<Player> pPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 4)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      pPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      pPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotpRD = new ColorOfTeam(Color.magenta);

      // the team
      Team pRD = new Team(pPlayersrd, cotpRD);

      // adding the team
      teams.add(pRD);

      // red's players
      ArrayList<Player> graPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 2)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      graPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      graPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotgraRD = new ColorOfTeam(Color.gray);

      // the team
      Team graRD = new Team(graPlayersrd, cotgraRD);

      // adding the team
      teams.add(graRD);

      System.out.println("The map is " + toPlay.getName() + '-' + toPlay.maxPlayerAm());
      int u = random.nextInt(teams.size()-1);
      youAreOn = teams.get(u);
      System.out.println("You are on team " + youAreOn.getName());
      for(int i=0; i<youAreOn.getPlayers().size(); i++)
      System.out.print("The players are " + youAreOn.getPlayers().get(i).getName());




      As you can see, this is very lengthy (I calculated that it takes up 438 lines of code), being lengthy because I wrote this before I got good at using for and while loops. My question is: can anyone find a way to shorten this? It got out of hand and is now hard to shorten for me. I've looked at it, and can't find a way to shorten it.

      The main reason I wanted to shorten it is so that it runs faster: I have a run() method that counts the ticks and frames of every second; the ticks and frames should be 60, because that's what I set my fps to, but they're always 0.







      share|improve this question











      I have a lot of code (probably about 1/2 of all of my 891 lines) dedicated to just making players and teams.

      Here's the code that makes the players and teams:



      private void makeTeams() 
      toPlay = maps.get(random.nextInt(maps.size())); // I have a method that I shortened to make maps

      pName = toPlay.islands().get(you).getTeam().players.get(0).getName();

      // red's players
      ArrayList<Player> redPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 8) // making players for solo
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      redPlayers.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // what color the team is
      ColorOfTeam cotred = new ColorOfTeam(Color.red);

      // the team
      Team red = new Team(redPlayers, cotred);

      // adding the team
      teams.add(red);

      // blue's players
      ArrayList<Player> bluePlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 7) // making players
      // making player

      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
      // adding players

      bluePlayers.add(toAdd);
      // removing the player

      toPlay.allPlayers().remove(toAdd);
      // what color the team is

      ColorOfTeam cotblue = new ColorOfTeam(Color.blue);
      // the team

      Team blue = new Team(bluePlayers, cotblue);
      // adding the team

      teams.add(blue);

      // red's players
      ArrayList<Player> greenPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 6) // making players for solo
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      greenPlayers.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // what color the team is
      ColorOfTeam cotgreen = new ColorOfTeam(Color.green);

      // the team
      Team green = new Team(greenPlayers, cotgreen);

      // adding the team
      teams.add(green);

      // blue's players
      ArrayList<Player> yellPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 5) // making players
      // making player

      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
      // adding players

      yellPlayers.add(toAdd);
      // removing the player

      toPlay.allPlayers().remove(toAdd);
      // what color the team is

      ColorOfTeam cotyell = new ColorOfTeam(Color.yellow);
      // the team

      Team yell = new Team(yellPlayers, cotyell);
      // adding the team

      teams.add(yell);

      // aqua's players
      ArrayList<Player> aquaPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 4) // making players for solo
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      aquaPlayers.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // what color the team is
      ColorOfTeam cotaqua = new ColorOfTeam(Color.cyan);

      // the team
      Team aqua = new Team(aquaPlayers, cotaqua);

      // adding the team
      teams.add(aqua);

      // white's players
      ArrayList<Player> whitePlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 3) // making players
      // making player

      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
      // adding players

      whitePlayers.add(toAdd);
      // removing the player

      toPlay.allPlayers().remove(toAdd);
      // what color the team is

      ColorOfTeam cotwhite = new ColorOfTeam(Color.lightGray);
      // the team

      Team white = new Team(whitePlayers, cotwhite);
      // adding the team

      teams.add(white);

      // pink's players
      ArrayList<Player> pinkPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 2) // making players for solo
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      pinkPlayers.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // what color the team is
      ColorOfTeam cotpink = new ColorOfTeam(Color.magenta);

      // the team
      Team pink = new Team(pinkPlayers, cotpink);

      // adding the team
      teams.add(pink);

      // gray's players
      ArrayList<Player> grayPlayers = new ArrayList<>();

      if(toPlay.allPlayers().size() == 1) // making players
      // making player

      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
      // adding players

      grayPlayers.add(toAdd);
      // removing the player

      toPlay.allPlayers().remove(toAdd);
      // what color the team is

      ColorOfTeam cotgray = new ColorOfTeam(Color.gray);
      // the team

      Team gray = new Team(grayPlayers, cotgray);
      // adding the team

      teams.add(gray);

      // red's players
      ArrayList<Player> redPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 16)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      redPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      redPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotredRD = new ColorOfTeam(Color.red);

      // the team
      Team redRD = new Team(redPlayersrd, cotredRD);

      // adding the team
      teams.add(redRD);

      // red's players
      ArrayList<Player> bPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 14)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      bPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      bPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotbRD = new ColorOfTeam(Color.blue);

      // the team
      Team bRD = new Team(bPlayersrd, cotbRD);

      // adding the team
      teams.add(bRD);
      // red's players
      ArrayList<Player> gPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 12)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      gPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      gPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotgRD = new ColorOfTeam(Color.green);

      // the team
      Team gRD = new Team(gPlayersrd, cotgRD);

      // adding the team
      teams.add(gRD);

      // red's players
      ArrayList<Player> yPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 10)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      yPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      yPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotyRD = new ColorOfTeam(Color.yellow);

      // the team
      Team yRD = new Team(yPlayersrd, cotyRD);

      // adding the team
      teams.add(yRD);
      // red's players
      ArrayList<Player> aquPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 8)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      aquPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      redPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotaquRD = new ColorOfTeam(Color.cyan);

      // the team
      Team aquRD = new Team(aquPlayersrd, cotaquRD);

      // adding the team
      teams.add(aquRD);

      // red's players
      ArrayList<Player> wPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 6)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      wPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      wPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotwRD = new ColorOfTeam(Color.white);

      // the team
      Team wRD = new Team(wPlayersrd, cotwRD);

      // adding the team
      teams.add(wRD);

      // red's players
      ArrayList<Player> pPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 4)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      pPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      pPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotpRD = new ColorOfTeam(Color.magenta);

      // the team
      Team pRD = new Team(pPlayersrd, cotpRD);

      // adding the team
      teams.add(pRD);

      // red's players
      ArrayList<Player> graPlayersrd = new ArrayList<>();

      if(toPlay.allPlayers().size() == 2)
      // making player
      Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      graPlayersrd.add(toAdd);

      // removing the player
      toPlay.allPlayers().remove(toAdd);

      // making player
      Player toAdd2 = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));

      // adding players
      graPlayersrd.add(toAdd2);

      // removing the player
      toPlay.allPlayers().remove(toAdd2);

      // what color the team is
      ColorOfTeam cotgraRD = new ColorOfTeam(Color.gray);

      // the team
      Team graRD = new Team(graPlayersrd, cotgraRD);

      // adding the team
      teams.add(graRD);

      System.out.println("The map is " + toPlay.getName() + '-' + toPlay.maxPlayerAm());
      int u = random.nextInt(teams.size()-1);
      youAreOn = teams.get(u);
      System.out.println("You are on team " + youAreOn.getName());
      for(int i=0; i<youAreOn.getPlayers().size(); i++)
      System.out.print("The players are " + youAreOn.getPlayers().get(i).getName());




      As you can see, this is very lengthy (I calculated that it takes up 438 lines of code), being lengthy because I wrote this before I got good at using for and while loops. My question is: can anyone find a way to shorten this? It got out of hand and is now hard to shorten for me. I've looked at it, and can't find a way to shorten it.

      The main reason I wanted to shorten it is so that it runs faster: I have a run() method that counts the ticks and frames of every second; the ticks and frames should be 60, because that's what I set my fps to, but they're always 0.









      share|improve this question










      share|improve this question




      share|improve this question









      asked Apr 27 at 11:44









      TheJavaNub

      356




      356




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          So you make a weird jump:



          if(toPlay.allPlayers().size() == 1) // making players
          ...
          toPlay.allPlayers().remove(toAdd);
          // what color the team is
          ...
          if(toPlay.allPlayers().size() == 16) {


          I'm working under the assumption toPlay.allPlayers().size() is 8 or 16 and you meant to do an if..else. This is also not knowing exactly what your other code is. I'd create an ArrayList of all the different players arrays. Then use a while loop to iterate while toPlay.allPlayers() has a player. You use a lot of repeat code that could be used once. I make a generic ColorOfTeam cot that based on which player is being sorted currently gets a corresponding color.



          private void makeTeams() 
          toPlay = maps.get(random.nextInt(maps.size())); // I have a method that I shortened to make maps

          pName = toPlay.islands().get(you).getTeam().players.get(0).getName();

          // player lists
          ArrayList<ArrayList<Player>> players = new ArrayList<>();
          ArrayList<Player> redPlayers = new ArrayList<>();
          ArrayList<Player> bluePlayers = new ArrayList<>();
          ArrayList<Player> greenPlayers = new ArrayList<>();
          ArrayList<Player> yellPlayers = new ArrayList<>();
          ArrayList<Player> aquaPlayers = new ArrayList<>();
          ArrayList<Player> whitePlayers = new ArrayList<>();
          ArrayList<Player> pinkPlayers = new ArrayList<>();
          ArrayList<Player> grayPlayers = new ArrayList<>();
          players.addAll(Arrays.asList(redPlayers,bluePlayers,greenPlayers,yellPlayers,aquaPlayers,whitePlayers,pinkPlayers,grayPlayers));

          int numberOfPlayers=toPlay.allPlayers().size();
          while(toPlay.allPlayers().size()>0)
          Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
          // adding players
          players.get(numberOfPlayers-toPlay.allPlayers().size()).add(toAdd);
          // what color the team is
          ColorOfTeam cot;
          //this is under the assumption number of players is 8 or 16, otherwise I'd switch to a if...else chain
          //probably would then use %8==0 else %8==1, etc
          switch(numberOfPlayers-toPlay.allPlayers().size())
          case 8:
          case 0:
          cot=new ColorOfTeam(Color.red);
          break;
          case 9:
          case 1:
          cot=new ColorOfTeam(Color.blue);
          break;
          case 10:
          case 2:
          cot=new ColorOfTeam(Color.green);
          break;
          case 11:
          case 3:
          cot=new ColorOfTeam(Color.yellow);
          break;
          case 12:
          case 4:
          cot=new ColorOfTeam(Color.cyan);
          break;
          case 13:
          case 5:
          cot=new ColorOfTeam(Color.lightGray);
          break;
          case 14:
          case 6:
          cot=new ColorOfTeam(Color.magenta);
          break;
          case 15:
          case 7:
          cot=new ColorOfTeam(Color.gray);
          break;

          // the team
          Team t = new Team(players.get(numberOfPlayers-toPlay.allPlayers().size()), cot);
          // adding the team
          teams.add(t);
          // removing the player
          toPlay.allPlayers().remove(toAdd);


          System.out.println("The map is " + toPlay.getName() + '-' + toPlay.maxPlayerAm());
          int u = random.nextInt(teams.size()-1);
          youAreOn = teams.get(u);
          System.out.println("You are on team " + youAreOn.getName());
          for(int i=0; i<youAreOn.getPlayers().size(); i++)
          System.out.print("The players are " + youAreOn.getPlayers().get(i).getName());







          share|improve this answer





















          • Just one error that I fixed: the while-loop needs to have && numberOfPlayers-toPlay.allPlayers.size()<8. If it doesn't, there's an error on players.get(numberOfPlayers-toPlay.allPlayers.size()).add(toAdd);
            – TheJavaNub
            May 5 at 12:26


















          up vote
          1
          down vote













          Well... now that you've learned how to use loops, why don't you just throw it all away and try to write it from scratch.



          Often it's easier to rewrite the entire thing instead of trying to improve the existing code.



          Don't be afraid to delete the code. You've learned a lot by writing it for the first time, it will not go to waste - you'll be smarter now, and it'll be much easier to write it the second time. You can back up the original code, so you can always safely return to it when your rewrite fails for some reason. There's nothing to loose.






          share|improve this answer

















          • 1




            this might be better as a comment
            – depperm
            Apr 27 at 15:39










          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f193073%2fmakes-a-bunch-of-players-and-adds-them-to-teams%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          So you make a weird jump:



          if(toPlay.allPlayers().size() == 1) // making players
          ...
          toPlay.allPlayers().remove(toAdd);
          // what color the team is
          ...
          if(toPlay.allPlayers().size() == 16) {


          I'm working under the assumption toPlay.allPlayers().size() is 8 or 16 and you meant to do an if..else. This is also not knowing exactly what your other code is. I'd create an ArrayList of all the different players arrays. Then use a while loop to iterate while toPlay.allPlayers() has a player. You use a lot of repeat code that could be used once. I make a generic ColorOfTeam cot that based on which player is being sorted currently gets a corresponding color.



          private void makeTeams() 
          toPlay = maps.get(random.nextInt(maps.size())); // I have a method that I shortened to make maps

          pName = toPlay.islands().get(you).getTeam().players.get(0).getName();

          // player lists
          ArrayList<ArrayList<Player>> players = new ArrayList<>();
          ArrayList<Player> redPlayers = new ArrayList<>();
          ArrayList<Player> bluePlayers = new ArrayList<>();
          ArrayList<Player> greenPlayers = new ArrayList<>();
          ArrayList<Player> yellPlayers = new ArrayList<>();
          ArrayList<Player> aquaPlayers = new ArrayList<>();
          ArrayList<Player> whitePlayers = new ArrayList<>();
          ArrayList<Player> pinkPlayers = new ArrayList<>();
          ArrayList<Player> grayPlayers = new ArrayList<>();
          players.addAll(Arrays.asList(redPlayers,bluePlayers,greenPlayers,yellPlayers,aquaPlayers,whitePlayers,pinkPlayers,grayPlayers));

          int numberOfPlayers=toPlay.allPlayers().size();
          while(toPlay.allPlayers().size()>0)
          Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
          // adding players
          players.get(numberOfPlayers-toPlay.allPlayers().size()).add(toAdd);
          // what color the team is
          ColorOfTeam cot;
          //this is under the assumption number of players is 8 or 16, otherwise I'd switch to a if...else chain
          //probably would then use %8==0 else %8==1, etc
          switch(numberOfPlayers-toPlay.allPlayers().size())
          case 8:
          case 0:
          cot=new ColorOfTeam(Color.red);
          break;
          case 9:
          case 1:
          cot=new ColorOfTeam(Color.blue);
          break;
          case 10:
          case 2:
          cot=new ColorOfTeam(Color.green);
          break;
          case 11:
          case 3:
          cot=new ColorOfTeam(Color.yellow);
          break;
          case 12:
          case 4:
          cot=new ColorOfTeam(Color.cyan);
          break;
          case 13:
          case 5:
          cot=new ColorOfTeam(Color.lightGray);
          break;
          case 14:
          case 6:
          cot=new ColorOfTeam(Color.magenta);
          break;
          case 15:
          case 7:
          cot=new ColorOfTeam(Color.gray);
          break;

          // the team
          Team t = new Team(players.get(numberOfPlayers-toPlay.allPlayers().size()), cot);
          // adding the team
          teams.add(t);
          // removing the player
          toPlay.allPlayers().remove(toAdd);


          System.out.println("The map is " + toPlay.getName() + '-' + toPlay.maxPlayerAm());
          int u = random.nextInt(teams.size()-1);
          youAreOn = teams.get(u);
          System.out.println("You are on team " + youAreOn.getName());
          for(int i=0; i<youAreOn.getPlayers().size(); i++)
          System.out.print("The players are " + youAreOn.getPlayers().get(i).getName());







          share|improve this answer





















          • Just one error that I fixed: the while-loop needs to have && numberOfPlayers-toPlay.allPlayers.size()<8. If it doesn't, there's an error on players.get(numberOfPlayers-toPlay.allPlayers.size()).add(toAdd);
            – TheJavaNub
            May 5 at 12:26















          up vote
          2
          down vote



          accepted










          So you make a weird jump:



          if(toPlay.allPlayers().size() == 1) // making players
          ...
          toPlay.allPlayers().remove(toAdd);
          // what color the team is
          ...
          if(toPlay.allPlayers().size() == 16) {


          I'm working under the assumption toPlay.allPlayers().size() is 8 or 16 and you meant to do an if..else. This is also not knowing exactly what your other code is. I'd create an ArrayList of all the different players arrays. Then use a while loop to iterate while toPlay.allPlayers() has a player. You use a lot of repeat code that could be used once. I make a generic ColorOfTeam cot that based on which player is being sorted currently gets a corresponding color.



          private void makeTeams() 
          toPlay = maps.get(random.nextInt(maps.size())); // I have a method that I shortened to make maps

          pName = toPlay.islands().get(you).getTeam().players.get(0).getName();

          // player lists
          ArrayList<ArrayList<Player>> players = new ArrayList<>();
          ArrayList<Player> redPlayers = new ArrayList<>();
          ArrayList<Player> bluePlayers = new ArrayList<>();
          ArrayList<Player> greenPlayers = new ArrayList<>();
          ArrayList<Player> yellPlayers = new ArrayList<>();
          ArrayList<Player> aquaPlayers = new ArrayList<>();
          ArrayList<Player> whitePlayers = new ArrayList<>();
          ArrayList<Player> pinkPlayers = new ArrayList<>();
          ArrayList<Player> grayPlayers = new ArrayList<>();
          players.addAll(Arrays.asList(redPlayers,bluePlayers,greenPlayers,yellPlayers,aquaPlayers,whitePlayers,pinkPlayers,grayPlayers));

          int numberOfPlayers=toPlay.allPlayers().size();
          while(toPlay.allPlayers().size()>0)
          Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
          // adding players
          players.get(numberOfPlayers-toPlay.allPlayers().size()).add(toAdd);
          // what color the team is
          ColorOfTeam cot;
          //this is under the assumption number of players is 8 or 16, otherwise I'd switch to a if...else chain
          //probably would then use %8==0 else %8==1, etc
          switch(numberOfPlayers-toPlay.allPlayers().size())
          case 8:
          case 0:
          cot=new ColorOfTeam(Color.red);
          break;
          case 9:
          case 1:
          cot=new ColorOfTeam(Color.blue);
          break;
          case 10:
          case 2:
          cot=new ColorOfTeam(Color.green);
          break;
          case 11:
          case 3:
          cot=new ColorOfTeam(Color.yellow);
          break;
          case 12:
          case 4:
          cot=new ColorOfTeam(Color.cyan);
          break;
          case 13:
          case 5:
          cot=new ColorOfTeam(Color.lightGray);
          break;
          case 14:
          case 6:
          cot=new ColorOfTeam(Color.magenta);
          break;
          case 15:
          case 7:
          cot=new ColorOfTeam(Color.gray);
          break;

          // the team
          Team t = new Team(players.get(numberOfPlayers-toPlay.allPlayers().size()), cot);
          // adding the team
          teams.add(t);
          // removing the player
          toPlay.allPlayers().remove(toAdd);


          System.out.println("The map is " + toPlay.getName() + '-' + toPlay.maxPlayerAm());
          int u = random.nextInt(teams.size()-1);
          youAreOn = teams.get(u);
          System.out.println("You are on team " + youAreOn.getName());
          for(int i=0; i<youAreOn.getPlayers().size(); i++)
          System.out.print("The players are " + youAreOn.getPlayers().get(i).getName());







          share|improve this answer





















          • Just one error that I fixed: the while-loop needs to have && numberOfPlayers-toPlay.allPlayers.size()<8. If it doesn't, there's an error on players.get(numberOfPlayers-toPlay.allPlayers.size()).add(toAdd);
            – TheJavaNub
            May 5 at 12:26













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          So you make a weird jump:



          if(toPlay.allPlayers().size() == 1) // making players
          ...
          toPlay.allPlayers().remove(toAdd);
          // what color the team is
          ...
          if(toPlay.allPlayers().size() == 16) {


          I'm working under the assumption toPlay.allPlayers().size() is 8 or 16 and you meant to do an if..else. This is also not knowing exactly what your other code is. I'd create an ArrayList of all the different players arrays. Then use a while loop to iterate while toPlay.allPlayers() has a player. You use a lot of repeat code that could be used once. I make a generic ColorOfTeam cot that based on which player is being sorted currently gets a corresponding color.



          private void makeTeams() 
          toPlay = maps.get(random.nextInt(maps.size())); // I have a method that I shortened to make maps

          pName = toPlay.islands().get(you).getTeam().players.get(0).getName();

          // player lists
          ArrayList<ArrayList<Player>> players = new ArrayList<>();
          ArrayList<Player> redPlayers = new ArrayList<>();
          ArrayList<Player> bluePlayers = new ArrayList<>();
          ArrayList<Player> greenPlayers = new ArrayList<>();
          ArrayList<Player> yellPlayers = new ArrayList<>();
          ArrayList<Player> aquaPlayers = new ArrayList<>();
          ArrayList<Player> whitePlayers = new ArrayList<>();
          ArrayList<Player> pinkPlayers = new ArrayList<>();
          ArrayList<Player> grayPlayers = new ArrayList<>();
          players.addAll(Arrays.asList(redPlayers,bluePlayers,greenPlayers,yellPlayers,aquaPlayers,whitePlayers,pinkPlayers,grayPlayers));

          int numberOfPlayers=toPlay.allPlayers().size();
          while(toPlay.allPlayers().size()>0)
          Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
          // adding players
          players.get(numberOfPlayers-toPlay.allPlayers().size()).add(toAdd);
          // what color the team is
          ColorOfTeam cot;
          //this is under the assumption number of players is 8 or 16, otherwise I'd switch to a if...else chain
          //probably would then use %8==0 else %8==1, etc
          switch(numberOfPlayers-toPlay.allPlayers().size())
          case 8:
          case 0:
          cot=new ColorOfTeam(Color.red);
          break;
          case 9:
          case 1:
          cot=new ColorOfTeam(Color.blue);
          break;
          case 10:
          case 2:
          cot=new ColorOfTeam(Color.green);
          break;
          case 11:
          case 3:
          cot=new ColorOfTeam(Color.yellow);
          break;
          case 12:
          case 4:
          cot=new ColorOfTeam(Color.cyan);
          break;
          case 13:
          case 5:
          cot=new ColorOfTeam(Color.lightGray);
          break;
          case 14:
          case 6:
          cot=new ColorOfTeam(Color.magenta);
          break;
          case 15:
          case 7:
          cot=new ColorOfTeam(Color.gray);
          break;

          // the team
          Team t = new Team(players.get(numberOfPlayers-toPlay.allPlayers().size()), cot);
          // adding the team
          teams.add(t);
          // removing the player
          toPlay.allPlayers().remove(toAdd);


          System.out.println("The map is " + toPlay.getName() + '-' + toPlay.maxPlayerAm());
          int u = random.nextInt(teams.size()-1);
          youAreOn = teams.get(u);
          System.out.println("You are on team " + youAreOn.getName());
          for(int i=0; i<youAreOn.getPlayers().size(); i++)
          System.out.print("The players are " + youAreOn.getPlayers().get(i).getName());







          share|improve this answer













          So you make a weird jump:



          if(toPlay.allPlayers().size() == 1) // making players
          ...
          toPlay.allPlayers().remove(toAdd);
          // what color the team is
          ...
          if(toPlay.allPlayers().size() == 16) {


          I'm working under the assumption toPlay.allPlayers().size() is 8 or 16 and you meant to do an if..else. This is also not knowing exactly what your other code is. I'd create an ArrayList of all the different players arrays. Then use a while loop to iterate while toPlay.allPlayers() has a player. You use a lot of repeat code that could be used once. I make a generic ColorOfTeam cot that based on which player is being sorted currently gets a corresponding color.



          private void makeTeams() 
          toPlay = maps.get(random.nextInt(maps.size())); // I have a method that I shortened to make maps

          pName = toPlay.islands().get(you).getTeam().players.get(0).getName();

          // player lists
          ArrayList<ArrayList<Player>> players = new ArrayList<>();
          ArrayList<Player> redPlayers = new ArrayList<>();
          ArrayList<Player> bluePlayers = new ArrayList<>();
          ArrayList<Player> greenPlayers = new ArrayList<>();
          ArrayList<Player> yellPlayers = new ArrayList<>();
          ArrayList<Player> aquaPlayers = new ArrayList<>();
          ArrayList<Player> whitePlayers = new ArrayList<>();
          ArrayList<Player> pinkPlayers = new ArrayList<>();
          ArrayList<Player> grayPlayers = new ArrayList<>();
          players.addAll(Arrays.asList(redPlayers,bluePlayers,greenPlayers,yellPlayers,aquaPlayers,whitePlayers,pinkPlayers,grayPlayers));

          int numberOfPlayers=toPlay.allPlayers().size();
          while(toPlay.allPlayers().size()>0)
          Player toAdd = toPlay.allPlayers().get(random.nextInt(toPlay.allPlayers().size()));
          // adding players
          players.get(numberOfPlayers-toPlay.allPlayers().size()).add(toAdd);
          // what color the team is
          ColorOfTeam cot;
          //this is under the assumption number of players is 8 or 16, otherwise I'd switch to a if...else chain
          //probably would then use %8==0 else %8==1, etc
          switch(numberOfPlayers-toPlay.allPlayers().size())
          case 8:
          case 0:
          cot=new ColorOfTeam(Color.red);
          break;
          case 9:
          case 1:
          cot=new ColorOfTeam(Color.blue);
          break;
          case 10:
          case 2:
          cot=new ColorOfTeam(Color.green);
          break;
          case 11:
          case 3:
          cot=new ColorOfTeam(Color.yellow);
          break;
          case 12:
          case 4:
          cot=new ColorOfTeam(Color.cyan);
          break;
          case 13:
          case 5:
          cot=new ColorOfTeam(Color.lightGray);
          break;
          case 14:
          case 6:
          cot=new ColorOfTeam(Color.magenta);
          break;
          case 15:
          case 7:
          cot=new ColorOfTeam(Color.gray);
          break;

          // the team
          Team t = new Team(players.get(numberOfPlayers-toPlay.allPlayers().size()), cot);
          // adding the team
          teams.add(t);
          // removing the player
          toPlay.allPlayers().remove(toAdd);


          System.out.println("The map is " + toPlay.getName() + '-' + toPlay.maxPlayerAm());
          int u = random.nextInt(teams.size()-1);
          youAreOn = teams.get(u);
          System.out.println("You are on team " + youAreOn.getName());
          for(int i=0; i<youAreOn.getPlayers().size(); i++)
          System.out.print("The players are " + youAreOn.getPlayers().get(i).getName());








          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Apr 27 at 16:09









          depperm

          30319




          30319











          • Just one error that I fixed: the while-loop needs to have && numberOfPlayers-toPlay.allPlayers.size()<8. If it doesn't, there's an error on players.get(numberOfPlayers-toPlay.allPlayers.size()).add(toAdd);
            – TheJavaNub
            May 5 at 12:26

















          • Just one error that I fixed: the while-loop needs to have && numberOfPlayers-toPlay.allPlayers.size()<8. If it doesn't, there's an error on players.get(numberOfPlayers-toPlay.allPlayers.size()).add(toAdd);
            – TheJavaNub
            May 5 at 12:26
















          Just one error that I fixed: the while-loop needs to have && numberOfPlayers-toPlay.allPlayers.size()<8. If it doesn't, there's an error on players.get(numberOfPlayers-toPlay.allPlayers.size()).add(toAdd);
          – TheJavaNub
          May 5 at 12:26





          Just one error that I fixed: the while-loop needs to have && numberOfPlayers-toPlay.allPlayers.size()<8. If it doesn't, there's an error on players.get(numberOfPlayers-toPlay.allPlayers.size()).add(toAdd);
          – TheJavaNub
          May 5 at 12:26













          up vote
          1
          down vote













          Well... now that you've learned how to use loops, why don't you just throw it all away and try to write it from scratch.



          Often it's easier to rewrite the entire thing instead of trying to improve the existing code.



          Don't be afraid to delete the code. You've learned a lot by writing it for the first time, it will not go to waste - you'll be smarter now, and it'll be much easier to write it the second time. You can back up the original code, so you can always safely return to it when your rewrite fails for some reason. There's nothing to loose.






          share|improve this answer

















          • 1




            this might be better as a comment
            – depperm
            Apr 27 at 15:39














          up vote
          1
          down vote













          Well... now that you've learned how to use loops, why don't you just throw it all away and try to write it from scratch.



          Often it's easier to rewrite the entire thing instead of trying to improve the existing code.



          Don't be afraid to delete the code. You've learned a lot by writing it for the first time, it will not go to waste - you'll be smarter now, and it'll be much easier to write it the second time. You can back up the original code, so you can always safely return to it when your rewrite fails for some reason. There's nothing to loose.






          share|improve this answer

















          • 1




            this might be better as a comment
            – depperm
            Apr 27 at 15:39












          up vote
          1
          down vote










          up vote
          1
          down vote









          Well... now that you've learned how to use loops, why don't you just throw it all away and try to write it from scratch.



          Often it's easier to rewrite the entire thing instead of trying to improve the existing code.



          Don't be afraid to delete the code. You've learned a lot by writing it for the first time, it will not go to waste - you'll be smarter now, and it'll be much easier to write it the second time. You can back up the original code, so you can always safely return to it when your rewrite fails for some reason. There's nothing to loose.






          share|improve this answer













          Well... now that you've learned how to use loops, why don't you just throw it all away and try to write it from scratch.



          Often it's easier to rewrite the entire thing instead of trying to improve the existing code.



          Don't be afraid to delete the code. You've learned a lot by writing it for the first time, it will not go to waste - you'll be smarter now, and it'll be much easier to write it the second time. You can back up the original code, so you can always safely return to it when your rewrite fails for some reason. There's nothing to loose.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Apr 27 at 11:59









          Rene Saarsoo

          2,026714




          2,026714







          • 1




            this might be better as a comment
            – depperm
            Apr 27 at 15:39












          • 1




            this might be better as a comment
            – depperm
            Apr 27 at 15:39







          1




          1




          this might be better as a comment
          – depperm
          Apr 27 at 15:39




          this might be better as a comment
          – depperm
          Apr 27 at 15:39












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f193073%2fmakes-a-bunch-of-players-and-adds-them-to-teams%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Chat program with C++ and SFML

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          Will my employers contract hold up in court?