所以我的问题有点棘手,至少对我而言。我试图用C++来制作一个游戏,以获得它的乐趣,基本上我就是这样一种鸟,它永远不会移动,但鸟背后的地图总是从右向左移动。基本上我迄今为止所做的是创建一个小网格5个空间和80个空间。我已经在地图底部的顶部5个空格处绘制了下划线字符_,并且从左侧开始,玩家是一个“O”三个空格。麻烦的是让高度上的第5个空间上方的4个空间移动,但同时不移动玩家“O”。这里是我的代码和迄今为止发生的一个草图。我很抱歉,这对我来说很难解释。我真的尽我所能。问题是我并不是很了解这一切。C++在win32控制台中制作游戏
#include <iostream>
#include <cstdlib>
#include <string>
#include <conio.h>
using namespace std;
bool gameOver;
// Global variables
const int WIDTH = 80;
const int HEIGHT = 5;
int x, y;
int speedX;
int percentX;
int someArray[100];
string anotherArray[100];
enum eKeys { STOP = 0, SPACE};
int gameSpeed;
eKeys key;
// Function declarations
void input() {
if (_kbhit()) {
switch (_getch()){
case ' ':
key = SPACE;
break;
}
}
}
void draw() {
for (int j = 0; j < HEIGHT; j++) {
for (int i = 0; i < WIDTH; i++) {
if (j < 4) {
std::cout << " ";
if (WIDTH == 20) {
_sleep(10);
}
}
if(j == 4){
anotherArray[i] = "_";
std::cout << anotherArray[i];
}
if (j== 3 && i == 3) {
std::cout << "O";
}
if (j == 3 && i == 140) {
}
}
}
}
void setup() {
gameOver = false;
key = STOP;
x = 3;
y = 2;
}
void logic() {
switch (key) {
case SPACE:
break;
}
}
int main()
{
// Your code goes here
setup();
//while(gameOver == false){
draw();
input();
logic();
//}
// Make sure we place the end message on a new line
std::cout << endl;
// The following is system dependent. It will only work on Windows
std::system("PAUSE");
/*
// A non-system dependent method is below
cout << "Press any key to continue";
cin.get();
*/
return 0;
}
该代码会产生在控制台此输出.... “这是控制台顶部的”
Ø
按任意键继续......
我想要的是在“_____”之上的所有东西都是从右向左移动而没有玩家移动。除了按空格跳跃时,“O”的y坐标将会改变。此外,我知道这可能会在课堂上做得更好,但是在我的书中我还没有那么深入,而我的C++课程现在刚刚启动了功能,因此现在最好远离它。
你没问实际问题,这是太宽泛反正。另外我不知道究竟你通过* – UnholySheep
我的意思是使用类做得更好*“的一类更好”的意思。就像如果我在java或swift中这样做的话,我可能会创建一个叫做player的类,它的结构中有一个名为Point的x和y。我只是说有更好的方法来做我在这里做的事(可能),我想知道如何用功能来做。 – devin
我不觉得它是广泛的。我基本上是在问一个适用于从右向左移动的游戏的概念。这一个更特定于C++,但我可能最有可能用不同的编程语言实现相同的答案。也许你不太了解这个问题。 @unholysheep – devin