1

グラフィックス.hおよびconio.hライブラリの使用方法を学習しようとしています.キーボード入力後に長方形を移動する必要があるグラフィックプログラムを開発しています.ex:プレーヤーが右を押すと、長方形は右側に移動する必要があります.問題は私ですユーザー入力を取得する方法がわかりません。ループ内でユーザー入力を連続的に取得する必要があります。これが私のコードです。どんな助けでも大歓迎です(キーワード、関数名など)

#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>

void drawrect(int left,int top,int right,int bot);

int main()
{
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\TC\\BGI");
    drawrect(5,400,40,450); // default start position
    firsttime=1;//counter for if its first time in for loop
    int currentl=5;
    int currentt=400;
    int currentr=40;
    int currentb=450;
        if(firsttime==1)
        {
              //get user input and drawrectangle with new inputs
              //if player press right add 5 to currentl and current r and
              //redraw the rectangle
        }


    getch();
    closegraph();
}

void drawrect(int left,int top,int right,int bot)
{
 rectangle(left,top,right,bot);
}
4

2 に答える 2

0

解決したこのコードは助けてくれてありがとう

#include #include

void drawrect(int left,int top,int right,int bot);

int main()
{
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\TC\\BGI");

    int firsttime=1;//counter for if its first time in for loop
    int currentl=5;
    int currentt=400;
    int currentr=40;
    int currentb=450;

    char ch;
    settextstyle(0, HORIZ_DIR, 1);
    outtextxy(20, 20, "To start press 'S'");
    ch = getch();
    cleardevice(); 
    drawrect(5,400,40,450); // default start position

        while(ch!='q')
       { 
        ch = getch();
        switch (ch)
        {
         case KEY_RIGHT:currentr=currentr+5;
                        currentl=currentl+5;
                        break;
         case KEY_LEFT:currentr=currentr-5;
                       currentl=currentl-5;
                       break;
        }
        cleardevice();
        drawrect(currentl,currentt,currentr,currentb);
       }




    getch();
    closegraph();
}

void drawrect(int left,int top,int right,int bot)
{
 rectangle(left,top,right,bot);
}
于 2015-02-05T23:01:39.467 に答える