#include "Interface/mainwindow.h"
#include "ui_mainwindow.h"
#include "Interface/newgamewindow.h"
#include "Model/GameLogic.h"
#include <QtGui>
#include <QLabel>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->graphicsView->setScene(scene);
ui->graphicsView->setSceneRect(-300, -300, 600, 600);
ui
->graphicsView
->setRenderHint
(QPainter::Antialiasing);
ui
->graphicsView
->setBackgroundBrush
(QPixmap(":/Background600pattern.jpg"));
connect(&theGameLogic, SIGNAL(FieldChangedOut(int,int,int)), this, SLOT(FieldChanged(int,int,int)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionNew_Game_triggered()
{
NewGameWindow NewGameWdw(this);
connect(&NewGameWdw, SIGNAL(BoardSizeSet(int)), this, SLOT(BoardSizeSet(int)));
connect(&NewGameWdw, SIGNAL(GameStarted()), this, SLOT(GameStarted()));
NewGameWdw.exec();
}
void MainWindow::on_actionExit_triggered()
{
this->close();
}
void MainWindow::BoardSizeSet(int Size)
{
if(!theGameLogic.SetSize(Size))
QMessageBox::warning(this,
"Error",
"Cannot set size. Game already started!");
else
{
BoardSize = Size;
int LineWidth = 4;
BorderWidth = 30;
GridWidth = (float)(600 - 2 * BorderWidth) / (BoardSize - 1);
LinePen.setWidth(LineWidth);
LinePen.setCapStyle(Qt::SquareCap);
for(int i = 0; i < BoardSize; i++)
{
scene->addLine(BorderWidth - 300 + (i * GridWidth), BorderWidth - 300, BorderWidth - 300 + (i * GridWidth), 300 - BorderWidth, LinePen); //paint vertical lines
scene->addLine(BorderWidth - 300, BorderWidth - 300 + (i * GridWidth), 300 - BorderWidth, BorderWidth - 300 + (i * GridWidth), LinePen); //paint horizontal lines
}
}
}
void MainWindow::GameStarted()
{
if(!theGameLogic.StartGame())
QMessageBox::warning(this,
"Error",
"Cannot start game. Game already started!");
else
{
// Allocation of Board //
circle = new MouseoverCircle**[ BoardSize ];
for( int Column = 0; Column < BoardSize; Column++ )
{
circle[ Column ] = new MouseoverCircle*[ BoardSize ];
for( int Row = 0; Row < BoardSize; Row++ )
{
circle[ Column ][ Row ] = new MouseoverCircle( Column, Row );
scene->addItem(circle[ Column ][ Row ]);
circle[ Column ][ Row ]->setPos(-300 + BorderWidth + GridWidth * Column, -300 + BorderWidth + GridWidth * Row);
connect(circle[Column][Row], SIGNAL(Mouseover(int,int)), this, SLOT(Mouseover(int,int)));
connect(circle[Column][Row], SIGNAL(Clicked(int,int)), this, SLOT(Clicked(int,int)));
}
}
}
}
void MainWindow::Mouseover(int Column, int Row)
{
switch (theGameLogic.LegalTurn(Column, Row))
{
case 0:
{
circle
[Column
][Row
]->Color
= QColor(0,
0,
0,
0);
}
case 1:
{
circle
[Column
][Row
]->Color
= QColor(0,
0,
0,
127);
break;
}
case 2:
{
circle
[Column
][Row
]->Color
= QColor(255,
255,
255,
127);
break;
}
}
}
void MainWindow::Clicked(int Column, int Row)
{
theGameLogic.ExecuteTurn(Column, Row);
}
void MainWindow::FieldChanged(int Column, int Row, int NewValue)
{
switch(NewValue)
{
case 0:
{
break;
}
case 1:
{
break;
}
case 2:
{
break;
}
default:
{
break;
}
}
scene->addEllipse(-325 + BorderWidth + GridWidth * Column, -325 + BorderWidth + GridWidth * Row, 50, 50, *RPen, *RBrush);
}
#include "Interface/mainwindow.h"
#include "ui_mainwindow.h"
#include "Interface/newgamewindow.h"
#include "Model/GameLogic.h"
#include <QtGui>
#include <QLabel>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
ui->graphicsView->setSceneRect(-300, -300, 600, 600);
ui->graphicsView->setRenderHint(QPainter::Antialiasing);
ui->graphicsView->setBackgroundBrush(QPixmap(":/Background600pattern.jpg"));
connect(&theGameLogic, SIGNAL(FieldChangedOut(int,int,int)), this, SLOT(FieldChanged(int,int,int)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionNew_Game_triggered()
{
NewGameWindow NewGameWdw(this);
connect(&NewGameWdw, SIGNAL(BoardSizeSet(int)), this, SLOT(BoardSizeSet(int)));
connect(&NewGameWdw, SIGNAL(GameStarted()), this, SLOT(GameStarted()));
NewGameWdw.exec();
}
void MainWindow::on_actionExit_triggered()
{
this->close();
}
void MainWindow::BoardSizeSet(int Size)
{
if(!theGameLogic.SetSize(Size))
QMessageBox::warning(this, "Error", "Cannot set size. Game already started!");
else
{
BoardSize = Size;
int LineWidth = 4;
BorderWidth = 30;
GridWidth = (float)(600 - 2 * BorderWidth) / (BoardSize - 1);
QPen LinePen(Qt::black);
LinePen.setWidth(LineWidth);
LinePen.setCapStyle(Qt::SquareCap);
for(int i = 0; i < BoardSize; i++)
{
scene->addLine(BorderWidth - 300 + (i * GridWidth), BorderWidth - 300, BorderWidth - 300 + (i * GridWidth), 300 - BorderWidth, LinePen); //paint vertical lines
scene->addLine(BorderWidth - 300, BorderWidth - 300 + (i * GridWidth), 300 - BorderWidth, BorderWidth - 300 + (i * GridWidth), LinePen); //paint horizontal lines
}
}
}
void MainWindow::GameStarted()
{
if(!theGameLogic.StartGame())
QMessageBox::warning(this, "Error", "Cannot start game. Game already started!");
else
{
// Allocation of Board //
circle = new MouseoverCircle**[ BoardSize ];
for( int Column = 0; Column < BoardSize; Column++ )
{
circle[ Column ] = new MouseoverCircle*[ BoardSize ];
for( int Row = 0; Row < BoardSize; Row++ )
{
circle[ Column ][ Row ] = new MouseoverCircle( Column, Row );
scene->addItem(circle[ Column ][ Row ]);
circle[ Column ][ Row ]->setPos(-300 + BorderWidth + GridWidth * Column, -300 + BorderWidth + GridWidth * Row);
connect(circle[Column][Row], SIGNAL(Mouseover(int,int)), this, SLOT(Mouseover(int,int)));
connect(circle[Column][Row], SIGNAL(Clicked(int,int)), this, SLOT(Clicked(int,int)));
}
}
}
}
void MainWindow::Mouseover(int Column, int Row)
{
switch (theGameLogic.LegalTurn(Column, Row))
{
case 0:
{
circle[Column][Row]->Color = QColor(0, 0, 0, 0);
}
case 1:
{
circle[Column][Row]->Color = QColor(0, 0, 0, 127);
break;
}
case 2:
{
circle[Column][Row]->Color = QColor(255, 255, 255, 127);
break;
}
}
}
void MainWindow::Clicked(int Column, int Row)
{
theGameLogic.ExecuteTurn(Column, Row);
}
void MainWindow::FieldChanged(int Column, int Row, int NewValue)
{
QPen *RPen;
QBrush *RBrush;
switch(NewValue)
{
case 0:
{
RPen = new QPen(QColor(127, 127, 127));
RBrush = new QBrush(QColor(127, 127, 127));
break;
}
case 1:
{
RPen = new QPen(QColor(0, 0, 0));
RBrush = new QBrush(QColor(0, 0, 0));
break;
}
case 2:
{
RPen = new QPen(QColor(255, 255, 255));
RBrush = new QBrush(QColor(255, 255, 255));
break;
}
default:
{
RPen = new QPen(QColor(255, 0, 0));
RBrush = new QBrush(QColor(255, 0, 0));
break;
}
}
scene->addEllipse(-325 + BorderWidth + GridWidth * Column, -325 + BorderWidth + GridWidth * Row, 50, 50, *RPen, *RBrush);
}
To copy to clipboard, switch view to plain text mode
Bookmarks