Changeset 1423 for trunk/MagicSoft/Mars/mgui
- Timestamp:
- 07/22/02 13:15:30 (22 years ago)
- Location:
- trunk/MagicSoft/Mars/mgui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
r1406 r1423 33 33 #include "MCamDisplay.h" 34 34 35 #include <math.h>36 35 #include <fstream.h> 37 36 #include <iostream.h> 38 37 39 #include <TClonesArray.h>40 #include <TCanvas.h>41 #include <TStyle.h>42 38 #include <TBox.h> 43 39 #include <TText.h> 40 #include <TStyle.h> 41 #include <TCanvas.h> 44 42 #include <TButton.h> 43 #include <TClonesArray.h> 45 44 46 45 #include "MHexagon.h" -
trunk/MagicSoft/Mars/mgui/MineSweeper.cc
r1406 r1423 26 26 // 27 27 // MineSweeper 28 // 29 // Camera Display Games 28 // ----------- 29 // 30 // Camera Display Games: Mine Sweeper 31 // 32 // Start the game by: 33 // MineSweeper mine; 34 // 35 // It is the well known Mine Sweeper. 36 // Set a mark using a single mouse click. 37 // Open a pixel using a double click. 38 // 39 // Try to open all pixels without bombs. If you open a pixel with no 40 // bomb around all pixels around are opened. 41 // 42 // To restart the game use the context menu. It can only be accessed if 43 // the game has been stopped (either because you win the game or because 44 // you hit a bomb) With the context menu you can also toggle between 45 // different camera layouts. 30 46 // 31 47 //////////////////////////////////////////////////////////////////////////// 32 48 #include "MineSweeper.h" 33 49 34 #include <math.h>35 #include <fstream.h>36 50 #include <iostream.h> 37 51 38 #include <TClonesArray.h>39 #include <TCanvas.h>40 52 #include <TText.h> 41 53 #include <TMarker.h> 42 54 #include <TRandom.h> 55 #include <TCanvas.h> 56 #include <TClonesArray.h> 57 #include <TInterpreter.h> 43 58 44 59 #include "MHexagon.h" … … 50 65 ClassImp(MineSweeper); 51 66 52 // gelb grn blau trkis rosa rot 53 // 0, 1 2 3 4 5 6 54 static Int_t InitColors[7] = { 22, 5, 3, 4, 7, 6, 2 }; 67 const Int_t MineSweeper::fColorBombs[7] = { 68 22, 69 kYellow, 70 kGreen, 71 kBlue, 72 kCyan, 73 kMagenta, 74 kRed 75 }; 55 76 56 77 void MineSweeper::Free() … … 159 180 : fGeomCam(NULL), fDone(NULL), fShow(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE) 160 181 { 161 memcpy(fColorBombs, InitColors, sizeof(InitColors));162 163 182 SetNewCamera(new MGeomCamMagic); 183 184 // 185 // Make sure, that the object is destroyed when the canvas/pad is 186 // destroyed. Make also sure, that the interpreter doesn't try to 187 // delete it a second time. 188 // 189 SetBit(kCanDelete); 190 gInterpreter->DeleteGlobal(this); 164 191 165 192 Draw(); … … 275 302 276 303 // 304 // Draw the title text 305 // 306 fShow = new TText; 307 fShow->SetTextAlign(23); // centered/bottom 308 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06) 309 fShow->SetBit(kNoContextMenu|kCannotPick); 310 #endif 311 fShow->Draw(); 312 // 277 313 // Reset the game pad 278 314 // … … 297 333 void MineSweeper::Reset() 298 334 { 299 if (!fShow)300 {301 302 fShow = new TText;303 fShow->SetTextAlign(23); // centered/bottom304 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)305 fShow->SetBit(kNoContextMenu|kCannotPick);306 #endif307 fShow->Draw();308 }309 310 335 if (fDone) 311 336 { … … 320 345 321 346 (*this)[i].SetFillColor(kHidden); 322 (*fGeomCam)[i].ResetBit(k HasBomb|kIsVisible|kHasFlag);347 (*fGeomCam)[i].ResetBit(kUserBits); 323 348 324 349 GetFlag(i)->SetMarkerColor(kBlack); … … 326 351 Update(fNumBombs); 327 352 353 TRandom rnd(0); 328 354 for (int i=0; i<fNumBombs; i++) 329 355 { 330 356 Int_t idx; 331 357 332 TRandom rnd(0); 333 while (1) 334 { 335 idx = (Int_t)rnd.Uniform(fNumPixels); 336 if (!(*fGeomCam)[idx].TestBit(kHasBomb)) 337 break; 338 } 358 do idx = (Int_t)rnd.Uniform(fNumPixels); 359 while ((*fGeomCam)[idx].TestBit(kHasBomb)); 339 360 340 361 (*fGeomCam)[idx].SetBit(kHasBomb); … … 432 453 return; 433 454 434 //cout << "Execute Event Camera " << event << " @ " << px << " " << py << endl; 455 /* 456 if (event==kKeyPress && py==0x1000) 457 { 458 Reset(); 459 return; 460 } 461 */ 435 462 436 463 UInt_t idx; … … 449 476 450 477 if (pix.TestBit(kHasBomb)) 451 Done("Argh... you hit the Bomb!!!", 2);478 Done("Argh... you hit the Bomb!!!", kRed); 452 479 } 453 480 … … 475 502 476 503 if (vis==fNumPixels && !fDone) 477 Done("Great! Congratulations, you did it!", 3);504 Done("Great! Congratulations, you did it!", kGreen); 478 505 479 506 fDrawingPad->Modified(); -
trunk/MagicSoft/Mars/mgui/MineSweeper.h
r1402 r1423 19 19 { 20 20 private: 21 static const Int_t fColorBombs[7]; // colors for the hexagons 22 21 23 MGeomCam *fGeomCam; // pointer to camera geometry 22 24 … … 32 34 TText *fShow; // TText showing the numbers of pixels and bombs 33 35 34 Int_t fColorBombs[7]; // colors for the hexagons35 36 36 UInt_t fW; // Width of canvas 37 37 UInt_t fH; // Height of canvas … … 41 41 enum 42 42 { 43 kBlack = 1, // schwarz44 kWhite = 10,43 // kBlack = 1, // schwarz 44 // kWhite = 10, 45 45 kHidden = 50, 46 46 kIsVisible = BIT(15), 47 47 kHasBomb = BIT(16), 48 kHasFlag = BIT(17) 48 kHasFlag = BIT(17), 49 kUserBits = 0x0000ff00, // 14-23 are allowed 50 49 51 }; 52 53 MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); } 50 54 51 55 TText *GetText(Int_t i) { return (TText*)fText->At(i); } 52 56 TMarker *GetFlag(Int_t i) { return (TMarker*)fFlags->At(i); } 53 57 54 MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); } 58 void Remove(TObject *); 59 void OpenHexagon(Int_t idx); 60 void Done(TString, Int_t); 61 void Update(Int_t); 62 void SetNewCamera(MGeomCam *); 63 void DrawHexagons(); 64 void Free(); 55 65 56 void Paint(Option_t *option=""); 57 58 void Remove(TObject *); 59 void OpenHexagon(Int_t idx); 60 void Done(TString, Int_t); 61 void Update(Int_t); 62 void SetNewCamera(MGeomCam *); 63 void DrawHexagons(); 64 void Free(); 66 void Paint(Option_t *option=""); 67 void Draw(Option_t *option=""); 68 void ExecuteEvent(Int_t event, Int_t px, Int_t py); 69 Int_t DistancetoPrimitive(Int_t px, Int_t py) { return 0; } 65 70 66 71 public: … … 68 73 ~MineSweeper(); 69 74 70 virtual Int_t DistancetoPrimitive(Int_t px, Int_t py) { return 0; } 71 virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py); 72 75 void Reset(); //*MENU* 73 76 void ChangeCamera(); //*MENU* 74 void Reset(); //*MENU*75 76 virtual void Draw(Option_t *option="");77 77 78 78 ClassDef(MineSweeper, 0) // Magic Camera Games
Note:
See TracChangeset
for help on using the changeset viewer.