Hello, I'm trying to make my maze game object-oriented. The problem is my mazeArray. I'm a bit confused on how to use it correctly to draw out my maze.

Map.h:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <process.h>
#include <cstdlib>
#include <ctime>
using namespace std;

#pragma once
class Map
{
    private:
        int m_mazeWidth;
        int m_mazeHeight;
        char m_mazeArray;

    public:
        WORD mazeColor;
        WORD endColor;
        WORD keyColor;
        WORD doorColor;
        WORD backgroundColor;
        WORD winColor;

        Map();
        ~Map();

        bool CanPlayerEnterSpace(int x, int y);
        void DrawASCIICharacter(int x, int y, unsigned char ch, WORD CharAttribute, CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight);
        void DrawMaze1234(char mazeArray, CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight);
        void ClearScreen(WORD CharAttribute, CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight);


};





Map.cpp :
Map::Map()
{
    m_mazeWidth;
    m_mazeHeight;

    m_mazeArray;


    mazeColor = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | BACKGROUND_INTENSITY;
    endColor = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_GREEN | BACKGROUND_INTENSITY;
    keyColor = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | BACKGROUND_INTENSITY;
    doorColor = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_RED | BACKGROUND_INTENSITY;
    backgroundColor = 0;
    winColor = BACKGROUND_BLUE | BACKGROUND_INTENSITY;

}


Map::~Map()
{
}
void Map::DrawASCIICharacter(int x, int y, unsigned char ch, WORD CharAttribute, CHAR_INFO *pScreen, int ScreenWidth, int ScreenHeight)
{
    if (x < 0) return;
    if (y < 0 ) return;
    if (x >= ScreenWidth) return;
    if (y >= ScreenHeight) return;

    pScreen[y*ScreenWidth + x].Char.AsciiChar = ch;
    pScreen[y*ScreenWidth + x].Attributes = CharAttribute;}


void Map::DrawMaze1234(char mazeArray, CHA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, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1,
    1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    };
    int mazeHeight = 45;
    int mazeWidth = 20;
    //int mazeArray[45*20];
    int r, c;
    for (r = 0; r < mazeHeight; r++)
    {
        for (c=0; c < mazeWidth; c++)
        {
            switch (mazeArray[r*mazeWidth + c])
            {
                case 1: DrawASCIICharacter(c, r, 219, mazeColor, pScreen, ScreenWidth, ScreenHeight); break;
                case 2: DrawASCIICharacter(c, r, 212, mazeColor, pScreen, ScreenWidth, ScreenHeight); break;
                case 3: DrawASCIICharacter(c, r, '*', endColor, pScreen, ScreenWidth, ScreenHeight); break;
                case 4: DrawASCIICharacter(c, r, 'K', keyColor, pScreen, ScreenWidth, ScreenHeight); break;
                case 5: DrawASCIICharacter(c, r, 68, doorColor, pScreen, ScreenWidth, ScreenHeight); break;

            }

        }
    }


}
bool Map::CanPlayerEnterSpace(int x, int y)
{
    int mazeArray[45*20];
    int mazeWidth = 20;
    int keys = 0;
    if (mazeArray[y*mazeWidth + x] == 1) return false;

    if (mazeArray[y*mazeWidth + x] == 5)
    {
        if (keys == 0) return false;
        else
        {
            keys--;
            mazeArray[y*mazeWidth + x] = 0;
            return true;
        }
    }

    return true;


}
void Map::ClearScreen(WORD CharAttribute, CHAR_INFO *pScreen,   int ScreenWidth, int ScreenHeight)
{
    int r, c;
    for (r = 0; r < ScreenHeight; r++)
    {
        for (c = 0; c < ScreenWidth; c++)
        {
            pScreen[r*ScreenWidth + c].Char.AsciiChar = ' ';
            pScreen[r*ScreenWidth + c].Attributes = CharAttribute;
        }
    }
}

Edited 3 Years Ago by GaryWazHere

What exactly is it doing wrong? Are you drawing the whole maze all at once? Do you have a screen shot, or detailed description, of how you want it to look?

This article has been dead for over six months. Start a new discussion instead.