Click here to Skip to main content
15,912,665 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: PropertyPages+Sheet Pin
PJ Arends1-Feb-06 7:55
professionalPJ Arends1-Feb-06 7:55 
QuestionHow to find Processor serial no? Pin
<color>Aljechin 31-Jan-06 21:35
<color>Aljechin 31-Jan-06 21:35 
AnswerRe: How to find Processor serial no? Pin
Owner drawn31-Jan-06 21:54
Owner drawn31-Jan-06 21:54 
AnswerRe: How to find Processor serial no? Pin
_AnsHUMAN_ 31-Jan-06 22:13
_AnsHUMAN_ 31-Jan-06 22:13 
Questionhello.. Pin
KORCARI31-Jan-06 21:35
KORCARI31-Jan-06 21:35 
AnswerRe: hello.. Pin
_AnsHUMAN_ 31-Jan-06 21:44
_AnsHUMAN_ 31-Jan-06 21:44 
QuestionI still dont know how to move the hole Pin
eivanlo31-Jan-06 21:04
eivanlo31-Jan-06 21:04 
AnswerRe: I still dont know how to move the hole Pin
Stephen Hewitt31-Jan-06 21:37
Stephen Hewitt31-Jan-06 21:37 
I'll assume we have an array as follows:
enum
{
     MatrixWidth = 2,
     MatrixHeight = 2
};

char g_Matrix[MatrixWidth][MatrixHeight];


I'll store the coordinates of the hole in the following variables:
int g_HoleX;
int g_HoleY;


To clarrify your matrix has the following properties:
 g_Matrix[0][0] = 'C';
 g_Matrix[1][0] = 'A';
 g_Matrix[0][1] = 'B';
 g_Matrix[1][1] = 'h';
 g_HoleX = 1;
 g_HoleY = 1;


The following function should move the hole:
enum Direction
{
     Up,
     Down,
     Left,
     Right
};

bool Move(Direction dir)
{
     int x = g_HoleX;
     int y = g_HoleY;
 
     switch(dir)
     {
     case Up:
         if (g_HoleY == 0)
         {
              return false;
         }
         y -= 1;
         break;
 
     case Down:
         if (g_HoleY == MatrixHeight-1)
         {
              return false;
         }
         y += 1;
         break;
 
     case Left:
         if (g_HoleX == 0)
         {
              return false;
         }
         x -= 1;
         break;
 
     case Right:
         if (g_HoleX == MatrixWidth-1)
         {
              return false;
         }
         x += 1;
         break;
     }
 
     char temp = g_Matrix[g_HoleX][g_HoleY];
     g_Matrix[g_HoleX][g_HoleY] = g_Matrix[x][y];
     g_Matrix[x][y] = temp;
     g_HoleX = x;
     g_HoleY = y;
 	
     return true;
}


NOTE: I have not tested any of this. If you want diagonals you'll have to modify it slightly.

Steve


-- modified at 4:56 Wednesday 1st February, 2006
Questionascii code for Ctrl+Esc Pin
mysticlol31-Jan-06 20:00
mysticlol31-Jan-06 20:00 
AnswerRe: ascii code for Ctrl+Esc Pin
kakan31-Jan-06 20:47
professionalkakan31-Jan-06 20:47 
AnswerRe: ascii code for Ctrl+Esc Pin
PJ Arends1-Feb-06 8:12
professionalPJ Arends1-Feb-06 8:12 
QuestionRelated to thunderbird extension Pin
baldha rakesh31-Jan-06 18:50
baldha rakesh31-Jan-06 18:50 
QuestionWM_OBJECTSEL Pin
ragavan31-Jan-06 18:47
ragavan31-Jan-06 18:47 
AnswerRe: WM_OBJECTSEL Pin
Stephen Hewitt31-Jan-06 22:08
Stephen Hewitt31-Jan-06 22:08 
GeneralRe: WM_OBJECTSEL Pin
ragavan31-Jan-06 22:53
ragavan31-Jan-06 22:53 
QuestionMemory usage decreases when the application GUI is minimized Pin
techratna31-Jan-06 15:33
techratna31-Jan-06 15:33 
AnswerRe: Memory usage decreases when the application GUI is minimized Pin
Stephen Hewitt31-Jan-06 15:52
Stephen Hewitt31-Jan-06 15:52 
GeneralRe: Memory usage decreases when the application GUI is minimized Pin
techratna1-Feb-06 1:56
techratna1-Feb-06 1:56 
AnswerRe: Memory usage decreases when the application GUI is minimized Pin
krmed1-Feb-06 1:54
krmed1-Feb-06 1:54 
Questioncontrol in View Pin
LeeeNN31-Jan-06 14:32
LeeeNN31-Jan-06 14:32 
AnswerRe: control in View Pin
Stephen Hewitt31-Jan-06 16:15
Stephen Hewitt31-Jan-06 16:15 
Questiontemplate classes & dlls Pin
Themis31-Jan-06 13:54
Themis31-Jan-06 13:54 
QuestionRemoving Min/Max buttons from an application Pin
rentzk31-Jan-06 13:50
rentzk31-Jan-06 13:50 
AnswerRe: Removing Min/Max buttons from an application Pin
Owner drawn31-Jan-06 16:56
Owner drawn31-Jan-06 16:56 
GeneralRe: Removing Min/Max buttons from an application Pin
rentzk1-Feb-06 6:41
rentzk1-Feb-06 6:41 

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.