Click here to Skip to main content
15,879,184 members
Articles / Programming Languages / C++
Article

CMapEditor

Rate me:
Please Sign up or sign in to vote.
4.00/5 (9 votes)
14 Oct 20032 min read 47.8K   1.2K   15   4
A simple and efficient interface for using a multi-level matrix of values.

Introduction

CMapEditor is a simple and efficient interface for using a multi-level matrix of values. This can be easily used in games or any other program that requires a versatile map structure.

Functions

How to use CMapEditor:

#include "CMapEditor.h"

Include the .h file in your code. Keep also in mind that CMapEditor requires the <vector> header to be present on your machine.

To initialize a map just use:

CMapEditor meEditor(WIDTH,HEIGHT,LEVELS);

or

CMapEditor *meEditor = new CMapEditor(WIDTH,HEIGHT,LEVELS);

To set a cell's value in the map, use:

meEditor->SetMapValue(X,Y,LEVEL,VALUE);

You can also use advanced operations, such as region fill, or drag-like procedures:

meEditor->Fill(X,Y,LEVEL,REPLACE_VALUE,VALUE);

and

meEditor->StartDrag(X,Y,LEVEL);
meEditor->EndDrag(DX,DY,VALUE);

CMapEditor also supports basic undo and redo operations. You can decide what is going to be undone by calling

meEditor->NextUndo();

before performing other operations. For example:

meEditor->NextUndo();
meEditor->SetMapValue(X,Y,LEVEL,VALUE);
eEditor->Fill(X,Y,LEVEL,REPLACE_VALUE,VALUE);
...

in this case, the SetMapValue() and the Fill() effects will be undone together. To perform undo and redo, just use:

meEditor->Undo();

and

meEditor->Redo();

Why did I write this class

Actually, the purpose of this class was for me to learn. And I did. As a matter of fact, class programming was a bizarre way of thinking about stuff before, therefore, I decided to start from the basics, and started learning about that. OK, I got the basics, but if you have any comments on how I programmed the class, please let me know. Secondly, I wanted to get familiar with Hungarian notation (all my other projects are big messes), so if you have comments also on that, let me know. And finally, I learned how to use vectors, which I didn't expect to use (actually, I didn't even know what thery were) and they seem to be pretty useful. Another reason for which I decided to write this class, is that I wanted to contribute something hopefully useful to CodeProject.

History

  • Last Update (15 Oct 2003)
    • I have fixed some memory leaks issues. Now the class destructor is correct.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralTaking it further Pin
lakie16-Oct-03 21:51
lakie16-Oct-03 21:51 
GeneralRe: Taking it further Pin
Klaus Nowikow19-Oct-03 23:08
Klaus Nowikow19-Oct-03 23:08 
GeneralNice Pin
Marc Clifton9-Oct-03 9:56
mvaMarc Clifton9-Oct-03 9:56 
Simple and elegant. And good formatting of the article. One thing--I get a "file corrupt" error when I try to download the source. Any ideas?

Keep up the good work!

Marc

Latest AAL Article
My blog
Join my forum!
GeneralRe: Nice Pin
eugi9-Oct-03 10:07
eugi9-Oct-03 10:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.