-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
audio.cs
93 lines (80 loc) · 2.83 KB
/
audio.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Windows.Media;
namespace Solitaire
{
static public class Audio
{
static private MediaPlayer musicPlayer = new MediaPlayer();
static private Uri[] musicUrls = new Uri[4]
{
new Uri(@"sounds/music1 - peaceful scene.mp3", UriKind.Relative),
new Uri(@"sounds/music2 - northern isles.mp3", UriKind.Relative),
new Uri(@"sounds/music3 - home.mp3", UriKind.Relative),
new Uri(@"sounds/music4 - cats and spies.mp3", UriKind.Relative)
};
static private int currentMusic = 0;
static private MediaPlayer soundPlayer = new MediaPlayer();
static private Uri dealingCard = new Uri(@"sounds/dealing card.mp3", UriKind.Relative);
static private Uri error = new Uri(@"sounds/error.mp3", UriKind.Relative);
static private Uri victory = new Uri(@"sounds/victory.mp3", UriKind.Relative);
static public void init()
{
Audio.musicPlayer.MediaEnded += Audio.changeMusic;
Audio.musicPlayer.Volume = Data.MusicVolume;
Audio.soundPlayer.Volume = Data.SoundVolume;
}
static public void playBackgroundMusic()
{
Audio.musicPlayer.Open(Audio.musicUrls[Audio.currentMusic]);
Audio.musicPlayer.Play();
}
static private void changeMusic(object sender, EventArgs e)
{
Audio.currentMusic++;
if (Audio.currentMusic >= Audio.musicUrls.Length)
{
Audio.currentMusic = 0;
}
Audio.playBackgroundMusic();
}
static public void playDealingCard()
{
Audio.soundPlayer.Open(Audio.dealingCard);
Audio.soundPlayer.Play();
}
static public void playError()
{
Audio.soundPlayer.Open(Audio.error);
Audio.soundPlayer.Play();
}
static public void playVictory()
{
Audio.soundPlayer.Open(Audio.victory);
Audio.soundPlayer.Play();
}
/**
* Set music volume (between 0 and 1).
*/
static public void setMusicVolume(double volume)
{
Audio.musicPlayer.Volume = volume;
Data.MusicVolume = volume;
}
static public double getMusicVolume()
{
return Audio.musicPlayer.Volume;
}
/**
* Set the game sound volume (between 0 and 1).
*/
static public void setSoundVolume(double volume)
{
Audio.soundPlayer.Volume = volume;
Data.SoundVolume = volume;
}
static public double getSoundVolume()
{
return Audio.soundPlayer.Volume;
}
}
}