这是上下左右?
#include<ggoot.h>
#include<conio.h>
using namespace std;
int main(){
HideTheCursor();
char b;
for(;;){
b = getch();
if (b == 'd') {
x++;
system("cls");
gotoxy(x, y);
cout << "+";
}
if (b == 's') {
y++;
system("cls");
gotoxy(x, y);
cout << "+";
}
if (b == 'a') {
x--;
system("cls");
gotoxy(x, y);
cout << "+";
}
if (b == 'w') {
y--;
system("cls");
gotoxy(x, y);
cout << "+";
}
}
return 0;
}
这是发射子弹
#include<ggoot.h>
#include<conio.h>
using namespace std;
int main(){
for(int i=1;i<=你要多远;i++){
system("cls");
gotoxy(i, 第几行);
cout << "-";
}
}
给一段游戏
#include<ggoot.h>
#include<conio.h>
#define KEY_DOWN(VK_RBUTTON) ((GetAsyncKeyState(VK_RBUTTON) & 0x8000) ? 1:0)
POINT p;
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HWND h = GetForegroundWindow();
CONSOLE_FONT_INFO consoleCurrentFont;
using namespace std;
int x = 2, y = 2;
int main() {
HideTheCursor();
cout << "are you want to start the game?";
char a, b;
a = getch();
if (a == 'Y') {
system("cls");
for (;;) {
b = getch();
if (b == 'd') {
x++;
system("cls");
gotoxy(x, y);
cout << "+";
}
if (b == 's') {
y++;
system("cls");
gotoxy(x, y);
cout << "+";
}
if (b == 'a') {
x--;
system("cls");
gotoxy(x, y);
cout << "+";
}
if (b == 'w') {
y--;
system("cls");
gotoxy(x, y);
cout << "+";
}
if (x == 3 && y == 3) {
gotoxy(3, 3);
cout << "*";
cout << "你拿到了星星";
break;
}
}
cout << "操作练习完成了,下面开始真正的游戏";
} else {
system("cls");
}
cout << "如要鼠标模式请输u,否则输w";
char aaa;
aaa = getch();
if (aaa == 'u') {
for (;;) {
POINT p;
GetCursorPos(&p);
ScreenToClient(h, &p);
GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont);
x = p.x /= consoleCurrentFont.dwFontSize.X;
y = p.y /= consoleCurrentFont.dwFontSize.Y;
system("cls");
gotoxy(x, y);
cout << "+";
}
} else {
system("cls");
for (;;) {
b = getch();
if (b == 'd') {
system("cls");
gotoxy(5, 5);
cout << "ss";
x++;
gotoxy(x, y);
cout << "+";
}
if (b == 's') {
system("cls");
gotoxy(5, 5);
cout << "ss";
y++;
gotoxy(x, y);
cout << "+";
}
if (b == 'a') {
system("cls");
gotoxy(5, 5);
cout << "ss";
x--;
gotoxy(x, y);
cout << "+";
}
if (b == 'w') {
system("cls");
gotoxy(5, 5);
cout << "ss";
y--;
gotoxy(x, y);
cout << "+";
}
if (b == ' ') {
system("cls");
gotoxy(5, 5);
cout << "ss";
gotoxy(x, y);
cout << "+";
for (int i = x + 1; i <= 10; i++) {
system("cls");
gotoxy(5, 5);
cout << "ss";
gotoxy(x, y);
cout << "+";
gotoxy(i, y);
cout << "-";
}
system("cls");
gotoxy(x, y);
cout << "+";
if (y == 5 && x < 5) {
system("cls");
cout << "nijishalediren";
}
}
}
}
return 0;
}
如有疑问,请留言。
|