XP系統 TC編譯器
main()
{
char c[4];
int y = 5;
int x = 5;
while(1)
{
clrscr();
gotoxy(x,y);
printf("*");
gotoxy(x,y);
gotoxy(50,10);
printf("x = %d y = %d",x,y);
c[0] = getch();
if( c[0] == 0x4b) /* 向左 */
{
x++;
}
else if(c[0] == 0x4d) /* 向右 */
{
x--;
}
else if(c[0] == 0x48) /* 向上 */
{
y--;
}
else if(c[0] == 0x50) /* 向下*/
{
y++;
}
if(c[0] == '0')
{
break;
}
if(c[0] == '1')
{
x = 5;
y = 5;
}
}
}
TC控制臺80*25 向左應該是++,向右應該是-- ,為什么這里是反著的?
uj5u.com熱心網友回復:
給你幾個程式就明白了
第一個:
#include <iostream>
#include <conio.h>
using namespace std;
int main(){
char ch1;
ch1= getch();
cout << "剛才的輸入是:" << int(ch1) << endl;
return 0;
}
↑這是getch用法
#include <iostream>
#include <conio.h>
using namespace std;
int main(){
char ch1;
ch1= getch();
cout << "剛才的輸入是:" << int(ch1) << endl;
ch1= getch();
cout << "剛才的輸入是:" << int(ch1) << endl;
return 0;
}
這是getch讀入方向鍵
-------
這個是方向鍵判斷(主要看這個)
#include<iostream>
#include<fstream>
#include <conio.h>
using namespace std;
void keyTest(){
char ch1;
while(true)
{
ch1=getch();
cout<<int(ch1)<<endl;
// 按一個鍵,回傳兩個值,第一個是224
switch(ch1){
case 72:
cout << "向上移動" << endl;
break;
case 80:
cout << "向下移動" << endl;
break;
case 75:
cout << "向左移動" << endl;
break;
case 77:
cout << "向右移動" << endl;
break;
}
}
}
int main(){
keyTest();
}
看懂了一定要結貼給分
點擊結貼,點擊平均給分,下面有個藍色的結貼給分,點啊!

我很想要分
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/134402.html
標籤:C語言
