mrlowbot
Member
- Joined
- Apr 30, 2021
- Messages
- 11
- Programming Experience
- Beginner
Hey.
I need some help when it comes to my code, its not meant to have a "main" method.
It is basically a chess program that takes values and compares them, checks players and how much they score.
This is what i need to do :
We organize a chess tournament in the local club. The members are divided into
"regular" players and grandmasters.
Write a class ChessTournament (line 33) that has:
Two private lists containing each class above (row 8, row 20)
Stuck here == > A suitable constructor
A Clear () method that removes all elements in both lists
A NumberPlayer () method that returns the number of players in the tournament
Two methods for adding a new player to the correct list
Stuck here == > A Maximum Score () method that returns the highest score any player has.
If all players have zero points, return zero instead.
(b) It's a bit clumsy to have two separate lists just because we have two different player classes.
Redesign the player classes, possibly with a third class or interface, to make it easier the handling. Write an updated version of ChessTournament that uses this.'
This is how far i've gotten:
How should i proceed to make this all work?
Regards,
I need some help when it comes to my code, its not meant to have a "main" method.
It is basically a chess program that takes values and compares them, checks players and how much they score.
This is what i need to do :
We organize a chess tournament in the local club. The members are divided into
"regular" players and grandmasters.
Write a class ChessTournament (line 33) that has:
Two private lists containing each class above (row 8, row 20)
Stuck here == > A suitable constructor
A Clear () method that removes all elements in both lists
A NumberPlayer () method that returns the number of players in the tournament
Two methods for adding a new player to the correct list
Stuck here == > A Maximum Score () method that returns the highest score any player has.
If all players have zero points, return zero instead.
(b) It's a bit clumsy to have two separate lists just because we have two different player classes.
Redesign the player classes, possibly with a third class or interface, to make it easier the handling. Write an updated version of ChessTournament that uses this.'
This is how far i've gotten:
Chess, NUnit testing:
class Program
{
class NormalPlayer
{
public string Name;
public int Score;
public int Handicap;
public NormalPlayer(string n, int h)
{
Name = n;
Score = 0;
Handicap = h;
}
}
class Grandmaster
{
public string Name;
public int Score;
public string Country;
public Grandmaster(string n, string c)
{
Name = n;
Score = 0;
Country = c;
}
}
class ChessTournament
{
/// <summary>
/// List for "NP = Normal players" and "GM = Grandmaster players".
/// </summary>
public List<NormalPlayer> NP = new List<NormalPlayer>();
public List<Grandmaster> GM = new List<Grandmaster>();
/// <summary>
/// Add normal players to the list.
/// </summary>
/// <param name="normalPlayer"></param>
public void AddNP(NormalPlayer normalPlayer)
{
NP.Add(normalPlayer);
}
/// <summary>
/// Add grand master players to the list.
/// </summary>
/// <param name="grandmaster"></param>
public void AddGM(Grandmaster grandmaster)
{
GM.Add(grandmaster);
}
/// <summary>
/// Stuck here!
/// </summary>
/// <param name="score"></param>
/// <returns></returns>
public string HighestScore(int score)
{
}
/// <summary>
/// Write the total amount of players in the game.
/// </summary>
/// <param name="players"></param>
/// <returns></returns>
public int TotalPlayers(int players)
{
players = GM.Count + NP.Count;
return players;
}
public void Clean()
{
NP.Clear();
GM.Clear();
}
}
How should i proceed to make this all work?
Regards,
Last edited: