尝试通过提供的uml为学校制作一个飞镖点计数器。我只是添加了球员的名字,但我现在坚持记分!我在这里完成的方式只会增加1名玩家的得分,但会覆盖第二名的名单。
你会被提示要添加多少玩家,然后添加玩家名称,但我无法了解如何让每个玩家获得他们的个人记录。 player1应该投掷3个箭头并在每个箭头上得到0-60点,然后它的player2转向做同样的事情。第一个人超过501获胜,所以我需要跟踪个别球员的得分,但不知道如何:/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ThrowDart
{
class Program
{
static void Main(string[] args)
{
Game game = new Game();
game.PlayGame();
}
}
public class Game
{
private List<Player> personer = new List<Player>();
public void AddPlayer(int Players)
{
int howMany = 0;
for (int i = 0; i < Players; i++)
{
personer.Add(new Player());
}
foreach (Player player in personer)
{
howMany = howMany + 1;
Console.WriteLine("Please name player " + howMany + ":");
player.Name = Console.ReadLine();
}
}
public void PlayGame()
{
start:
Console.WriteLine("Welcome to DartGame");
Console.WriteLine("How many players would you like to add?");
int antalSpelare;
string input = Console.ReadLine();
if (Int32.TryParse(input, out antalSpelare))
{
AddPlayer(antalSpelare);
}
else
{
Console.WriteLine("Numbers only for adding players, please.");
Console.ReadLine();
Console.Clear();
goto start;
}
for (int i = 0; i < personer.Count; i++)
{
Console.WriteLine("points for player " + personer[i]);
Console.WriteLine("First arrow points: ");
int throw1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Second arrow points:");
int throw2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Third arrow points:");
int throw3 = Convert.ToInt32(Console.ReadLine());
Arrows arrows = new Arrows(throw1, throw2, throw3);
foreach (var item in arrows.arrowList)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}
public class Player : Game
{
public List<int> arrowList = new List<int>();
public string Name { get; set; }
public Player()
{
}
public string player(string name)
{
return "";
}
public int CalculatePoints()
{
for (int i = 0; i < arrowList.Count; i++)
{
}
return 0;
}
public void AddArrows(string Arrows)
{
}
public override string ToString()
{
return Name;
}
}
public class Arrows : Player
{
private int arrowOne;
private int arrowTwo;
private int arrowThree;
public Arrows(int arrowOne, int arrowTwo, int arrowThree)
{
this.arrowOne = arrowOne;
this.arrowTwo = arrowTwo;
this.arrowThree = arrowThree;
arrowList.Add(arrowOne);
arrowList.Add(arrowTwo);
arrowList.Add(arrowThree);
}
public int GetScore()
{
return 0;
}
public override string ToString()
{
return base.ToString() + "ToString override 2";
}
}
}