拼图游戏,C++与easyx实现
立即下载
资源介绍:
拼图游戏,C++与easyx实现
#include
#include
#include
#include
using namespace std;
int draw[10][10];
IMAGE YiLeiNa[100],YiReiNa, background_win;
void initdraw() {
int demp = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
draw[i][j] = demp;
demp++;
}
}
IMAGE img;
demp = 0;
loadimage(&img, ".\\image\\YILeiNa1.png");\
loadimage(&YiReiNa, ".\\image\\YILeiNa1.png", 400, 400);
putimage(0, 0, &img);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
getimage(&YiLeiNa[demp++], j * 75, i * 75, 75, 75);
}
}
cleardevice();
}
void randimage() {
for (int i = 0; i < 300; i++) {
//std::srand(std::time(0));
// 生成两个随机数
int random_number1 = std::rand()%100;
int random_number2 = std::rand()%100;
int temp = draw[random_number1 / 10][random_number1 % 10];
draw[random_number1 / 10][random_number1 % 10] = draw[random_number2 / 10][random_number2 % 10];
draw[random_number2 / 10][random_number2 % 10] = temp;
cout << random_number1 << " " << random_number2 << endl;
}
}
void drawallchain() {
for (int i = 0; i < 10; i++) {
setcolor(WHITE);
//上面的按钮
//line(50+i * 75 + 10, 10, 50+i * 75 + 65, 40);
line(50 + i * 75 + 10, 10, 50 + i * 75 + 65, 10);
line(50 + i * 75 + 65, 40, 50 + i * 75 + 65, 10);
line(50 + i * 75 + 10, 40, 50 + i * 75 + 65, 40);
line(50 + i * 75 + 10, 10, 50 + i * 75 + 10, 40);
line(50 + i * 75 + 15, 20, 50 + i * 75 + 37, 15);
line(50 + i * 75 + 60, 20, 50 + i * 75 + 37, 15);
line(50 + i * 75 + 15, 30, 50 + i * 75 + 37, 25);
line(50 + i * 75 + 60, 30, 50 + i * 75 + 37, 25);
//下面的按钮
line(50 + i * 75 + 10, 10 + 800, 50 + i * 75 + 65, 10 + 800);
line(50 + i * 75 + 65, 40 + 800, 50 + i * 75 + 65, 10 + 800);
line(50 + i * 75 + 10, 40 + 800, 50 + i * 75 + 65, 40 + 800);
line(50 + i * 75 + 10, 10 + 800, 50 + i * 75 + 10, 40 + 800);
line(50 + i * 75 + 15, 15 + 800, 50 + i * 75 + 37, 25 + 800);
line(50 + i * 75 + 60, 15 + 800, 50 + i * 75 + 37, 25 + 800);
line(50 + i * 75 + 15, 25 + 800, 50 + i * 75 + 37, 35 + 800);
line(50 + i * 75 + 60, 25 + 800, 50 + i * 75 + 37, 35 + 800);
//左边的按钮
line(10, 50 + i * 75 + 10, 10, 50 + i * 75 + 65);
line(40, 50 + i * 75 + 10, 40, 50 + i * 75 + 65);
line(10, 50 + i * 75 + 10, 40, 50 + i * 75 + 10);
line(10, 50 + i * 75 + 65, 40, 50 + i * 75 + 65);
line(20, 50 + i * 75 + 15, 15, 50 + i * 75 + 37);
line(20, 50 + i * 75 + 60, 15, 50 + i * 75 + 37);
line(30, 50 + i * 75 + 15, 25, 50 + i * 75 + 37);
line(30, 50 + i * 75 + 60, 25, 50 + i * 75 + 37);
//左边的按钮
line(10 + 800, 50 + i * 75 + 10, 10 + 800, 50 + i * 75 + 65);
line(40 + 800, 50 + i * 75 + 10, 40 + 800, 50 + i * 75 + 65);
line(10 + 800, 50 + i * 75 + 10, 40 + 800, 50 + i * 75 + 10);
line(10 + 800, 50 + i * 75 + 65, 40 + 800, 50 + i * 75 + 65);
line(15 + 800, 50 + i * 75 + 15, 25 + 800, 50 + i * 75 + 37);
line(15 + 800, 50 + i * 75 + 60, 25 + 800, 50 + i * 75 + 37);
line(25 + 800, 50 + i * 75 + 15, 35 + 800, 50 + i * 75 + 37);
line(25 + 800, 50 + i * 75 + 60, 35 + 800, 50 + i * 75 + 37);
}
for (int i = 0; i < 11; i++) {
setcolor(BLACK);
line(i * 75 + 50, 50, i * 75 + 50, 850);
line(50, i * 75 + 50, 850, i * 75 + 50);
}
}
static void drawImage() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
putimage(50 + j * 75, 50 + i * 75, &YiLeiNa[draw[i][j]]);
}
}
putimage(875, 25, &YiReiNa);
drawallchain();
}
void Operate() {
if (MouseHit()) {
MOUSEMSG msg = GetMouseMsg();
if (msg.uMsg == WM_LBUTTONDOWN) {
for (int i = 0; i < 10; i++) {
if (msg.x <= 50 + i * 75 + 65 && msg.x >= 50 + i * 75 + 10 && msg.y <= 40 && msg.y >= 10) {
int temp = draw[0][i];
for (int j = 0; j < 9; j++) {
draw[j][i] = draw[j + 1][i];
}
draw[9][i] = temp;
}
if (msg.x <= 50 + i * 75 + 65 && msg.x >= 50 + i * 75 + 10 && msg.y <= 840 && msg.y >= 810) {
int temp = draw[9][i];
for (int j = 9; j >0; j--) {
draw[j][i] = draw[j - 1][i];
}
draw[0][i] = temp;
}
if (msg.y <= 50 + i * 75 + 65 && msg.y >= 50 + i * 75 + 10 && msg.x <= 40 && msg.x >= 10) {
int temp = draw[i][0];
for (int j = 0; j < 9; j++) {
draw[i][j] = draw[i][j + 1];
}
draw[i][9] = temp;
}
if (msg.y <= 50 + i * 75 + 65 && msg.y >= 50 + i * 75 + 10 && msg.x <= 840 && msg.x >= 810) {
int temp = draw[i][9];
for (int j = 9; j > 0; j--) {
draw[i][j] = draw[i][j - 1];
}
draw[i][0] = temp;
}
}
}
}
}
bool panduan() {
int temp = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (draw[i][j] != temp) {
return 0;
}
temp++;
}
}
return 1;
}
void jiemian_win() {
loadimage(&background_win, ".\\image\\win.jpg", 700, 700);
putimage(300, 75, &background_win);
setbkmode(TRANSPARENT);
setcolor(BLACK);
//setcolor(WHITE);
outtextxy(500, 575, _T("真棒,我就知道你能行!!"));
Sleep(5000);
}
int main()
{
std::srand(std::time(0));
initgraph(1300, 850);
//jiemian_win();
//initgraph(1300, 850, EX_SHOWCONSOLE);
initdraw();
drawImage();
randimage();
drawallchain();
while (1) {
BeginBatchDraw();
cleardevice();
drawImage();
Operate();
if (panduan()) {
break;
}
EndBatchDraw();
}
cleardevice();
jiemian_win();
return 0;
}