Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 1422)
+++ trunk/MagicSoft/Mars/Changelog	(revision 1423)
@@ -1,3 +1,19 @@
                                                                   -*-*- END -*-*-
+
+ 2002/07/22: Thomas Bretz
+
+   * mgui/MCamDisplay.cc:
+     - removed some unecessary includes
+     - replaced *fPixels by *this
+
+   * mgui/MineSweeper.[h,cc]:
+     - added more comments
+     - removed some unnecessary includes
+     - replaced enum constants for colors by the root ones
+     - added gInterpreter->DeleteGlobal(this)
+     - removed the deletion of the self-allocated fDrawingPad
+     - added kUserBits, replacing kBitMask
+
+
 
  2002/07/16: Thomas Bretz
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 1422)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 1423)
@@ -33,14 +33,13 @@
 #include "MCamDisplay.h"
 
-#include <math.h>
 #include <fstream.h>
 #include <iostream.h>
 
-#include <TClonesArray.h>
-#include <TCanvas.h>
-#include <TStyle.h>
 #include <TBox.h>
 #include <TText.h>
+#include <TStyle.h>
+#include <TCanvas.h>
 #include <TButton.h>
+#include <TClonesArray.h>
 
 #include "MHexagon.h"
Index: trunk/MagicSoft/Mars/mgui/MineSweeper.cc
===================================================================
--- trunk/MagicSoft/Mars/mgui/MineSweeper.cc	(revision 1422)
+++ trunk/MagicSoft/Mars/mgui/MineSweeper.cc	(revision 1423)
@@ -26,19 +26,34 @@
 //
 // MineSweeper
-//
-// Camera Display Games
+// -----------
+//
+// Camera Display Games: Mine Sweeper
+//
+// Start the game by:
+//   MineSweeper mine;
+//
+// It is the well known Mine Sweeper.
+// Set a mark using a single mouse click.
+// Open a pixel using a double click.
+//
+// Try to open all pixels without bombs. If you open a pixel with no
+// bomb around all pixels around are opened.
+//
+// To restart the game use the context menu. It can only be accessed if
+// the game has been stopped (either because you win the game or because
+// you hit a bomb) With the context menu you can also toggle between
+// different camera layouts.
 //
 ////////////////////////////////////////////////////////////////////////////
 #include "MineSweeper.h"
 
-#include <math.h>
-#include <fstream.h>
 #include <iostream.h>
 
-#include <TClonesArray.h>
-#include <TCanvas.h>
 #include <TText.h>
 #include <TMarker.h>
 #include <TRandom.h>
+#include <TCanvas.h>
+#include <TClonesArray.h>
+#include <TInterpreter.h>
 
 #include "MHexagon.h"
@@ -50,7 +65,13 @@
 ClassImp(MineSweeper);
 
-//                                 gelb grn blau trkis rosa  rot
-//                              0, 1    2    3    4      5     6
-static Int_t InitColors[7] = { 22, 5,   3,   4,   7,     6,    2 };
+const Int_t MineSweeper::fColorBombs[7] = {
+    22,
+    kYellow,
+    kGreen,
+    kBlue,
+    kCyan,
+    kMagenta,
+    kRed
+};
 
 void MineSweeper::Free()
@@ -159,7 +180,13 @@
     : fGeomCam(NULL), fDone(NULL), fShow(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
 {
-    memcpy(fColorBombs, InitColors, sizeof(InitColors));
-
     SetNewCamera(new MGeomCamMagic);
+
+    //
+    // Make sure, that the object is destroyed when the canvas/pad is
+    // destroyed. Make also sure, that the interpreter doesn't try to
+    // delete it a second time.
+    //
+    SetBit(kCanDelete);
+    gInterpreter->DeleteGlobal(this);
 
     Draw();
@@ -275,4 +302,13 @@
 
     //
+    // Draw the title text
+    //
+    fShow = new TText;
+    fShow->SetTextAlign(23);   // centered/bottom
+#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
+    fShow->SetBit(kNoContextMenu|kCannotPick);
+#endif
+    fShow->Draw();
+    //
     // Reset the game pad
     //
@@ -297,15 +333,4 @@
 void MineSweeper::Reset()
 {
-    if (!fShow)
-    {
-
-        fShow = new TText;
-        fShow->SetTextAlign(23);   // centered/bottom
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        fShow->SetBit(kNoContextMenu|kCannotPick);
-#endif
-        fShow->Draw();
-    }
-
     if (fDone)
     {
@@ -320,5 +345,5 @@
 
         (*this)[i].SetFillColor(kHidden);
-        (*fGeomCam)[i].ResetBit(kHasBomb|kIsVisible|kHasFlag);
+        (*fGeomCam)[i].ResetBit(kUserBits);
 
         GetFlag(i)->SetMarkerColor(kBlack);
@@ -326,15 +351,11 @@
     Update(fNumBombs);
 
+    TRandom rnd(0);
     for (int i=0; i<fNumBombs; i++)
     {
         Int_t idx;
 
-        TRandom rnd(0);
-        while (1)
-        {
-            idx = (Int_t)rnd.Uniform(fNumPixels);
-            if (!(*fGeomCam)[idx].TestBit(kHasBomb))
-                break;
-        }
+        do idx = (Int_t)rnd.Uniform(fNumPixels);
+        while ((*fGeomCam)[idx].TestBit(kHasBomb));
 
         (*fGeomCam)[idx].SetBit(kHasBomb);
@@ -432,5 +453,11 @@
         return;
 
-    //cout << "Execute Event Camera " << event << " @ " << px << " " << py << endl;
+    /*
+    if (event==kKeyPress && py==0x1000)
+    {
+        Reset();
+        return;
+    }
+    */
 
     UInt_t idx;
@@ -449,5 +476,5 @@
 
         if (pix.TestBit(kHasBomb))
-            Done("Argh... you hit the Bomb!!!", 2);
+            Done("Argh... you hit the Bomb!!!", kRed);
     }
 
@@ -475,5 +502,5 @@
 
     if (vis==fNumPixels && !fDone)
-        Done("Great! Congratulations, you did it!", 3);
+        Done("Great! Congratulations, you did it!", kGreen);
 
     fDrawingPad->Modified();
Index: trunk/MagicSoft/Mars/mgui/MineSweeper.h
===================================================================
--- trunk/MagicSoft/Mars/mgui/MineSweeper.h	(revision 1422)
+++ trunk/MagicSoft/Mars/mgui/MineSweeper.h	(revision 1423)
@@ -19,4 +19,6 @@
 {
 private:
+    static const Int_t fColorBombs[7]; // colors for the hexagons
+
     MGeomCam      *fGeomCam;       // pointer to camera geometry
 
@@ -32,6 +34,4 @@
     TText         *fShow;          // TText showing the numbers of pixels and bombs
 
-    Int_t          fColorBombs[7]; // colors for the hexagons
-
     UInt_t         fW;             // Width of canvas
     UInt_t         fH;             // Height of canvas
@@ -41,26 +41,31 @@
     enum
     {
-        kBlack     =  1,      // schwarz
-        kWhite     = 10,
+//        kBlack     =  1,      // schwarz
+//        kWhite     = 10,
         kHidden    = 50,
         kIsVisible = BIT(15),
         kHasBomb   = BIT(16),
-        kHasFlag   = BIT(17)
+        kHasFlag   = BIT(17),
+        kUserBits  = 0x0000ff00, // 14-23 are allowed
+
     };
+
+    MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
 
     TText   *GetText(Int_t i) { return (TText*)fText->At(i); }
     TMarker *GetFlag(Int_t i) { return (TMarker*)fFlags->At(i); }
 
-    MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
+    void  Remove(TObject *);
+    void  OpenHexagon(Int_t idx);
+    void  Done(TString, Int_t);
+    void  Update(Int_t);
+    void  SetNewCamera(MGeomCam *);
+    void  DrawHexagons();
+    void  Free();
 
-    void Paint(Option_t *option="");
-
-    void Remove(TObject *);
-    void OpenHexagon(Int_t idx);
-    void Done(TString, Int_t);
-    void Update(Int_t);
-    void SetNewCamera(MGeomCam *);
-    void DrawHexagons();
-    void Free();
+    void  Paint(Option_t *option="");
+    void  Draw(Option_t *option="");
+    void  ExecuteEvent(Int_t event, Int_t px, Int_t py);
+    Int_t DistancetoPrimitive(Int_t px, Int_t py) { return 0; }
 
 public:
@@ -68,11 +73,6 @@
     ~MineSweeper();
 
-    virtual Int_t DistancetoPrimitive(Int_t px, Int_t py) { return 0; }
-    virtual void  ExecuteEvent(Int_t event, Int_t px, Int_t py);
-
+    void Reset();        //*MENU*
     void ChangeCamera(); //*MENU*
-    void Reset();        //*MENU*
-
-    virtual void Draw(Option_t *option="");
 
     ClassDef(MineSweeper, 0) // Magic Camera Games
