I'm trying out tile engine making but it isn't working!?!?!?!
Why o why....
(i know the code is sloppy i just wanted it to work)
Code:
#include <fstream.h>
#include <stdlib.h>
#include <dos.h>
#include <stdio.h>
#include <string.h>
#include <conio.c>
int tiles[16][26];
int tile = 1;
int row = 1;
char filename[50];
int px,py;
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
int main() {
cout << "Filename: ";
cin >> filename;
ifstream in(filename);
char temp[200];
while(row!=17){
cout << in.tellg();
for(int tnr = 1;tnr!=25;tnr++){
in >> tiles[row][tnr];
}
row++;
}
tile = 1;
row = 1;
clrscr();
while(row != 16 || tile != 25){
switch(tiles[row][tile]){
case 1:
SetConsoleTextAttribute(hStdout, BACKGROUND_RED|BACKGROUND_BLUE|BACKGROUND_GREEN);
cout << " ";
break;
case 2:
SetConsoleTextAttribute(hStdout, BACKGROUND_GREEN);
cout << " ";
break;
case 3:
SetConsoleTextAttribute(hStdout, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY | BACKGROUND_GREEN);
cout << "$";
break;
}
if(tile!=25) {
tile++;
}
else
{
if(row!=16) {
tile = 1;
}
row++;
textbackground( BLACK );
textcolor(LIGHTGRAY);
}
}
char ch[20];
px = 5;
py = 5;
while(strcmp(ch,"exit")!=0) {
gotoxy(px,py);
SetConsoleTextAttribute(hStdout, FOREGROUND_RED|BACKGROUND_GREEN);
cout << "X";
gotoxy(5,22);
SetConsoleTextAttribute(hStdout, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|BLACK);
cout << " ";
gotoxy(5,22);
cout << "Go <n>orth, <s>out, <w>est, <e>ast or <exit>: ";
cin.clear();
ch = getch();
gotoxy(px,py);
SetConsoleTextAttribute(hStdout, FOREGROUND_RED|BACKGROUND_GREEN);
cout << " ";
if(strcmp(ch,"n")==0) {
py-=1;
} else if(strcmp(ch,"s")==0) {
py+=1;
} else if(strcmp(ch,"w")==0) {
px-=1;
} else if(strcmp(ch,"e")==0) {
px+=1;
}
}
}
EDIT:: i do not know why i have included dos.h...