如何为该游戏添加声音? (这就像一个推箱子游戏吗?) [英] how can i add sound for this game? (This is like a sokoban game ?)
本文介绍了如何为该游戏添加声音? (这就像一个推箱子游戏吗?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.SetCursorPosition(0, 0);
string str;
StreamReader f = File.OpenText("c:\\Ourscreen.txt");
do
{
str = Convert.ToString(f.ReadLine());
Console.WriteLine(str);
} while (!f.EndOfStream);
f.Close();
int ran1, ran2;
char[] setnames = new char[8] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
Random random = new Random();
int m = 2;
int[,] sets = new int[8, 8];
for (int i = 0; i <8; i++)
{
Console.SetCursorPosition(27, m);
m++;
Console.Write(setnames[i]+"={");
ran2 = random.Next(4, 9);
for (int j = 0; j < ran2; j++)
{
ran1 = random.Next(1, 21);
for (int k = 0; k < sets.GetLength(1); k++)
{
if (sets[i,k] == ran1)
{
ran1 = random.Next(1, 21);
k = 0;
}
}
sets[i,j] = ran1;
if (j == ran2 - 1)
Console.Write(sets[i,j]);
else
{
Console.Write(sets[i,j] + ",");
}
}
Console.Write("}");
Console.WriteLine();
}
Console.ReadLine();
}
}
}
推荐答案
使用 ^ ]:
Use the System.Media.SoundPlayer class[^]:
System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer();
soundPlayer.SoundLocation = "sound.wav";
soundPlayer.Play(); // to play the sound in a loop, call soundPlayer.PlayLooping();
警告:这仅适用于.wav文件.
希望这会有所帮助.
Warning: this will only work for .wav files.
Hope this helps.
这篇关于如何为该游戏添加声音? (这就像一个推箱子游戏吗?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文