(WinXP Borland C++ Free Command Line Compiler)
I must be terrible at making walls, I have once again added a wall that doesnt work. I cant find why though, I have repaired two other walls, but this one just doesnt work... The weird thing is, the wall is only non-existant for enemies, and the weirder thing is, only one enemy fits in the wall, and the rest just bounce off after that, until it comes out.
I'm so lost... This is the weirdest error I have come across... For the last few hours, all my attempts to reformat my code, re-edit my enemy layout, nothing works. (Though, it did help me optimize my code)
I swear, I would french-kiss a toad to get this to work -,-.
Well, heres my code with enemies added (Getting bigger):
Code:
#include <windows.h>
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
enum {
ESC_KEY = 27,
UP_ARROW = 256+72,
DOWN_ARROW = 256+80,
LEFT_ARROW = 256+75,
RIGHT_ARROW = 256+77
};
COORD Pos;
COORD Pos2;
SHORT grid_x; //Shorts take less room than integers.
SHORT grid_y; //Y axis grid for main player.
SHORT Counter; //Universal counter.
SHORT c2; //A second universal counter.
SHORT Epos_X[4]; //Enemy position X, totals 5(C++ is 0 based)
SHORT Epos_Y[4]; //Enemy Position Y.
byte b1=0; //Boolean 1.
byte b2=0; //Boolean 2. Bytes are the smallest integer-type value.
void yourturn();
void enemyturn();
void GAMEOVER();
int get_arrow();
int get_random(int cap);
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
HANDLE h2 = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD Color;
CONSOLE_SCREEN_BUFFER_INFO inf;
CONSOLE_CURSOR_INFO Cur;
int main() { //Main thing, sets up everything.
srand(time(NULL));
clrscr();
GetConsoleScreenBufferInfo(h2, &inf);
Color = inf.wAttributes;
Cur.bVisible = FALSE;
Cur.dwSize = 1;
SetConsoleTextAttribute(h, BACKGROUND_RED | BACKGROUND_INTENSITY);
SetConsoleCursorInfo(h, &Cur);
SetConsoleTitle("Some Weird Game (Esc to exit.)");
Pos2.X = 0;
Pos2.Y = 0;
Epos_X[0] = 10;
Epos_Y[0] = 7;
Epos_X[1] = 5;
Epos_Y[1] = 15;
Epos_X[2] = 13;
Epos_Y[2] = 8;
Epos_X[3] = 5;
Epos_Y[3] = 7;
Epos_X[4] = 20;
Epos_Y[4] = 12;
grid_x = 10;
grid_y = 13;
for(Counter=0; Counter < 80; Counter++)
for(c2=0; c2 < 25; c2++) {
Pos.X = Counter;
Pos.Y = c2;
SetConsoleCursorPosition(h, Pos);
if(Counter == grid_x && c2 == grid_y)
cout << "*" << endl;
else
cout << " " << endl;
if(Counter == Epos_X[0] && c2 == Epos_Y[0]) {
SetConsoleTextAttribute(h, BACKGROUND_GREEN | BACKGROUND_INTENSITY);
Pos.X = Epos_X[0];
Pos.Y = Epos_Y[0];
SetConsoleCursorPosition(h, Pos);
cout << "@" << endl;
SetConsoleTextAttribute(h, BACKGROUND_RED | BACKGROUND_INTENSITY);
}
SetConsoleCursorPosition(h, Pos2);
}
SetConsoleCursorPosition(h, Pos2);
for(;;) //63
yourturn();
clrscr();
SetConsoleTextAttribute(h2, Color);
return 0;
}
void yourturn() {
SHORT buffer;
buffer = get_arrow();
if(buffer == ESC_KEY) {
clrscr();
SetConsoleTextAttribute(h2, Color);
exit(0);
}
if(buffer == DOWN_ARROW)
if(grid_y == 23)
cout << "";
else
grid_y++;
if(buffer == UP_ARROW)
if(grid_y == 1)
cout << "";
else
grid_y--;
if(buffer == LEFT_ARROW)
if(grid_x == 1)
cout << "";
else
grid_x--;
if(buffer == RIGHT_ARROW)
if(grid_x == 78)
cout << "";
else
grid_x++;
enemyturn();
}
void enemyturn() {
SHORT buffer;
SHORT sMov;
SHORT x;
for(x=0; x < 5; x++) {
sMov = get_random(8);
if(sMov == 1 || sMov == 5)
if(Epos_X[x] < 77 && b1 == 0)
Epos_X[x]++;
else
b1=1;
if(sMov == 2 || sMov == 6)
if(Epos_X[x] > 1 && b1 == 1)
Epos_X[x]--;
else {
Epos_X[x]++;
b1=0;
}
if(sMov == 3 || sMov == 7)
if(Epos_Y[x] < 23 && b2 == 0)
Epos_Y[x]++;
else
b2=1;
if(sMov == 4 || sMov == 8)
if(Epos_Y[x] > 1 && b2 == 1)
Epos_Y[x]--;
else {
Epos_Y[x]++;
b2=0;
}
}
for(Counter=0; Counter < 80; Counter++)
for(c2=0; c2 < 25; c2++) {
Pos.X = Counter;
Pos.Y = c2;
SetConsoleCursorPosition(h, Pos);
if(Counter == grid_x && c2 == grid_y)
cout << "*" << endl;
else
cout << " " << endl;
for(x=0; x < 5; x++) {
if(Counter == Epos_X[x] && c2 == Epos_Y[x]) {
SetConsoleTextAttribute(h, BACKGROUND_GREEN | BACKGROUND_INTENSITY);
Pos.X = Epos_X[x];
Pos.Y = Epos_Y[x];
SetConsoleCursorPosition(h, Pos);
cout << "@" << endl;
SetConsoleTextAttribute(h, BACKGROUND_RED | BACKGROUND_INTENSITY);
}
}
SetConsoleCursorPosition(h, Pos2);
}
for(x=0; x < 5; x++)
if(Epos_X[x] == grid_x && Epos_Y[x] == grid_y)
GAMEOVER();
}
void GAMEOVER() {
clrscr();
for(c2=0; c2 < 25; c2++)
for(Counter=0; Counter < 80; Counter++) {
Pos.X = Counter;
Pos.Y = c2;
SetConsoleCursorPosition(h, Pos);
SetConsoleTextAttribute(h, BACKGROUND_BLUE | FOREGROUND_INTENSITY);
cout << " " << endl;
}
SetConsoleCursorPosition(h, Pos2);
Sleep(2000);
clrscr();
cout << "You have DIED! Sorry, to lazy to make a restart function :P" << endl;
SetConsoleTextAttribute(h, Color);
Sleep(2000);
exit(0);
}
int get_arrow() {
int ch = getch();
if(ch == 0 || ch == 224)
ch = 256 + getch();
return ch;
}
int get_random(int cap) {
return (rand() % cap) + 1;
}
Sorry to post two of theyse, but I just cant find this damned error...
THANK YOU VERY MUCH in advance!!!!!!!!!!!!!!!!!!!!!!!!!