テストプロジェクト名:
空間制御飛ぶ鳥と
II。パイロットプロジェクトの説明:
スペースコントロール、鳥の飛行ゲームは失敗し、0または1選択ゲームを再起動するかどうかを決定しています
III。プロジェクトのモジュール構造の説明:
モジュール:このプロジェクトは、機能部を座標定義された、関連する変数関数部分の定義、部分的な相関演算鳥の機能が作動、関連する壁TRANSFORMATION、一部の鳥の飛行、そして最後の試合が失敗した後に移動し、その後、再生を継続するかどうかを選択主な機能部!
全体的な構造:
void gotoxy(int x, int y)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle, pos);
}
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
int high;
int width;
int bird_x;
int bird_y;
int bar1_y;
int bar1_xTop;
int bar1_xDown;
int score;
void startup()
{
high = 15;
width = 25;
bird_x = high / 2;
bird_y = width / 4;
bar1_y = width - 1;
bar1_xTop = high / 4;
bar1_xDown = high / 2;
score = 0;
}
void show()
{
gotoxy(0, 0);
int i, j;
for (i = 0; i < high; i++)
{
for (j = 0; j < width; j++)
{
if ((i == bird_x) && (j == bird_y))
{
printf("@");
}
else if ((j == bar1_y) && ((i < bar1_xTop) || (i > bar1_xDown)))
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
printf("score:%d\n", score);
}
int updateWithoutInput()
{
bird_x++;
bar1_y--;
if (bird_y == bar1_y)
{
if ((bird_x >= bar1_xTop) && (bird_x <= bar1_xDown))
{
score++;
}
else
{
printf("Game failed!!!");
return -1;
}
}
else
{
if (bird_x > high)
{
printf("gamefailed!!!");
return -1;
}
}
if (bar1_y <= 0)
{
bar1_y = width - 1;
int upside = rand() % (int)(high * 0.6) + 1;
bar1_xTop = upside;
int opening = rand() % (int)(high * 0.2) + 2;
while ((bar1_xDown = bar1_xTop + opening) > high - 2)
{
opening = rand() % (int)(high * 0.2) + 2;
}
}
Sleep(150);
return 0;
}
void updateWithInput()
{
char input;
if (_kbhit())
{
input = _getch();
if (input == ' ' && bird_x > 0)
{
bird_x = bird_x - 2;
}
}
}
int main()
{
srand((unsigned)time(NULL));
HideCursor();
again:
startup();
while (1)
{
show();
int ret = updateWithoutInput();
if (ret == -1)
{
system("CLS");
printf("1.restard\n0.exit\nchoose please:");
int input = 0;
scanf("%d", &input);
if (input)
{
goto again;
}
else
return 0;
}
updateWithInput();
}
return 0;
}
IV。ページの表示を達成するために
V.コードホスティングリンク
https://gitee.com/WangYaqiong/wang_ya_qiong/blob/master/mayunyouxi.cpp.cpp
VI。実験の概要
このシーケンスは、後に戦うために、より革新的なプログラムを設計することができる、給油を継続するために、教科書の執筆、少数の問題上のプログラミング演習プログラムテンプレートに従ったものです。使用Gitのが多くの問題あったが、自己試運転され、ゆっくりと手探りしている一方で、彼らは感じるだろうが、将来のプロジェクト設計のコースで使用するのは難しいことではありません給油するための努力を継続する必要があります。