Skip to content

Commit

Permalink
Merge pull request #2 from akhtyamovpavel/interface
Browse files Browse the repository at this point in the history
Interface
  • Loading branch information
akhtyamovpavel committed Nov 24, 2014
2 parents 14950e5 + 7eee759 commit da7829e
Show file tree
Hide file tree
Showing 30 changed files with 684 additions and 2,775 deletions.
31 changes: 18 additions & 13 deletions Balda.pro
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
#-------------------------------------------------
#
# Project created by QtCreator 2014-11-08T00:04:46
# Project created by QtCreator 2014-11-14T14:41:25
#
#-------------------------------------------------

QT += core
QT += core gui

QT -= gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Balda
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

CONFIG += c++11

SOURCES += main.cpp \
SOURCES += main.cpp\
mainwindow.cpp \
board.cpp \
cell.cpp \
dictionary.cpp \
gamemanager.cpp \
logger.cpp \
player.cpp \
tst_testmainclassestest.cpp \
wordcollector.cpp \
bot/bor.cpp \
bot/bot.cpp \
bot/letter.cpp
bot/letter.cpp \
logger.cpp \
interface/buttoncell.cpp \
interface/graphicboard.cpp

HEADERS += \
HEADERS += mainwindow.h \
board.h \
cell.h \
Dictionary.h \
gamemanager.h \
logger.h \
player.h \
wordcollector.h \
bot/bor.h \
bot/bot.h \
bot/letter.h
bot/letter.h \
logger.h \
gamemanager.h \
interface/buttoncell.h \
interface/graphicboard.h

FORMS += mainwindow.ui
16 changes: 8 additions & 8 deletions Balda.pro.user
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.2.1, 2014-11-11T18:12:55. -->
<!-- Written by QtCreator 3.2.1, 2014-11-21T17:58:17. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{d3e5dd09-98ef-4e5e-9296-b50d3902153d}</value>
<value type="QByteArray">{0bce4d35-5304-462f-a5e9-3deeb219af70}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
Expand Down Expand Up @@ -65,7 +65,7 @@
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/Users/Aliaksei Semchankau/Git/build-Balda-Desktop_Qt_5_3_MinGW_32bit-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:/Projects/build-Balda-Desktop_Qt_5_3_MinGW_32bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
Expand All @@ -74,7 +74,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments">&quot;GONFIG += c++11&quot;</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
Expand Down Expand Up @@ -118,7 +118,7 @@
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/Users/Aliaksei Semchankau/Git/build-Balda-Desktop_Qt_5_3_MinGW_32bit-Release</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:/Projects/build-Balda-Desktop_Qt_5_3_MinGW_32bit-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
Expand Down Expand Up @@ -223,12 +223,12 @@
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Balda</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Aliaksei Semchankau/Git/Balda/Balda.pro</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Balda2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/Projects/BaldaGit/Balda/Balda.pro</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">Balda.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
Expand Down
2 changes: 2 additions & 0 deletions Dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Dictionary : public QObject
public:
explicit Dictionary(QObject *parent = 0);

QString getFirstWord();


void setUpConnection(QObject* wordCollector);
void connectToBot(QObject* bot);
Expand Down
87 changes: 56 additions & 31 deletions board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@
#include <QTextStream>
#include <QVector>


#include "logger.h"
#include "wordcollector.h"
#include "cell.h"


Board::Board(QObject *parent) :
QObject(parent)
{
isChanged = false;
isApproved = false;
board_.resize(HEIGHT, std::vector<Cell*>(WIDTH));


for (int i = 0; i < 5; ++i){
for(int j = 0; j <5; ++j) {
board_[i][j] = new Cell(QChar('-'));
board_.push_back(QVector<Cell*>());
board_[i].push_back(new Cell(QChar('-'), parent));
}
}
currentPlayer = FIRST_PLAYER;
setFirstWord();

}


//Connections

void Board::setUpConnection(QObject* wordCollector) {
connect(this, SIGNAL(commitLetter(QChar)), wordCollector, SLOT(addLetter(QChar)));
void Board::setUpConnection(WordCollector* wordCollector) {
connect(this, &Board::commitLetter, wordCollector, &WordCollector::addLetter);
//connect(this, SIGNAL(commitLetter(QChar)), wordCollector, SLOT(addLetter(QChar)));
connect(this, SIGNAL(commitX(int)), wordCollector, SLOT(addX(int)));
connect(this, SIGNAL(commitY(int)), wordCollector, SLOT(addY(int)));
connect(this, SIGNAL(commitWord()), wordCollector, SLOT(checkWord()));
Expand All @@ -35,13 +42,17 @@ void Board::setUpConnection(QObject* wordCollector) {
void Board::connectToPlayers(QObject* player1, QObject* player2) {
connect(this, SIGNAL(moveEnded(QString)), player1, SLOT(approveWord(QString)));
connect(this, SIGNAL(chooseError(QString)), player1, SLOT(badChooseLetter(QString)));
connect(this, SIGNAL(letterChosen()), player1, SLOT(letterChosen()));
connect(this, SIGNAL(letterChosen(QPair<QPair<int,int>, QChar>)), player1, SLOT(letterChosen(QPair<QPair<int,int>, QChar >)));
connect(this, SIGNAL(sendBoardFirst(QVector<QVector<QChar> >)), player1, SLOT(setCurrentBoard(QVector<QVector<QChar> >)));
connect(this, SIGNAL(resetWordFirst(const QPair<int,int>&)),
player1, SLOT(onBoardResetWord(const QPair<int,int>&)));

connect(this, SIGNAL(moveEndedSecond(QString)), player2, SLOT(approveWord(QString)));
connect(this, SIGNAL(chooseErrorSecond(QString)), player2, SLOT(badChooseLetter(QString)));
connect(this, SIGNAL(letterChosenSecond()), player2, SLOT(letterChosen()));
connect(this, SIGNAL(letterChosenSecond(QPair<QPair<int,int>, QChar>)), player2, SLOT(letterChosen(QPair<QPair<int,int>, QChar>)));
connect(this, SIGNAL(sendBoardSecond(QVector<QVector<QChar> >)), player2, SLOT(setCurrentBoard(QVector<QVector<QChar> >)));
connect(this, SIGNAL(resetWordSecond(const QPair<int,int>&)),
player2, SLOT(onBoardResetWord(const QPair<int,int>&)));

}

Expand All @@ -52,12 +63,10 @@ void Board::connectToGameManager(QObject* gameManager) {

//Methods

void Board::setFirstWord() {
board_[2][0]->setLetter(tr("б")[0]);
board_[2][1]->setLetter(tr("а")[0]);
board_[2][2]->setLetter(tr("л")[0]);
board_[2][3]->setLetter(tr("д")[0]);
board_[2][4]->setLetter(tr("а")[0]);
void Board::setFirstWord(QString firstWord) {
for (int i = 0; i < 5; ++i) {
board_[2][i]->setLetter(firstWord[i]);
}
}

void Board::setFirstPlayer(int player) {
Expand All @@ -83,7 +92,7 @@ void Board::showBoard(){
QTextStream out(stdout);
for(int i = 0; i < HEIGHT; ++i){
for(int j = 0; j < WIDTH; ++j) {
out << board_[i][j]->getLetter()<<" ";
out << board_[i][j]->getLetter() << " ";
}
out <<"\n";
}
Expand All @@ -101,18 +110,18 @@ void Board::changeLetter(int x, int y, QChar letter) {
sendError(tr("Error cell chosen"));
return;
}
std::cout << x << " " << y << std::endl;

board_[x][y]->setLetter(letter);
isChanged = true;
setMarked(x, y, true);
setChanged(true);
showBoard();
QPair<QPair<int,int>, QChar> sendLetter = qMakePair(qMakePair(x, y), letter);
emit addNewLetter(QPair<int,int>(x, y));
if (currentPlayer == FIRST_PLAYER) {
emit letterChosen();
emit letterChosen(sendLetter);
} else {
emit letterChosenSecond();
emit letterChosenSecond(sendLetter);
}

}
Expand Down Expand Up @@ -162,19 +171,32 @@ void Board::setChanged(bool changed) {
//slots

void Board::resetState(const QPair<int,int>& coordinates) {
isChanged = false;
for (int i = 0; i < WIDTH; ++i) {
for (int j = 0; j < HEIGHT; ++j) {
if (getLetter(i,j) != '-') {
setMarked(i, j, false);
}
}
}
std::cout<<"reset state from" << coordinates.first << " " << coordinates.second << std::endl;
std::cout.flush();
setLetter(coordinates.first, coordinates.second, '-');
setMarked(coordinates.first, coordinates.second, false);
if (currentPlayer == FIRST_PLAYER) {
emit resetWordFirst(coordinates);
} else {
emit resetWordSecond(coordinates);
}
}

void Board::remakeMove(const QString& word) {

std::cout<<"New move\n";
std::cout.flush();
std::cout << std::endl;
isChanged = false;
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
for (int i = 0; i < WIDTH; ++i) {
for (int j = 0; j < HEIGHT; ++j) {
if (getLetter(i,j) != '-') {
setMarked(i, j, false);
}
Expand All @@ -184,12 +206,15 @@ void Board::remakeMove(const QString& word) {
//switchPlayer;
isApproved = false;
currentPlayer = 3 - currentPlayer;
if (currentPlayer == 2) {
switch (currentPlayer) {
case 1:
emit moveEnded(word);
} else {
break;

case 2:
emit moveEndedSecond(word);
break;
}

} else {
showBoard();
}
Expand All @@ -203,13 +228,13 @@ void Board::setApproved() {
* Slots from Player
* */

void Board::chooseLetterFirst(QPair<QPair<int,int>,QChar>& letter) {
void Board::chooseLetterFirst(QPair<QPair<int,int>, QChar>& letter) {
changeLetter(letter.first.first, letter.first.second, letter.second);
Logger l;
l.printLog(DEBUG, "GET");
l.printLog(DEBUG, letter.first.first);
l.printLog(DEBUG, letter.first.second);
l.printLog(DEBUG, letter.second);
l.printLog<QString>(DEBUG, tr("GET"));
l.printLog<int>(DEBUG, letter.first.first);
l.printLog<int>(DEBUG, letter.first.second);
l.printLog<QChar>(DEBUG, letter.second);
}

void Board::chooseLetterSecond(QPair<QPair<int,int>,QChar>& letter) {
Expand All @@ -224,9 +249,9 @@ void Board::pushLetterSecond(QPair<int, int>& coordinates) {
}

void Board::showBoardToPlayer() {
QVector<QVector<QChar> > result(5, QVector<QChar>(5));
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
QVector<QVector<QChar> > result(WIDTH, QVector<QChar>(HEIGHT));
for (int i = 0; i < WIDTH; ++i) {
for (int j = 0; j < HEIGHT; ++j) {
result[i][j] = getLetter(i,j);
}
}
Expand Down
17 changes: 10 additions & 7 deletions board.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

#include "logger.h"

class WordCollector;

class Board : public QObject
{
Q_OBJECT
std::vector<std::vector<Cell*> > board_;
QVector<QVector<Cell*> > board_;
int currentPlayer;
bool isChanged;
bool isApproved;
Expand All @@ -24,16 +25,17 @@ class Board : public QObject

const int WIDTH = 5;
const int HEIGHT = 5;
void setFirstWord();

void sendError(QString message);
bool rangeCheck(int x, int y);

public:

explicit Board(QObject *parent = 0);

void setFirstPlayer(int player);

void setUpConnection(QObject* wordCollector);
void setFirstWord(QString firstWord);
void setUpConnection(WordCollector* wordCollector);

void connectToPlayers(QObject* player1, QObject* player2);

Expand Down Expand Up @@ -76,14 +78,15 @@ class Board : public QObject

void moveEnded(QString word);
void chooseError(QString message);
void letterChosen();
void letterChosen(QPair<QPair<int,int>, QChar>);
void sendBoardFirst(QVector<QVector<QChar> >);
void resetWordFirst(const QPair<int,int>&);

void moveEndedSecond(QString word);
void chooseErrorSecond(QString message);
void letterChosenSecond();
void letterChosenSecond(QPair<QPair<int,int>, QChar>);
void sendBoardSecond(QVector<QVector<QChar> >);

void resetWordSecond(const QPair<int,int>&);
/*
* Signals to GameManager
*/
Expand Down
9 changes: 0 additions & 9 deletions bot/bor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ Bor::Bor(){

borVertices.push_back(Letter());

//TakeVocavulary();

/*fstream::ifstream in("vocabulary.txt");
string s;
while (in >> s)
BOR.addWord(s);*/


}

void Bor::addWord(const QString& word){
Expand Down
Loading

0 comments on commit da7829e

Please sign in to comment.