簡單的彈彈牆小遊戲

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>


int width;
int high;

int ball_x;
int ball_y;
int ball_vx;
int ball_vy;

void startup() {
	width = 20;
	high = 10;
	ball_x = 0;
	ball_y = width / 2;
	ball_vx = 1;
	ball_vy = 1;
}

void show()
{
	int j;
	int i;
	system("cls");

	for (i = 0; i <= high; i++) {
		for (j = 0; j <= width; j++) {
			if (i == ball_x && j == ball_y)
				printf("G");
			else if (j == width)
				printf("|");
			else if (i == high)
				printf("-");
			else
				printf(" ");
		}
		printf("\n");
	}
	Sleep(500);
}

void update()
{
	ball_x += ball_vx;
	ball_y += ball_vy;

	if (ball_x == high || ball_x == 0)
		ball_vx = -ball_vx;
	if (ball_y == width || ball_y == 0)
		ball_vy = -ball_vy;
}
int main()
{
	startup();

	while (1) {
		show();
		update();
	}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章