Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Új fájl: feladat_osszevagas.py
- import math
- import sys
- import codecs
- import os
- def mai_munka():
- f = codecs.open("mastermind.cs","w","utf-8")
- for root, dir, files in os.walk("."):
- for ik in files:
- print("Új fájl: "+ ik+"\n",file = f)
- k = codecs.open(ik, "r",encoding='utf-8', errors='ignore').read().splitlines()
- print("\n".join(k),file=f)
- f.close()
- if __name__ == '__main__':
- print("Mai munkám összevágása indul.")
- mai_munka()
- Új fájl: main.cpp
- #include "mainwindow.h"
- #include <QApplication>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- MainWindow w;
- w.show();
- return a.exec();
- }
- Új fájl: mainwindow.cpp
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QPainter>
- #include <QLineF>
- #include <QColor>
- #include <QDesktopServices>
- #include <QDesktopWidget>
- #include <QDebug>
- #include <QMouseEvent>
- #include <QString>
- #include <QRect>
- #include <QMessageBox>
- #include "mastermind.h"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow),
- Game(new MasterMind(this))
- {
- ui->setupUi(this);
- this->genExampleCircle();
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::mousePressEvent(QMouseEvent *event){
- if(currentStage == 10){
- QMessageBox::information(0,"Mastermind","A játék véget ért, ha szeretnél kezdj egy újat.");
- }
- QPoint po = event->pos();
- //Cella kiszámítása:
- int x = po.x() - 210;
- int y = po.y() - 200;
- if((x > 0 && y > 0) && (x < 501 && y < 201)){
- if(this->valasztott_szin == -1){
- QMessageBox::information(0,"MasterMind","Nem választottál színt, kérlek válassz egyet!");
- return;
- }
- int sor = y/50;
- int oszlop = x/50;
- if (oszlop != currentStage){
- QMessageBox::information(0,"MasterMind","Ide nem tehetsz \"kört\", jelenleg a(z) " +
- QString::number(this->currentStage+1) + ". oszlopnál tartasz.");
- return;
- }
- int tmp = Game->Stages[currentStage]->insertColor(valasztott_szin,sor);
- switch(tmp){
- case(2):
- QMessageBox::information(0,"Mastermind","Ide nem tehetsz már semmilyen színt!");
- break;
- case(1):
- Game->checkStage();
- currentStage++;
- case(0):
- this->szinletesz(sor,oszlop);
- break;
- }
- if(currentStage == 10){
- QMessageBox::information(0,"Mastermind","A játék véget ért, ha szeretnél kezdj egy újat.");
- }
- }
- }
- void MainWindow::szinletesz(int sor,int oszlop){
- QPoint BalFelsoKord(oszlop*50 + 209,sor*50 + 198);
- QPushButton * p = new QPushButton(" ",this);
- p->setVisible(true);
- p->setGeometry(QRect(BalFelsoKord,QSize(50, 50)));
- p->setStyleSheet(this->cPathImage(this->valasztott_szin));
- p->raise(); //TOP layerként helyezi el.
- letettGombok[letettGombCounter++] = p;
- connect(p,SIGNAL(released()),this,SLOT(gombvalaszt_Click()));
- }
- QString MainWindow::cPathImage(int szin){
- return QString("background-color: transparent;background-image: url(C:/Users/User/Desktop/MasterMind/"+a[szin]+"circle.png"+");");
- }
- void MainWindow::genExampleCircle(){
- for (int i = 1;i <= a.size();i++) {
- QPushButton * currentButton = new QPushButton(QString::number(i),this);
- currentButton->setGeometry(QRect(QPoint(266+((i-1)*55), 130),
- QSize(50, 50)));
- currentButton->setStyleSheet("background-color: transparent;background-image: url(C:/Users/User/Desktop/MasterMind/"+a[i-1]+"circle.png);");
- this->valasztani_gombok[i-1] = currentButton;
- connect(currentButton,SIGNAL(released()),this,SLOT(gombvalaszt_Click()));
- }
- }
- void MainWindow::gombvalaszt_Click(){
- QPushButton * senderObj = (QPushButton*)sender();
- if(senderObj->text() == " "){
- QMessageBox::information(this,"Mastermind","Nem tehetsz ide kört.");
- return;
- }
- int senderName = senderObj->text().toInt();
- QString valasztott_temp = "<html><head/><body><p> \
- Választott szín: { <span style=\" font-weight:600;\"> \
- <font color=\""+this->a[senderName-1]+"\">"+this->szinhelper[senderName-1]+"</font> </span> }</p></body></html>";
- //ui->label_2->setText("\tA választott szín: { "+this->szinhelper[senderName-1]+" }");
- ui->label_2->setText(valasztott_temp);
- ui->label_2->setGeometry(375,162,ui->label_2->width(),ui->label_2->height());
- this->valasztott_szin = senderName-1;
- }
- void MainWindow::paintEvent(QPaintEvent *)
- {
- QPainter painter(this);
- QPen pen(Qt::black);
- pen.setWidth(2);
- painter.setPen(pen);
- for(int i = 0;i < 5;i++){
- QLineF line(210,200+(i*50),210+(10*50),200+(i*50));
- painter.drawLine(line);
- }
- for(int i = 0;i < 11;i++){
- QLineF linefuggoleges(210+(i*50),200,210+(i*50),200+(50*4));
- painter.drawLine(linefuggoleges);
- }
- }
- void MainWindow::on_pushButton_2_clicked()
- {
- if(this->currentStage < 10){
- QMessageBox::information(0,"Mastermind kiértékelés",
- "Csak akkor kérhetsz kiértékelést, ha a 10. lépésnél se adtál helyes megoldást.");
- return;
- }else{
- //Kiértékelés függvény hívás
- }
- }
- void MainWindow::on_pushButton_clicked()
- {
- if(this->currentStage < 5){
- QMessageBox::information(0,"Mastermind segítség","Csak a 6. lépéstől kezdve kérhetsz segítséget.");
- }else{
- //segítség függvény
- }
- }
- void MainWindow::resetGame(){
- currentStage = 0;
- for(int i = 0; i < letettGombCounter;i++){
- letettGombok[i]->hide();
- delete letettGombok[i];
- }
- delete Game;
- Game = new MasterMind(this);
- }
- void MainWindow::on_pushButton_3_clicked()
- {
- this->resetGame();
- }
- Új fájl: mainwindow.h
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QMainWindow>
- #include <QTableWidget>
- #include <QStringList>
- #include <QPainter>
- #include <QRectF>
- #include <QPainter>
- #include <QPushButton>
- #include <QStringList>
- #include <QPushButton>
- enum szinek{
- blue,
- gray,
- green,
- orange,
- purple,
- red,
- yellow
- };
- class MasterMind;
- namespace Ui {
- class MainWindow;
- }
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- explicit MainWindow(QWidget *parent = 0);
- ~MainWindow();
- void paintEvent(QPaintEvent *event);
- void mousePressEvent(QMouseEvent *event);
- void genExampleCircle();
- void szinletesz(int,int);
- void resetGame();
- MasterMind * Game;
- QPushButton * letettGombok[40];
- int letettGombCounter = 0;
- QString cPathImage(int szin);
- QStringList szinhelper = {"Kék","Szürke","Zöld","Narancs sárga","Lila","Piros","Citrom sárga"};
- QPushButton* valasztani_gombok[7];
- unsigned short int currentStage = 0;
- QStringList a = {"blue" ,"gray" , "green",
- "orange","purple","red","yellow"};
- int valasztott_szin = -1;
- public slots:
- void gombvalaszt_Click();
- private slots:
- void on_pushButton_2_clicked();
- void on_pushButton_clicked();
- void on_pushButton_3_clicked();
- private:
- Ui::MainWindow *ui;
- };
- #endif // MAINWINDOW_H
- Új fájl: mastermind.cpp
- #include "mastermind.h"
- #include "mainwindow.h"
- #include <vector>
- MasterMind::MasterMind(MainWindow * szulo):parent(szulo){
- for(int i = 0;i < 10; i++){
- this->Stages[i] = new Stage(i);
- }
- this->genRandomTask();
- this->currentStage = &parent->currentStage;
- qDebug() << parent->currentStage;
- qDebug() << feladvany.cella[0] << feladvany.cella[1] << feladvany.cella[2] << feladvany.cella[3];
- }
- void MasterMind::genRandomTask(){
- std::vector<int> tmp = {0,1,2,3,4,5,6};
- for(int i = 0;i < 4;i++){
- int randint = rand() % (tmp.size());
- feladvany.insertColor(tmp[randint],i);
- tmp.erase(tmp.begin()+randint);
- }
- }
- void MasterMind::checkStage(){
- if(feladvany == *this->Stages[*currentStage]){
- qDebug() << "helyes megoldás.";
- }
- }
- Új fájl: mastermind.cs
- Új fájl: feladat_osszevagas.py
- import math
- import sys
- import codecs
- import os
- def mai_munka():
- f = codecs.open("mastermind.cs","w","utf-8")
- for root, dir, files in os.walk("."):
- for ik in files:
- print("Új fájl: "+ ik+"\n",file = f)
- k = codecs.open(ik, "r",encoding='utf-8', errors='ignore').read().splitlines()
- print("\n".join(k),file=f)
- f.close()
- if __name__ == '__main__':
- print("Mai munkám összevágása indul.")
- mai_munka()
- Új fájl: main.cpp
- #include "mainwindow.h"
- #include <QApplication>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- MainWindow w;
- w.show();
- return a.exec();
- }
- Új fájl: mainwindow.cpp
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QPainter>
- #include <QLineF>
- #include <QColor>
- #include <QDesktopServices>
- #include <QDesktopWidget>
- #include <QDebug>
- #include <QMouseEvent>
- #include <QString>
- #include <QRect>
- #include <QMessageBox>
- #include "mastermind.h"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow),
- Game(new MasterMind(this))
- {
- ui->setupUi(this);
- this->genExampleCircle();
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::mousePressEvent(QMouseEvent *event){
- if(currentStage == 10){
- QMessageBox::information(0,"Mastermind","A játék véget ért, ha szeretnél kezdj egy újat.");
- }
- QPoint po = event->pos();
- //Cella kiszámítása:
- int x = po.x() - 210;
- int y = po.y() - 200;
- if((x > 0 && y > 0) && (x < 501 && y < 201)){
- if(this->valasztott_szin == -1){
- QMessageBox::information(0,"MasterMind","Nem választottál színt, kérlek válassz egyet!");
- return;
- }
- int sor = y/50;
- int oszlop = x/50;
- if (oszlop != currentStage){
- QMessageBox::information(0,"MasterMind","Ide nem tehetsz \"kört\", jelenleg a(z) " +
- QString::number(this->currentStage+1) + ". oszlopnál tartasz.");
- return;
- }
- int tmp = Game->Stages[currentStage]->insertColor(valasztott_szin,sor);
- switch(tmp){
- case(2):
- QMessageBox::information(0,"Mastermind","Ide nem tehetsz már semmilyen színt!");
- break;
- case(1):
- Game->checkStage();
- currentStage++;
- case(0):
- this->szinletesz(sor,oszlop);
- break;
- }
- if(currentStage == 10){
- QMessageBox::information(0,"Mastermind","A játék véget ért, ha szeretnél kezdj egy újat.");
- }
- }
- }
- void MainWindow::szinletesz(int sor,int oszlop){
- QPoint BalFelsoKord(oszlop*50 + 209,sor*50 + 198);
- QPushButton * p = new QPushButton(" ",this);
- p->setVisible(true);
- p->setGeometry(QRect(BalFelsoKord,QSize(50, 50)));
- p->setStyleSheet(this->cPathImage(this->valasztott_szin));
- p->raise(); //TOP layerként helyezi el.
- letettGombok[letettGombCounter++] = p;
- connect(p,SIGNAL(released()),this,SLOT(gombvalaszt_Click()));
- }
- QString MainWindow::cPathImage(int szin){
- return QString("background-color: transparent;background-image: url(C:/Users/User/Desktop/MasterMind/"+a[szin]+"circle.png"+");");
- }
- void MainWindow::genExampleCircle(){
- for (int i = 1;i <= a.size();i++) {
- QPushButton * currentButton = new QPushButton(QString::number(i),this);
- currentButton->setGeometry(QRect(QPoint(266+((i-1)*55), 130),
- QSize(50, 50)));
- currentButton->setStyleSheet("background-color: transparent;background-image: url(C:/Users/User/Desktop/MasterMind/"+a[i-1]+"circle.png);");
- this->valasztani_gombok[i-1] = currentButton;
- connect(currentButton,SIGNAL(released()),this,SLOT(gombvalaszt_Click()));
- }
- }
- void MainWindow::gombvalaszt_Click(){
- QPushButton * senderObj = (QPushButton*)sender();
- if(senderObj->text() == " "){
- QMessageBox::information(this,"Mastermind","Nem tehetsz ide kört.");
- return;
- }
- int senderName = senderObj->text().toInt();
- QString valasztott_temp = "<html><head/><body><p> \
- Választott szín: { <span style=\" font-weight:600;\"> \
- <font color=\""+this->a[senderName-1]+"\">"+this->szinhelper[senderName-1]+"</font> </span> }</p></body></html>";
- //ui->label_2->setText("\tA választott szín: { "+this->szinhelper[senderName-1]+" }");
- ui->label_2->setText(valasztott_temp);
- ui->label_2->setGeometry(375,162,ui->label_2->width(),ui->label_2->height());
- this->valasztott_szin = senderName-1;
- }
- void MainWindow::paintEvent(QPaintEvent *)
- {
- QPainter painter(this);
- QPen pen(Qt::black);
- pen.setWidth(2);
- painter.setPen(pen);
- for(int i = 0;i < 5;i++){
- QLineF line(210,200+(i*50),210+(10*50),200+(i*50));
- painter.drawLine(line);
- }
- for(int i = 0;i < 11;i++){
- QLineF linefuggoleges(210+(i*50),200,210+(i*50),200+(50*4));
- painter.drawLine(linefuggoleges);
- }
- }
- void MainWindow::on_pushButton_2_clicked()
- {
- if(this->currentStage < 10){
- QMessageBox::information(0,"Mastermind kiértékelés",
- "Csak akkor kérhetsz kiértékelést, ha a 10. lépésnél se adtál helyes megoldást.");
- return;
- }else{
- //Kiértékelés függvény hívás
- }
- }
- void MainWindow::on_pushButton_clicked()
- {
- if(this->currentStage < 5){
- QMessageBox::information(0,"Mastermind segítség","Csak a 6. lépéstől kezdve kérhetsz segítséget.");
- }else{
- //segítség függvény
- }
- }
- void MainWindow::resetGame(){
- currentStage = 0;
- for(int i = 0; i < letettGombCounter;i++){
- letettGombok[i]->hide();
- delete letettGombok[i];
- }
- delete Game;
- Game = new MasterMind(this);
- }
- void MainWindow::on_pushButton_3_clicked()
- {
- this->resetGame();
- }
- Új fájl: mainwindow.h
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QMainWindow>
- #include <QTableWidget>
- #include <QStringList>
- #include <QPainter>
- #include <QRectF>
- #include <QPainter>
- #include <QPushButton>
- #include <QStringList>
- #include <QPushButton>
- enum szinek{
- blue,
- gray,
- green,
- orange,
- purple,
- red,
- yellow
- };
- class MasterMind;
- namespace Ui {
- class MainWindow;
- }
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- explicit MainWindow(QWidget *parent = 0);
- ~MainWindow();
- void paintEvent(QPaintEvent *event);
- void mousePressEvent(QMouseEvent *event);
- void genExampleCircle();
- void szinletesz(int,int);
- void resetGame();
- MasterMind * Game;
- QPushButton * letettGombok[40];
- int letettGombCounter = 0;
- QString cPathImage(int szin);
- QStringList szinhelper = {"Kék","Szürke","Zöld","Narancs sárga","Lila","Piros","Citrom sárga"};
- QPushButton* valasztani_gombok[7];
- unsigned short int currentStage = 0;
- QStringList a = {"blue" ,"gray" , "green",
- "orange","purple","red","yellow"};
- int valasztott_szin = -1;
- public slots:
- void gombvalaszt_Click();
- private slots:
- void on_pushButton_2_clicked();
- void on_pushButton_clicked();
- void on_pushButton_3_clicked();
- private:
- Ui::MainWindow *ui;
- };
- #endif // MAINWINDOW_H
- Új fájl: mastermind.cpp
- #include "mastermind.h"
- #include "mainwindow.h"
- #include <vector>
- MasterMind::MasterMind(MainWindow * szulo):parent(szulo){
- for(int i = 0;i < 10; i++){
- this->Stages[i] = new Stage(i);
- }
- this->genRandomTask();
- this->currentStage = &parent->currentStage;
- qDebug() << parent->currentStage;
- qDebug() << feladvany.cella[0] << feladvany.cella[1] << feladvany.cella[2] << feladvany.cella[3];
- }
- void MasterMind::genRandomTask(){
- std::vector<int> tmp = {0,1,2,3,4,5,6};
- for(int i = 0;i < 4;i++){
- int randint = rand() % (tmp.size());
- feladvany.insertColor(tmp[randint],i);
- tmp.erase(tmp.begin()+randint);
- }
- }
- void MasterMind::checkStage(){
- if(feladvany == *this->Stages[*currentStage]){
- qDebug() << "helyes megoldás.";
- }
- }
- Új fájl: mastermind.h
- #ifndef MASTERMIND_H
- #define MASTERMIND_H
- #include <QObject>
- #include "stage.h"
- #include <QDebug>
- #include <stdlib.h>
- class MainWindow;
- class MasterMind
- {
- public:
- MasterMind(){;}
- MasterMind(MainWindow * szulo);
- ~MasterMind(){
- qDebug() << "Call mastermind dtor";
- for(int i = 0;i < 10;i++){
- delete Stages[i];
- }
- }
- unsigned short int * currentStage;
- MainWindow * parent;
- Stage* Stages[10];
- Stage feladvany;
- int pontszam;
- int elsojo;
- void genRandomTask();
- void checkStage();
- void segitseg();
- void kiertekel();
- void tobbszin();
- void utolsotipp();
- void egyszersem();
- void csakszinhelyes();
- };
- #endif // MASTERMIND_H
- Új fájl: stage.cpp
- #include "stage.h"
- #include <QDebug>
- int Stage::insertColor(int szin,int sor){
- if(pos != 4 && cella[sor] == -1){
- this->cella[sor] = szin;
- pos++;
- return (pos == 4) ? 1 : 0;
- }else if(cella[sor] != -1){
- return 2;
- }
- }
- Új fájl: stage.h
- #ifndef STAGE_H
- #define STAGE_H
- class Stage
- {
- public:
- Stage(){;}
- Stage(int stageID):ID(stageID),pos(0) {;}
- int ID;
- int cella[4] = {-1,-1,-1,-1};
- int pos;
- int insertColor(int szin,int sor);
- friend bool operator==(const Stage& s1, const Stage& s2)
- {
- return (s1.cella[0] == s2.cella[0]) &&
- (s1.cella[1] == s2.cella[1]) &&
- (s1.cella[2] == s2.cella[2]) &&
- (s1.cella[3] == s2.cella[3]);
- }
- };
- #endif // STAGE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement