this version without bugs
This commit is contained in:
@@ -7,53 +7,83 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
{
|
||||
qDebug() << "Load START!";
|
||||
ui->setupUi(this);
|
||||
wd = new USWidget(ui->frGame);
|
||||
//ui->frGame->addWidget(wd);
|
||||
wd->resize(ui->frGame->size());
|
||||
connect(wd,SIGNAL(paintEvent(QPaintEvent*)),this,SLOT(paint(QPaintEvent*)));
|
||||
connect(wd,SIGNAL(mouseMoveEvent(QMouseEvent*)),
|
||||
this,SLOT(mouse_move(QMouseEvent*)));
|
||||
connect(wd,SIGNAL(mousePressEvent(QMouseEvent*)),
|
||||
this,SLOT(mouse_press(QMouseEvent*)));
|
||||
//sndr = new UdpSender("127.0.0.1",10101);
|
||||
//sndr->connectSend("hellow");
|
||||
int cellsize = 16;
|
||||
timer = new QTimer(this);
|
||||
//adp = new adpainter(this->width(),this->height(),cellsize);
|
||||
//adp->clear();
|
||||
//adp->drawgrid();
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(ADrender()));
|
||||
GameMain = new games(this->size(),QPoint(0,this->height()/2),QPoint(this->width()-cellsize,this->height()/2), cellsize);
|
||||
qDebug() << wd->size();
|
||||
GameMain = new games(wd->size(),QPoint(0,wd->height()/2),
|
||||
QPoint(wd->width()-cellsize,wd->height()/2),
|
||||
cellsize);
|
||||
maliens = new Aliens(GameMain);
|
||||
maliens->AddAlien();
|
||||
mmap = new map(GameMain);
|
||||
mmap->clear();
|
||||
mmap->drawgrid();
|
||||
mtowers = new towers(GameMain);
|
||||
this->setGeometry(100,100,this->width(),this->height());
|
||||
//this->setGeometry(100,100,this->width(),this->height());
|
||||
timer->start(50);
|
||||
mousebt = 0;
|
||||
qDebug() << "Load DONE!";
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::ADrender()
|
||||
void MainWindow::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
//adp->drawAlien(aliens->alienAt(0));
|
||||
maliens->drawAliens();
|
||||
this->repaint();
|
||||
int cellsize = 16;
|
||||
wd->resize(ui->frGame->size());
|
||||
delete mtowers;
|
||||
delete mmap;
|
||||
delete maliens;
|
||||
delete GameMain;
|
||||
GameMain = new games(wd->size(),QPoint(0,wd->height()/2),
|
||||
QPoint(wd->width()-cellsize,wd->height()/2),
|
||||
cellsize);
|
||||
maliens = new Aliens(GameMain);
|
||||
maliens->AddAlien();
|
||||
mmap = new map(GameMain);
|
||||
mmap->clear();
|
||||
mmap->drawgrid();
|
||||
mtowers = new towers(GameMain);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::paintEvent(QPaintEvent*)
|
||||
void MainWindow::ADrender()
|
||||
{
|
||||
QString str;
|
||||
maliens->drawAliens();
|
||||
str.setNum(maliens->size());
|
||||
ui->lbCount->setText(QString::fromUtf8("Количество: ")+str+QString::fromUtf8(" шт"));
|
||||
wd->repaint();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::paint(QPaintEvent* )
|
||||
{
|
||||
QPainter painter;
|
||||
painter.begin(this);
|
||||
painter.begin(wd);
|
||||
painter.drawPixmap(0,0,*GameMain->buff);
|
||||
painter.end();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::mouseMoveEvent (QMouseEvent *event)
|
||||
void MainWindow::mouse_move(QMouseEvent *event)
|
||||
{
|
||||
if (mousebt == 1) ClearCell(event->pos());
|
||||
if (mousebt == 2) SetCell(event->pos());
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::mousePressEvent (QMouseEvent *event)
|
||||
void MainWindow::mouse_press(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::RightButton) {
|
||||
ClearCell(event->pos());
|
||||
@@ -73,13 +103,15 @@ void MainWindow::SetCell(QPoint pos)
|
||||
{
|
||||
bool trace = false;
|
||||
QPoint cp;
|
||||
QRect wdrect(0, 0, (this->width()/GameMain->cellsize)*GameMain->cellsize,
|
||||
(this->height()/GameMain->cellsize)*GameMain->cellsize);
|
||||
QRect wdrect(0, 0, (wd->width()/GameMain->cellsize)*GameMain->cellsize,
|
||||
(wd->height()/GameMain->cellsize)*GameMain->cellsize);
|
||||
if (wdrect.contains(pos)) {
|
||||
cp.setX(pos.x()/GameMain->cellsize);
|
||||
cp.setY(pos.y()/GameMain->cellsize);
|
||||
//qDebug() << cp << GameMain->Cells[cp.x()][cp.y()];
|
||||
if (GameMain->Cells[cp.x()][cp.y()] == 10) return;
|
||||
mtowers->drawcell(cp);
|
||||
if (GameMain->Cells[cp.x()][cp.y()] == 1) trace = true;
|
||||
if (GameMain->Cells[cp.x()][cp.y()] == 5) trace = true;
|
||||
GameMain->Cells[cp.x()][cp.y()] = - 1;
|
||||
if (trace)
|
||||
if (!maliens->retrace()) ClearCell(pos);
|
||||
@@ -90,11 +122,12 @@ void MainWindow::SetCell(QPoint pos)
|
||||
void MainWindow::ClearCell(QPoint pos)
|
||||
{
|
||||
QPoint cp;
|
||||
QRect wdrect(0, 0, (this->width()/GameMain->cellsize)*GameMain->cellsize,
|
||||
(this->height()/GameMain->cellsize)*GameMain->cellsize);
|
||||
QRect wdrect(0, 0, (wd->width()/GameMain->cellsize)*GameMain->cellsize,
|
||||
(wd->height()/GameMain->cellsize)*GameMain->cellsize);
|
||||
if (wdrect.contains(pos)) {
|
||||
cp.setX(pos.x()/GameMain->cellsize);
|
||||
cp.setY(pos.y()/GameMain->cellsize);
|
||||
if (GameMain->Cells[cp.x()][cp.y()] == 10) return;
|
||||
GameMain->Cells[cp.x()][cp.y()] = 0;
|
||||
mtowers->clearcell(cp);
|
||||
maliens->retrace();
|
||||
@@ -104,7 +137,7 @@ void MainWindow::ClearCell(QPoint pos)
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent * e)
|
||||
{
|
||||
qDebug() << e->key();
|
||||
//qDebug() << e->key();
|
||||
switch(e->key()) {
|
||||
case 65:
|
||||
maliens->AddAlien();
|
||||
@@ -123,5 +156,19 @@ MainWindow::~MainWindow()
|
||||
delete mmap;
|
||||
delete maliens;
|
||||
delete GameMain;
|
||||
//delete adp;
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_clicked()
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_3_clicked()
|
||||
{
|
||||
if (maliens->size() > 0) maliens->DelAlien(maliens->size()-1);
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_2_clicked()
|
||||
{
|
||||
maliens->AddAlien();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user