Click here to Skip to main content
Click here to Skip to main content

CMapEditor

, 14 Oct 2003
Rate this:
Please Sign up or sign in to vote.
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

About the Author

eugi

United States United States
No Biography provided

Comments and Discussions

 
GeneralTaking it further Pinsusslakie16-Oct-03 21:51 
GeneralRe: Taking it further PinmemberKlaus Nowikow19-Oct-03 23:08 
GeneralNice PineditorMarc Clifton9-Oct-03 9:56 
GeneralRe: Nice Pinmembereugi9-Oct-03 10:07 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 15 Oct 2003
Article Copyright 2003 by eugi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid