I would be grateful for a little help. This is supposed to be a console game that uses elements from bagels, role-playing games, sandboxes, and survival games.
I tried to get a working architecture about three times. Every time I came across problems that I could not solve without hacking my way ...
I have already looked at numerous blogs and tutorials for this, but none of them matched my purpose.
1) http://trystans.blogspot.co.at/2011/08/roguelike-tutorial-01-java-eclipse.html
2) http://www.kathekonta.com/rlguide/index.html
I have already followed the Trystan block, which uses Java, and recreated its design in Java and AS3.
However, I'm not completely happy with the way he put classes together. Commands like World.dig () - it makes sense for me to call Player.dig () - or representing the map as an array of 3d (!) Made me believe that there should be a better way to do this.
The second link I posted is encoded in C ++, however there is only one central map. My goal is to have several cards that I can enter with characters, etc.
I will post the code of my last attempt below. It does not have any movement or interaction at all, since I want to get the design from the very beginning, without failing after several hours spent in the project (which I have already met too often).
main.cpp:
# include <iostream>
# include "World.h"
# include "Entity.h"
using namespace std;
int main(){
int testFloor[] = {
0, 0, 0, 0, 0,
0, 1, 1, 1, 0,
0, 1, 0, 0, 0,
0, 1, 1, 1, 0,
0, 0, 0, 0, 0
};
World world(testFloor, 5, 5);
Entity nine(9, 0);
world.addEntity(nine);
world.draw(0,0,5,5);
system("PAUSE");
return 0;
}
World.h:
# ifndef WORLD_H
# define WORLD_H
# include <vector>
# include "Entity.h"
using namespace std;
class World {
private:
int* _floor;
int _width;
int _height;
vector<Entity> _entities;
public:
World(int* floor, int width, int height) :
_floor(floor), _width(width), _height(height){}
void addEntity(Entity e){
_entities.push_back(e);
}
int glyph(int ID){
int out = _floor[ID];
for(Entity e : _entities){
if(e.pos() == ID){
out = e.glyph();
break;
}
}
return out;
}
void draw(int left, int top, int width, int height){
system("cls");
int ID;
for(int y = 0; y < height; y++){
for(int x = 0; x < width; x++){
ID = (x+left)+(y+top)*width;
cout << glyph(ID);
}
cout << endl;
}
}
};
# endif
Entity.h:
# ifndef ENTITY_H
# define ENTITY_H
class Entity{
private:
int _glyph;
int _pos;
public:
Entity(int glyph, int pos) : _glyph(glyph), _pos(pos) {}
int glyph(){return _glyph;}
int pos(){return _pos;}
};
# endif
. Entity , "9", , , ... .
1) Entity, (Worldposition), , .
2) , , , , , .
, , Entity.
, World.update(), , , , , ... , .
, / .
, :
- , ?
- - , ( , )?
: , , . , , , , .
!