나는 C# 콘솔에서 테트리스 게임을 만들고있다. 나는 대부분의 게임을했지만 파일 핸들링에 박혀있다. 나는 이것과 관련이있는 것을 발견하지 못했고 그래서 나는 그에게 한 발을내어 그것을 물어볼지도 모른다고 생각했다. 내가하려고하는 것은 플레이어의 이름과 점수를 txt 파일에 NAME : SCORE로 저장하는 것이다. 어떻게 든 후 점수 판으로 상위 10 위를 인쇄 점수하여 분류 내가 가진 얼마나 멀리로 여기 은 다음과 같습니다.테트리스 게임을위한 스코어 보드 .txt 점수 판
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace scoreb
{
class Program
{
private static Random _random = new Random();
private static ConsoleColor GetRandomConsoleColor()
{
var consoleColors = Enum.GetValues(typeof(ConsoleColor));
return (ConsoleColor)consoleColors.GetValue(_random.Next(consoleColors.Length));
}
static void Main(string[] args)
{
int n = 10;
string[] names;
string[] name = new string[n];
string[] score = new string[n];
int i = 0;
while(name[i] != "*"){
Console.WriteLine("Supply your name please!!");
name[i] = Convert.ToString(Console.ReadLine());
Console.WriteLine("Give your score!");
score[i] = Convert.ToString(Console.ReadLine());
Console.WriteLine(name[i] + score[i]);
names = new string[] { name[i] + " " + score[i] };
i++;
}
Console.ReadLine();
//Printout
Console.Clear();
Console.WriteLine();
Console.ForegroundColor = GetRandomConsoleColor();
Console.WriteLine(" *****************************");
Console.ForegroundColor = GetRandomConsoleColor();
Console.WriteLine(" HIGH SCORES");
Console.ForegroundColor = GetRandomConsoleColor();
Console.WriteLine(" *****************************");
Console.WriteLine();
string[] lines = File.ReadAllLines("C:\\asd.txt");
Array.Sort(lines);
string read = null;
StreamReader b = File.OpenText("C:/asd.txt");
Console.WriteLine(" Név Pont");
while ((read = b.ReadLine()) != null)
{
int j = 0;
Console.WriteLine();
Console.ForegroundColor = GetRandomConsoleColor();
Console.WriteLine(" " + (j + 1) + ". " + lines[j]);
Console.WriteLine();
j++;
}
b.Close();
Console.ReadLine();
}
}
}
고맙습니다. 이것은 정말로 도움이되었습니다. –