You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.5 KiB
126 lines
3.5 KiB
13 years ago
|
package GameBoard;
|
||
|
use strict;
|
||
13 years ago
|
use TQt;
|
||
|
use TQt::isa qw(TQt::Widget);
|
||
|
use TQt::slots
|
||
13 years ago
|
fire => [],
|
||
|
hit => [],
|
||
|
missed => [],
|
||
|
newGame => [];
|
||
13 years ago
|
use TQt::attributes qw(
|
||
13 years ago
|
hits
|
||
|
shotsLeft
|
||
|
cannonField
|
||
|
);
|
||
|
|
||
|
use LCDRange;
|
||
|
use CannonField;
|
||
|
|
||
|
sub NEW {
|
||
|
shift->SUPER::NEW(@_);
|
||
|
|
||
13 years ago
|
my $quit = TQt::PushButton("&Quit", this, "quit");
|
||
|
$quit->setFont(TQt::Font("Times", 18, &TQt::Font::Bold));
|
||
13 years ago
|
|
||
13 years ago
|
TQt::app->connect($quit, TQT_SIGNAL('clicked()'), TQT_SLOT('quit()'));
|
||
13 years ago
|
|
||
|
my $angle = LCDRange("ANGLE", this, "angle");
|
||
|
$angle->setRange(5, 70);
|
||
|
|
||
|
my $force = LCDRange("FORCE", this, "force");
|
||
|
$force->setRange(10, 50);
|
||
|
|
||
13 years ago
|
my $box = TQt::VBox(this, "cannonFrame");
|
||
13 years ago
|
$box->setFrameStyle($box->WinPanel | $box->Sunken);
|
||
|
|
||
|
cannonField = CannonField($box, "cannonField");
|
||
|
|
||
13 years ago
|
cannonField->connect($angle, TQT_SIGNAL('valueChanged(int)'), TQT_SLOT('setAngle(int)'));
|
||
|
$angle->connect(cannonField, TQT_SIGNAL('angleChanged(int)'), TQT_SLOT('setValue(int)'));
|
||
13 years ago
|
|
||
13 years ago
|
cannonField->connect($force, TQT_SIGNAL('valueChanged(int)'), TQT_SLOT('setForce(int)'));
|
||
|
$force->connect(cannonField, TQT_SIGNAL('forceChanged(int)'), TQT_SLOT('setValue(int)'));
|
||
13 years ago
|
|
||
13 years ago
|
this->connect(cannonField, TQT_SIGNAL('hit()'), TQT_SLOT('hit()'));
|
||
|
this->connect(cannonField, TQT_SIGNAL('missed()'), TQT_SLOT('missed()'));
|
||
13 years ago
|
|
||
13 years ago
|
my $shoot = TQt::PushButton('&Shoot', this, "shoot");
|
||
|
$shoot->setFont(TQt::Font("Times", 18, &TQt::Font::Bold));
|
||
13 years ago
|
|
||
13 years ago
|
this->connect($shoot, TQT_SIGNAL('clicked()'), TQT_SLOT('fire()'));
|
||
13 years ago
|
|
||
13 years ago
|
$shoot->connect(cannonField, TQT_SIGNAL('canShoot(bool)'), TQT_SLOT('setEnabled(bool)'));
|
||
13 years ago
|
|
||
13 years ago
|
my $restart = TQt::PushButton('&New Game', this, "newgame");
|
||
|
$restart->setFont(TQt::Font("Times", 18, &TQt::Font::Bold));
|
||
13 years ago
|
|
||
13 years ago
|
this->connect($restart, TQT_SIGNAL('clicked()'), TQT_SLOT('newGame()'));
|
||
13 years ago
|
|
||
13 years ago
|
hits = TQt::LCDNumber(2, this, "hits");
|
||
|
shotsLeft = TQt::LCDNumber(2, this, "shotsleft");
|
||
|
my $hitsL = TQt::Label("HITS", this, "hitsLabel");
|
||
|
my $shotsLeftL = TQt::Label("SHOTS LEFT", this, "shotsLeftLabel");
|
||
13 years ago
|
|
||
13 years ago
|
my $accel = TQt::Accel(this);
|
||
|
$accel->connectItem($accel->insertItem(TQt::KeySequence(int &Key_Enter)),
|
||
|
this, TQT_SLOT('fire()'));
|
||
|
$accel->connectItem($accel->insertItem(TQt::KeySequence(int &Key_Return)),
|
||
|
this, TQT_SLOT('fire()'));
|
||
|
$accel->connectItem($accel->insertItem(TQt::KeySequence(int &CTRL+&Key_Q)),
|
||
|
TQt::app, TQT_SLOT('quit()'));
|
||
13 years ago
|
|
||
13 years ago
|
my $grid = TQt::GridLayout(this, 2, 2, 10);
|
||
13 years ago
|
$grid->addWidget($quit, 0, 0);
|
||
|
$grid->addWidget($box, 1, 1);
|
||
|
$grid->setColStretch(1, 10);
|
||
|
|
||
13 years ago
|
my $leftBox = TQt::VBoxLayout;
|
||
13 years ago
|
$grid->addLayout($leftBox, 1, 0);
|
||
|
$leftBox->addWidget($angle);
|
||
|
$leftBox->addWidget($force);
|
||
|
|
||
13 years ago
|
my $topBox = TQt::HBoxLayout;
|
||
13 years ago
|
$grid->addLayout($topBox, 0, 1);
|
||
|
$topBox->addWidget($shoot);
|
||
|
$topBox->addWidget(hits);
|
||
|
$topBox->addWidget($hitsL);
|
||
|
$topBox->addWidget(shotsLeft);
|
||
|
$topBox->addWidget($shotsLeftL);
|
||
|
$topBox->addStretch(1);
|
||
|
$topBox->addWidget($restart);
|
||
|
|
||
|
$angle->setValue(60);
|
||
|
$force->setValue(25);
|
||
|
$angle->setFocus();
|
||
|
|
||
|
newGame();
|
||
|
}
|
||
|
|
||
|
sub fire {
|
||
|
return if cannonField->gameOver or cannonField->isShooting;
|
||
|
shotsLeft->display(int(shotsLeft->intValue - 1));
|
||
|
cannonField->shoot;
|
||
|
}
|
||
|
|
||
|
sub hit {
|
||
|
hits->display(int(hits->intValue + 1));
|
||
|
if(shotsLeft->intValue == 0) {
|
||
|
cannonField->setGameOver;
|
||
|
} else {
|
||
|
cannonField->newTarget;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sub missed {
|
||
|
cannonField->setGameOver if shotsLeft->intValue == 0;
|
||
|
}
|
||
|
|
||
|
sub newGame {
|
||
|
shotsLeft->display(int(15));
|
||
|
hits->display(0);
|
||
|
cannonField->restartGame;
|
||
|
cannonField->newTarget;
|
||
|
}
|
||
|
|
||
|
1;
|