今回は移動先のマスに敵キャラが居るかどうかの判定処理なのですが、コンパイルすると
エラー E2227 last4.cpp 75: there() の呼び出しに余分なパラメータがある(関数 main() )
とエラーを返されてしまいます。同じエラーが4ヶ所分出ております。
敵キャラ側の判定の関数は以降作るとして、今回は何が原因なのでしょうか…。
お手数ですが教えていただきたいです。
関数thereに引数として渡された座標(x,y)座標に敵がいるかどうかチェックし、いれば1,いなければ0を返す形の関数です。
#include <stdio.h>
#include <stdlib.h> //system構文のため
#include <conio.h> //kbhit構文のため
#include <time.h> //モンスター用
void title(void); //タイトル表示
char charamake(void); //名前設定
void danjonmap(); //マップ描画
char there(); //主人公と敵のすれ違い阻止
// 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, hp, potion;
};
struct mons{ //モンスターの構造体宣言
int id, level, x, y, hp, attack, move, search;
};
struct chara pc = {"", 0, 1, 0, 100, 2};
struct mons inp = {0, 0, 9, 8, 1, 5, 1, 1};
int main(void){
char res = 'n';
char zhjkl;
int key;
int mons;
int i;
int damage;
srand(time(NULL));
title();
while (res != 'y'){
res = charamake();
}
system("cls");
danjonmap();
while (1){ //移動処理とゴール処理,ゲームオーバー判定
if (pc.hp <= 0){
printf("%s「もう、体力が…。」\n\nGAMEOVER\n",pc.name);
break;
}
if (kbhit()){
key = getch();
if (key ==119) { //w
if((pc.y >= 1) &&(danjon[pc.stage][pc.x][pc.y-1] != 1) && there(pc.x, pc.y-1) == 0) pc.y --;
}
if (key ==120) { //x
if((pc.y <= 8) &&(danjon[pc.stage][pc.x][pc.y+1] != 1) && there(pc.x, pc.y+1) == 0) pc.y ++;
}
if (key ==97) { //a
if((pc.y >= 1) &&(danjon[pc.stage][pc.x-1][pc.y] != 1) && there(pc.x-1, pc.y) == 0) pc.x --;
}
if (key ==100) { //d
if((pc.y <= 8) &&(danjon[pc.stage][pc.x+1][pc.y] != 1) && there(pc.x+1, pc.y) == 0) pc.x ++;
}
//モンスターのターン
if(((pc.x == inp.x) && (pc.y == inp.y -1)) || //モンスターからの索敵
((pc.y == inp.y) && (pc.x == inp.x + 1)) ||
((pc.x == inp.x) && (pc.y == inp.y + 1)) ||
((pc.y == inp.y) && (pc.x == inp.x - 1))){
printf("インプ「%sがいたぞ!」", pc.name);
getch();
i = rand() %100 + 1; //モンスターの攻撃
if (i <= inp.attack * 10) {
damage = rand() % inp.attack + 1;
printf("インプの攻撃を受けた(%dダメージ)\n", damage);
getch();
pc.hp -= damage;
}
else {
printf("インプの攻撃は外れた(乱数=%d:攻撃力=%d)", i, inp.attack);
}
getch();
}
mons = rand()%4; //モンスター移動処理、0:上 1:右 2:下 3:左
switch (mons){
case 0: //上
if((inp.y >= 1) && (danjon[pc.stage][inp.x][inp.y-1] != 1)) inp.y--;
break;
case 2: //下
if((inp.y <= 8) && (danjon[pc.stage][inp.x][inp.y+1] != 1)) inp.y++;
break;
case 3: //左
if((inp.x >= 1) && (danjon[pc.stage][inp.x-1][inp.y] != 1)) inp.x--;
break;
case 1: //右
if((inp.x <= 8) && (danjon[pc.stage][inp.x+1][inp.y] != 1)) inp.x++;
break;
default:
printf("変数monsの値が想定外です:%d", mons);
break;
}
danjonmap();
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("迷路\n\n");
}
char charamake(void){ //名前設定
char yesno;
printf("主人公の名前をいれてね:");
scanf("%s", pc.name);
printf("「%s」でよろしいですか?(y/n)", pc.name);
scanf("%*c%c", &yesno);
return yesno;
}
void danjonmap(){ //画面表示
int i, j;
system("cls");
for(j = 0; j < 10; j++){
for(i = 0; i < 10; i++){
if(i == pc.x && j == pc.y) printf("☆");
else if (i == inp.x && j == inp.y) printf("敵");
else if (danjon[pc.stage][i][j] == 0) printf("□");
else if (danjon[pc.stage][i][j] == 2) printf("〓");
else printf("■");
}
switch(j) { //ステータス・システム
case 0:
printf(" --------------------");
break;
case 1:
printf(" * 現在位置:地下%d階", pc.stage+1);
break;
case 2:
printf(" * 名 前:%s", pc.name);
break;
case 3:
printf(" * 体 力:%d", pc.hp);
break;
case 4:
printf(" * アイテム:%d", pc.potion);
break;
case 7:
printf(" --------------------");
break;
}
printf("\n");
}
}
char there(int x, int y){
if((inp.x == x) && (inp.y == y)) return 1;
else return 0;
}