Im doing another school project and im kinda stuck.. Im building a pretty simple dartgame and have made a class for creating players with a string for name and int for points. I made a list of that class and i think i managed to get it working this far. this is where im stuck tho. Which would be the best way to roll through the list of players, showing the current player name and points, im thinking im gonna have the player enter their points manually or choose to get 3 random points between 1-20 that are written out before added to their current points and then moves on to the next player. All ideas are welcome im a proper noob!
dartgame:
using System;
using System.Collections.Generic;
using System.Text;
namespace dartboardskiss
{
class Game
{
private List<Player> players = new List<Player>();
public void AddPlayer()
{
Console.WriteLine("Type the name of the player and press enter.");
string name = Console.ReadLine();
Player person = new Player(name, 0);
players.Add(person);
}
private int PlayerCounter() //method to keep track of players
{
int playercounter = 0;
foreach (Player _player in players)
{
if (_player != null)
playercounter++;
}
return playercounter;
}
public Game()
{
do
{
//switch statement menu
Console.WriteLine("Welcome to the Dartgame, what would you like to do?");
Console.WriteLine("1. Add player");
Console.WriteLine("2. Start the game");
int choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
this.AddPlayer();
break;
case 2:
Console.WriteLine("");
break;
default:
Console.WriteLine("");
break;
}
} while (true);
}
}
class Player //class for creating player
{
private string name;
private int points;
public Player(string name, int points)
{
this.name = name;
this.points = points;
}
//Tuple for returning values
public static implicit operator Player((string nname, int npoints) v)
{
return new Player(v.nname, v.npoints);
}
}
}