This blob of a code isint going to be readable by anyone. But you asked for it. Strangely enough, this does exactly what its suposed to. Probably because it does nothing. I'd have to post the whole code, which I'll add to the end of this post.
Code:
#include <windows>
#include <iostream>
#include <string>
#include <conio>
#include <fstream>
#include <vector>
using namespace std;
#define Enemy1 '@'
#define Enemy2 '&'
#define Enemy3 '$'
#define Enemy4 '%'
#define E_Left 10 //Movement Definitions.
#define E_Right 20
#define E_Up 30
#define E_Down 40
#define Blank ' '
#define Wall1 '|'
#define Wall2 '/'
#define Wall3 '\\'
#define Wall4 '>'
#define Wall5 '<'
#define Wall6 '['
#define Wall7 ']'
#define Wall8 '-'
#define Wall9 '='
#define Wall10 '^'
#define Up 1
#define Down 2
#define Left 3
#define Right 4
#define Esc 5
HANDLE hOt = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
class Enemy {
private:
char Ent;
int ex_pos;
int ey_pos;
int tag;
int mproc;
SHORT alive;
public:
Enemy() {Ent=0;ex_pos=0;ey_pos=0;tag=0;mproc=0;alive=0;}
Enemy(char t, int ex, int ey, int etag, int moving, SHORT live) {Ent=t; ex_pos=ex;ey_pos=ey;tag=etag;mproc=moving;alive=live;}
COORD GetPos() {COORD m; m.X=ex_pos; m.Y=ey_pos; return m;}
char GetType() {return Ent;}
int GetX() {return ex_pos;}
int GetY() {return ey_pos;}
int GetTag() {return tag;}
int GetMovement() {return mproc;}
SHORT IsAlive() {return alive;}
SHORT operator==(Enemy X);
SHORT IsNull();
void SetType(char c) {Ent=c;}
void SetX(int x) {ex_pos=x;}
void SetY(int y) {ey_pos=y;}
void SetTag(int Tag) {tag=Tag;}
void SetMovement(int Move) {mproc=Move;}
void SetLive(int live) {alive=live;}
void Delete();
};
SHORT Enemy::operator==(Enemy X) {
if(this->GetType() == X.GetType() && this->GetX() == X.GetX() && this->GetY() == X.GetY() && this->GetTag() == X.GetTag())
return 1;
return 0;
}
SHORT Enemy::IsNull() {
Enemy Null(0, 0, 0, -1, 0, 0);
if(*this == Null)
return 1;
return 0;
}
void Enemy::Delete() {
COORD m;
m.X = this->GetX();
m.Y = this->GetY();
SetConsoleCursorPosition(hOt, m);
cout << ' ';
}
vector <Enemy> Ens;
WORD Scolor;
CONSOLE_SCREEN_BUFFER_INFO inf;
void SetPos(SHORT x, SHORT y, int ix=0, int iy=0) {
COORD Pos;
SHORT v;
Pos.X = x;
Pos.Y = y;
for(v=0; v < ix; v++)
Pos.X++;
for(v=0; v > ix; v--)
Pos.X--;
for(v=0; v < iy; v++)
Pos.Y++;
for(v=0; v > iy; v--)
Pos.Y--;
SetConsoleCursorPosition(hOt, Pos);
return;
}
void SetColor(char c) {
if(c == 'o')
SetConsoleTextAttribute(hOt, Scolor);
if(c == 'r')
SetConsoleTextAttribute(hOt, FOREGROUND_RED | FOREGROUND_INTENSITY);
if(c == 'g')
SetConsoleTextAttribute(hOt, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
if(c == 'b')
SetConsoleTextAttribute(hOt, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
if(c == '1')
SetConsoleTextAttribute(hOt, BACKGROUND_RED | BACKGROUND_INTENSITY);
if(c == '2')
SetConsoleTextAttribute(hOt, BACKGROUND_GREEN | BACKGROUND_INTENSITY);
if(c == '3')
SetConsoleTextAttribute(hOt, BACKGROUND_BLUE | BACKGROUND_INTENSITY);
if(c == 's')
SetConsoleTextAttribute(hOt, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
}
char ReadPos(SHORT x, SHORT y, SHORT ix=0, SHORT iy=0) {
DWORD reader;
COORD Pos;
char EEE[1];
SHORT v;
Pos.X = x + ix;
Pos.Y = y + iy;
ReadConsoleOutputCharacter(hOt, &EEE[0], 1, Pos, &reader);
return EEE[0];
}
void MoveEnemies() {
vector<Enemy>::iterator it;
unsigned int x;
COORD xy;
SHORT d;
Enemy En;
if(Ens.empty())
return;
for(it = Ens.begin(); it != Ens.end(); it++) {
En = *it;
En.SetMovement(E_Left);
xy=En.GetPos();
d=En.GetMovement();
if(d == E_Right) {
SetPos(xy.X, xy.Y, 0, 0);
cout << Blank;
SetPos(xy.X, xy.Y, 1, 0);
En.SetX(xy.X+1);
SetColor('r');
cout << En.GetType();
SetColor('o');
} else
if(d == E_Left) {
SetPos(xy.X, xy.Y, 0, 0);
cout << Blank;
SetPos(xy.X, xy.Y, -1, 0);
En.SetX(xy.X-1);
SetColor('r');
cout << En.GetType();
SetColor('o');
}
}
}
void EvaluateEnemies() {
unsigned int x, y;
COORD xy;
char Yam[2];
vector<Enemy>::iterator it;
Enemy en;
if(Ens.empty())
return;
for(it = Ens.begin(); it != Ens.end(); it++) {
en = *it;
xy=en.GetPos();
Yam[0]=ReadPos(xy.X, xy.Y, 1, 1);
Yam[1]=ReadPos(xy.X, xy.Y, -1, 1);
if(Yam[0] == Blank && Yam[1] == Blank)
en.SetMovement(0);
if(Yam[0] == Blank)
en.SetMovement(E_Left);
if(Yam[1] == Blank)
en.SetMovement(E_Right);
}
}
int EnemyMain() {
cout << '1';
EvaluateEnemies();
cout << '2';
MoveEnemies();
cout << '3';
return 0;
}
int main() {
EnemyMain();
}
As I said, this example doesnt crash. But it wont do anything either. Heres my whole code, do whatever you want with it.
The upload limit prevents me from uploading all the neccesary files, so save this as EnemyClass.h;
Code:
#include "KeeperClass.h"
#define Enemy1 '@'
#define Enemy2 '&'
#define Enemy3 '$'
#define Enemy4 '%'
#define E_Left 10 //Movement Definitions.
#define E_Right 20
#define E_Up 30
#define E_Down 40
class Enemy {
private:
char Ent;
int ex_pos;
int ey_pos;
int tag;
int mproc;
SHORT alive;
public:
Enemy() {Ent=0;ex_pos=0;ey_pos=0;tag=0;mproc=0;alive=0;}
Enemy(char t, int ex, int ey, int etag, int moving, SHORT live) {Ent=t; ex_pos=ex;ey_pos=ey;tag=etag;mproc=moving;alive=live;}
COORD GetPos() {COORD m; m.X=ex_pos; m.Y=ey_pos; return m;}
char GetType() {return Ent;}
int GetX() {return ex_pos;}
int GetY() {return ey_pos;}
int GetTag() {return tag;}
int GetMovement() {return mproc;}
SHORT IsAlive() {return alive;}
SHORT operator==(Enemy X);
SHORT IsNull();
void SetType(char c) {Ent=c;}
void SetX(int x) {ex_pos=x;}
void SetY(int y) {ey_pos=y;}
void SetTag(int Tag) {tag=Tag;}
void SetMovement(int Move) {mproc=Move;}
void SetLive(int live) {alive=live;}
void Delete();
};
SHORT Enemy::operator==(Enemy X) {
if(this->GetType() == X.GetType() && this->GetX() == X.GetX() && this->GetY() == X.GetY() && this->GetTag() == X.GetTag())
return 1;
return 0;
}
SHORT Enemy::IsNull() {
Enemy Null(0, 0, 0, -1, 0, 0);
if(*this == Null)
return 1;
return 0;
}
void Enemy::Delete() {
COORD m;
m.X = this->GetX();
m.Y = this->GetY();
SetConsoleCursorPosition(hOt, m);
cout << ' ';
}
1.txt needs to be in the c:\ folder.
Thats everything I think. I'll thank anyone who even attempts to read my coding :P.