C Language Console Snake 1

Source: Internet
Author: User
Tags clear screen

  

First, the cover

1. Cover Style (example)

void Cover () {    printf ("\n\n\n\t\t\t       <<snake>>\n\n");    printf ("\n\n\n\t\t\t<<w,s,a,d control move>>\n\n");    printf ("\n\n\n\t\t\t    <<space begin>>\n\n\n\n");}

2. Add background music

(1) Use the function : BOOL WINAPI PlaySound(LPCSTR pszsound, hmodule hmod, DWORD fdwsound);//check MSDN, etc.

(2) The PlaySound function is used to the header file :

#include <Windows.h> #include <mmsystem.h> #pragma comment (lib, "Winmm.lib")

(3) The function return value type is boolean .

  

3. Key detection of Switch to game page in main function

Char Chinput;  while (1)    {        = _getch ();         if (' = = chinput ')        {            break;        }    }

The full code is as follows:

#include <stdio.h>#include<stdlib.h>#include<conio.h>//three-piece set: function to add music#include <Windows.h>#include<mmsystem.h>#pragmaComment (lib, "Winmm.lib")//Home PagevoidCover () {printf ("\n\n\n\t\t\t <<snake>>\n\n"); printf ("\n\n\n\t\t\t<<w,s,a,d Control move>>\n\n"); printf ("\n\n\n\t\t\t <<space begin>>\n\n\n\n");}//Play MusicvoidBGM () {PlaySound ("C:\\windows\\media\\alarm03.wav", NULL, Snd_filename |Snd_async); //example of a. wav file in a C-drive system file}intMain () {CharChinput; //Play MusicBGM (); //Show HomeCover (); //Detection Keys     while(1) {Chinput=_getch (); if(' '==chinput) {             Break; }    }    //Stop playingPlaySound (NULL,0,0); //Clear ScreenSystem"CLS"); printf ("\n\n\n\t\t start the game \ n"); System ("Pause"); return 0;}

C Language Console Snake 1

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.