【发布时间】:2020-05-30 23:24:15
【问题描述】:
更新!我想出了如何找到密钥并在我的代码中定义它们。问题是我不知道如何制作它,所以控制台打印选择,它让你有时间按下一个键。然后它被插入到根据按下的键打印当前枪的开关上。我也在使用 Windows 10。我还遇到了另一个问题,我希望它先打印出 Guns,然后要求输入(这部分工作正常),但它不仅打印附件,还打印出附件和人性化级别.
#include <iostream>
#include <istream>
#include <fstream>
#include <string.h>
#include <conio.h>
#include <string>
using namespace std;
#define KEY_F1 17
#define KEY_F2 18
#define KEY_F3 19
#define KEY_F4 20
#define KEY_F5 21
#define KEY_F6 22
#define KEY_F7 23
#define KEY_F8 24
#define KEY_F9 25
#define KEY_F10 26
#define KEY_F11 27
#define KEY_F12 28
#define KEY_N7 103
#define KEY_N8 104
#define KEY_N9 105
int main() {
char gun;
char att;
char hum;
char key = _getch();
int value = key;
cout << "" << endl;
cout << "Developed by ! CaptaiN#9999" << endl;
cout << "" << endl;
cout << "Guns" << endl;
cout << "" << endl;
cout << "[F1] AK" << endl;
cout << "[F2] MP5" << endl;
cout << "[F3] M2" << endl;
cout << "[F4] SAR" << endl;
cout << "[F5] Tommy" << endl;
cout << "[F6] Custom" << endl;
cin >> gun;
cout << "" << endl;
cout << "Attachnments" << endl;
cout << "" << endl;
cout << "[F7] Holosight" << endl;
cout << "[F8] Simplesight" << endl;
cout << "[F9] Silencer" << endl;
cout << "[F10] 8x Zoom Scope" << endl;
cout << "[F11] 16x Zoom Scope" << endl;
cout << "[F12] No Attachment" << endl;
cin >> att;
cout << "" << endl;
cout << "Humanize Levels" << endl;
cout << "" << endl;
cout << "[Numpad 7] 3 (HIGH)" << endl;
cout << "[Numpad 8] 2 (MODERATE)" << endl;
cout << "[Numpad 9] 1 (LOW)" << endl;
cin >> hum;
//system("CLS");
while (value != KEY_X) {
switch (_getch()) {
case KEY_F1:
cout << "Current Gun: AK" << endl;
break;
case KEY_F2:
cout << "Current Gun: MP5" << endl;
break;
case KEY_F3:
cout << "Current Gun: M2" << endl;
break;
case KEY_F4:
cout << "Current Gun: SAR" << endl;
break;
case KEY_F5:
cout << "Current Gun: Tommy" << endl;
break;
case KEY_F6:
cout << "Current Gun: Custom" << endl;
break;
}
switch (att) {
case KEY_F7:
cout << "Current Attachment: Holosight" << endl;
break;
case KEY_F8:
cout << "Current Attachment: Simplesight" << endl;
break;
case KEY_F9:
cout << "Current Attachment: Silencer" << endl;
break;
case KEY_F10:
cout << "Current Attachment: 8x Zoom Scope" << endl;
break;
case KEY_F11:
cout << "Current Attachment: 16x Zoom Scope" << endl;
break;
case KEY_F12:
cout << "Current Attachment: None" << endl;
break;
}
switch (hum) {
case KEY_N7:
cout << "Humanized Level: 3" << endl;
break;
case KEY_N8:
cout << "Humanized Level: 2" << endl;
break;
case KEY_N9:
cout << "Humanized Level: 1" << endl;
break;
}
}
}
【问题讨论】:
-
给我们看一些代码,
-
如果您按
A之类的常用键(之后不按回车键),甚至没有一种标准方法可以让您的程序打印任何内容。对于此类事情,您将需要特定于平台的代码。有适用于大多数平台的库,例如ncurses和pdcurses。
标签: c++ windows input switch-statement