소스 검색

merge fix

Bernardo Magri 10 달 전
부모
커밋
b6a6e16d3a
4개의 변경된 파일17개의 추가작업 그리고 15개의 파일을 삭제
  1. 1 2
      src/minefield.cpp
  2. 1 1
      src/minefield.hpp
  3. 14 11
      src/window.cpp
  4. 1 1
      src/window.hpp

+ 1 - 2
src/minefield.cpp

@@ -57,14 +57,13 @@ void MineField::initBombs(int x, int y) {
   startTimer();
 
   //init the timer to zero and start the timer thread
-  //  m_time = 0;
-  //timerThread = std::thread(&MineField::timerTick, this);
   //timerThread.detach(); //not sure if this is okay (better to call join() when I set the condition to stop the thread)
 }
 
 bool MineField::openCell(int x, int y) {
   if(isBomb(x, y)) {
     m_exploded = true;
+    timerThread.join();
     gameOverSignal.emit();
     stopTimer();
     return false;

+ 1 - 1
src/minefield.hpp

@@ -56,5 +56,5 @@ public:
   sigc::signal<void(int)>          remainingFlagsSignal;
   sigc::signal<void(void)>         gameWonSignal;
   sigc::signal<void(void)>         gameOverSignal;
-  sigc::signal<void(unsigned int)> timerSignal;
+  sigc::signal<void(size_t)>       timerSignal;
 };

+ 14 - 11
src/window.cpp

@@ -163,20 +163,22 @@ void MainWindow::gameOver() {
   //std::cout << "Signal gameOver emmited\n";
 }
 
-bool MainWindow::updateClockLabel()
+void MainWindow::updateClockLabel(size_t time)
 {
-  ++m_elapsedTime;
+  //++m_elapsedTime;
 
-  int deciseconds = m_elapsedTime % 10;
-  int seconds = (m_elapsedTime / 10) % 60;
-  int minutes = (m_elapsedTime /600) % 60;
+  //int deciseconds = m_elapsedTime % 10;
+  //int seconds = (m_elapsedTime / 10) % 60;
+  //int minutes = (m_elapsedTime /600) % 60;
 
-  Glib::ustring msg = Glib::ustring::compose("Elapsed time: %1:%2.%3", \
-					     Glib::ustring::format(std::setfill(L'0'), std::setw(2), minutes), \
- 					     Glib::ustring::format(std::setfill(L'0'), std::setw(2), seconds), \
- 					     Glib::ustring::format(std::setfill(L'0'), std::setw(1), deciseconds));
+  Glib::ustring msg = Glib::ustring::compose("Elapsed time: %1", time);
+  
+  // Glib::ustring msg = Glib::ustring::compose("Elapsed time: %1:%2.%3", \
+  // 					     Glib::ustring::format(std::setfill(L'0'), std::setw(2), minutes), \
+  // 					     Glib::ustring::format(std::setfill(L'0'), std::setw(2), seconds), \
+  // 					     Glib::ustring::format(std::setfill(L'0'), std::setw(1), deciseconds));
   clockLabel.set_label(msg);
-  return true;
+  //return true;
 }
 
 MainWindow::MainWindow()
@@ -273,9 +275,10 @@ MainWindow::MainWindow()
 
   //optionButton.set_icon_name("open-menu");
 
+  field.timerSignal.connect(sigc::bind(sigc::mem_fun(*this, &MainWindow::updateClockLabel)));
   //if (clockSignalConn.connected()) clockSignalConn.disconnect();
   //elapsedTime = 0;
-  clockSignalConn = Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::updateClockLabel), 100);
+  //clockSignalConn = Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::updateClockLabel), 100);
      //}
   //create the minefield
   //field = new MineField(COLS, MINES);

+ 1 - 1
src/window.hpp

@@ -32,7 +32,7 @@ class MainWindow : public Gtk::Window
   void updateCell(int x, int y);
   void openBombs();
   void updateFlagsLabel(int flags);
-  bool updateClockLabel();
+  void updateClockLabel(size_t time);
   void gameWon();
   void gameOver();
   sigc::connection clockSignalConn;