Public feed #603148

Stuff

public text v1 · immutable
Raw Edit
·published 2007-07-04 15:47 UTC
rendered paste body
#include <iostream>
#include <fstream>

using namespace std;

#define NL              "\n"
#define MAP_HEIGHT      10
#define MAP_WIDTH       10


void LoadMap(char map[MAP_HEIGHT][MAP_WIDTH]) {
     ifstream file ("map.txt");
 
     /*
     map.txt -tiedosto on seuraavanlainen:
     0000000000
     0111011110
     0111011110
     0111011110
     0100001100
     0101111110
     0101111110
     0101111110
     0111111110
     0000000000
     */
 
     if (file.is_open()) {
 
         for (int n=0; n < MAP_HEIGHT; n++) {
             for (int m=0; m < MAP_WIDTH; m++) {
                 map[n][m] = file.get();
             }
         }
 
         file.close();
         
     }
     else { cout << "Unable to open file!" << NL; }
 
}
 
 
void DrawMap (char map[MAP_HEIGHT][MAP_WIDTH]) {
     for (int n=0; n<MAP_HEIGHT; n++) {
         for (int m=0; m<MAP_WIDTH; m++) {
             cout << map[n][m];
         }
 
     cout << NL;
     }
}
 
int main() {
    char kartta[MAP_HEIGHT][MAP_WIDTH];
    LoadMap(kartta);
 
    DrawMap (kartta);
 
    return 0;
}