Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
#include <QStatusBar> | |||
#include <QMessageBox> | |||
#include "MainWindow.h" | |||
#include "Board.h" | |||
#include "BoardView.h" | |||
#include "PlayerManagerWET.h" | |||
#include "ScoreCounter.h" | |||
|
|||
MainWindow::MainWindow(QWidget *parent) | |||
: QMainWindow(parent) | |||
, m_player_manager(new PlayerMangerWET) | |||
{ | |||
setMinimumSize(640, 480); | |||
Board *board = new Board(3, 3, this); | |||
board->setPlayerManager(m_player_manager.get()); | |||
|
|||
ScoreCounter *counter = new ScoreCounter(this); | |||
board->setScoreCounter(counter); | |||
|
|||
QStatusBar *bar = statusBar(); | |||
bar->showMessage("First: 0 - Second: 0"); | |||
|
|||
connect(counter, | |||
SIGNAL(statusUpdated(QString)), | |||
bar, | |||
SLOT(showMessage(const QString&))); | |||
|
|||
connect(board, | |||
SIGNAL(gameOver()), | |||
this, | |||
SLOT(makeGameOver())); | |||
|
|||
|
|||
BoardView *view = new BoardView(this); | |||
view->setModel(board); | |||
|
|||
setCentralWidget(view); | |||
} | |||
|
|||
void MainWindow::makeGameOver() | |||
{ | |||
QMessageBox::information(this, "Game over!", "Game Over!"); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
#pragma once | |||
#include <memory> | |||
#include <QMainWindow> | |||
#include "IPlayerManager.h" | |||
|
|||
class MainWindow : public QMainWindow | |||
{ | |||
Q_OBJECT | |||
public: | |||
MainWindow(QWidget *parent = 0); | |||
private slots: | |||
void makeGameOver(); | |||
private: | |||
std::unique_ptr<IPlayerManager> m_player_manager; | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
#pragma once | |||
#include "IPlayerManager.h" | |||
|
|||
class PlayerMangerWET : public IPlayerManager | |||
{ | |||
int m_player; | |||
public: | |||
inline PlayerMangerWET() | |||
{ | |||
m_player = 0; | |||
} | |||
|
|||
inline int nextPlayer(bool is_captured) | |||
{ | |||
return (m_player = (m_player == 0 ? 1 : 0)); | |||
} | |||
|
|||
inline int currentPlayer() const | |||
{ | |||
return m_player; | |||
} | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
#pragma once | |||
#include <QObject> | |||
|
|||
class ScoreCounter : public QObject | |||
{ | |||
Q_OBJECT | |||
public: | |||
inline ScoreCounter(QObject *parent = 0) | |||
: QObject(parent) | |||
{ | |||
m_mark[0] = 0; | |||
m_mark[1] = 0; | |||
} | |||
|
|||
inline void increase(int owner) | |||
{ | |||
if (owner > -1 && owner < 2) | |||
{ | |||
++m_mark[owner]; | |||
emit statusUpdated(QString("First: %1 - Second: %2").arg(QString::number(m_mark[0]), QString::number(m_mark[1]))); | |||
} | |||
} | |||
|
|||
private: | |||
int m_mark[2]; | |||
|
|||
signals: | |||
void statusUpdated(const QString&); | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,40 +1,12 @@ | |||
#include <QApplication> | #include <QApplication> | ||
#include "Board.h" | #include "MainWindow.h" | ||
#include "BoardView.h" | |||
#include "IPlayerManager.h" | |||
|
|||
class PlayerManger : public IPlayerManager | |||
{ | |||
int m_player; | |||
public: | |||
PlayerManger() | |||
{ | |||
m_player = 0; | |||
} | |||
|
|||
inline int nextPlayer(bool is_captured) | |||
{ | |||
return (m_player = (m_player == 0 ? 1 : 0)); | |||
} | |||
|
|||
inline int currentPlayer() const | |||
{ | |||
return m_player; | |||
} | |||
}; | |||
|
|
||
int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||
{ | { | ||
QApplication app(argc, argv); | QApplication app(argc, argv); | ||
|
|
||
Board board(10, 10); | MainWindow w; | ||
PlayerManger manager; | w.show(); | ||
board.setPlayerManager(&manager); | |||
|
|||
BoardView view; | |||
view.setModel(&board); | |||
|
|||
view.show(); | |||
|
|
||
return app.exec(); | return app.exec(); | ||
} | } |