Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the Brick Game in C language

Shulou Source: shulou.com Published: 2022-05-31 17:50:04 09月14日 Update

This article mainly introduces "how to play brick games with C language". In daily operation, I believe that many people have doubts about how to play brick games with C language. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about how C language realizes the brick game! Next, please follow the editor to study!

The effect is as follows:

Code:

# include#include#include#includeint score;int ball_row, ball_col;int ball_vv, ball_vh;int area_height, area_width;int baffle_col, baffle_row, baffle_size;int brick_col, brick_row;bool isLose;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 = {1Power0}; SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), & cursor_info);} void startup () {area_height = 20; area_width = 40; ball_row = area_height / 2; ball_col = area_width / 2; ball_vv = 1; ball_vh = 1; baffle_col = area_width / 2; baffle_row = area_height-2 Baffle_size = 8; brick_row = 1; brick_col = rand ()% area_width; score = 0; isLose = false;} void show () {gotoxy (0,0); int I, j; / / system ("cls"); for (I = 0; I = brick_col-1 & & ball_col = area_height) isLose = true; count++;} void updateWithInput () {char input If (kbhit ()) {input = getch (); switch (input) {case'asides: if (baffle_col > 0 + 1) baffle_col--; break; case'wages: if (baffle_row > 0 + 1) baffle_row--; break; case'dcards: if (baffle_col)

< area_width - baffle_size - 1)baffle_col++; break; case 's': if (baffle_row < area_height - 1)baffle_row++; break; default: break; } }}int Lost(){ if(ball_row >

Area_height) return 1; return 0;} int IsFinish () {/ / whether the game is over or not if (score = = 100) {system ("cls"); printf ("congretationsplaying games!"); score = 0; _ sleep (500); / / pause humanized system ("pause") in reality first; return 1 } else if (Lost () = = 1) {system ("cls"); printf ("you have lostworthiness!"); score = 0; _ sleep (500); system ("pause"); return 1;} return 0;} int main () {HideCursor (); startup (); while (1) {show (); updateWithInput () UpdateWithhoutInput (); if (IsFinish () = = 1) {startup (); continue;}} return 0;} at this point, the study on "how to play the brick game in C language" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Bricks language learning more help practical next human nature code effects articles methods reality theory knowledge articles websites materials follow questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft NVidia Shulou Information Shulou Technology macOS