Architecture Exercises: C language Realization Snake (a): Draw map and Mushroom

Source: Internet
Author: User

Currently just draw maps, and randomly spawn mushrooms based on the current time

Next:

(1) Implement a Refresh method similar to top

(2) Realization of Snake walking

(3) to realize the merger of snake eating mushrooms and the generation of new mushrooms

(4) Implementation of schema modification and optimization

[email protected]:/mnt/shared/appbox/snake# cat snake.c #include <stdio.h> #include <string.h># Include <unistd.h> #include <stdlib.h> #include <time.h> #define Game_width 50#define game_higth 25int        Up_line_create () {int i;        for (i=0; i<game_width;i++) {printf ("-");        } printf ("\ n"); return 0;}        int bottom_line_create () {int i;        for (i=0; i<game_width;i++) {printf ("-");        } printf ("\ n"); return 0;}        int middle_line_create (int x_site, int y_site) {int I, J;                        for (j=0;j<game_higth;j++) {for (i=0;i<game_width;i++) {                        if (i = = X_site && j = = Y_site) {printf ("*");                       } else if (0 = = i) {printf ("|"); } else if (i== (game_width-1)) {printf ("|\n"                        );                        } else {printf (""); }}} return 0;}         int target_create (int *x_site, int *y_site) {int seconds= time ((time_t*) NULL);        *y_site = ABS (Seconds*random ())%game_higth;        *x_site = ABS (Seconds*random ())%game_width; return 0;}        int frame_create (void) {int I, J;        int X_site, y_site;        Target_create (&x_site, &y_site);        printf ("x:%d, y:%d\n", X_site, Y_site);                while (1) {up_line_create ();                Middle_line_create (X_site, y_site);                Bottom_line_create ();        Sleep (1); } return 0;}        int main (int argc, char *argv[]) {frame_create (); return 0;}


Architecture Exercises: C language Realization Snake (a): Draw map and Mushroom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.