mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-11 12:32:37 +01:00
Plugins/Battleship: simplify some stuff
This commit is contained in:
parent
db911b4ee9
commit
1304dfde76
@ -626,9 +626,7 @@ sub place_ship {
|
|||||||
my ($x, $y, $o, $i, $l);
|
my ($x, $y, $o, $i, $l);
|
||||||
my ($yd, $xd) = (0, 0);
|
my ($yd, $xd) = (0, 0);
|
||||||
|
|
||||||
my $fail = 0;
|
for (my $attempt = 0; $attempt < 1000; $attempt++) {
|
||||||
|
|
||||||
while (++$fail < 5000) {
|
|
||||||
$x = $self->number(0, $self->{N_X});
|
$x = $self->number(0, $self->{N_X});
|
||||||
$y = $self->number(0, $self->{N_Y});
|
$y = $self->number(0, $self->{N_Y});
|
||||||
|
|
||||||
@ -702,7 +700,7 @@ sub place_ship {
|
|||||||
sub place_whirlpool {
|
sub place_whirlpool {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
for (my $try = 0; $try < 1000; $try++) {
|
for (my $attempt = 0; $attempt < 1000; $attempt++) {
|
||||||
my $x = $self->number(0, $self->{N_X});
|
my $x = $self->number(0, $self->{N_X});
|
||||||
my $y = $self->number(0, $self->{N_Y});
|
my $y = $self->number(0, $self->{N_Y});
|
||||||
|
|
||||||
@ -806,7 +804,7 @@ sub get_attack_text {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# checks if we hit whirlpool, ocean, ship, etc
|
# checks if we hit whirlpool, ocean, ship, etc
|
||||||
# places miss markers, reveals whirlpools
|
# reveals struck whirlpools
|
||||||
sub check_hit {
|
sub check_hit {
|
||||||
my ($self, $state, $player, $location_data) = @_;
|
my ($self, $state, $player, $location_data) = @_;
|
||||||
|
|
||||||
@ -895,14 +893,15 @@ sub perform_attack {
|
|||||||
};
|
};
|
||||||
|
|
||||||
# launch a shot and see if it hit a ship (handles hitting whirlpools, ocean, etc)
|
# launch a shot and see if it hit a ship (handles hitting whirlpools, ocean, etc)
|
||||||
if ($self->check_hit($state, $player, $location_data)) {
|
my $hit_ship = $self->check_hit($state, $player, $location_data);
|
||||||
# player hit a ship!
|
|
||||||
|
|
||||||
# location_data can be updated by whirlpools, etc
|
# location_data can be updated by whirlpools, etc
|
||||||
$x = $location_data->{x};
|
$x = $location_data->{x};
|
||||||
$y = $location_data->{y};
|
$y = $location_data->{y};
|
||||||
$location = $location_data->{location};
|
$location = $location_data->{location};
|
||||||
|
|
||||||
|
if ($hit_ship) {
|
||||||
|
# player hit a ship!
|
||||||
$self->send_message($self->{channel}, "$player->{name} $attack $location! $color{red}--- HIT! --- $color{reset}");
|
$self->send_message($self->{channel}, "$player->{name} $attack $location! $color{red}--- HIT! --- $color{reset}");
|
||||||
|
|
||||||
$player->{hit}++;
|
$player->{hit}++;
|
||||||
@ -959,17 +958,11 @@ sub perform_attack {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
# player missed
|
# player missed
|
||||||
|
|
||||||
# location_data can be updated by whirlpools, etc
|
|
||||||
$x = $location_data->{x};
|
|
||||||
$y = $location_data->{y};
|
|
||||||
$location = $location_data->{location};
|
|
||||||
|
|
||||||
$self->send_message($self->{channel}, "$player->{name} $attack $location! --- miss ---");
|
$self->send_message($self->{channel}, "$player->{name} $attack $location! --- miss ---");
|
||||||
|
|
||||||
$player->{miss}++;
|
$player->{miss}++;
|
||||||
|
|
||||||
# update board tile
|
# place miss marker
|
||||||
if ($self->{board}->[$x][$y]->{type} == $self->{TYPE_OCEAN}) {
|
if ($self->{board}->[$x][$y]->{type} == $self->{TYPE_OCEAN}) {
|
||||||
$self->{board}->[$x][$y]->{tile} = $self->{TILE_MISS};
|
$self->{board}->[$x][$y]->{tile} = $self->{TILE_MISS};
|
||||||
$self->{board}->[$x][$y]->{missed_by} = $player->{id};
|
$self->{board}->[$x][$y]->{missed_by} = $player->{id};
|
||||||
|
Loading…
Reference in New Issue
Block a user