0
已解决
王子逸
新手天翼
新手天翼
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
void HideCursor(){
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void gotoxy(int x,int y){
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
int IsEnd;
int interface_x,interface_y;
int block_y;
int ctrlline_width,ctrlline_left,ctrlline_right;
int ball_x,ball_y;
int ballv_x,ballv_y;
int scores;
int ballv_num;
int ballv_num_i;
void startup(){
HideCursor();
IsEnd = 0;
interface_x = 22;
interface_y = 30;
block_y = rand()%(interface_y-6)+2;
ctrlline_width=8;
ctrlline_left=(interface_y-ctrlline_width-2)/2+1+1;
ctrlline_right=ctrlline_left+ctrlline_width-1;
ball_x=interface_x-1;
ball_y=ctrlline_left+ctrlline_width/2;
ballv_x=1;
ballv_y=1;
scores=0;
ballv_num=3;
ballv_num_i=1;
}
void show_begin(){
int i,j;
int start=0;
char input;
while(!start){
gotoxy(0,0);
for(i=1;i<=interface_x/2-4;i++) printf("\n");
for(i=1;i<interface_y/2-8;i++) printf(" ");
printf("一定要开英文\n\n");
for(i=1;i<interface_y/2-9;i++) printf(" ");
printf("请按空格键开始游戏,a,d移动\n作者--王子逸\n");
for(i=1;i<=interface_x/2-6;i++) printf("\n");
if(kbhit()){
input = getch();
if(input) start=1;
}
}
}
void show(){
gotoxy(0,0);
int i,j;
for(i=1;i<=interface_y/2-8;i++) printf(" ");
printf("《反弹球消砖块》") ;
for(i=1;i<=interface_y/2-8-8;i++) printf(" ");
printf("分数:%3d\n",scores);
for(i=1;i<=interface_x;i++){
printf(" ");
for(j=1;j<=interface_y;j++){
if(j==1||j==interface_y){
printf("|");
}else if(i==interface_x){
printf("_");
}else if(i==1){
printf("V");
}else if(i==interface_x-1&&(j>=ctrlline_left&&j<=ctrlline_right)){
printf("*");
}else if(i==2&&(j>=block_y&&j<=block_y+4)){
printf("H");
}else if(i==ball_x&&j==ball_y){
printf("O");
}else printf(" ");
}
printf("\n");
}
}
void update_outinput(){
ballv_num_i= (ballv_num_i==ballv_num)?1:ballv_num_i+1;
if(ballv_num_i==ballv_num){
if(ball_y==2||ball_y==interface_y-1){
ballv_y *= -1;
}
if(ball_x==2){
if(ball_y>=block_y&&ball_y<=block_y+4){
block_y = rand()%(interface_y-6)+2;
scores++;
printf("\a");
}
ballv_x *= -1;
}
if(ball_x==interface_x-1){
if(ball_y>=ctrlline_left && ball_y<=ctrlline_right){
ballv_x *= -1;
}else{
IsEnd = 1;
}
}
ball_x += ballv_x;
ball_y += ballv_y;
}
}
void update_input(){
char input;
if(kbhit()){
input = getch();
if( input == 'a'){
ctrlline_left= (ctrlline_left==2)?2:ctrlline_left-1;
ctrlline_right= ctrlline_left+ctrlline_width-1;
}else if( input == 'd'){
ctrlline_left= (ctrlline_left==interface_y-ctrlline_width)?\
interface_y-ctrlline_width:ctrlline_left+1;
ctrlline_right= ctrlline_left+ctrlline_width-1;
}
}
}
void show_end(){
system("cls");
printf("\n\n\n\n\n\n\t\t\tgame over!\n\n\n\n\n\n\n\n\n\n\n\n\n");
system("pause");
system("pause");
}
int main(){
startup();
show_begin();
while(!IsEnd){
show();
update_outinput();
update_input();
}
show_end();
return 0;
}
1
0
0
侯平仄
新手天翼
新手天翼
0
0
0