如何显示以前的所有分数? [英] How to show all previous score?
问题描述
所以我现在有一个问题,就像我现在看到的那样。该计划应该做到:一旦一名球员获胜,他的名字就会出现在屏幕上,之后他的所有飞镖都会打印出来。每个系列的三个飞镖都会出现,这样你就可以了解每一轮是如何抛出的。
我的程序显示的是名字,但不是更多。
So i have one problem left whit this program as i see it now. The program should do: Once a player has won , his name appears on the screen, after which all his dart printed for how he threw . Each series of three dart to appear so that you understand how each round has been thrown.
My program shows the name but not more.
if (name.Sum >= 501)
{
winner = name;
Console.WriteLine("\nVinnare är: " + winner.Name + " med " +"????" );
break;
}
这是我有问题的代码的一部分?应该是类似于列表或某事物的东西
和代码行是在游戏的中间阶段。
现在有人这个问题吗?
对不起所有代码。
This is the part of the code that i have problem whit ???? should be somthing like a list or somthing
and the code line is in the mid of class Game.
Anyone now this problem?
Sorry for all the code.
namespace _501
{
class Program
{
static void Main(string[] args)
{
Console.Title = "###### Nicklas Dart Räknare ######";
Game game = new Game();
game.PlayGame();
}
}
//***************************************************************************
class Game
{
private List<player> players = new List<player>();
public void AddPlayer(string name)
{
Player person = new Player(name);
players.Add(person);
}
public void PlayGame()
{
int a1 = 0;
int a2 = 0;
int a3 = 0;
Arrows arrow = new Arrows(a1, a2, a3);
int s1 = 0;
Player score = new Player(s1);
try
{
Console.Write("Hur många spelare? ");
int numberOfPlayers = Convert.ToInt32(Console.ReadLine());
Player winner = null;
for (int i = 0; i < numberOfPlayers; i++)
{
Console.Write("Skriv in spelarens namn: ");
string playerName = Console.ReadLine();
AddPlayer(playerName);
}
while (players.Max((a) => a.Sum) < 500)
{
foreach (Player name in players)
{
string str1 = name.Name;
string str2 = "Dator";
// Computer input
if (str1 == str2)
{
//if (name.Sum < 501)
//{
Console.WriteLine(name + "ns första poäng (mellan 0-60)");
arrow.ArrowOne = Random();
Console.WriteLine(arrow.ArrowOne);
name.Sum += arrow.ArrowOne;
Console.WriteLine(name + "ns andra poäng (mellan 0-60)");
arrow.ArrowTwo = Random();
Console.WriteLine(arrow.ArrowTwo);
name.Sum += arrow.ArrowTwo;
Console.WriteLine(name + "ns tredje poäng (mellan 0-60)");
arrow.ArrowThree = Random();
Console.WriteLine(arrow.ArrowThree);
name.Sum += arrow.ArrowThree;
if (name.Sum >= 501)
{
winner = name;
Console.WriteLine("Vinnare är: " + winner.Name +" med "+ name.Sum);
break;
}
int sum = arrow.GetScore();
Console.WriteLine("\n" + name + "ns totala summan av all tre kast blev: " + sum.ToString());
Console.WriteLine(name + "ns totala summan av all kast hitils: " + name.Sum+"\n");
}
// Humen input
else
{
// if (name.Sum < 501)
//{
Console.WriteLine(name + " första poäng (mellan 0-60)");
arrow.ArrowOne = Int32.Parse(Console.ReadLine());
if ((arrow.ArrowOne > 0) && (arrow.ArrowOne < 60))
{
name.Sum += arrow.ArrowOne;
}
else
{
Console.WriteLine("Värdet var inte mellan 0-60 och blir då 0");
arrow.ArrowOne = 0;
name.Sum += arrow.ArrowOne;
}
Console.WriteLine(name + " andra poäng (mellan 0-60)");
arrow.ArrowTwo = Int32.Parse(Console.ReadLine());
if ((arrow.ArrowTwo > 0) && (arrow.ArrowTwo < 60))
{
name.Sum += arrow.ArrowTwo;
}
else
{
Console.WriteLine("Värdet var inte mellan 0-60 och blir då 0");
arrow.ArrowTwo = 0;
name.Sum += arrow.ArrowTwo;
}
Console.WriteLine(name + " tredje poäng (mellan 0-60)");
arrow.ArrowThree = Int32.Parse(Console.ReadLine());
if ((arrow.ArrowThree > 0) && (arrow.ArrowThree < 60))
{
name.Sum += arrow.ArrowThree;
}
else
{
Console.WriteLine("Värdet var inte mellan 0-60 och blir då 0");
arrow.ArrowThree = 0;
name.Sum += arrow.ArrowThree;
}
if (name.Sum >= 501)
{
winner = name;
Console.WriteLine("\nVinnare är: " + winner.Name + " med " +"????" );
break;
}
int sum = arrow.GetScore();
Console.WriteLine("\n" + name + " totala summan av all tre kast blev: " + sum.ToString());
Console.WriteLine(name + " totala summan av all kast hitils: " + name.Sum + "\n");
}
}
if (winner != null)
//Console.WriteLine("\nVinnare är: " + winner.Name + " med " + arrowList);
Console.ReadKey();
}
}
catch (FormatException)
{
Console.WriteLine("Var snäll och skriv in ett nummer");
Console.ReadKey();
}
catch (OverflowException)
{
Console.WriteLine("Bara nummer mellan {0} och {1}", Int32.MinValue, Int32.MaxValue);
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message+" troligen valt 0 spelare");
Console.ReadKey();
}
}
//Random for Dator
public int Random()
{
Random random = new Random();
int randomNumber = random.Next(0, 60);
System.Threading.Thread.Sleep(10);
return randomNumber;
}
}
//***************************************************************************
class Player
{
public int Sum { get; set; }
public string Name { get; set; }
public List<arrows> arrowList = new List<arrows>();
public Player(string name = "")
{
Name = name;
}
public Player(int sum = 0)
{
Sum = sum;
}
public void AddArrows(Arrows arrows)
{
arrowList.Add(arrows);
}
public int CalculatePoints()
{
foreach (Arrows arrow in arrowList)
arrow.GetScore();
return Sum;
}
public override string ToString()
{
return string.Format("{0}", Name);
}
}
//***************************************************************************
class Arrows
{
private int arrowOne;
private int arrowTwo;
private int arrowThree;
public int ArrowOne
{
get { return arrowOne; }
set { arrowOne = value;}
}
public int ArrowTwo
{
get { return arrowTwo; }
set { arrowTwo = value; }
}
public int ArrowThree
{
get { return arrowThree; }
set { arrowThree = value; }
}
public Arrows(int arrowOne, int arrowTwo, int arrowThree )
{
ArrowOne = arrowOne;
ArrowTwo = arrowTwo;
ArrowThree = arrowThree;
}
public int GetScore()
{
return arrowOne + arrowTwo + arrowThree;
}
public override string ToString()
{
return string.Format("Din totala summa är {0}",GetScore());
}
}
}
我尝试了什么:
我试图获得arrowList值
我一直在谷歌搜索找到类似的问题
What I have tried:
I have tried to get the arrowList values
I have been searching on google to find something similar problem
推荐答案
对于这些信息的临时可用性,您可以使用我们的数组或列表。
我没有在VS中输入此信息我通常不会编写控制台应用程序,因此可能会出现错误,但它应该可以为您提供一些想法...
For a temporary availability of this information you could us an array or list.
I did not type this out in VS and I don't usually write console apps, so this may be riddled with bugs, but it should serve to give you some ideas...
class Program
{
static void Main(string[] args)
{
Console.Title = "###### Nicklas Dart Räknare ######";
List<player> players = new List<players>();
Boolean cont = true;
while(cont)
{
String selection = Console.ReadLine();
switch(selection)
{
case "1": // play game
Game game = new Game();
// notice... for this to work this way you will need to return a player.
// There are plenty of other ways to make it work though.
players.add(game.PlayGame());
foreach(Player player in players)
{
Console.WriteLine(player.name);
Console.WriteLine(player.score);
}
break;
case "2" // exit
cont = false;
// do fancy exit stuff here
break;
default:
Console.WriteLine("Invalid Input");
break;
}
}
}</players></player>
对于perminent有限长度列表,您可以使用设置比如Properties.Settings.Default.yourVariableHere ...我通常将它用于用户选项和连接字符串。
当然你可以尝试序列化...
对于一个非常庞大的长度列表,您可能想要使用数据库。
For a perminent limited length list, you could use the Settings like Properties.Settings.Default.yourVariableHere... I usually use this for user options and connection strings.
Of course you could experiment with serialization...
For a perminent huge length list you might want to use a database.
这篇关于如何显示以前的所有分数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!