📄 e19-01.cpp
字号:
// =======================================================
// Chapter 19, Example 1
// Converting a tilemap to the new map format.
// =======================================================
#include <iostream.h>
#include <stdio.h>
#include "Array3D.h"
void main()
{
// name of the file to convert
char filename[64];
// the 4-layer 64x64 map
Array3D<int> mapdata( 64, 64, 4 );
// the exit strings
char exits[3][64];
// the type of map. 0 is a 64x64x2 tilemap with 2 extra layers
// for items and people (see chapter 9).
int maptype = 0;
// the file to convert.
FILE* f = 0;
cout << "Enter a filename: ";
cin >> filename;
cout << "converting file...";
f = fopen( filename, "rb" );
// read in the map
fread( mapdata.m_array, 64*64*4, sizeof(int), f );
// read in the exit strings
fread( exits[0], 64, sizeof(char), f );
fread( exits[1], 64, sizeof(char), f );
fread( exits[2], 64, sizeof(char), f );
// close the file.
fclose( f );
// now save the data back to disk in the new format:
f = fopen( filename, "wb" );
// write the version number
fwrite( &maptype, 1, sizeof(int), f );
// write the map data
fwrite( mapdata.m_array, 64*64*4, sizeof(int), f );
// write the exit strings
fwrite( exits[0], 64, sizeof(char), f );
fwrite( exits[1], 64, sizeof(char), f );
fwrite( exits[2], 64, sizeof(char), f );
// close the file
fclose( f );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -