Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

This is the updated code using all suggestions from the previous question that I made here here.

I have revised the naming of the variables, and i have included the classes that this part of code is using, in order to have a better understanding.

I'm making a game battle system, where there are 2 players.

It is like a round based game.

  • Every player can have multiple units to control, but can only use one of them each round..
  • Every unit has an int CurrentSpeed variable;

I need to have in 2 variables who attacks first (Player firstPlayer) and who attacks second (Player secondPlayer), based on the speed of the active Unit.

At the moment I have this code:

public class Player {
 public int Id { get; set; }
 public string Name { get; set; }
 public List<Unit> Party { get; set; }
 public Unit Active { get; set; }
}
public class Unit {
 public string Name;
 public int InitialSpeed { get; set; }
 public int CurrentSpeed { get; set; }
}
public class BattleSystem {
 private void BattleTurn(){
 Player firstPlayer = null; //Player attacking first
 Player secondPlayer = null; //Player attacking second
 //Check the speed of the units, and determine who attack first
 firstPlayer = player_1.Active.CurrentSpeed > player_2.Active.CurrentSpeed ? player_1 : player_1.Active.CurrentSpeed < player_2.Active.CurrentSpeed ? player_2 : null;
 //if firstPlayer is null (active units have the same CurrentSpeed)
 if(firstPlayer == null){
 //Randomize who goes first
 System.Random rnd = new System.Random();
 int rng = rnd.Next(2);
 firstPlayer = rng == 0 ? player_1 : player_2;
 secondPlayer = rng == 0 ? player_2 : player_1;
 }else{
 secondPlayer = firstPlayer.Id == player_1.Id ? player_2 : player_1;
 }
 }
}

The part of determine the firstPlayer is ok, but I don't like the checks and assignments of the secondPlayer, like checking the ids.

I need tips on how I can code this in a better way.

This is the updated code using all suggestions from the previous question that I made here.

I have revised the naming of the variables, and i have included the classes that this part of code is using, in order to have a better understanding.

I'm making a game battle system, where there are 2 players.

It is like a round based game.

  • Every player can have multiple units to control, but can only use one of them each round..
  • Every unit has an int CurrentSpeed variable;

I need to have in 2 variables who attacks first (Player firstPlayer) and who attacks second (Player secondPlayer), based on the speed of the active Unit.

At the moment I have this code:

public class Player {
 public int Id { get; set; }
 public string Name { get; set; }
 public List<Unit> Party { get; set; }
 public Unit Active { get; set; }
}
public class Unit {
 public string Name;
 public int InitialSpeed { get; set; }
 public int CurrentSpeed { get; set; }
}
public class BattleSystem {
 private void BattleTurn(){
 Player firstPlayer = null; //Player attacking first
 Player secondPlayer = null; //Player attacking second
 //Check the speed of the units, and determine who attack first
 firstPlayer = player_1.Active.CurrentSpeed > player_2.Active.CurrentSpeed ? player_1 : player_1.Active.CurrentSpeed < player_2.Active.CurrentSpeed ? player_2 : null;
 //if firstPlayer is null (active units have the same CurrentSpeed)
 if(firstPlayer == null){
 //Randomize who goes first
 System.Random rnd = new System.Random();
 int rng = rnd.Next(2);
 firstPlayer = rng == 0 ? player_1 : player_2;
 secondPlayer = rng == 0 ? player_2 : player_1;
 }else{
 secondPlayer = firstPlayer.Id == player_1.Id ? player_2 : player_1;
 }
 }
}

The part of determine the firstPlayer is ok, but I don't like the checks and assignments of the secondPlayer, like checking the ids.

I need tips on how I can code this in a better way.

This is the updated code using all suggestions from the previous question that I made here.

I have revised the naming of the variables, and i have included the classes that this part of code is using, in order to have a better understanding.

I'm making a game battle system, where there are 2 players.

It is like a round based game.

  • Every player can have multiple units to control, but can only use one of them each round..
  • Every unit has an int CurrentSpeed variable;

I need to have in 2 variables who attacks first (Player firstPlayer) and who attacks second (Player secondPlayer), based on the speed of the active Unit.

At the moment I have this code:

public class Player {
 public int Id { get; set; }
 public string Name { get; set; }
 public List<Unit> Party { get; set; }
 public Unit Active { get; set; }
}
public class Unit {
 public string Name;
 public int InitialSpeed { get; set; }
 public int CurrentSpeed { get; set; }
}
public class BattleSystem {
 private void BattleTurn(){
 Player firstPlayer = null; //Player attacking first
 Player secondPlayer = null; //Player attacking second
 //Check the speed of the units, and determine who attack first
 firstPlayer = player_1.Active.CurrentSpeed > player_2.Active.CurrentSpeed ? player_1 : player_1.Active.CurrentSpeed < player_2.Active.CurrentSpeed ? player_2 : null;
 //if firstPlayer is null (active units have the same CurrentSpeed)
 if(firstPlayer == null){
 //Randomize who goes first
 System.Random rnd = new System.Random();
 int rng = rnd.Next(2);
 firstPlayer = rng == 0 ? player_1 : player_2;
 secondPlayer = rng == 0 ? player_2 : player_1;
 }else{
 secondPlayer = firstPlayer.Id == player_1.Id ? player_2 : player_1;
 }
 }
}

The part of determine the firstPlayer is ok, but I don't like the checks and assignments of the secondPlayer, like checking the ids.

I need tips on how I can code this in a better way.

Tweeted twitter.com/#!/StackCodeReview/status/458025206423240704
added 24 characters in body
Source Link
Fr0z3n
  • 225
  • 1
  • 4

This is the updated code using all suggestions from the previous question that I made here.

I have revised the naming of the variables, and i have included the classes that this part of code is using, in order to have a better understanding.

I'm making a game battle system, where there are 2 players.

It is like a round based game.

  • Every player can have multiple units to control, but can only use one of them each round..
  • Every unit has an int CurrentSpeed variable;

I need to have in 2 variables who attacks first (Player firstPlayer) and who attacks second (Player secondPlayer), based on the speed of the active Unit.

At the moment I have this code:

public class Player {
 public int Id { get; set; }
 public string Name { get; set; }
 public List<Unit> Party { get; set; }
 public Unit Active { get; set; }
}
public class Unit {
 public string Name;
 public int InitialSpeed { get; set; }
 public int CurrentSpeed { get; set; }
}
public class BattleSystem {
 private void BattleTurn(){
 Player firstPlayer = null; //Player attacking first
 Player secondPlayer = null; //Player attacking second
 //Check the speed of the units, and determine who attack first
 firstPlayer = player_1.Active.CurrentSpeed > player_2.Active.CurrentSpeed ? player_1 : player_1.Active.CurrentSpeed < player_2.Active.CurrentSpeed ? player_2 : null;
 //if ffirstPlayer is null (active units have the same speedCurrentSpeed)
 if(firstPlayer == null){
 //Randomize who goes first
 System.Random rnd = new System.Random();
 int rng = rnd.Next(2);
 firstPlayer = rng == 0 ? player_1 : player_2;
 secondPlayer = rng == 0 ? player_2 : player_1;
 }else{
 secondPlayer = firstPlayer.Id == player_1.Id ? player_2 : player_1;
 }
 }
}

The part of determine the firstPlayer is ok, but I don't like the checks and assignments of the secondPlayer, like checking the ids.

I need tips on how I can code this in a better way.

This is the updated code using all suggestions from the previous question that I made here.

I have revised the naming of the variables, and i have included the classes that this part of code is using, in order to have a better understanding.

I'm making a game battle system, where there are 2 players.

It is like a round based game.

  • Every player can have multiple units to control, but can only use one of them each round..
  • Every unit has an int CurrentSpeed variable;

I need to have in 2 variables who attacks first (Player firstPlayer) and who attacks second (Player secondPlayer), based on the speed of the active Unit.

At the moment I have this code:

public class Player {
 public int Id { get; set; }
 public string Name { get; set; }
 public List<Unit> Party { get; set; }
 public Unit Active { get; set; }
}
public class Unit {
 public string Name;
 public int InitialSpeed { get; set; }
 public int CurrentSpeed { get; set; }
}
public class BattleSystem {
 private void BattleTurn(){
 Player firstPlayer = null; //Player attacking first
 Player secondPlayer = null; //Player attacking second
 //Check the speed of the units, and determine who attack first
 firstPlayer = player_1.Active.CurrentSpeed > player_2.Active.CurrentSpeed ? player_1 : player_1.Active.CurrentSpeed < player_2.Active.CurrentSpeed ? player_2 : null;
 //if f is null (units have the same speed)
 if(firstPlayer == null){
 //Randomize who goes first
 System.Random rnd = new System.Random();
 int rng = rnd.Next(2);
 firstPlayer = rng == 0 ? player_1 : player_2;
 secondPlayer = rng == 0 ? player_2 : player_1;
 }else{
 secondPlayer = firstPlayer.Id == player_1.Id ? player_2 : player_1;
 }
 }
}

The part of determine the firstPlayer is ok, but I don't like the checks and assignments of the secondPlayer, like checking the ids.

I need tips on how I can code this in a better way.

This is the updated code using all suggestions from the previous question that I made here.

I have revised the naming of the variables, and i have included the classes that this part of code is using, in order to have a better understanding.

I'm making a game battle system, where there are 2 players.

It is like a round based game.

  • Every player can have multiple units to control, but can only use one of them each round..
  • Every unit has an int CurrentSpeed variable;

I need to have in 2 variables who attacks first (Player firstPlayer) and who attacks second (Player secondPlayer), based on the speed of the active Unit.

At the moment I have this code:

public class Player {
 public int Id { get; set; }
 public string Name { get; set; }
 public List<Unit> Party { get; set; }
 public Unit Active { get; set; }
}
public class Unit {
 public string Name;
 public int InitialSpeed { get; set; }
 public int CurrentSpeed { get; set; }
}
public class BattleSystem {
 private void BattleTurn(){
 Player firstPlayer = null; //Player attacking first
 Player secondPlayer = null; //Player attacking second
 //Check the speed of the units, and determine who attack first
 firstPlayer = player_1.Active.CurrentSpeed > player_2.Active.CurrentSpeed ? player_1 : player_1.Active.CurrentSpeed < player_2.Active.CurrentSpeed ? player_2 : null;
 //if firstPlayer is null (active units have the same CurrentSpeed)
 if(firstPlayer == null){
 //Randomize who goes first
 System.Random rnd = new System.Random();
 int rng = rnd.Next(2);
 firstPlayer = rng == 0 ? player_1 : player_2;
 secondPlayer = rng == 0 ? player_2 : player_1;
 }else{
 secondPlayer = firstPlayer.Id == player_1.Id ? player_2 : player_1;
 }
 }
}

The part of determine the firstPlayer is ok, but I don't like the checks and assignments of the secondPlayer, like checking the ids.

I need tips on how I can code this in a better way.

added 8 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

This is the Updatedupdated code using all suggestions from the previous question that iI madehere.

Link: Initial starting player

I have revised the naming of the variables, and i have included the Classesclasses that this part of code is using, in order to have a better understanding.

The part of determine the firstPlayerfirstPlayer is ok, but iI don't like the checks and assignementsassignments of the secondPlayersecondPlayer, like checking the ids.

I need tips on how iI can code this in a better way.

This is the Updated code using all suggestions from the previous question that i made.

Link: Initial starting player

I have revised the naming of the variables, and i have included the Classes that this part of code is using, in order to have a better understanding.

The part of determine the firstPlayer is ok, but i don't like the checks and assignements of the secondPlayer, like checking the ids.

I need tips on how i can code this in a better way.

This is the updated code using all suggestions from the previous question that I madehere.

I have revised the naming of the variables, and i have included the classes that this part of code is using, in order to have a better understanding.

The part of determine the firstPlayer is ok, but I don't like the checks and assignments of the secondPlayer, like checking the ids.

I need tips on how I can code this in a better way.

Source Link
Fr0z3n
  • 225
  • 1
  • 4
Loading
lang-cs

AltStyle によって変換されたページ (->オリジナル) /