Skip to content

Commit

Permalink
Improve the code
Browse files Browse the repository at this point in the history
I improve the code and I do these things:
* Make game music resources
* remove declares of i and j
  • Loading branch information
Fibird committed Nov 4, 2016
1 parent 25cdb59 commit 5ea4d68
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 19 deletions.
7 changes: 6 additions & 1 deletion Tetris/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#define IDB_RIGHTCOL 332
#define IDB_MIDDLE 333
#define IDB_START_BK 335
#define IDR_UPGRADE_WAVE 345
#define IDR_BGM_WAVE 346
#define IDR_FAIL_WAVE 349
#define IDR_WAVE2 350
#define IDR_VICTORY_WAVE 350
#define IDC_BUTTON1 1000
#define IDC_LEVEL_EDIT 1001
#define IDC_NAME_EDIT 1002
Expand Down Expand Up @@ -71,7 +76,7 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 344
#define _APS_NEXT_RESOURCE_VALUE 351
#define _APS_NEXT_COMMAND_VALUE 32793
#define _APS_NEXT_CONTROL_VALUE 1017
#define _APS_NEXT_SYMED_VALUE 310
Expand Down
11 changes: 4 additions & 7 deletions Tetris/Rule.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "stdafx.h"
#include "Rule.h"
#include <mmsystem.h>

#include "resource.h"
CRule::CRule()
{
m_nLevel = 1;
Expand All @@ -19,11 +19,10 @@ void CRule::SetLevel(int nLevel)

int CRule::UpLevel(int nLine, int &countline)
{
LPCWSTR UPM = L".\\sound\\upgrade.wav";
if (nLine / 2) //如果可以整除,等级升级
{
m_nLevel++;
sndPlaySound(UPM, SND_ASYNC);
PlaySound((LPCTSTR)IDR_UPGRADE_WAVE, AfxGetInstanceHandle(), SND_RESOURCE | SND_ASYNC);
countline = 0; // 行数清零
}

Expand All @@ -32,11 +31,9 @@ int CRule::UpLevel(int nLine, int &countline)

bool CRule::Win(int Now[4][4], int Russia[100][100], CPoint NowPosition)
{
LPCWSTR VM = L".\\sound\\victory.wav";
LPCWSTR FM = L".\\sound\\fail.wav";
if (m_nLevel == 11) //游戏等级超过最高
{ //超过10级游戏结束
sndPlaySound(VM, SND_ASYNC);
PlaySound((LPCTSTR)IDR_VICTORY_WAVE, AfxGetInstanceHandle(), SND_RESOURCE | SND_ASYNC);
return true;
}

Expand All @@ -48,7 +45,7 @@ bool CRule::Win(int Now[4][4], int Russia[100][100], CPoint NowPosition)
{//到了顶点
if (Russia[i + NowPosition.x][j + NowPosition.y] == 1)
{
sndPlaySound(FM, SND_ASYNC);
PlaySound((LPCTSTR)IDR_FAIL_WAVE, AfxGetInstanceHandle(), SND_RESOURCE | SND_ASYNC);
return true; //游戏结束
}
}
Expand Down
18 changes: 9 additions & 9 deletions Tetris/Russia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ void CRussia::Move(int direction)
bool CRussia::Change(int a[][4], CPoint p, int b[][100])
{
int tmp[4][4];
int i, j;
// int i, j;
int k = 4, l = 4;

for (i = 0; i<4; i++)
for (int i = 0; i<4; i++)
{
for (j = 0; j<4; j++)
for (int j = 0; j<4; j++)
{
tmp[i][j] = a[j][3 - i];
After[i][j] = 0; //存放变换后的方块矩阵
}
}

for (i = 0; i<4; i++)
for (int i = 0; i<4; i++)
{
for (j = 0; j<4; j++)
for (int j = 0; j<4; j++)
{
if (tmp[i][j] == 1)
{
Expand All @@ -161,17 +161,17 @@ bool CRussia::Change(int a[][4], CPoint p, int b[][100])
}
}
}
for (i = k; i<4; i++)
for (int i = k; i<4; i++)
{
for (j = l; j<4; j++)
for (int j = l; j<4; j++)
{
After[i - k][j - l] = tmp[i][j];
} //把变换后的矩阵移到左上角
}
//判断是否接触,是:返回失败
for (i = 0; i<4; i++)
for (int i = 0; i<4; i++)
{
for (j = 0; j<4; j++)
for (int j = 0; j<4; j++)
{
if (After[i][j] == 0)
{
Expand Down
14 changes: 14 additions & 0 deletions Tetris/Tetris.rc
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,20 @@ BEGIN
END


/////////////////////////////////////////////////////////////////////////////
//
// WAVE
//

IDR_UPGRADE_WAVE WAVE "Sound\\upgrade.wav"

IDR_BGM_WAVE WAVE "Sound\\BGM.wav"

IDR_FAIL_WAVE WAVE "Sound\\fail.wav"

IDR_VICTORY_WAVE WAVE "Sound\\victory.wav"


/////////////////////////////////////////////////////////////////////////////
//
// String Table
Expand Down
9 changes: 9 additions & 0 deletions Tetris/Tetris.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@
</ItemGroup>
<ItemGroup>
<None Include="ClassDiagram.cd" />
<None Include="res\music1.bin" />
<None Include="res\Tetris.rc2" />
<None Include="res\wave1.bin" />
<None Include="res\wave2.bin" />
<None Include="Tetris.reg" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -254,6 +257,12 @@
<Image Include="res\Toolbar.bmp" />
<Image Include="res\top.bmp" />
</ItemGroup>
<ItemGroup>
<Media Include="Sound\BGM.wav" />
<Media Include="Sound\fail.wav" />
<Media Include="Sound\upgrade.wav" />
<Media Include="Sound\victory.wav" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
23 changes: 23 additions & 0 deletions Tetris/Tetris.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@
<Filter>Resource Files</Filter>
</None>
<None Include="ClassDiagram.cd" />
<None Include="res\music1.bin">
<Filter>Resource Files</Filter>
</None>
<None Include="res\wave2.bin">
<Filter>Resource Files</Filter>
</None>
<None Include="res\wave1.bin">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Tetris.rc">
Expand Down Expand Up @@ -179,4 +188,18 @@
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<Media Include="Sound\upgrade.wav">
<Filter>Resource Files</Filter>
</Media>
<Media Include="Sound\BGM.wav">
<Filter>Resource Files</Filter>
</Media>
<Media Include="Sound\fail.wav">
<Filter>Resource Files</Filter>
</Media>
<Media Include="Sound\victory.wav">
<Filter>Resource Files</Filter>
</Media>
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions Tetris/TetrisView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ void CTetrisView::OnGameLevel()
void CTetrisView::OnBkmusicOn()
{
// 打开背景音乐
LPCWSTR BGM = L".\\sound\\BGM.wav";
sndPlaySound(BGM, SND_ASYNC | SND_LOOP);
PlaySound((LPCTSTR)IDR_BGM_WAVE, AfxGetInstanceHandle(), SND_RESOURCE | SND_SYNC | SND_LOOP);
}


Expand Down

0 comments on commit 5ea4d68

Please sign in to comment.