所以我的問題有點棘手,至少對我而言。我試圖用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