Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
kinomoto
Zuma_built_with_easyx
Commits
0616cfc2
Unverified
Commit
0616cfc2
authored
Dec 25, 2020
by
Sakurababycat
Committed by
GitHub
Dec 25, 2020
Browse files
Add files via upload
parent
ee8baf77
Changes
11
Hide whitespace changes
Inline
Side-by-side
Appearance.cpp
0 → 100644
View file @
0616cfc2
//
// Created by AMD on 2020/4/7.
//
#include
"Appearance.h"
//定位按钮鼠标位置
int
findMouse
(
int
x
,
int
y
)
{
choiceButton
button
;
if
(
x
<
button
.
width
)
{
if
(
y
<
(
450
+
button
.
height
)
&&
y
>
450
)
return
0
;
else
return
-
1
;
}
else
if
(
x
<
2
*
button
.
width
)
{
if
(
y
<
(
500
+
button
.
height
)
&&
y
>
500
)
return
1
;
else
return
-
1
;
}
else
if
(
x
<
3
*
button
.
width
)
{
if
(
y
<
(
450
+
button
.
height
)
&&
y
>
450
)
return
2
;
else
return
-
1
;
}
else
if
(
x
<
4
*
button
.
width
)
{
if
(
y
<
(
500
+
button
.
height
)
&&
y
>
500
)
return
3
;
else
return
-
1
;
}
else
return
-
1
;
}
//显示透明png图片,将原图中纯白色消除
void
putTransPic
(
LPCTSTR
buffer
,
int
leftPos
,
int
upPos
,
int
width
,
int
height
,
\
int
leftPosOri
,
int
upPosOri
,
int
widthOri
,
int
heightOri
,
long
color
)
{
IMAGE
img
;
loadimage
(
&
img
,
buffer
);
HDC
dstDC
=
GetImageHDC
();
HDC
srcDC
=
GetImageHDC
(
&
img
);
TransparentBlt
(
dstDC
,
leftPos
,
upPos
,
width
,
height
,
srcDC
,
leftPosOri
,
upPosOri
,
widthOri
,
heightOri
,
color
);
//FlushBatchDraw();
}
//显示难度选项
void
difChoicePic
(
int
order
[
8
])
{
int
num
=
0
;
choiceButton
button
=
{
200
,
100
};
cleardevice
();
BeginBatchDraw
();
IMAGE
wallpaper
;
loadimage
(
&
wallpaper
,
difWallPaper
);
putimage
(
0
,
0
,
&
wallpaper
);
for
(
num
;
num
<
4
;
num
++
)
{
putTransPic
(
posS
[
order
[
num
]
+
4
*
order
[
num
+
4
]],
button
.
width
*
num
,
450
+
50
*
(
num
%
2
),
\
button
.
width
,
button
.
height
,
0
,
0
,
button
.
width
,
button
.
height
);
}
FlushBatchDraw
();
}
//显示欢迎界面
void
startGame
()
{
//initgraph(WINDOWWITH, WINDOWHEIGHT, EW_NOCLOSE);
initgraph
(
WINDOWWITH
,
WINDOWHEIGHT
);
char
*
buffer
,
note
[]
=
"
\n\n
图片加载失败
\n
请检查resource文件夹是否在该目录下
\n\n
按任意键继续
\0
"
,
helloImg
[
30
];
buffer
=
_getcwd
(
NULL
,
0
);
int
length
=
strlen
(
buffer
),
i
=
0
,
j
=
0
,
flag
;
char
*
imgErr
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
length
+
length
/
48
+
10
)
+
strlen
(
note
)
*
sizeof
(
char
));
memset
(
imgErr
,
0
,
sizeof
(
imgErr
));
for
(
i
=
0
;
i
<
length
;
i
++
)
{
flag
=
i
%
(
WINDOWWITH
);
if
(
flag
>=
70
&&
imgErr
[
j
-
1
]
==
'\\'
)
imgErr
[
j
++
]
=
'\n'
;
imgErr
[
j
++
]
=
buffer
[
i
];
}
imgErr
[
j
]
=
'\0'
;
length
=
strlen
(
imgErr
)
+
strlen
(
note
)
+
1
;
strcat_s
(
imgErr
,
length
,
note
);
setbkcolor
(
WHITE
);
setfillcolor
(
WHITE
);
fillrectangle
(
0
,
0
,
WINDOWWITH
,
WINDOWHEIGHT
);
settextcolor
(
BLACK
);
RECT
REC
=
{
0
,
0
,
WINDOWWITH
,
WINDOWHEIGHT
};
CString
sName
(
imgErr
);
//LPCTSTR lpszName = sName;
settextstyle
(
0
,
0
,
sName
);
drawtext
(
sName
,
&
REC
,
DT_CENTER
|
DT_VCENTER
);
IMAGE
img
;
for
(
i
=
1
;
i
<=
16
;
i
++
)
{
if
(
i
<=
6
)
sprintf_s
(
helloImg
,
".
\\
resource
\\
hello%d.png"
,
i
);
else
sprintf_s
(
helloImg
,
".
\\
resource
\\
hellop%d.png"
,
i
-
6
);
CString
imgS
(
helloImg
);
loadimage
(
&
img
,
imgS
);
putimage
(
0
,
0
,
&
img
);
Sleep
(
100
);
}
while
(
true
)
{
if
(
MouseHit
())
{
if
(
GetMouseMsg
().
uMsg
==
WM_LBUTTONDOWN
||
\
GetMouseMsg
().
uMsg
==
WM_RBUTTONDOWN
)
{
cleardevice
();
free
(
imgErr
);
free
(
buffer
);
break
;
}
Sleep
(
1
);
}
}
}
//设置选择难度
int
chooseDifficulty
()
{
IMAGE
wallpaper
;
setbkcolor
(
WHITE
);
loadimage
(
&
wallpaper
,
difWallPaper
);
putimage
(
0
,
0
,
&
wallpaper
);
int
order
[
8
]
=
{
0
,
1
,
2
,
3
,
false
,
false
,
false
,
false
},
position
=
-
1
,
ifChoose
=
3
;
difChoicePic
(
order
);
MOUSEMSG
mouse
;
while
(
true
)
{
//cleardevice();
//BeginBatchDraw();
if
(
MouseHit
())
{
mouse
=
GetMouseMsg
();
switch
(
mouse
.
uMsg
)
{
case
WM_MOUSEMOVE
:
{
if
(
position
!=
findMouse
(
mouse
.
x
,
mouse
.
y
))
{
if
(
position
!=
-
1
)
order
[
position
+
4
]
=
false
;
//cleardevice();
position
=
findMouse
(
mouse
.
x
,
mouse
.
y
);
if
(
position
!=
-
1
)
order
[
position
+
4
]
=
true
;
if
(
position
!=
-
1
)
{
_beginthreadex
(
NULL
,
0
,
playMusic
,
music
+
button
,
0
,
NULL
);
difChoicePic
(
order
);
}
else
difChoicePic
(
order
);
//FlushBatchDraw();
}
break
;
}
case
WM_LBUTTONDOWN
:
{
if
(
position
!=
-
1
)
{
if
(
ifChoose
==
0
||
order
[
position
]
!=
0
)
return
order
[
position
];
else
{
ifChoose
--
;
int
temp
,
random
,
i
;
temp
=
order
[
position
];
do
{
random
=
rand
()
%
4
;
}
while
(
random
==
temp
);
for
(
i
=
0
;
i
<
4
;
i
++
)
{
if
(
order
[
i
]
==
random
)
{
order
[
i
]
=
temp
;
order
[
position
]
=
random
;
break
;
}
}
_beginthreadex
(
NULL
,
0
,
playMusic
,
music
+
move
,
0
,
NULL
);
difChoicePic
(
order
);
}
}
}
case
WM_RBUTTONDOWN
:
break
;
}
}
//FlushBatchDraw();
Sleep
(
1
);
}
}
//显示设置菜单
void
setMenu
()
{
}
//显示排行榜
void
scoreBoard
(
TCHAR
newName
[
MAX_COUNT
],
long
newNum
)
{
FILE
*
file
;
int
count
=
0
,
numOfScores
=
0
;
struct
{
long
num
;
char
name
[
MAX_COUNT
]
=
"
\0
"
;
}
scores
[
MAX_COUNT
],
temp
;
fopen_s
(
&
file
,
".
\\
GameRanking.txt"
,
"r"
);
if
(
file
)
{
fscanf_s
(
file
,
"%d"
,
&
numOfScores
);
fgetc
(
file
);
while
(
count
<
numOfScores
)
{
if
(
!
fgets
(
scores
[
count
].
name
,
MAX_COUNT
-
1
,
file
))
break
;
fscanf_s
(
file
,
"%ld"
,
&
(
scores
[
count
++
].
num
));
fgetc
(
file
);
}
fclose
(
file
);
}
if
(
newName
)
{
sprintf_s
(
scores
[
count
].
name
,
MAX_COUNT
,
"%ls
\n
"
,
newName
);
//scores[count].name[strlen(scores[count].name)] = '\n';
scores
[
count
++
].
num
=
newNum
;
}
for
(
int
i
=
count
;
i
>
0
;
i
--
)
for
(
int
j
=
0
;
j
<
i
;
j
++
)
{
if
(
scores
[
j
].
num
<
scores
[
j
+
1
].
num
)
{
temp
=
scores
[
j
];
scores
[
j
]
=
scores
[
j
+
1
];
scores
[
j
+
1
]
=
temp
;
}
}
fopen_s
(
&
file
,
".
\\
GameRanking.txt"
,
"w"
);
fprintf
(
file
,
"%d
\n
"
,
count
);
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
fprintf
(
file
,
"%s"
,
scores
[
i
].
name
);
fprintf
(
file
,
"%ld
\n
"
,
scores
[
i
].
num
);
}
fclose
(
file
);
RECT
rec
=
{
recl
,
recu
,
rankr
,
recu
+
textHeight
};
setbkmode
(
TRANSPARENT
);
settextcolor
(
DARKGRAY
);
LOGFONT
font
;
gettextstyle
(
&
font
);
font
.
lfHeight
=
20
;
font
.
lfWeight
=
20
;
font
.
lfWeight
=
FW_SEMIBOLD
;
font
.
lfOutPrecision
=
OUT_TT_PRECIS
;
font
.
lfQuality
=
ANTIALIASED_QUALITY
|
PROOF_QUALITY
;
settextstyle
(
&
font
);
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
BeginBatchDraw
();
if
(
i
%
10
==
0
)
{
cleardevice
();
loadimage
(
0
,
scorePic
);
rec
.
bottom
=
recu
,
rec
.
top
=
recu
+
textHeight
;
rec
.
left
=
recl
,
rec
.
right
=
rankr
;
drawtext
(
CString
(
"rank"
),
&
rec
,
DT_CENTER
|
DT_VCENTER
|
DT_SINGLELINE
|
DT_WORD_ELLIPSIS
);
rec
.
left
=
rankr
,
rec
.
right
=
namer
;
drawtext
(
CString
(
"name"
),
&
rec
,
DT_CENTER
|
DT_VCENTER
|
DT_SINGLELINE
|
DT_WORD_ELLIPSIS
);
rec
.
left
=
namer
,
rec
.
right
=
recr
;
drawtext
(
CString
(
"score"
),
&
rec
,
DT_CENTER
|
DT_VCENTER
|
DT_SINGLELINE
|
DT_WORD_ELLIPSIS
);
rec
.
bottom
+=
textHeight
,
rec
.
top
+=
textHeight
;
}
{
char
tmp
[
MAX_COUNT
];
rec
.
left
=
recl
,
rec
.
right
=
rankr
;
sprintf_s
(
tmp
,
MAX_COUNT
,
"%ld"
,
i
+
1
);
drawtext
(
CString
(
tmp
),
&
rec
,
DT_CENTER
|
DT_VCENTER
|
DT_SINGLELINE
|
DT_WORD_ELLIPSIS
);
rec
.
left
=
rankr
,
rec
.
right
=
namer
;
drawtext
(
CString
(
scores
[
i
].
name
),
&
rec
,
DT_CENTER
|
DT_VCENTER
|
DT_SINGLELINE
|
DT_WORD_ELLIPSIS
);
rec
.
left
=
namer
,
rec
.
right
=
recr
;
sprintf_s
(
tmp
,
MAX_COUNT
,
"%ld"
,
scores
[
i
].
num
);
drawtext
(
CString
(
tmp
),
&
rec
,
DT_CENTER
|
DT_VCENTER
|
DT_SINGLELINE
|
DT_WORD_ELLIPSIS
);
}
FlushBatchDraw
();
if
((
i
+
1
)
%
10
==
0
||
i
+
1
==
count
)
{
int
whichButton
=
0
;
bool
flag
=
false
;
MOUSEMSG
mouse
=
GetMouseMsg
();
while
(
!
flag
)
{
mouse
=
GetMouseMsg
();
if
(
mouse
.
x
<=
buttonWEIGHT
&&
mouse
.
y
<=
buttonWEIGHT
)
{
if
(
whichButton
!=
1
)
_beginthreadex
(
NULL
,
0
,
playMusic
,
music
+
button
,
0
,
NULL
);
whichButton
=
1
;
}
else
if
(
mouse
.
y
-
buttonUp
>=
0
&&
mouse
.
y
-
buttonUp
<=
buttonWEIGHT
)
{
if
(
mouse
.
x
>=
pastl
&&
mouse
.
x
<=
pastr
)
{
if
(
whichButton
!=
2
)
_beginthreadex
(
NULL
,
0
,
playMusic
,
music
+
button
,
0
,
NULL
);
whichButton
=
2
;
}
else
if
(
mouse
.
x
>=
nextl
&&
mouse
.
x
<=
nextr
)
{
if
(
whichButton
!=
3
)
_beginthreadex
(
NULL
,
0
,
playMusic
,
music
+
button
,
0
,
NULL
);
whichButton
=
3
;
}
else
whichButton
=
0
;
}
else
whichButton
=
0
;
if
(
mouse
.
uMsg
==
WM_LBUTTONDOWN
)
switch
(
whichButton
)
{
case
1
:
return
;
case
2
:
if
(
i
/
10
)
{
i
-=
i
%
10
+
11
;
flag
=
true
;
}
break
;
case
3
:
if
(
i
<
count
-
1
)
flag
=
true
;
break
;
}
}
}
rec
.
bottom
+=
textHeight
;
rec
.
top
+=
textHeight
;
}
cleardevice
();
}
\ No newline at end of file
Appearance.h
0 → 100644
View file @
0616cfc2
//
// Created by AMD on 2020/4/7.
//
#ifndef ZUMA_V1_0_APPEARANCE_H
#define ZUMA_V1_0_APPEARANCE_H
#include
<direct.h>
#include
<atlstr.h>
#include
<conio.h>
#include
<graphics.h>
#include
<windows.h>
#include
"Multi_tread.h"
#pragma comment(lib, "Winmm.lib")
#pragma comment(lib, "MSIMG32.LIB")
#define WINDOWWITH 800 //窗口的宽度
#define WINDOWHEIGHT 650 //窗口的高度
#define LifeDist 100 //扣除生命的半径
#define numOfMusic 7 //音乐数量
#define numOfMusOperate 3 //每个音乐操作的数量
#define MAX_COUNT 100 //排行榜总记录量
#define setPicRadius 60 //游戏主界面设置按钮长宽
#define setPicR 640 //设置条的右边界
#define newGameL 70 //新游戏左边界
#define newGameR 170 //新游戏右边界
#define ScoreL 190 //排行榜左边界
#define ScoreR 280 //排行榜右边界
#define endGameL 300 //结束游戏左边界
#define endGameR 420 //结束游戏右边界
#define setL 440 //设置左边界
#define setR 505 //设置右边界
#define nextl 540 //排行榜下一页按钮左边界
#define nextr 570 //排行榜下一页按钮右边界
#define pastl 230 //排行榜上一页按钮左边界
#define pastr 260 //排行榜上一页按钮右边界
#define buttonWEIGHT 30 //排行榜按钮直径
#define buttonUp 590 //排行榜翻页按钮上边界
#define recl 100 //排行榜矩形左边界
#define rankr 200 //排行榜rank列右边界
#define namer 600 //排行榜name列右边界
#define recr 700 // 排行榜矩形右边界
#define recu 125 // 排行榜矩形上边界
#define recd 565 //排行榜矩形下边界
#define textHeight 40 //排行榜每行文字占用宽度
//各种音频接口
enum
MusS
{
bgm
,
shoot
,
hurt
,
insert
,
erase
,
button
,
move
};
static
MusS
music
[
numOfMusic
]
=
{
bgm
,
shoot
,
hurt
,
insert
,
erase
,
button
,
move
};
const
static
CString
musics
[
numOfMusic
][
numOfMusOperate
]
=
{
{
"open .
\\
resource
\\
flower_dance.mp3 alias myMusic"
,
"play myMusic repeat"
,
"close myMusic"
},
{
"open .
\\
resource
\\
shoot.mp3 alias shoot"
,
"play shoot"
,
"close shoot"
},
{
"open .
\\
resource
\\
hurt.mp3 alias hurt"
,
"play hurt"
,
"close hurt"
},
{
"open .
\\
resource
\\
insert.wav alias insert"
,
"play insert"
,
"close insert"
},
{
"open .
\\
resource
\\
erase.mp3 alias erase"
,
"play erase"
,
"close erase"
},
{
"open .
\\
resource
\\
button.mp3 alias butMus"
,
"play butMus"
,
"close butMus"
},
{
"open .
\\
resource
\\
move.mp3 alias move"
,
"play move"
,
"close move"
}
};
//const CString load("open .\\resource\\flower_dance.mp3 alias myMusic"), play("play myMusic repeat"), close("close myMusic");
//const CString loadShoot("open .\\resource\\boom.mp3 alias shoot"), playShoot("play shoot"), closeShoot("close shoot");
//const CString loadHurt("open .\\resource\\hurt.mp3 alias hurt"), playHurt("play hurt"), closeHurt("close hurt");
//const CString loadIns("open .\\resource\\insert.mp3 alias insert"), playIns("play insert"), closeIns("close insert");
//const CString loadErase("open .\\resource\\erase.mp3 alias erase"), playErase("play erase"), closeErase("close erase");
//const CString loadBut("open .\\resource\\button.mp3 alias butMus"), playBut("play butMus"), closeBut("close butMus");
//const CString loadMov("open .\\resource\\move.mp3 alias move"), playMov("play move"), closeMov("close move");
//图片接口
const
static
CString
gameWallImg
(
".
\\
resource
\\
gamewall.jpg"
);
const
static
CString
difWallPaper
(
".
\\
resource
\\
wallpaper.jpg"
);
const
static
CString
setting
(
".
\\
resource
\\
setting.jpg"
);
const
static
CString
scorePic
(
".
\\
resource
\\
scores.jpg"
);
const
static
CString
posS
[
8
]
=
{
".
\\
resource
\\
0Odiff.png"
,
".
\\
resource
\\
1Odiff.png"
,
".
\\
resource
\\
2Odiff.png"
,
".
\\
resource
\\
3Odiff.png"
,
".
\\
resource
\\
0Xdiff.png"
,
".
\\
resource
\\
1Xdiff.png"
,
".
\\
resource
\\
2Xdiff.png"
,
".
\\
resource
\\
3Xdiff.png"
};
//定义颜色
const
static
COLORREF
ballColorTable
[]
=
{
0xffa2a2
/*类粉*/
,
0xfeff88
/*天蓝(PS中为黄色)*/
,
\
0x42ff00
/*草绿*/
,
0x71fff0
/*金黄(PS中为蓝色)*/
,
\
0xff0090
/*纯紫*/
,
0xde00ff
/*玫红*/
,
0xeadddf
/*银白*/
};
//按钮大小
typedef
struct
{
int
width
=
200
;
int
height
=
100
;
}
choiceButton
;
//定位按钮鼠标位置
int
findMouse
(
int
x
,
int
y
);
//显示透明png图片,将原图中纯白色消除
void
putTransPic
(
LPCTSTR
buffer
,
int
leftPos
,
int
upPos
,
int
width
,
int
height
,
\
int
leftPosOri
,
int
upPosOri
,
int
widthOri
,
int
heightOri
,
long
color
=
0xffffff
);
//显示难度选项
void
difChoicePic
(
int
order
[
8
]);
//显示欢迎界面
void
startGame
();
//设置选择难度
int
chooseDifficulty
();
//设置菜单
void
setMenu
();
//排行榜
void
scoreBoard
(
TCHAR
newName
[
MAX_COUNT
]
=
NULL
,
long
newNum
=
0
);
#endif //ZUMA_V1_0_APPEARANCE_H
HelixOperate.cpp
0 → 100644
View file @
0616cfc2
//
// Created by desktop on 2020/3/21.
//
//螺旋线函数
//void helix(double theta, float& xPos, float& yPos)
//{
// float rho = (3 * M_PI - theta) * (WINDOWWITH / (6 * M_PI));
// xPos = WINDOWWITH / 2 - rho * cos(theta);
// yPos = rho * sin(theta) / 2 + WINDOWHEIGHT / 2;
//}
//
//
////寻找下一个球心坐标
//bool nextHelixPos(float& x, float& y)
//{
// float xNex, yNex, dis;
// if ((pow(x - WINDOWWITH / 2, 2) + pow(y - WINDOWHEIGHT / 2, 2)) < 2500) return false;
// double thetaSmall, thetaMid, thetaLarge;
// thetaSmall = atan((y - WINDOWHEIGHT / 2) / (WINDOWWITH / 2 - x));
// if (thetaSmall <= 2 * M_PI) thetaLarge = thetaSmall + M_PI;
// else thetaLarge = 3 * M_PI;
// do
// {
// thetaMid = (thetaLarge + thetaSmall) / 2;
// helix(thetaMid, xNex, yNex);
// dis = (x - xNex) * (x - xNex) + (y - yNex) * (y - yNex) - 400;
// if (dis > 0 && x < xNex)
// thetaLarge = thetaMid;
// else thetaSmall = thetaMid;
// } while (abs(dis) >= 1 || x >= xNex);
// x = xNex;
// y = yNex;
// return true;
//}
//
////更新球链中球的位置
//int updateBallPos(Node* head)
//{
// Node* p = head;
// int numOfHurt = 0, index = 0;
// float xPos = 10;
// float yPos = WINDOWHEIGHT / 2;
// while (p->next != NULL)
// {
// p = p->next;
// p->data.x = xPos;
// p->data.y = yPos;
//
// if (!nextHelixPos(xPos, yPos))
// {
// numOfHurt++;
// ListDelete(head, index);
// }
// index++;
// }
// return 0;
//}
LinkList.cpp
0 → 100644
View file @
0616cfc2
#include
"LinkList.h"
/*
Args:
* None.
Return:
* Pointer of the head node.
Description:
* Create an empty linked list with a head node.
* The "next" field of the head node should point to NULL.
*/
Node
*
CreateEmptyList
()
{
Node
*
head
;
head
=
(
Node
*
)
malloc
(
sizeof
(
Node
));
head
->
next
=
NULL
;
head
->
past
=
NULL
;
return
head
;
}
/*
Args:
* addr: pointer of an array.
* n: length of the array.
Return:
* Pointer of the head node.
Description:
* Initialize a linked list with an array.
*/
Node
*
CreateList
(
DataType
*
addr
,
unsigned
int
n
)
{
Node
*
head
;
head
=
(
Node
*
)
malloc
(
sizeof
(
Node
));
head
->
next
=
NULL
;
for
(
unsigned
int
i
=
0
;
i
<
n
;
i
++
)
{
ListInsert
(
head
,
i
,
addr
[
i
]);
}
return
head
;
}
/*
Args:
* head: pointer of the head node.
Returns:
* None
Description:
* Destroy the linked list.
* Release all allocated memory.
*/
void
DestroyList
(
Node
*
head
)
{
Node
*
p
;
while
(
head
->
next
!=
NULL
)
{
p
=
head
->
next
;
free
(
head
);
head
=
p
;
}
free
(
head
);
}
/*
Args: