前提・実現したいこと
配列が上手に代入できないかもしれない。また思った通りに表示できない。
コメントアウトのようになり、本当はキャラクターが迷路を通過していくようにしたいのですが、迷路の手前で消えてしまいます。厳密にいうと迷路の再右端で終わりなのですが。どうしたらよいでしょうか?
発生している問題・エラーメッセージ
上記に同じ
該当のソースコード
/* ■■■■■■■■ ■ ○■ ■ ¥ ¥ ■■ ■ ■ 三 (` ・ ω・´) ■ ■ ■■■ (O TO ) ■ ■■ ■ 三 - ◎J◎◎ ■ ■■■ ■ ■ ■★■ ■■■■■■■■ ←A →D ↑W ↓S>s ime:4(s) ■■■■■■■■ ■ ■ ■ ¥ ■■○ ■ ■ 三 (` ・ ω ■ ■ ■■■ (O T ■ ■■ ■ 三 - ◎J◎ ■ ■■■ ■ ■ ■★■ ■■■■■■■■ キャラクターが迷路を通過していかないのはどうしてでしょうか? */ #include <stdio.h> #include <time.h> #define SIZE1 8 #define SIZE2 25 void disp_maze(int ar_x, int ar_y, int map[][SIZE2], int ar_time); clock_t t1, t2; int main(void) { char key, ch; int plx = 18, ply = 1; static int t3; int map[SIZE1][SIZE2] = { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1 }, { 0,0,0,0,3,0,0,3,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,1 }, { 5,0,6,7,0,8,9,8,10,11,0,0,0,0,0,0,0,1,0,0,1,0,1,1,1 }, { 0,0,0,0,6,12,13,12,11,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0,1 }, { 0,5,0,14,15,16,15,15,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,1 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,2,1 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1 } }; printf("キーボードを入力した直後始まります.\n"); ch = getchar(); printf("よーいスタート!!\n\n"); t1 = clock(); while (1) { t2 = clock(); if ((t2 - t1) / CLOCKS_PER_SEC >= 5) break;//ゲーム終了条件(時間切れ)continue用 printf("Time:%d(s)\n\n",5-(t2-t1)/CLOCKS_PER_SEC); disp_maze(plx, ply, map, (t2-t1)/CLOCKS_PER_SEC); printf("←A →D ↑W ↓S>"); key = getchar(); ch = getchar(); if ((t2-t1)/CLOCKS_PER_SEC >= 5) break;//ゲーム終了条件(時間切れ) if (plx <= 9 + 3*(t2 - t1)/CLOCKS_PER_SEC)break;//ゲーム終了条件(迷路崩壊の被害) if (key == 'a') { if (map[ply][plx - 1] ==1) { printf("×Miss!\n"); continue; } else { plx--; } } else if (key == 'd') { if (map[ply][plx + 1] ==1) { printf("×Miss!\n"); continue; } else { plx++; } } else if (key == 'w') { if (map[ply - 1][plx] ==1) { printf("×Miss!\n"); continue; } else { ply--; } } else if (key == 's') { if (map[ply + 1][plx] ==1) { printf("×Miss!\n"); continue; } else { ply++; } } else { printf("×Miss!\n"); continue; } if (map[ply][plx] == 2) break;//ゲーム終了条件 } if ((t2 -t1)/CLOCKS_PER_SEC >= 5)printf("時間切れです.\tGame Over\n"); else if (plx <= 9 + 3*(t2 - t1)/CLOCKS_PER_SEC)printf("迷路崩壊に巻き込まれました.\tGame Over\n"); else printf("Stage Clear!!\n"); return 0; } void disp_maze(int ar_x, int ar_y, int ar_map[][SIZE2], int ar_time) { int counta; int countb; int count = ar_time; int position = 9;//ar_mapは常にリセットされるので、移動物の再右端は変わらない. if (count > 0) { for (counta = 0; counta < 8; counta++) { for (countb = position; countb >= 0; countb--) { ar_map[counta][countb + 3 * count ] = ar_map[counta][countb];//右に時間数*3ずつ移動していく. ar_map[counta][countb] = 0; } } } for (counta = 0; counta < 8; counta++) { for (countb = 0; countb < 25; countb++) { if (counta == ar_y && countb == ar_x) { printf("○"); } else { switch (ar_map[counta][countb]) { case 1: printf("■"); break; case 2: printf("★"); break; case 0: printf(" "); break; case 3: printf("¥"); break; case 4: printf("_ "); break; case 5: printf("三"); break; case 6: printf(" ("); break; case 7: printf("`"); break; case 8: printf("・"); break; case 9: printf(" ω"); break; case 10: printf("´"); break; case 11: printf(") "); break; case 12: printf("O "); break; case 13: printf("T"); break; case 14: printf("- "); break; case 15: printf("◎"); break; case 16: printf("J"); break; } } } printf("\n"); } }
試したこと
補足情報(FW/ツールのバージョンなど)
visual studio
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/04 13:08