#pragma warning(disable : 4996)
#include<graphics.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
IMAGE img[6]; //6張
//分析推箱子
//二維陣列充當地圖
//0:背景,1:障礙,3:武器,4:將軍,5:公主,7:怪物
int map[8][8]=
{
1,1,1,1,1,1,1,1,
1,0,0,0,3,0,0,1,
1,0,1,0,1,1,0,1,
1,0,1,1,5,0,0,1,
1,4,0,0,0,0,0,1,
1,1,1,1,1,1,1,1
};
//載入資源:初始化變數
void loadResource()
//重複有規律的事情,採用迴圈
//沒有規律,創造規律
int imgIndex[6] = { 0,1,3,4,5,7 };
//imgIndex[i].png;
for (int i=0; i<6; i++)
char fileName[20] = "";
sprintf(fileName, "%d,png", imgIndex[i]); //fileName=0.png
loadimage(img+i,fileName);
}
//批次載入
//繪製地圖:陣列的知識--->一個蘿蔔一個坑
void drawGraph()
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
int x = 64 * j;
int y = 64 * i;
switch ((map[i][j]))
case 0:putimage(x, y, img + 0);
break;
case 1:putimage(x, y, img + 1);
case 3:putimage(x, y, img + 2);
case 4:putimage(x, y, img + 3);
case 5:putimage(x, y, img + 4);
case 7:putimage(x, y, img + 5);
//玩遊戲:按鍵互動
int main()
/*
4.1 拿到素材
4.2 建立一個C++環境的專案
4.3 把素材放到當前專案目錄下
4.4 寫一個最簡單的圖形化視窗
*/
initgraph(64 * 8, 64 * 8);
loadResource();
drawGraph();
_getch();
closegraph();
return 0;
#pragma warning(disable : 4996)
#include<graphics.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
IMAGE img[6]; //6張
//分析推箱子
//二維陣列充當地圖
//0:背景,1:障礙,3:武器,4:將軍,5:公主,7:怪物
int map[8][8]=
{
1,1,1,1,1,1,1,1,
1,0,0,0,3,0,0,1,
1,0,1,0,1,1,0,1,
1,0,1,1,5,0,0,1,
1,0,1,0,1,1,0,1,
1,0,1,0,1,1,0,1,
1,4,0,0,0,0,0,1,
1,1,1,1,1,1,1,1
};
//載入資源:初始化變數
void loadResource()
{
//重複有規律的事情,採用迴圈
//沒有規律,創造規律
int imgIndex[6] = { 0,1,3,4,5,7 };
//imgIndex[i].png;
for (int i=0; i<6; i++)
{
char fileName[20] = "";
sprintf(fileName, "%d,png", imgIndex[i]); //fileName=0.png
loadimage(img+i,fileName);
}
//批次載入
}
//繪製地圖:陣列的知識--->一個蘿蔔一個坑
void drawGraph()
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
int x = 64 * j;
int y = 64 * i;
switch ((map[i][j]))
{
case 0:putimage(x, y, img + 0);
break;
case 1:putimage(x, y, img + 1);
break;
case 3:putimage(x, y, img + 2);
break;
case 4:putimage(x, y, img + 3);
break;
case 5:putimage(x, y, img + 4);
break;
case 7:putimage(x, y, img + 5);
break;
}
}
}
}
//玩遊戲:按鍵互動
int main()
{
/*
4.1 拿到素材
4.2 建立一個C++環境的專案
4.3 把素材放到當前專案目錄下
4.4 寫一個最簡單的圖形化視窗
*/
initgraph(64 * 8, 64 * 8);
loadResource();
drawGraph();
_getch();
closegraph();
return 0;
}