标签:oci namespace win top tom ott rgba c语言 printf
1 #include <iostream> 2 #include <cstdlib> 3 #include <Windows.h> 4 using namespace std; 5 6 int main() 7 { 8 int i, j; 9 int x = 0; 10 int y = 5; 11 int velocity_x = 1; 12 int velocity_y = 1; 13 int left = 0; 14 int right = 20; 15 int top = 0; 16 int bottom = 10; 17 18 while(1){ 19 20 x = x + velocity_x; 21 y = y + velocity_y; 22 system("cls"); 23 24 for (i = 0; i < x; i++) 25 cout << endl; 26 for (j = 0; j < y; j++) 27 printf(" "); 28 printf("o\n"); 29 30 Sleep(50); 31 if (x == top || x == bottom) { 32 velocity_x *= -1; 33 printf("\a"); 34 } 35 36 if (y == left || y == right) { 37 velocity_y *= -1; 38 printf("\a"); 39 } 40 } 41 return 0; 42 }
最基础的实现,小球撞到墙壁即反弹,触碰会发出声音,仅此而已。
时隔一年,又看到了这份代码,就发出来吧。
2021-05-15
标签:oci namespace win top tom ott rgba c语言 printf
原文地址:https://www.cnblogs.com/2015-16/p/14772228.html