简体   繁体   English

如何创建一致的文件路径以在多台计算机上运送

[英]How do I create a consistent file path for shipping on multiple computers

I am a novice programmer that knows a bit but not a lot about c#, regardless I want to use what I knew to make this little console text game as a joke to send to my friends.我是一个新手程序员,对 c# 了解一点但不是很多,但我想用我所知道的来制作这个小控制台文本游戏作为一个笑话发送给我的朋友。 It has a failure sound effect that uses System.Media.SoundPlayer and from what I know, SoundPlayer needs a path in order to grab a file and play it.它有一个使用 System.Media.SoundPlayer 的失败音效,据我所知,SoundPlayer 需要一个路径才能获取文件并播放它。 It works fine on my computer under the file path "C:\\Users\\lambk\\source\\repos\\Retarded Game 2022\\scare_effectHipitch.wav" (sorry about the project title to anyone offended) but obviously this file path doesn't work for my friends who will download it to their downloads folder and will not be using a user called "lambk".它在我的计算机上的文件路径“C:\\Users\\lambk\\source\\repos\\Retarded Game 2022\\scare_effectHipitch.wav”下工作正常(对不起,冒犯了任何人的项目标题)但显然这个文件路径不适用于我的朋友会将它下载到他们的下载文件夹中,并且不会使用名为“lambk”的用户。 Is there a sort of file path framework that would solve this issue for me?是否有一种文件路径框架可以为我解决这个问题? If not then how do people typically circumvent this problem?如果不是,那么人们通常如何规避这个问题?

Script for reference:脚本供参考:

class Program
{
    static void Main(string[] args)
    {
        System.Media.SoundPlayer failureSound = new System.Media.SoundPlayer(@"C:\Users\lambk\source\repos\Retarded Game 2022\scare_effectHipitch.wav");
        Console.WriteLine("Guard: Hello Strange Traveler.\n State Your Business In The Motherland.");
        Console.WriteLine("\nA) I have come to inaugurate a new king with this dagger!\nB) Seeking Trade Amongst The People, For I Am A Merchant From The B Lands");
        string answer = Console.ReadLine();
        if (answer == "Seeking Trade Amongst The People, For I Am A Merchant From The B Lands" || answer == "b" || answer == "B")
        {
            Console.WriteLine("Swell, the motherland may always welcome additional merchendise. \n (you enter the motherland and are greeted with vast stretches of merchendise, selling souvineirs for all the visitors to snag before they leave. You accept this competition wholeheartedly, as you've come to sell not trivial materialistic items, but rather weaponry in the form of bows, arrows, swords, and shields, perhaps also as a souvinier though visitors aren't your core consumers.)\n(you make your way to your new shop)\n");
            Console.Read();
        }
        else
        {
            failure();
        }
        //-------VOID CLASSIFICATION-------//
        void failure()
        {
            int counter = 0;
            failureSound.PlayLooping();
            while (counter < 350)
            {
                Console.Write("FAILURE_FAILURE_FAILURE_FAILURE_FAILURE_FAILURE_FAILURE_FAILURE_");
                Thread.Sleep(1);
                counter++;
                if (counter == 350)
                {
                    failureSound.Stop();
                    Console.WriteLine("\nPress Enter To Restart");
                    Console.Read();
                    Application.Restart();
                }
            }
        }
        //-------VOID CLASSIFICATION-------//
    }

}

} }

Assuming that the sound file is located in the Downloads folder, you can reference that folder using:假设声音文件位于Downloads文件夹中,您可以使用以下命令引用该文件夹:

 // using Microsoft.Win32;
string GetDownloadFolderPath() 
{
    return Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "{374DE290-123F-4565-9164-39C4925E467B}", String.Empty).ToString();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM