C-language Receive direction key instruction allows the output on the screen to move

Source: Internet
Author: User
Tags clear screen

First, you need to know the console coordinates

#include <stdio.h>#include<stdlib.h>#include<conio.h>Main () {intx=0, y=0, I; CharKey//Accept InputPutchar ('O');//a Little Dot     while(1) {Key=getch ();//accept input without echo    if(key=='Q') Break;//input WASD, enter Q to exit    Switch(key) {//Set any hotkey//Case ' W ': (x>0?--x:x);//Case ' s ': x++;break;//Case ' a ': (y>0--y:y);//Case ' d ': ++y;break;//Default:break;//////////Set any hotkey     Case- +: Key=Getch (); Switch(key) { Case  the: (x>0?--x:x); Break;  Case  the: x++; Break;  Case  the: (Y>0? --Y:Y); Break;  Case  the:             ++y; Break; default: Break; }            default: Break; } System ("CLS");//Clear Screen     for(i=0; i<x;i++) printf ("\ n");  for(i=0; i<y;i++) printf (" "); Putchar ('O');//Output}}

C-language Receive direction key instruction allows the output on the screen to move

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.