forked from luckymark/wuziqi2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouseveents.h
98 lines (90 loc) · 2.93 KB
/
mouseveents.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef MOUSEVEENTS_H
#define MOUSEVEENTS_H
#include <mainwindow.h>
void MainWindow::mouseReleaseEvent(QMouseEvent *e)
{
int x, y,j1,j2,j3,j4;
// if(e->x() >= x_o && e->x() < x_o+WIDTH*(SIZE-1) && e->y() >= 20 && e->y() < 1900)
if(e->x()>=x_o&&e->x()<=x_o+WIDTH*(SIZE-1)&&e->y()>=y_o&&e->y()<y_o+WIDTH*(SIZE-1))
{
int x1=(e->x())-x_o;
int y1=e->y()-y_o;
int rest_x=x1/WIDTH;
int x_x=x1%WIDTH;
int rest_y=y1/WIDTH;
int y_y=y1%WIDTH;
if(x_x>WIDTH/2){
if(y_y>WIDTH/2){
x1=rest_x+1;
y1=rest_y+1;
}else{
x1=rest_x+1;
y1=rest_y-1;
}
}else{
if(y_y>WIDTH/2){
x1=rest_x-1;
y1=rest_y+1;
}else{
x1=rest_x-1;
y1=rest_y-1;
}
}
x=(x1<0)?0:x1;
y=(y1<0)?0:y1;
// x = (e->x() - 20) / 40;
// y = (e->y() - 20) / 40;
if (a[x][y] == 0)
{
a[x][y] = player++;
// if(player == renshu+1)
// player =1;
}
j1 = jiance(1,0,a[x][y],x,y); //检测x
j2 = jiance(0,1,a[x][y],x,y); //检测y
j3 = jiance(1,1,a[x][y],x,y); //检测45度
j4 = jiance(1,-1,a[x][y],x,y); //检测135度
if(j1 ==4||j2==4||j3==4||j4==4)
{
this->update();
//setEnabled(false);
if(a[x][y] == 1)
{
QMessageBox::information(this, "Win", "Black Win!", QMessageBox::Ok);
}
if(a[x][y] == 2)
{
QMessageBox::information(this, "Win", "White Win!", QMessageBox::Ok);
}
// if(a[x][y] == 3)
// {
// QMessageBox::information(this, "Win", "Red Win!", QMessageBox::Ok);
// }
// if(a[x][y] == 4)
// {
// QMessageBox::information(this, "Win", "Blue Win!", QMessageBox::Ok);
// }
// if(a[x][y] == 5)
// {
// QMessageBox::information(this, "Win", "Yellow Win!", QMessageBox::Ok);
// }
emit gameover();
}
}
this->update();
}
void MainWindow::wheelEvent(QWheelEvent *event)
{
int numDegrees = event->delta() / 8;//滚动的角度,*8就是鼠标滚动的距离
int numSteps = numDegrees / 15;//滚动的步数,*15就是鼠标滚动的角度
if (event->orientation() == Qt::Horizontal)
{
qDebug()<<"horiz";
}
else
{
qDebug()<<"llll"<<numSteps<<" "<<numDegrees;
}
event->accept(); //接收该事件
}
#endif // MOUSEVEENTS_H