https://dianxnao.com/c%E8%A8%80%E8%AA%9 ... %E3%83%A0/
今エラーが出ているのはソースコードのmain関数の中の二次元配列に数値を代入し、ステージの骨格を決めるところなのですが二次元配列のmap[GYO][RETU]=の直後の{で
expected expression before '{' token
というエラーが出ていますが何が原因であるかがわかりません
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define GYO 10
#define RETU 10
struct Map{
int map[GYO][RETU];
};
int px, py; //プレイヤーの座標
int goalcount;
int count;
void reset(int select,struct Map *pstage){
int x, y;
count = 0;
px = 1;
py = 1;
for(y=0; y<GYO; y++)
for(x=0; x<RETU; x++)
if((pstage+(select-1))->map[y][x] == 2) (pstage+(select-1))->map[y][x] = 0; // 塗りつぶし部分をもとに戻す
}
// 塗りつぶすべき床の数をカウントする
void goal_check(int select,struct Map *pstage){
int x, y;
goalcount = 0;
for(y=0; y<GYO; y++)
for(x=0; x<RETU; x++)
if((pstage+(select-1))->map[y][x] == 0) goalcount++; // 移動可能な床の数をカウント
}
// 迷路を描く
void draw_map(int select,struct Map *pstage){
int x, y;
for(y=0; y<GYO; y++){
for(x=0; x<RETU; x++){
if(x == px && y == py){ // プレイヤーの位置のとき
(pstage+(select-1))->map[y][x] = 2; // 塗りつぶし済みにする
count ++; // 塗りつぶした数をカウント
printf("★"); // プレイヤー
}
else if((pstage+(select-1))->map[y][x] == 0) // 移動可能な床
printf(" "); //全角スペース
else if((pstage+(select-1))->map[y][x] == 1) // 壁
printf("■");
else if((pstage+(select-1))->map[y][x] == 2) // 塗った床
printf("○");
}
printf("\n");
}
printf("move: ←↑→↓ restart: ESC\n"); /* 操作説明 */
}
void key_input(int select,struct Map *pstage){
int key;
while (1) { // キーが押されるまで待つ
if ( kbhit() ){
key = getch(); //入力されたキー番号
break ;
}
}
if(key == 72 && (pstage+(select-1))->map[py-1][px] == 0) // ↑キー入力
py --;
else if(key == 80 && (pstage+(select-1))->map[py+1][px] == 0) // ↓キー入力
py ++;
else if(key == 75 && (pstage+(select-1))->map[py][px-1] == 0) // ←キー入力
px --;
else if(key == 77 && (pstage+(select-1))->map[py][px+1] == 0) // →キー入力
px ++;
else if(key == 27) // ESCキー
reset(select,pstage);
else
key_input(select,pstage);
}
int main(void){
int select;
struct Map stage[2];
struct Map *pstage;
stage[0].map[GYO][RETU]=
{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 1, 0, 0, 1},
{1, 0, 1, 1, 1, 0, 1, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 1, 0, 1, 1},
{1, 1, 0, 0, 1, 1, 1, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 0, 1},
{1, 1, 0, 0, 0, 1, 0, 0, 0, 1},
{1, 1, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
stage[1].map[GYO][RETU]=
{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 0, 1, 0, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 0, 1, 0, 0, 0, 1, 1},
{1, 0, 1, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 1, 1, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 0, 0, 0, 1, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
stage[2].map[GYO][RETU]=
{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 1, 0, 0, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 1, 1},
{1, 0, 0, 0, 1, 1, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 0, 1, 0, 1, 1, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 0, 0, 0, 1, 0, 0, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
pstage=stage;
while(1){
printf("ステージを1~3で選んでください");
scanf("%d",&select);
if(select==1 || select==2 || select==3){
break;
}else{
printf("正しく入力してください");
}
}
px = 1;
py = 1;
count = 0;
goal_check(select,pstage); // 塗りつぶすべき床の数をカウントする
// ゲームループ
while(1){
system("cls"); // コンソール画面をクリア
draw_map(select,pstage); // 迷路を表示
if(count == goalcount){ //床を全て塗りつぶしたかのチェック
printf("全て塗りました!\n");
break;
}
key_input(select,pstage); //キー入力受付
}
return 0;
}