1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <Windows.h>
#include <Tchar.h>
HANDLE wHnd; // Handle to write to the console.
HANDLE rHnd; // Handle to read from the console.
using namespace std;
class Map
{
public:
int m_nPosX, m_nPosY, m_nItem;
void SetInfo(int nItem, int nPosX, int nPosY)
{
m_nItem = nItem;
m_nPosX = nPosX;
m_nPosY = nPosY;
}
void Print()
{
cout << (char)m_nItem;
cout << " at position (" << m_nPosX << "," << m_nPosY << ")" << endl;
}
};
int main()
{
int i, j;
// Set up the handles for reading/writing:
wHnd = GetStdHandle(STD_OUTPUT_HANDLE);
rHnd = GetStdHandle(STD_INPUT_HANDLE);
// Change the window title:
SetConsoleTitle(TEXT("2D Array Test"));
// Set up the required window size:
SMALL_RECT windowSize = {0, 0, 79, 49};
// Change the console window size:
SetConsoleWindowInfo(wHnd, TRUE, &windowSize);
// Create a COORD to hold the buffer size:
COORD bufferSize = {80, 50};
// Change the internal buffer size:
SetConsoleScreenBufferSize(wHnd, bufferSize);
Map arryMap[80][50];
for (i=0; i<80; i++){
for (j=0; j<50; j++){
Map arryMap[i][j].SetInfo(01, i, j);
}
}
// Set up the positions:
COORD charBufSize = {80,50};
COORD characterPos = {0,0};
SMALL_RECT writeArea = {0,0,79,49};
// Copy to display:
WriteConsoleOutputA(wHnd, arryMap, charBufSize, characterPos, &writeArea);
}
|