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:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
|
//main.cpp - Nigotris
#include <wx/wx.h>
#include <ddraw.h>
#include <dsound.h>
#include "main.h"
#include "ddutil.h"
#include "dsutil.h"
IMPLEMENT_APP(Anwendung)
bool Anwendung::OnInit()
{
//Fenster
Fenster *wnd = new Fenster(wxT("Nigotris V0.1"), 350, 150, 360, 520);
wnd->Show(true);
SetTopWindow(wnd);
//Komponeneten
wxMenu *Spiel = new wxMenu();
wxMenuBar *menu = new wxMenuBar();
wxMenuItem *Sound = new wxMenuItem(Spiel, wxID_PAGE_SETUP, wxT("&Sound tAlt+S"), wxT("Schalten sie den Ton an/aus..."), true, NULL);
Spiel->Append(wxID_NEW, wxT("&Neues SpieltAlt+N"), wxT("Beginnen sie ein neues Spiel..."));
Spiel->Append(wxID_STOP, wxT("&PausetAlt+P"), wxT("Pausieren sie das Spiel..."));
Spiel->Append(Sound);
//Testfunktion
Spiel->AppendSeparator();
Spiel->Append(wxID_SETUP, wxT("&Test!tAlt+T"), wxT("Testfunktion"));
//Ende Testfunktion
Spiel->AppendSeparator();
Spiel->Append(wxID_EXIT, wxT("&EndetAlt+X"), wxT("Beenden sie das Spiel..."));
menu->Append(Spiel, wxT("&Nigotris"));
wnd->SetMenuBar(menu);
//WindowCreate
if( ng_sounds.init(wnd->GetHandle()) < 0)
{
wxMessageBox(wxT("Es ist ein schwerwiegender Systemfehler aufgetreten!"), wxT("Nigotrissystem"));
}
return true;
}
BEGIN_EVENT_TABLE(Fenster, wxFrame)
EVT_MENU(wxID_SETUP, Fenster::OnTest)
EVT_MENU(wxID_PAGE_SETUP, Fenster::OnSound)
END_EVENT_TABLE()
Fenster::Fenster(const wxChar *title,
int xpos, int ypos,
int width, int height)
: wxFrame((wxFrame *) NULL,
-1, title,
wxPoint(xpos, ypos),
wxSize(width, height))
{
}
Fenster::~Fenster()
{
}
void Fenster::OnTest(wxCommandEvent &event)
{
//Testfunktion
}
void Fenster::OnSound(wxCommandEvent &event)
{
wxMessageBox(wxT("Soundfunktion"), wxT("OnSound()"));
}
//----------------------//
// Sound //
//----------------------//
const int sound_start = 0;
const int sound_dreh = 1;
const int sound_mov = 2;
const int sound_down = 3;
const int sound_row1 = 4;
const int sound_row2 = 5;
const int sound_ende = 6;
const int sound_win = 7;
const int anzahl_sounds = 8;
//Sounds
class sounds
{
private:
CSoundManager sManager;
CSound *sSound[anzahl_sounds];
public:
int on;
sounds();
int init(HWND wnd);
void play(int snr);
~sounds();
};
//-----------------------
char *soundfiles[anzahl_sounds] =
{
"start.wav",
"dreh.wav",
"mov.wav",
"down.wav",
"row1.wav",
"row2.wav",
"ende.wav",
"win.wav"
};
//-----------------------
sounds::sounds()
{
int i;
for(i=0; i < anzahl_sounds; i++)
{
sSound[i] = 0;
}
on = 1;
}
//-----------------------
int sounds::init(HWND wnd)
{
HRESULT ret;
int i;
ret = sManager.Initialize(wnd, DSSCL_PRIORITY, 2, 22050, 16);
if(ret < 0)
return ret;
for(i=0; i < anzahl_sounds; i++)
{
ret = sManager.Create( sSound+i, reinterpret_cast <LPTSTR> (soundfiles[i]));
if(ret < 0)
return ret;
}
return S_OK;
}
//-----------------------
sounds::~sounds()
{
int i;
for(i=0; i < anzahl_sounds; i++)
{
if(sSound[i])
delete sSound[i];
}
}
//-----------------------
void sounds::play(int snr)
{
if(!on)
return;
if(sSound[snr]->IsSoundPlaying())
{
sSound[snr]->Stop();
sSound[snr]->Reset();
}
sSound[snr]->Play(0, 0);
}
|