gerade jetzt bin ich ein halb so gut in einer Weise Programmierer und ich versuche, ein textbasiertes Spiel zu machen. Ich habe heute angefangen und ich habe was von einer Weltkarte gemacht, die später aktualisiert wird und ich werde es riesig machen! aber für das Leben von mir kann ich Frames nicht richtig aktualisieren. Ich benutze das normale Fenster, und ich habe meinen Code unten gesetzt. Bitte hilf mir meine Frames sauber zu aktualisieren!wie aktualisiere ich frames für ein textbasiertes spiel
Karte Klasse und Kopf
#include<string>
#include <Windows.h>
class map {
protected:
char mep[200][50];
public:
map();
~map();
void bs();
void buildTree(int X, int Y);
void addTree();
void buildMap();
void printMap(int X, int Y);
};
#include"map.h"
map::map() {
buildMap();
printMap(0, 0);
}
map::~map() {
}
void map::bs() {
//this builds a square world later cool things like trees get added
for (int x = 0; x<200; x++) {
for (int y = 0; y<500; y++) {
mep[x][y] = '_';
}
}
}
void map::buildTree(int X, int Y) {
//¨ /\¨ [x][y-4]
// /\"[x][y-3]
//¨ /-o \¨ [x][y-2]
//¨ /-o-o- \¨[x][y-1]
//¨/o0-o \¨ [x][y]
//¨/o-ooo- \¨[x][y+1]
//¨ ||||¨ [x][y+2]
//¨ ||||¨ [x][y+3]
mep[X][Y - 4] = '/'; mep[X + 1][Y - 4] = '\\';
mep[X - 1][Y - 3] = '/'; mep[X][Y - 3] = ' '; mep[X + 1][Y - 3] = ' '; mep[X + 2][Y - 3] = '\\';
mep[X - 2][Y - 2] = '/'; mep[X - 1][Y - 2] = '-'; mep[X][Y - 2] = 'o'; mep[X + 1][Y - 2] = ' '; mep[X + 2][Y - 2] = ' '; mep[X + 3][Y - 2] = '\\';
mep[X - 3][Y - 1] = '/'; mep[X - 2][Y - 1] = '-'; mep[X - 1][Y - 1] = 'o'; mep[X][Y - 1] = '-'; mep[X + 1][Y - 1] = 'o'; mep[X + 2][Y - 1] = '-'; mep[X + 3][Y - 1] = ' '; mep[X + 4][Y - 1] = '\\';
mep[X - 3][Y] = '/'; mep[X - 2][Y] = ' '; mep[X - 1][Y] = 'o'; mep[X][Y] = '0'; mep[X + 1][Y] = '-'; mep[X + 2][Y] = 'o'; mep[X + 3][Y] = ' '; mep[X + 4][Y] = '\\';
mep[X - 4][Y + 1] = '/'; mep[X - 3][Y + 1] = 'o'; mep[X - 2][Y + 1] = '-'; mep[X - 1][Y + 1] = 'o'; mep[X][Y + 1] = 'o'; mep[X + 1][Y + 1] = 'o'; mep[X + 2][Y + 1] = '-'; mep[X + 3][Y + 1] = ' '; mep[X + 4][Y + 1] = ' '; mep[X + 5][Y + 1] = '\\';
mep[X - 1][Y + 2] = '|'; mep[X][Y + 2] = '|'; mep[X + 1][Y + 2] = '|'; mep[X + 2][Y + 2] = '|';
mep[X - 1][Y + 3] = '|'; mep[X][Y + 3] = '|'; mep[X + 1][Y + 3] = '|'; mep[X + 2][Y + 3] = '|';
}
void map::addTree() {
buildTree(74, 69);
buildTree(5, 6);
//add 18 more
}
void map::buildMap() {
bs();
addTree();
}
void map::printMap(int X, int Y) {
//this is what the players will see
std::string viewMap[15];
for (int x = 0; x<15; x++) {
for (int y = 0; y <= 70; y++) {
viewMap[x] += mep[Y + y][X + x];
}
}
//this prints the visible map for the players
std::cout << viewMap[1] + "\n" + viewMap[2] + "\n" + viewMap[3]
+ "\n" + viewMap[4] + "\n" + viewMap[5] + "\n" + viewMap[6]
+ "\n" + viewMap[7] + "\n" + viewMap[8] + "\n" + viewMap[9]
+ "\n" + viewMap[10] + "\n" + viewMap[11] + "\n" + viewMap[12]
+ "\n" + viewMap[13] + "\n" + viewMap[14] << std::endl;
}
int main()
{
//this is my main im using it as an update frames right now
while (1) {
//also i will have the world render and build it self as a whole first and only loop the frame update ik its given but ill say it anway
map mp;
mp.~map();
}
}
Sie Destruktoren nicht manuell aufrufen. – melpomene
Ich war zuerst mit dem Destruktor, um den Bildschirm zu löschen und ich verwendet Google Docs, die Caps für mich tut. –
Der Destruktor eines Objekts wird automatisch aufgerufen, wenn die Lebensdauer des Objekts endet. Es gibt sehr, sehr wenige Situationen, in denen Sie es explizit nennen sollten, und das ist keiner von ihnen. –