[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
for StarShip game ppl
This is just a preliminary sketch in c++ of some of the ideas and
classes used in the game. Mostly this is for Kenn, but whoever is
interested in helping us let me know.
I want to clean up the variables, Kenn already gave some suggestions,
but I haven't got to that yet. Right now you can move about a bit, but
only in text, and there isn't actually anything going on. In fact it is
in a total state of un-gameness (tm).
darelf@crafton.net
/* #include <GPL> */
#include <iostream.h>
class Port { //this is the class for handling all port activities
char *name; //please add variables to this to extend functionality
int xPosition;
int yPosition;
public:
Port(int x, int y)
{
name = "Unnamed";
xPosition = x;
yPosition = y;
}
~Port() { if(name) delete name; }
void ShowStats()
{
cout << "Name: " << name << endl;
cout << "Coord " << xPosition << ", " << yPosition << endl;
}
void ChangeName(char *str)
{
name = new char[strlen(str)+1];
strcpy(name, str);
}
};
class P {
Port *port[10][10];
public:
P() { //this constructor just inits all ports
for(int x = 0; x < 10; x++) {
for(int y =0;y<10;y++) {
port[x][y] = new Port(x, y);
}
}
}
Port *GetPort(int x, int y) //currently only returns the port requested
{
return port[x][y];
}
};
struct uni_map { //haven't done anything with this yet
P *portlist;
};
void main()
{
Port *currentPort; //the port that the ship is currently in
P *currentMap; //the map being used
char ch = 'h'; //these two are used for input
char buffer[20];
char buffer2[20];
currentMap = new P();
currentPort = currentMap->GetPort(0, 0);
cout << "StarShip version 0.0.1" << endl;
while(strcmp(buffer, "quit")) {
cout << ".";
cin >> buffer;
if(!strcmp(buffer, "view")) currentPort->ShowStats();
if(!strcmp(buffer, "change")) {
cout << "Name: ";
cin >> buffer2;
currentPort->ChangeName(buffer2);
}
if(!strcmp(buffer, "goto")) {
int x;
int y;
cout << "X: ";
cin >> x;
cout << "Y: ";
cin >> y;
currentPort = currentMap->GetPort(x, y);
}
}
}