Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Brick Game in C language

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 226

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report