So the thing is, that my function that is spupposed to dynamically create a board of empty buttons and then save each one of them in an array of buttons isnt working;
To be precise, it is supposed to create 2 types of board: 3on3 and 20on20;
3on3 is working but 20on20 isnt and i dont know why becouse the code is the same in both variables;
Here is my code:
TicTacToe.h
#ifndef RYSUJ_PLANSZE_H
#define RYSUJ_PLANSZE_H
#include <QWidget>
{
public:
void create(); //input od gracza czy mapa 3na3 czy 5na5
TicTacToe();
int height; //rz?dy
int width; //kolumny
int winning_length;
bool button_array[];
};
#endif // RYSUJ_PLANSZE_H
#ifndef RYSUJ_PLANSZE_H
#define RYSUJ_PLANSZE_H
#include <QWidget>
class TicTacToe :public QWidget
{
public:
void create(); //input od gracza czy mapa 3na3 czy 5na5
TicTacToe();
int height; //rz?dy
int width; //kolumny
int winning_length;
bool button_array[];
};
#endif // RYSUJ_PLANSZE_H
To copy to clipboard, switch view to plain text mode
TicTacToe.cpp
#include "TicTacToe.h"
#include <QApplication>
#include <QLabel>
#include <QtWidgets>
#include <QtCore>
#include <QMessageBox>
#include <QDialog>
#include <QGridLayout>
TicTacToe::TicTacToe()
{
reply
= QMessageBox::question(this,
"Question",
"If You want to play 3on3 map click 'Yes', " "if You want to play 5on5 map click 'No'");
}
void TicTacToe::create()
{
window->setWindowTitle("Tic-Tac-Toe");
//-------------------------------------------------------------------------------------------------------
{
int w = 3;
int h = 3;
TicTacToe::width = w;
TicTacToe::height = h;
TicTacToe::winning_length = 3;
for(int i = 0; i<w; i++)
{
for(int j = 0; j<h; j++)
{
layout->addWidget(button[i][j], i, j);
button_array[i,j] = false;
}
}
}
else
{
int w = 20;
int h = 20;
TicTacToe::width = w;
TicTacToe::height = h;
TicTacToe::winning_length = 5;
for(int i = 0; i<h; i++)
{
for(int j = 0; j<w; j++)
{
layout->addWidget(button[i][j], i, j);
button_array[i,j] = false;
}
}
}
//---------------------------------------------------------------------------------------------------
window->setLayout(layout);
window->show();
}
#include "TicTacToe.h"
#include <QApplication>
#include <QLabel>
#include <QtWidgets>
#include <QtCore>
#include <QMessageBox>
#include <QDialog>
#include <QGridLayout>
QMessageBox::StandardButton reply;
TicTacToe::TicTacToe()
{
reply = QMessageBox::question(this, "Question", "If You want to play 3on3 map click 'Yes', "
"if You want to play 5on5 map click 'No'");
}
void TicTacToe::create()
{
QWidget *window = new QWidget;
QGridLayout *layout = new QGridLayout;
window->setWindowTitle("Tic-Tac-Toe");
//-------------------------------------------------------------------------------------------------------
if(reply==QMessageBox::Yes)
{
int w = 3;
int h = 3;
TicTacToe::width = w;
TicTacToe::height = h;
TicTacToe::winning_length = 3;
for(int i = 0; i<w; i++)
{
for(int j = 0; j<h; j++)
{
QPushButton *button[i][j];
button[i][j] = new QPushButton();
layout->addWidget(button[i][j], i, j);
button[i][j]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
button_array[i,j] = false;
}
}
}
else
{
int w = 20;
int h = 20;
TicTacToe::width = w;
TicTacToe::height = h;
TicTacToe::winning_length = 5;
for(int i = 0; i<h; i++)
{
for(int j = 0; j<w; j++)
{
QPushButton *button[i][j];
button[i][j] = new QPushButton();
layout->addWidget(button[i][j], i, j);
button[i][j]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
button_array[i,j] = false;
}
}
}
//---------------------------------------------------------------------------------------------------
window->setLayout(layout);
window->show();
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include "TicTacToe.h"
#include <QApplication>
#include <QLabel>
#include <QtWidgets>
#include <QtCore>
#include <QMessageBox>
#include <QDialog>
#include <QGridLayout>
int main(int argc, char *argv[])
{
//--------------------------------------------------------------
TicTacToe *R = new TicTacToe;
R->create();
//--------------------------------------------------------------
return app.exec();
}
#include "TicTacToe.h"
#include <QApplication>
#include <QLabel>
#include <QtWidgets>
#include <QtCore>
#include <QMessageBox>
#include <QDialog>
#include <QGridLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//--------------------------------------------------------------
TicTacToe *R = new TicTacToe;
R->create();
//--------------------------------------------------------------
return app.exec();
}
To copy to clipboard, switch view to plain text mode
And my question rn is --> What i going on? The error i get is --> The program has unexpectedly finished
Bookmarks