推箱子控制台 贴图 显示黑屏
最近,编推箱子的时候想给每个元素贴对应的图,可控制台运行时发现是黑屏,不知道是怎么了?程序代码:
#include<stdio.h> #include<conio.h> #include<Windows.h> #include<graphics.h> #include<stdlib.h> #pragma comment(lib, "winmm.lib") int map[9][11] = { {0,1,1,1,1,1,1,1,1,1,0}, {0,1,0,0,0,1,0,0,0,1,0}, {0,1,0,4,4,4,4,4,0,1,0}, {0,1,0,4,0,4,0,4,0,1,1}, {0,1,5,0,0,0,0,0,4,0,1}, {1,1,0,1,1,1,1,0,4,0,1}, {1,0,3,3,3,3,3,1,0,0,1}, {1,0,3,3,3,3,3,0,0,1,1}, {1,1,1,1,1,1,1,1,1,1,0} }; IMAGE box, wall, redbox, people, blank, end, pbox; void DrawMap() { for (int i = 0; i < 9; i++) { for (int j = 0; j < 11; j++) { switch (map[i][j]) { case 0: putimage(i * 50, j * 50, &blank); //putimage(i * 50, j * 50, &blank); //空地 break; case 1: putimage(i * 50, j * 50, &wall); //墙 break; case 3: putimage(i * 50, j * 50, &end); //目的地 break; case 4: putimage(i * 50, j * 50, &box); //箱子 break; case 5: putimage(i * 50, j * 50, &people); //人 break; case 7: putimage(i * 50, j * 50, &redbox); //箱子和目的地重合 break; case 8: putimage(i * 50, j * 50, &pbox);//人和目的地重合 break; } } printf("\n"); } } void PlayGame() { char key; //保存按键的值 int r, c; //保存人的下标 //获取人的位置 for (int i=0;i<9;i++) for (int j = 0; j < 11; j++) { if (map[i][j] == 5 || map[i][j] == 8) { r = i; c = j; } } key = _getch(); //接受键盘按键 switch (key) { case 72: //up //map[r][c] map[r-1][c] //1.人的前面是空地 2.人的前面是目的地 if (map[r - 1][c] == 0 ||map[r-1][c]==3) { map[r - 1][c] += 5; map[r][c] -= 5; } //3.人的前面是箱子 不一定 //3.1箱子的前面是空地 //3.2箱子的前面是目的地 if (map[r - 1][c] == 4 || map[r - 1][c] == 7) { if (map[r - 2][c] == 0 || map[r - 2][c] == 3) { map[r - 2][c] += 4; map[r - 1][c] += 1; map[r][c] -= 5; } } break; case 80: //down if (map[r + 1][c] == 0 || map[r + 1][c] == 3) { map[r + 1][c] += 5; map[r][c] -= 5; } if (map[r + 1][c] == 4 || map[r + 1][c] == 7) { if (map[r + 2][c] == 0 || map[r + 2][c] == 3) { map[r + 2][c] += 4; map[r + 1][c] += 1; map[r][c] -= 5; } } break; case 75: // left if (map[r][c-1] == 0 || map[r][c-1] == 3) { map[r][c-1] += 5; map[r][c] -= 5; } if (map[r][c-1] == 4 || map[r][c-1] == 7) { if (map[r][c-2] == 0 || map[r][c-2] == 3) { map[r][c-2] += 4; map[r][c-1] += 1; map[r][c] -= 5; } } break; case 77: // right if (map[r][c + 1] == 0 || map[r][c + 1] == 3) { map[r][c + 1] += 5; map[r][c] -= 5; } if (map[r][c + 1] == 4 || map[r][c + 1] == 7) { if (map[r][c + 2] == 0 || map[r][c + 2] == 3) { map[r][c + 2] += 4; map[r][c + 1] += 1; map[r][c] -= 5; } } break; } } int main(void) { initgraph(450, 550); loadimage(&box, L"./box.jpg", 50, 50); loadimage(&redbox, L"./redbox.jpg", 50, 50); loadimage(&people, L"./people.jpg", 50, 50); loadimage(&wall, L"./wall.jpg", 50, 50); loadimage(&blank, L"./blank.jpg", 50, 50); loadimage(&end, L"./end.jpg", 50, 50); loadimage(&pbox, L"./pbox.jpg", 50, 50); // mciSendString(L"open fade.mp3", 0, 0, 0); DrawMap(); //mciSendString(L"play",0,0,0); while (1) { //system("cls"); //cleardevice(); DrawMap(); PlayGame(); } //EndBatchDraw(); closegraph(); return 0; }
我已经装了easyx了;