qtbindings 4.8.6.3-x64-mingw32 → 4.8.6.4-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/bin/2.4/rbrcc.exe +0 -0
- data/bin/2.4/rbuic4.exe +0 -0
- data/bin/2.4/smokeapi.exe +0 -0
- data/bin/2.4/smokedeptool.exe +0 -0
- data/examples/tutorial/t10/cannon.rb +72 -72
- data/examples/tutorial/t10/lcdrange.rb +45 -45
- data/examples/tutorial/t10/t10.rb +55 -55
- data/examples/tutorial/t11/cannon.rb +123 -124
- data/examples/tutorial/t11/lcdrange.rb +45 -45
- data/examples/tutorial/t11/t11.rb +65 -65
- data/examples/tutorial/t12/cannon.rb +157 -158
- data/examples/tutorial/t12/lcdrange.rb +58 -59
- data/examples/tutorial/t12/t12.rb +65 -66
- data/examples/tutorial/t13/cannon.rb +206 -208
- data/examples/tutorial/t13/gamebrd.rb +112 -113
- data/examples/tutorial/t13/lcdrange.rb +59 -60
- data/examples/tutorial/t13/t13.rb +11 -11
- data/examples/tutorial/t14/cannon.rb +262 -263
- data/examples/tutorial/t14/gamebrd.rb +122 -123
- data/examples/tutorial/t14/lcdrange.rb +61 -63
- data/examples/tutorial/t14/t14.rb +11 -11
- data/examples/tutorial/t3/t3.rb +17 -18
- data/examples/tutorial/t4/t4.rb +23 -25
- data/examples/tutorial/t5/t5.rb +35 -37
- data/examples/tutorial/t6/t6.rb +48 -52
- data/examples/tutorial/t7/lcdrange.rb +32 -32
- data/examples/tutorial/t7/t7.rb +40 -42
- data/examples/tutorial/t8/cannon.rb +37 -38
- data/examples/tutorial/t8/lcdrange.rb +45 -45
- data/examples/tutorial/t8/t8.rb +43 -43
- data/examples/tutorial/t9/cannon.rb +44 -45
- data/examples/tutorial/t9/lcdrange.rb +46 -46
- data/examples/tutorial/t9/t9.rb +43 -43
- data/lib/2.4/libqtruby4shared.dll +0 -0
- data/lib/2.4/libsmokebase.dll +0 -0
- data/lib/2.4/libsmokeqtcore.dll +0 -0
- data/lib/2.4/libsmokeqtdeclarative.dll +0 -0
- data/lib/{2.2 → 2.4}/libsmokeqtgui.dll +0 -0
- data/lib/2.4/libsmokeqthelp.dll +0 -0
- data/lib/2.4/libsmokeqtmultimedia.dll +0 -0
- data/lib/2.4/libsmokeqtnetwork.dll +0 -0
- data/lib/2.4/libsmokeqtopengl.dll +0 -0
- data/lib/2.4/libsmokeqtscript.dll +0 -0
- data/lib/2.4/libsmokeqtsql.dll +0 -0
- data/lib/2.4/libsmokeqtsvg.dll +0 -0
- data/lib/2.4/libsmokeqttest.dll +0 -0
- data/lib/2.4/libsmokeqtuitools.dll +0 -0
- data/lib/2.4/libsmokeqtwebkit.dll +0 -0
- data/lib/2.4/libsmokeqtxml.dll +0 -0
- data/lib/2.4/libsmokeqtxmlpatterns.dll +0 -0
- data/lib/2.4/qtdeclarative.so +0 -0
- data/lib/2.4/qtruby4.so +0 -0
- data/lib/2.4/qtscript.so +0 -0
- data/lib/2.4/qttest.so +0 -0
- data/lib/2.4/qtuitools.so +0 -0
- data/lib/2.4/qtwebkit.so +0 -0
- data/lib/Qt4.rb +119 -111
- data/lib/qtbindings_version.rb +2 -2
- data/qtbindings.gemspec +18 -18
- data/qtbindingsnative.gemspec +19 -19
- metadata +38 -114
- data/bin/2.0/rbrcc.exe +0 -0
- data/bin/2.0/rbuic4.exe +0 -0
- data/bin/2.0/smokeapi.exe +0 -0
- data/bin/2.0/smokedeptool.exe +0 -0
- data/bin/2.1/rbrcc.exe +0 -0
- data/bin/2.1/rbuic4.exe +0 -0
- data/bin/2.1/smokeapi.exe +0 -0
- data/bin/2.1/smokedeptool.exe +0 -0
- data/bin/2.2/rbrcc.exe +0 -0
- data/bin/2.2/rbuic4.exe +0 -0
- data/bin/2.2/smokeapi.exe +0 -0
- data/bin/2.2/smokedeptool.exe +0 -0
- data/bin/2.3/rbrcc.exe +0 -0
- data/bin/2.3/rbuic4.exe +0 -0
- data/bin/2.3/smokeapi.exe +0 -0
- data/bin/2.3/smokedeptool.exe +0 -0
- data/lib/2.0/libqtruby4shared.dll +0 -0
- data/lib/2.0/libsmokebase.dll +0 -0
- data/lib/2.0/libsmokeqtcore.dll +0 -0
- data/lib/2.0/libsmokeqtdeclarative.dll +0 -0
- data/lib/2.0/libsmokeqtgui.dll +0 -0
- data/lib/2.0/libsmokeqthelp.dll +0 -0
- data/lib/2.0/libsmokeqtmultimedia.dll +0 -0
- data/lib/2.0/libsmokeqtnetwork.dll +0 -0
- data/lib/2.0/libsmokeqtopengl.dll +0 -0
- data/lib/2.0/libsmokeqtscript.dll +0 -0
- data/lib/2.0/libsmokeqtsql.dll +0 -0
- data/lib/2.0/libsmokeqtsvg.dll +0 -0
- data/lib/2.0/libsmokeqttest.dll +0 -0
- data/lib/2.0/libsmokeqtuitools.dll +0 -0
- data/lib/2.0/libsmokeqtwebkit.dll +0 -0
- data/lib/2.0/libsmokeqtxml.dll +0 -0
- data/lib/2.0/libsmokeqtxmlpatterns.dll +0 -0
- data/lib/2.0/qtdeclarative.so +0 -0
- data/lib/2.0/qtruby4.so +0 -0
- data/lib/2.0/qtscript.so +0 -0
- data/lib/2.0/qttest.so +0 -0
- data/lib/2.0/qtuitools.so +0 -0
- data/lib/2.0/qtwebkit.so +0 -0
- data/lib/2.1/libqtruby4shared.dll +0 -0
- data/lib/2.1/libsmokebase.dll +0 -0
- data/lib/2.1/libsmokeqtcore.dll +0 -0
- data/lib/2.1/libsmokeqtdeclarative.dll +0 -0
- data/lib/2.1/libsmokeqtgui.dll +0 -0
- data/lib/2.1/libsmokeqthelp.dll +0 -0
- data/lib/2.1/libsmokeqtmultimedia.dll +0 -0
- data/lib/2.1/libsmokeqtnetwork.dll +0 -0
- data/lib/2.1/libsmokeqtopengl.dll +0 -0
- data/lib/2.1/libsmokeqtscript.dll +0 -0
- data/lib/2.1/libsmokeqtsql.dll +0 -0
- data/lib/2.1/libsmokeqtsvg.dll +0 -0
- data/lib/2.1/libsmokeqttest.dll +0 -0
- data/lib/2.1/libsmokeqtuitools.dll +0 -0
- data/lib/2.1/libsmokeqtwebkit.dll +0 -0
- data/lib/2.1/libsmokeqtxml.dll +0 -0
- data/lib/2.1/libsmokeqtxmlpatterns.dll +0 -0
- data/lib/2.1/qtdeclarative.so +0 -0
- data/lib/2.1/qtruby4.so +0 -0
- data/lib/2.1/qtscript.so +0 -0
- data/lib/2.1/qttest.so +0 -0
- data/lib/2.1/qtuitools.so +0 -0
- data/lib/2.1/qtwebkit.so +0 -0
- data/lib/2.2/libqtruby4shared.dll +0 -0
- data/lib/2.2/libsmokebase.dll +0 -0
- data/lib/2.2/libsmokeqtcore.dll +0 -0
- data/lib/2.2/libsmokeqtdeclarative.dll +0 -0
- data/lib/2.2/libsmokeqthelp.dll +0 -0
- data/lib/2.2/libsmokeqtmultimedia.dll +0 -0
- data/lib/2.2/libsmokeqtnetwork.dll +0 -0
- data/lib/2.2/libsmokeqtopengl.dll +0 -0
- data/lib/2.2/libsmokeqtscript.dll +0 -0
- data/lib/2.2/libsmokeqtsql.dll +0 -0
- data/lib/2.2/libsmokeqtsvg.dll +0 -0
- data/lib/2.2/libsmokeqttest.dll +0 -0
- data/lib/2.2/libsmokeqtuitools.dll +0 -0
- data/lib/2.2/libsmokeqtwebkit.dll +0 -0
- data/lib/2.2/libsmokeqtxml.dll +0 -0
- data/lib/2.2/libsmokeqtxmlpatterns.dll +0 -0
- data/lib/2.2/qtdeclarative.so +0 -0
- data/lib/2.2/qtruby4.so +0 -0
- data/lib/2.2/qtscript.so +0 -0
- data/lib/2.2/qttest.so +0 -0
- data/lib/2.2/qtuitools.so +0 -0
- data/lib/2.2/qtwebkit.so +0 -0
- data/lib/2.3/libqtruby4shared.dll +0 -0
- data/lib/2.3/libsmokebase.dll +0 -0
- data/lib/2.3/libsmokeqtcore.dll +0 -0
- data/lib/2.3/libsmokeqtdeclarative.dll +0 -0
- data/lib/2.3/libsmokeqtgui.dll +0 -0
- data/lib/2.3/libsmokeqthelp.dll +0 -0
- data/lib/2.3/libsmokeqtmultimedia.dll +0 -0
- data/lib/2.3/libsmokeqtnetwork.dll +0 -0
- data/lib/2.3/libsmokeqtopengl.dll +0 -0
- data/lib/2.3/libsmokeqtscript.dll +0 -0
- data/lib/2.3/libsmokeqtsql.dll +0 -0
- data/lib/2.3/libsmokeqtsvg.dll +0 -0
- data/lib/2.3/libsmokeqttest.dll +0 -0
- data/lib/2.3/libsmokeqtuitools.dll +0 -0
- data/lib/2.3/libsmokeqtwebkit.dll +0 -0
- data/lib/2.3/libsmokeqtxml.dll +0 -0
- data/lib/2.3/libsmokeqtxmlpatterns.dll +0 -0
- data/lib/2.3/qtdeclarative.so +0 -0
- data/lib/2.3/qtruby4.so +0 -0
- data/lib/2.3/qtscript.so +0 -0
- data/lib/2.3/qttest.so +0 -0
- data/lib/2.3/qtuitools.so +0 -0
- data/lib/2.3/qtwebkit.so +0 -0
- data/lib/qtbindings_qt_version.rb +0 -2
@@ -1,113 +1,112 @@
|
|
1
|
-
require 'Qt'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
class GameBoard < Qt::Widget
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
1
|
+
require 'Qt'
|
2
|
+
require_relative 'lcdrange.rb'
|
3
|
+
require_relative 'cannon.rb'
|
4
|
+
|
5
|
+
class GameBoard < Qt::Widget
|
6
|
+
slots 'fire()', 'hit()', 'missed()', 'newGame()'
|
7
|
+
|
8
|
+
def initialize(parent = nil)
|
9
|
+
super
|
10
|
+
quit = Qt::PushButton.new('&Quit')
|
11
|
+
quit.setFont(Qt::Font.new('Times', 18, Qt::Font::Bold))
|
12
|
+
|
13
|
+
connect(quit, SIGNAL('clicked()'), $qApp, SLOT('quit()'))
|
14
|
+
|
15
|
+
angle = LCDRange.new('ANGLE', self)
|
16
|
+
angle.range = 5..70
|
17
|
+
|
18
|
+
force = LCDRange.new('FORCE', self)
|
19
|
+
force.range = 10..50
|
20
|
+
|
21
|
+
@cannonField = CannonField.new(self)
|
22
|
+
|
23
|
+
connect(angle, SIGNAL('valueChanged(int)'),
|
24
|
+
@cannonField, SLOT('setAngle(int)'))
|
25
|
+
connect(@cannonField, SIGNAL('angleChanged(int)'),
|
26
|
+
angle, SLOT('setValue(int)'))
|
27
|
+
|
28
|
+
connect(force, SIGNAL('valueChanged(int)'),
|
29
|
+
@cannonField, SLOT('setForce(int)'))
|
30
|
+
connect(@cannonField, SIGNAL('forceChanged(int)'),
|
31
|
+
force, SLOT('setValue(int)'))
|
32
|
+
|
33
|
+
connect(@cannonField, SIGNAL('hit()'),
|
34
|
+
self, SLOT('hit()'))
|
35
|
+
connect(@cannonField, SIGNAL('missed()'),
|
36
|
+
self, SLOT('missed()'))
|
37
|
+
|
38
|
+
shoot = Qt::PushButton.new('&Shoot', self)
|
39
|
+
shoot.setFont(Qt::Font.new('Times', 18, Qt::Font::Bold))
|
40
|
+
|
41
|
+
connect(shoot, SIGNAL('clicked()'), SLOT('fire()'))
|
42
|
+
connect(@cannonField, SIGNAL('canShoot(bool)'),
|
43
|
+
shoot, SLOT('setEnabled(bool)'))
|
44
|
+
|
45
|
+
restart = Qt::PushButton.new('&New Game', self)
|
46
|
+
restart.setFont(Qt::Font.new('Times', 18, Qt::Font::Bold))
|
47
|
+
|
48
|
+
connect(restart, SIGNAL('clicked()'), self, SLOT('newGame()'))
|
49
|
+
|
50
|
+
@hits = Qt::LCDNumber.new(2, self)
|
51
|
+
@shotsLeft = Qt::LCDNumber.new(2, self)
|
52
|
+
hitsLabel = Qt::Label.new('HITS', self)
|
53
|
+
shotsLeftLabel = Qt::Label.new('SHOTS LEFT', self)
|
54
|
+
|
55
|
+
topLayout = Qt::HBoxLayout.new
|
56
|
+
topLayout.addWidget(shoot)
|
57
|
+
topLayout.addWidget(@hits)
|
58
|
+
topLayout.addWidget(hitsLabel)
|
59
|
+
topLayout.addWidget(@shotsLeft)
|
60
|
+
topLayout.addWidget(shotsLeftLabel)
|
61
|
+
topLayout.addStretch(1)
|
62
|
+
topLayout.addWidget(restart)
|
63
|
+
|
64
|
+
leftLayout = Qt::VBoxLayout.new()
|
65
|
+
leftLayout.addWidget(angle)
|
66
|
+
leftLayout.addWidget(force)
|
67
|
+
|
68
|
+
gridLayout = Qt::GridLayout.new
|
69
|
+
gridLayout.addWidget(quit, 0, 0)
|
70
|
+
gridLayout.addLayout(topLayout, 0, 1)
|
71
|
+
gridLayout.addLayout(leftLayout, 1, 0)
|
72
|
+
gridLayout.addWidget(@cannonField, 1, 1, 2, 1)
|
73
|
+
gridLayout.setColumnStretch(1, 10)
|
74
|
+
setLayout(gridLayout)
|
75
|
+
|
76
|
+
angle.setValue(60)
|
77
|
+
force.setValue(25)
|
78
|
+
angle.setFocus()
|
79
|
+
|
80
|
+
newGame()
|
81
|
+
end
|
82
|
+
|
83
|
+
def fire()
|
84
|
+
if @cannonField.gameOver() || @cannonField.isShooting()
|
85
|
+
return
|
86
|
+
end
|
87
|
+
@shotsLeft.display(@shotsLeft.intValue() - 1)
|
88
|
+
@cannonField.shoot()
|
89
|
+
end
|
90
|
+
|
91
|
+
def hit()
|
92
|
+
@hits.display(@hits.intValue() + 1)
|
93
|
+
if @shotsLeft.intValue() == 0
|
94
|
+
@cannonField.setGameOver()
|
95
|
+
else
|
96
|
+
@cannonField.newTarget()
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def missed()
|
101
|
+
if @shotsLeft.intValue() == 0
|
102
|
+
@cannonField.setGameOver()
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def newGame()
|
107
|
+
@shotsLeft.display(15.0)
|
108
|
+
@hits.display(0)
|
109
|
+
@cannonField.restartGame()
|
110
|
+
@cannonField.newTarget()
|
111
|
+
end
|
112
|
+
end
|
@@ -1,60 +1,59 @@
|
|
1
|
-
require 'Qt'
|
2
|
-
|
3
|
-
class LCDRange < Qt::Widget
|
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
|
-
end
|
1
|
+
require 'Qt'
|
2
|
+
|
3
|
+
class LCDRange < Qt::Widget
|
4
|
+
signals 'valueChanged(int)'
|
5
|
+
slots 'setValue(int)', 'setRange(int, int)', 'setText(const char*)'
|
6
|
+
|
7
|
+
def initialize(s, parent = nil)
|
8
|
+
super(parent)
|
9
|
+
init()
|
10
|
+
setText(s)
|
11
|
+
end
|
12
|
+
|
13
|
+
def init()
|
14
|
+
lcd = Qt::LCDNumber.new(2)
|
15
|
+
@slider = Qt::Slider.new(Qt::Horizontal)
|
16
|
+
@slider.range = 0..99
|
17
|
+
@slider.value = 0
|
18
|
+
|
19
|
+
@label = Qt::Label.new
|
20
|
+
@label.setAlignment(Qt::AlignHCenter.to_i | Qt::AlignTop.to_i)
|
21
|
+
@label.setSizePolicy(Qt::SizePolicy::Preferred, Qt::SizePolicy::Fixed)
|
22
|
+
|
23
|
+
connect(@slider, SIGNAL('valueChanged(int)'), lcd, SLOT('display(int)'))
|
24
|
+
connect(@slider, SIGNAL('valueChanged(int)'), SIGNAL('valueChanged(int)'))
|
25
|
+
|
26
|
+
layout = Qt::VBoxLayout.new
|
27
|
+
layout.addWidget(lcd)
|
28
|
+
layout.addWidget(@slider)
|
29
|
+
setLayout(layout)
|
30
|
+
|
31
|
+
setFocusProxy(@slider)
|
32
|
+
end
|
33
|
+
|
34
|
+
def value()
|
35
|
+
@slider.value()
|
36
|
+
end
|
37
|
+
|
38
|
+
def setValue(value)
|
39
|
+
@slider.setValue(value)
|
40
|
+
end
|
41
|
+
|
42
|
+
def range=(r)
|
43
|
+
setRange(r.begin, r.end)
|
44
|
+
end
|
45
|
+
|
46
|
+
def setRange(minVal, maxVal)
|
47
|
+
if minVal < 0 || maxVal > 99 || minVal > maxVal
|
48
|
+
qWarning("LCDRange::setRange(#{minVal},#{maxVal})\n" +
|
49
|
+
"\tRange must be 0..99\n" +
|
50
|
+
"\tand minVal must not be greater than maxVal")
|
51
|
+
return
|
52
|
+
end
|
53
|
+
@slider.setRange(minVal, maxVal)
|
54
|
+
end
|
55
|
+
|
56
|
+
def setText(s)
|
57
|
+
@label.setText(s)
|
58
|
+
end
|
59
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$VERBOSE = true; $:.unshift File.dirname($0)
|
3
|
-
|
4
|
-
require 'Qt'
|
5
|
-
|
6
|
-
|
7
|
-
app = Qt::Application.new(ARGV)
|
8
|
-
gb = GameBoard.new
|
9
|
-
gb.setGeometry(
|
10
|
-
gb.show
|
11
|
-
app.exec
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$VERBOSE = true; $:.unshift File.dirname($0)
|
3
|
+
|
4
|
+
require 'Qt'
|
5
|
+
require_relative 'gamebrd.rb'
|
6
|
+
|
7
|
+
app = Qt::Application.new(ARGV)
|
8
|
+
gb = GameBoard.new
|
9
|
+
gb.setGeometry(100, 100, 500, 355)
|
10
|
+
gb.show
|
11
|
+
app.exec
|
@@ -1,263 +1,262 @@
|
|
1
|
-
include Math
|
2
|
-
|
3
|
-
class CannonField < Qt::Widget
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
end
|
1
|
+
include Math
|
2
|
+
|
3
|
+
class CannonField < Qt::Widget
|
4
|
+
signals 'hit()', 'missed()', 'angleChanged(int)', 'forceChanged(int)',
|
5
|
+
'canShoot(bool)'
|
6
|
+
|
7
|
+
slots 'angle=(int)', 'force=(int)', 'shoot()', 'moveShot()',
|
8
|
+
'newTarget()', 'setGameOver()', 'restartGame()'
|
9
|
+
|
10
|
+
def initialize(parent = nil)
|
11
|
+
super
|
12
|
+
@currentAngle = 45
|
13
|
+
@currentForce = 0
|
14
|
+
@timerCount = 0;
|
15
|
+
@autoShootTimer = Qt::Timer.new(self)
|
16
|
+
connect(@autoShootTimer, SIGNAL('timeout()'),
|
17
|
+
self, SLOT('moveShot()'))
|
18
|
+
@shootAngle = 0
|
19
|
+
@shootForce = 0
|
20
|
+
@target = Qt::Point.new(0, 0)
|
21
|
+
@gameEnded = false
|
22
|
+
@barrelPressed = false
|
23
|
+
setPalette(Qt::Palette.new(Qt::Color.new(250, 250, 200)))
|
24
|
+
setAutoFillBackground(true)
|
25
|
+
newTarget()
|
26
|
+
@barrelRect = Qt::Rect.new(30, -5, 20, 10)
|
27
|
+
end
|
28
|
+
|
29
|
+
def angle()
|
30
|
+
return @currentAngle
|
31
|
+
end
|
32
|
+
|
33
|
+
def force()
|
34
|
+
return @currentForce
|
35
|
+
end
|
36
|
+
|
37
|
+
def gameOver()
|
38
|
+
return @gameEnded
|
39
|
+
end
|
40
|
+
|
41
|
+
def angle=(degrees)
|
42
|
+
if degrees < 5
|
43
|
+
degrees = 5
|
44
|
+
elsif degrees > 70
|
45
|
+
degrees = 70
|
46
|
+
end
|
47
|
+
if @currentAngle == degrees
|
48
|
+
return
|
49
|
+
end
|
50
|
+
@currentAngle = degrees
|
51
|
+
update(cannonRect())
|
52
|
+
emit angleChanged(@currentAngle)
|
53
|
+
end
|
54
|
+
|
55
|
+
def force=(newton)
|
56
|
+
if newton < 0
|
57
|
+
newton = 0
|
58
|
+
end
|
59
|
+
if @currentForce == newton
|
60
|
+
return
|
61
|
+
end
|
62
|
+
@currentForce = newton
|
63
|
+
emit forceChanged(@currentForce)
|
64
|
+
end
|
65
|
+
|
66
|
+
def shoot()
|
67
|
+
if shooting?
|
68
|
+
return
|
69
|
+
end
|
70
|
+
@timerCount = 0
|
71
|
+
@shootAngle = @currentAngle
|
72
|
+
@shootForce = @currentForce
|
73
|
+
@autoShootTimer.start(25)
|
74
|
+
emit canShoot(false)
|
75
|
+
end
|
76
|
+
|
77
|
+
@@first_time = true
|
78
|
+
|
79
|
+
def newTarget()
|
80
|
+
if @@first_time
|
81
|
+
@@first_time = false
|
82
|
+
midnight = Qt::Time.new(0, 0, 0)
|
83
|
+
srand(midnight.secsTo(Qt::Time.currentTime()))
|
84
|
+
end
|
85
|
+
@target = Qt::Point.new(200 + rand(190), 10 + rand(255))
|
86
|
+
update()
|
87
|
+
end
|
88
|
+
|
89
|
+
def setGameOver()
|
90
|
+
if @gameEnded
|
91
|
+
return
|
92
|
+
end
|
93
|
+
if shooting?
|
94
|
+
@autoShootTimer.stop()
|
95
|
+
end
|
96
|
+
@gameEnded = true
|
97
|
+
update()
|
98
|
+
end
|
99
|
+
|
100
|
+
def restartGame()
|
101
|
+
if shooting?
|
102
|
+
@autoShootTimer.stop()
|
103
|
+
end
|
104
|
+
@gameEnded = false
|
105
|
+
update()
|
106
|
+
emit canShoot(true)
|
107
|
+
end
|
108
|
+
|
109
|
+
def moveShot()
|
110
|
+
r = Qt::Region.new(shotRect())
|
111
|
+
@timerCount += 1
|
112
|
+
|
113
|
+
shotR = shotRect()
|
114
|
+
|
115
|
+
if shotR.intersects(targetRect())
|
116
|
+
@autoShootTimer.stop()
|
117
|
+
emit hit()
|
118
|
+
emit canShoot(true)
|
119
|
+
elsif shotR.x() > width() || shotR.y() > height() ||
|
120
|
+
shotR.intersects(barrierRect())
|
121
|
+
@autoShootTimer.stop()
|
122
|
+
emit missed()
|
123
|
+
emit canShoot(true)
|
124
|
+
else
|
125
|
+
r = r.unite(Qt::Region.new(shotR))
|
126
|
+
end
|
127
|
+
|
128
|
+
update(r)
|
129
|
+
end
|
130
|
+
private :moveShot
|
131
|
+
|
132
|
+
def mousePressEvent(e)
|
133
|
+
if e.button() != Qt::LeftButton
|
134
|
+
return
|
135
|
+
end
|
136
|
+
if barrelHit(e.pos())
|
137
|
+
@barrelPressed = true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def mouseMoveEvent(e)
|
142
|
+
if !@barrelPressed
|
143
|
+
return
|
144
|
+
end
|
145
|
+
pnt = e.pos();
|
146
|
+
if pnt.x() <= 0
|
147
|
+
pnt.setX(1)
|
148
|
+
end
|
149
|
+
if pnt.y() >= height()
|
150
|
+
pnt.setY(height() - 1)
|
151
|
+
end
|
152
|
+
rad = atan2((rect().bottom() - pnt.y()), pnt.x())
|
153
|
+
self.angle = (rad * 180 / 3.14159265).round
|
154
|
+
end
|
155
|
+
|
156
|
+
def mouseReleaseEvent(e)
|
157
|
+
if e.button() == Qt::LeftButton
|
158
|
+
@barrelPressed = false
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def paintEvent(e)
|
163
|
+
painter = Qt::Painter.new(self)
|
164
|
+
|
165
|
+
if @gameEnded
|
166
|
+
painter.pen = Qt::Color.new(Qt::black)
|
167
|
+
painter.font = Qt::Font.new('Courier', 48, Qt::Font::Bold)
|
168
|
+
painter.drawText(rect(), Qt::AlignCenter, 'Game Over')
|
169
|
+
end
|
170
|
+
paintCannon(painter)
|
171
|
+
paintBarrier(painter)
|
172
|
+
if shooting?
|
173
|
+
paintShot(painter)
|
174
|
+
end
|
175
|
+
if !@gameEnded
|
176
|
+
paintTarget(painter)
|
177
|
+
end
|
178
|
+
|
179
|
+
painter.end
|
180
|
+
end
|
181
|
+
|
182
|
+
def paintShot(painter)
|
183
|
+
painter.pen = Qt::NoPen
|
184
|
+
painter.brush = Qt::Brush.new(Qt::black)
|
185
|
+
painter.drawRect(shotRect())
|
186
|
+
end
|
187
|
+
|
188
|
+
def paintTarget(painter)
|
189
|
+
painter.brush = Qt::Brush.new(Qt::red)
|
190
|
+
painter.pen = Qt::Color.new(Qt::black)
|
191
|
+
painter.drawRect(targetRect())
|
192
|
+
end
|
193
|
+
|
194
|
+
def paintBarrier(painter)
|
195
|
+
painter.brush = Qt::Brush.new(Qt::yellow)
|
196
|
+
painter.pen = Qt::Color.new(Qt::black)
|
197
|
+
painter.drawRect(barrierRect())
|
198
|
+
end
|
199
|
+
|
200
|
+
def paintCannon(painter)
|
201
|
+
painter.pen = Qt::NoPen
|
202
|
+
painter.brush = Qt::Brush.new(Qt::blue)
|
203
|
+
|
204
|
+
painter.save
|
205
|
+
painter.translate(0, height())
|
206
|
+
painter.drawPie(Qt::Rect.new(-35, -35, 70, 70), 0, 90 * 16)
|
207
|
+
painter.rotate(- @currentAngle)
|
208
|
+
painter.drawRect(@barrelRect)
|
209
|
+
painter.restore
|
210
|
+
end
|
211
|
+
|
212
|
+
private :paintShot, :paintTarget, :paintBarrier, :paintCannon
|
213
|
+
|
214
|
+
def cannonRect()
|
215
|
+
r = Qt::Rect.new(0, 0, 50, 50)
|
216
|
+
r.moveBottomLeft(rect().bottomLeft())
|
217
|
+
return r
|
218
|
+
end
|
219
|
+
|
220
|
+
def shotRect()
|
221
|
+
gravity = 4.0
|
222
|
+
|
223
|
+
time = @timerCount / 4.0
|
224
|
+
velocity = @shootForce
|
225
|
+
radians = @shootAngle * 3.14159265 / 180.0
|
226
|
+
|
227
|
+
velx = velocity * cos(radians)
|
228
|
+
vely = velocity * sin(radians)
|
229
|
+
x0 = (@barrelRect.right() + 5.0) * cos(radians)
|
230
|
+
y0 = (@barrelRect.right() + 5.0) * sin(radians)
|
231
|
+
x = x0 + velx * time
|
232
|
+
y = y0 + vely * time - 0.5 * gravity * time * time
|
233
|
+
|
234
|
+
r = Qt::Rect.new(0, 0, 6, 6);
|
235
|
+
r.moveCenter(Qt::Point.new(x.round, height() - 1 - y.round))
|
236
|
+
return r
|
237
|
+
end
|
238
|
+
|
239
|
+
def targetRect()
|
240
|
+
r = Qt::Rect.new(0, 0, 20, 10)
|
241
|
+
r.moveCenter(Qt::Point.new(@target.x(), height() - 1 - @target.y()))
|
242
|
+
return r
|
243
|
+
end
|
244
|
+
|
245
|
+
def barrierRect()
|
246
|
+
return Qt::Rect.new(145, height() - 100, 15, 99)
|
247
|
+
end
|
248
|
+
|
249
|
+
def barrelHit(pos)
|
250
|
+
matrix = Qt::Matrix.new
|
251
|
+
matrix.translate(0, height())
|
252
|
+
matrix.rotate(- @currentAngle)
|
253
|
+
matrix = matrix.inverted()
|
254
|
+
return @barrelRect.contains(matrix.map(pos))
|
255
|
+
end
|
256
|
+
|
257
|
+
private :cannonRect, :shotRect, :targetRect, :barrierRect, :barrelHit
|
258
|
+
|
259
|
+
def shooting?
|
260
|
+
return @autoShootTimer.active?
|
261
|
+
end
|
262
|
+
end
|