声明:
此片作为博主学习记录#程序代码 实现限定区域内小球弹跳的效果
#include<stdio.h> #include<stdlib.h> #include<windows.h> int main() { int i,j; int x=0; int y=0; int a,b; //set the border int left=0; int right=30; int top=0; int bottom=20; int velocity_x=1; int velocity_y=1; while(1) { x=x+velocity_x; y=y+velocity_y; } system("cls"); //clear the screen //put in a blank line above the ball for(i=0;i<x;i++) printf("\n"); //put in the blank space on the left of the ball for(j=0;j<y;j++) printf(" "); printf("o"); printf("\n"); //Program hangs Sleep(50); //wait 50ms after image output if((x==top)||(x==bottom)) { velocity_x=-velocity_x; printf("\a"); } if((y==left)||(y==right)) { velocity_y=-velocity_y; printf("\a"); } } return 0; }#未解决问题 想在程序中绘制边框的但是,不知道和system(“cls”)如何调节,做到边框固定显示
//put out the border for(a=0;a<=30;a++) { if(a==0||a==30) { for(b=0;b<=20;b++) printf("="); printf("\n"); } else { printf("="); for(b=0;b<=18;b++) printf(" "); printf("=\n"); } }