OS:win7(64bit),Vc++2008 Dxライブラリ環境にて作成した物ですが、map_walk()にて再帰処理されずにそのまま抜けてしまう状態です。
戻り値の宣言(voidでの宣言)がおかしいのかな?と推察したのですがmap_walk( x,y, hosuu);と宣言するとビジー状態になったり
int map_walk(int,int,int);等いくつか試したのですがコンパイルが通らなかったりと意図した通りに動きません。
9/6からC++の勉強を始め、まだ日も浅く書式や文法が分からないので、引数と戻り値がある時の宣言の仕方をお教えては頂けないでしょうか?
意図:波状走査開始地点(x,y)から障害物・壁(99)を避けて通った歩数をmw[12][12]に収める
#include "DxLib.h"
#include <math.h>
//速度調整
int g_lastcalltime = 0;
float g_frametime = 0;
//プロトタイプ宣言
void Getpointer();
void Map_Line_Print();
void Map_enemy_move();
void Map_myship_move();
void m_map_sea();
void m_map_sea2();
void map_walk(int, int, int);
int timetime=0;
int Sx , Sy , Cb ;
int pointerx=0;
int pointery=0;
//マップ処理
//マップデータ(y-xに注意)
int mapgridx = 12;
int mapgridy = 12;
int mappoint[12][12]={
{1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1},//2列目
{1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0},
{1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0},
{1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0},
{1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1},//6
{0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1},
{0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1},//8
{0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1},
{0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1},//10
{0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1},
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}};
int map_enemyx=1,map_enemyy=0;
//マップサーチ用変数
int i,j,color;
int mw[12][12]={{},{},{},{},{},{},{},{},{},{},{},{}};
int map_enemy_targetx=6, map_enemy_targety=1;
int x=map_enemy_targetx;
int y=map_enemy_targety;
int hosuu=0;
int flag =1;
// プログラムは WinMain から始まります
int WINAPI WinMain( HINSTANCE hI, HINSTANCE hP, LPSTR lpC, int nC){
ChangeWindowMode(TRUE);
if( DxLib_Init() == -1 ) return -1; // エラーが起きたら直ちに終了
/* メイン処理 */
g_lastcalltime = GetNowCount() & INT_MAX;
SetDrawScreen(DX_SCREEN_BACK);
while(ProcessMessage() == 0 ){
//現在時間を計測
int curtime = GetNowCount() & INT_MAX;
int curinterval =
curtime - g_lastcalltime;
ClsDrawScreen();
//1ループにかかった時間(秒数)を求める
g_frametime = (float)(curinterval) / 1000.0f;
//メイン処理
Getpointer();
Map_Line_Print();
m_map_sea();
m_map_sea2();
if(flag == 1){
map_walk(x,y, hosuu);
}
/* メインループここまで*/
ScreenFlip();
}
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}
void Getpointer(){
int Cr = GetColor( 255 , 255 , 255 ); // 白色の値を取得
for(i = 0; i < mapgridx+1; ++i){
for(j = 0; j < mapgridy+1; j++){
DrawLine( i*32, j*32, Sx, j*32, Cr);
DrawLine( i*32, j*32, i*32, Sy, Cr);
}
}
}
//壁扱いの要素(1)を表示
void Map_Line_Print(){
int color = GetColor( 255 , 0 , 0 );
for(int i = 0; i < mapgridx; i++){
for(int j = 0; j < mapgridy; j++){
if(mappoint[i][j]==1){
DrawFormatString( j*32, i*32, color, "壁");
DrawFormatString( j*32, i*32+16, color, "%d-%d", j,i);
}
}
}
}
//初期配列mappoint[][]の要素(1)を要素(99)へ変換
void m_map_sea(){
color = GetColor( 255 , 0 , 0 );
for(i = 0; i < mapgridx; i++){
for(j = 0; j < mapgridy; j++){
if(mappoint[i][j]==1){
mw[i][j]=99;
}
}
}
}
//配列mw[][]の内容表示
void m_map_sea2(){
color = GetColor( 0, 255 , 0 );
for(i = 0; i < mapgridx; i++){
for(j = 0; j < mapgridy; j++){
DrawFormatString( j*32+16, i*32, color, "%d", mw[i][j]);
}
}
}
void map_walk( int, int, int){
color = GetColor( 0 , 0, 200 );
DrawFormatString( x*32+16, y*32, color, "%d", hosuu);
flag=0;
hosuu=hosuu+1;
if( 0 < y || mw[y-1][x] !=99){
if( mw[y-1][x] == 0 || mw[y-1][x] > hosuu){
mw[y-1][x] = hosuu;
map_walk( x, y-1, hosuu+1);
hosuu=hosuu-1;
}
}
if( 11 < y || mw[y+1][x] !=99){
if( mw[y+1][x] == 0 || mw[y+1][x] > hosuu){
mw[y+1][x] = hosuu;
map_walk( x,y+1, hosuu+1);
hosuu=hosuu-1;
}
}
if( 0 > x || mw[y][x-1] !=99){
if( mw[y][x-1] == 0 || mw[y][x-1] > hosuu){
mw[y][x-1]= hosuu;
map_walk( x-1,y, hosuu+1);
hosuu=hosuu-1;
}
}
if( 11 > x || mw[y][x+1] !=99){
if( mw[y][x+1] == 0 || mw[y][x+1] > hosuu){
mw[y][x+1] = hosuu;
map_walk( x+1, y, hosuu+1);
hosuu=hosuu-1;
}
}
}