Skip to content

Commit

Permalink
change single cell
Browse files Browse the repository at this point in the history
  • Loading branch information
HirojiFukuyama committed May 28, 2022
1 parent 14d22f8 commit 3583f13
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This is a course project for ***Practice of Programming in C/C++*** in Peking Un

__Author__: 所以爱会消失对不队

## 简介

## 功能实现
- [x] 基本游戏界面及窗口
- [x] 随机初始化画布
Expand All @@ -14,6 +16,7 @@ __Author__: 所以爱会消失对不队
- [x] 持续演化功能
- [x] 停止持续演化功能
- [x] 自定义规则功能
- [x] 修改单个细胞功能
- [ ] 特殊图案功能
- [ ] 菜单、帮助页面
- [ ] 更多玩法...
Expand Down
25 changes: 25 additions & 0 deletions gamewig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "mainwindow.h"
#include <QPainter>
#include "ui_mainwindow.h"
#include <QPoint>
#include <QMouseEvent>

const int gridSize = 5;
const int CEN_W = 401;
const int CEN_H = 361;
Expand All @@ -22,6 +25,8 @@ gameWig::gameWig(QWidget *parent) : QWidget(parent)
}
cen_w = CEN_W;
cen_h = CEN_H;

connect(this, SIGNAL(clicked()), this, SLOT(mouseClicked()));
}

void gameWig::init() {
Expand Down Expand Up @@ -101,3 +106,23 @@ void gameWig::evolve() {
}
}
}


void gameWig::mouseReleaseEvent(QMouseEvent *e) {
if (mousePos == QPoint(e->x(), e->y()))
emit clicked();
}


void gameWig::mousePressEvent(QMouseEvent *e) {
mousePos = QPoint(e->x(), e->y());
}

// 反转颜色
void gameWig::mouseClicked() {
int i = mousePos.x()/gridSize;
int j = mousePos.y()/gridSize;
value[i][j] = (value[i][j]+1)%2;

update();
}
8 changes: 8 additions & 0 deletions gamewig.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class gameWig : public QWidget
int few = 1, born = 3, many = 4;
MainWindow* Parent;
int cen_w, cen_h;
QPoint mousePos;

explicit gameWig(QWidget *parent = 0);
int hGrid, wGrid;
Expand All @@ -27,7 +28,14 @@ class gameWig : public QWidget


signals:
void clicked();

protected:
virtual void mouseReleaseEvent(QMouseEvent* e);
virtual void mousePressEvent(QMouseEvent* e);

public slots:
void mouseClicked();
};

#endif // GAMEWIG_H
6 changes: 4 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void MainWindow::on_pushButton_7_clicked()
// 自定义设置
void MainWindow::on_pushButton_5_clicked()
{
ui->widget->flag = false;
setting* d = new setting(this);
d->setWindowTitle("自定义设置");
// 现在的参数
Expand Down Expand Up @@ -76,23 +77,24 @@ void MainWindow::on_pushButton_3_clicked()
// 清空画面
void MainWindow::on_pushButton_4_clicked()
{
ui->widget->flag = false;
for (int i = 0; i < 1505; ++i) {
for (int j = 0; j < 1505; ++j) {
ui->widget->value[i][j] = 0;
}
}
ui->widget->flag = false;
ui->widget->update();
}

// 随机生成画面
void MainWindow::on_pushButton_6_clicked()
{
ui->widget->flag = false;
ui->widget->init();
ui->widget->update();
}

// 停下
// 暂停
void MainWindow::on_pushButton_2_clicked()
{
if (!ui->widget->flag)
Expand Down

0 comments on commit 3583f13

Please sign in to comment.