学習を始めたばかりなので、C言語の知識は浅いです。
課題でローグライクRPGを作っているのですが、ダンジョンの描画が上手く行かずに困っています。
コンパイルすると、
・11行目:'danjon(int, int, int)' の再宣言で型が一致していない
・11行目:宣言の構文エラー
・61,64,67,70行目:それぞれに'void(int, int, int)'型のサイズは未知あるいはゼロ
というエラーが主に出るのですが、何が原因なのでしょうか。
OSはWindows7、コンパイラはCPad for Borland C++Compilerです。
以下が書いてみたソースコードです。宜しくお願いします。
#include <stdio.h>
#include <stdlib.h> //system構文のため
#include <conio.h> //kbhit構文のため
void title(void);
char charamake(void);
void danjon(int, int, int);
// 0:移動可能 1:壁 2:ゴール
char danjon[2][10][10] ={{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 0, 1, 1, 1, 1, 0, 1},
{1, 0, 0, 0, 1, 0, 0, 0, 0, 1},
{1, 0, 1, 1, 1, 0, 1, 0, 0, 1},
{1, 0, 0, 1, 0, 0, 0, 0, 0, 1},
{1, 1, 2, 1, 0, 1, 0, 0, 0, 1},
{1, 0, 1, 1, 0, 0, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}},
{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 1, 0, 0, 0, 1, 0, 2, 1},
{1, 0, 1, 0, 1, 0, 1, 0, 1, 1},
{1, 0, 1, 0, 0, 0, 1, 0, 0, 1},
{1, 0, 1, 0, 0, 0, 1, 1, 0, 1},
{1, 0, 1, 0, 0, 0, 0, 1, 0, 1},
{1, 0, 1, 0, 0, 1, 0, 0, 0, 1},
{1, 0, 1, 0, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}};
struct chara{
char name[5];
int stage, x, y;
};
struct chara pc = {"", 0, 1, 0};
int main(void){
char res = 'n';
char zhjkl;
int key;
int i;
title();
while (res ! = 'y'){
res = charamake();
}
system("cls");
danjon(pc.stage, pc.x, pc.y);
while (1){ //移動処理とゴール処理
if (kbhit()){
key = getch();
if (key ==119) { //w
if((pc.y >= 1) &&(danjon[pc.stage][pc.x][pc.y-1] ! = 1)) pc.y --;
}
if (key ==120) { //s
if((pc.y <= 8) &&(danjon[pc.stage][pc.x][pc.y+1] ! = 1)) pc.y ++;
}
if (key ==97) { //a
if((pc.y >= 1) &&(danjon[pc.stage][pc.x-1][pc.y] ! = 1)) pc.x --;
}
if (key ==100) { //d
if((pc.y <= 8) &&(danjon[pc.stage][pc.x+1][pc.y] ! = 1)) pc.x ++;
}
danjon(pc.stage, pc.x, pc.y);
if((danjon[pc.stage][pc.x][pc.y] == 2) && (pc.stage < 1)){
printf("%s「ゴール!」\n(次のステージへ進みます【Enter】",pc.name
while (1){
if (kbhit()){
pc.stage++;
break;
}
}
}
}
}
}
void title(void){ //タイトル画面
system("cls");
printf("迷路");
}
char charamake(void){ //名前設定
char yesno;
printf("主人公の名前をいれてね:");
scanf("%s", pc.name);
printf("「%s」でよろしいですか?(y/n)", pc.name);
scanf("%c%c", &yesno);
return yesno;
}
void danjon(int stage, int x, int y){
int i, j;
system("cls");
for(j = 0; j < 10; j++){
for(1 = 0; i < 10; i++){
if(i == x && j == y) printf("☆");
else if (danjon[pc.stage][i][j] == 0) printf("□");
else if (danjon[pc.stage][i][j] == 2) printf("〓");
else printf("■");
}
printf("\n");
}
}