Ignore:
Timestamp:
07/22/02 13:15:30 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mgui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mgui/MCamDisplay.cc

    r1406 r1423  
    3333#include "MCamDisplay.h"
    3434
    35 #include <math.h>
    3635#include <fstream.h>
    3736#include <iostream.h>
    3837
    39 #include <TClonesArray.h>
    40 #include <TCanvas.h>
    41 #include <TStyle.h>
    4238#include <TBox.h>
    4339#include <TText.h>
     40#include <TStyle.h>
     41#include <TCanvas.h>
    4442#include <TButton.h>
     43#include <TClonesArray.h>
    4544
    4645#include "MHexagon.h"
  • trunk/MagicSoft/Mars/mgui/MineSweeper.cc

    r1406 r1423  
    2626//
    2727// 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.
    3046//
    3147////////////////////////////////////////////////////////////////////////////
    3248#include "MineSweeper.h"
    3349
    34 #include <math.h>
    35 #include <fstream.h>
    3650#include <iostream.h>
    3751
    38 #include <TClonesArray.h>
    39 #include <TCanvas.h>
    4052#include <TText.h>
    4153#include <TMarker.h>
    4254#include <TRandom.h>
     55#include <TCanvas.h>
     56#include <TClonesArray.h>
     57#include <TInterpreter.h>
    4358
    4459#include "MHexagon.h"
     
    5065ClassImp(MineSweeper);
    5166
    52 //                                 gelb grn blau trkis rosa  rot
    53 //                              0, 1    2    3    4      5     6
    54 static Int_t InitColors[7] = { 22, 5,   3,   4,   7,     6,    2 };
     67const Int_t MineSweeper::fColorBombs[7] = {
     68    22,
     69    kYellow,
     70    kGreen,
     71    kBlue,
     72    kCyan,
     73    kMagenta,
     74    kRed
     75};
    5576
    5677void MineSweeper::Free()
     
    159180    : fGeomCam(NULL), fDone(NULL), fShow(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
    160181{
    161     memcpy(fColorBombs, InitColors, sizeof(InitColors));
    162 
    163182    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);
    164191
    165192    Draw();
     
    275302
    276303    //
     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    //
    277313    // Reset the game pad
    278314    //
     
    297333void MineSweeper::Reset()
    298334{
    299     if (!fShow)
    300     {
    301 
    302         fShow = new TText;
    303         fShow->SetTextAlign(23);   // centered/bottom
    304 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    305         fShow->SetBit(kNoContextMenu|kCannotPick);
    306 #endif
    307         fShow->Draw();
    308     }
    309 
    310335    if (fDone)
    311336    {
     
    320345
    321346        (*this)[i].SetFillColor(kHidden);
    322         (*fGeomCam)[i].ResetBit(kHasBomb|kIsVisible|kHasFlag);
     347        (*fGeomCam)[i].ResetBit(kUserBits);
    323348
    324349        GetFlag(i)->SetMarkerColor(kBlack);
     
    326351    Update(fNumBombs);
    327352
     353    TRandom rnd(0);
    328354    for (int i=0; i<fNumBombs; i++)
    329355    {
    330356        Int_t idx;
    331357
    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));
    339360
    340361        (*fGeomCam)[idx].SetBit(kHasBomb);
     
    432453        return;
    433454
    434     //cout << "Execute Event Camera " << event << " @ " << px << " " << py << endl;
     455    /*
     456    if (event==kKeyPress && py==0x1000)
     457    {
     458        Reset();
     459        return;
     460    }
     461    */
    435462
    436463    UInt_t idx;
     
    449476
    450477        if (pix.TestBit(kHasBomb))
    451             Done("Argh... you hit the Bomb!!!", 2);
     478            Done("Argh... you hit the Bomb!!!", kRed);
    452479    }
    453480
     
    475502
    476503    if (vis==fNumPixels && !fDone)
    477         Done("Great! Congratulations, you did it!", 3);
     504        Done("Great! Congratulations, you did it!", kGreen);
    478505
    479506    fDrawingPad->Modified();
  • trunk/MagicSoft/Mars/mgui/MineSweeper.h

    r1402 r1423  
    1919{
    2020private:
     21    static const Int_t fColorBombs[7]; // colors for the hexagons
     22
    2123    MGeomCam      *fGeomCam;       // pointer to camera geometry
    2224
     
    3234    TText         *fShow;          // TText showing the numbers of pixels and bombs
    3335
    34     Int_t          fColorBombs[7]; // colors for the hexagons
    35 
    3636    UInt_t         fW;             // Width of canvas
    3737    UInt_t         fH;             // Height of canvas
     
    4141    enum
    4242    {
    43         kBlack     =  1,      // schwarz
    44         kWhite     = 10,
     43//        kBlack     =  1,      // schwarz
     44//        kWhite     = 10,
    4545        kHidden    = 50,
    4646        kIsVisible = BIT(15),
    4747        kHasBomb   = BIT(16),
    48         kHasFlag   = BIT(17)
     48        kHasFlag   = BIT(17),
     49        kUserBits  = 0x0000ff00, // 14-23 are allowed
     50
    4951    };
     52
     53    MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
    5054
    5155    TText   *GetText(Int_t i) { return (TText*)fText->At(i); }
    5256    TMarker *GetFlag(Int_t i) { return (TMarker*)fFlags->At(i); }
    5357
    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();
    5565
    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; }
    6570
    6671public:
     
    6873    ~MineSweeper();
    6974
    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*
    7376    void ChangeCamera(); //*MENU*
    74     void Reset();        //*MENU*
    75 
    76     virtual void Draw(Option_t *option="");
    7777
    7878    ClassDef(MineSweeper, 0) // Magic Camera Games
Note: See TracChangeset for help on using the changeset viewer.