Hello community,
here is the log from the commit of package knavalbattle for openSUSE:Factory checked in at 2014-01-27 11:18:04
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/knavalbattle (Old)
and /work/SRC/openSUSE:Factory/.knavalbattle.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "knavalbattle"
Changes:
--------
--- /work/SRC/openSUSE:Factory/knavalbattle/knavalbattle.changes 2013-12-19 13:19:02.000000000 +0100
+++ /work/SRC/openSUSE:Factory/.knavalbattle.new/knavalbattle.changes 2014-01-27 11:18:05.000000000 +0100
@@ -1,0 +2,7 @@
+Sat Jan 11 16:01:44 UTC 2014 - tittiatcoke@gmail.com
+
+- Update to 4.12.1
+ * KDE 4.12.1 release
+ * See http://www.kde.org/announcements/announce-4.12.1.php
+
+-------------------------------------------------------------------
Old:
----
knavalbattle-4.12.0.tar.xz
New:
----
knavalbattle-4.12.1.tar.xz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ knavalbattle.spec ++++++
--- /var/tmp/diff_new_pack.CBMxcl/_old 2014-01-27 11:18:06.000000000 +0100
+++ /var/tmp/diff_new_pack.CBMxcl/_new 2014-01-27 11:18:06.000000000 +0100
@@ -1,7 +1,7 @@
#
# spec file for package knavalbattle
#
-# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -23,7 +23,7 @@
License: GPL-2.0+
Group: Amusements/Games/Board/Other
Url: http://www.kde.org
-Version: 4.12.0
+Version: 4.12.1
Release: 0
Source0: knavalbattle-%{version}.tar.xz
BuildRoot: %{_tmppath}/%{name}-%{version}-build
++++++ knavalbattle-4.12.0.tar.xz -> knavalbattle-4.12.1.tar.xz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/ai/dummyai.cpp new/knavalbattle-4.12.1/src/ai/dummyai.cpp
--- old/knavalbattle-4.12.0/src/ai/dummyai.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/ai/dummyai.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -44,8 +44,8 @@
Coord c(rand() % m_sea->size().x, rand() % m_sea->size().y);
Ship::Direction dir = rand() % 2 == 0 ? Ship::LEFT_TO_RIGHT : Ship::TOP_DOWN;
if (m_sea->canAddShip(m_player, c, i, dir)) {
- ship = new Ship(i, dir);
- m_sea->add(m_player, c, ship);
+ ship = new Ship(i, dir, c);
+ m_sea->add(m_player, ship);
}
}
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/ai/smartai.cpp new/knavalbattle-4.12.1/src/ai/smartai.cpp
--- old/knavalbattle-4.12.0/src/ai/smartai.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/ai/smartai.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -331,8 +331,8 @@
Coord c(rand() % m_sea->size().x, rand() % m_sea->size().y);
Ship::Direction dir = rand() % 2 == 0 ? Ship::LEFT_TO_RIGHT : Ship::TOP_DOWN;
if (m_sea->canAddShip(m_player, c, i, dir)) {
- ship = new Ship(i, dir);
- m_sea->add(m_player, c, ship);
+ ship = new Ship(i, dir, c);
+ m_sea->add(m_player, ship);
}
}
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/aientity.cpp new/knavalbattle-4.12.1/src/aientity.cpp
--- old/knavalbattle-4.12.0/src/aientity.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/aientity.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -11,13 +11,14 @@
#include "ai/smartai.h"
#include "ai/dummyai.h"
#include "shot.h"
+#include "seaview.h"
#include <KgDifficulty>
#include <KIcon>
-AIEntity::AIEntity(Sea::Player player, Sea* sea)
-: Entity(player)
+AIEntity::AIEntity(Sea::Player player, Sea* sea, SeaView *seaview)
+: Entity(player, seaview)
, m_sea(sea)
{
switch (Kg::difficultyLevel()) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/aientity.h new/knavalbattle-4.12.1/src/aientity.h
--- old/knavalbattle-4.12.0/src/aientity.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/aientity.h 2014-01-08 14:13:24.000000000 +0100
@@ -19,12 +19,12 @@
Q_OBJECT
AI* m_ai;
Sea* m_sea;
-
+
void getShoot();
-
+
friend class DelayedShot;
public:
- AIEntity(Sea::Player player, Sea* sea);
+ AIEntity(Sea::Player player, Sea* sea, SeaView *seaview);
virtual ~AIEntity();
virtual void notify(Sea::Player player, const Coord& c, const HitInfo& info);
@@ -33,7 +33,7 @@
virtual void start(bool);
virtual void startPlaying();
virtual void hit(Shot* shot);
-
+
virtual KIcon icon() const;
public slots:
virtual void notifyAbort() { }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/animation.cpp new/knavalbattle-4.12.1/src/animation.cpp
--- old/knavalbattle-4.12.0/src/animation.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/animation.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -68,6 +68,7 @@
, m_from(from)
, m_to(to)
, m_time(time)
+, m_start(0)
{
}
@@ -100,6 +101,7 @@
, m_from(from)
, m_to(to)
, m_time(time)
+, m_start(0)
{
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/battlefield.cpp new/knavalbattle-4.12.1/src/battlefield.cpp
--- old/knavalbattle-4.12.0/src/battlefield.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/battlefield.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -61,9 +61,9 @@
m_ships += n;
}
-void BattleField::add(const Coord& pos, Ship* ship)
+void BattleField::add(Ship* ship)
{
- Coord p = pos;
+ Coord p = ship->position();
for (unsigned int i = 0; i < ship->size(); i++) {
set(p, Element(ship));
p = p + ship->increment();
@@ -88,7 +88,7 @@
}
}
-bool BattleField::canAddShip(const Coord& pos, unsigned int size, Ship::Direction direction, const bool allow_adjacent_ships) const
+bool BattleField::canAddShip(const Coord& pos, unsigned int size, Ship::Direction direction) const
{
Coord p = pos;
Coord inc = Ship::increment(direction);
@@ -99,7 +99,7 @@
p += inc;
}
// nor over another ship
- if (allow_adjacent_ships) {
+ if (m_allow_adjacent_ships) {
p = pos;
for (unsigned int i = 0; i < size; i++) {
if (valid(p) && !get(p).water())
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/battlefield.h new/knavalbattle-4.12.1/src/battlefield.h
--- old/knavalbattle-4.12.0/src/battlefield.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/battlefield.h 2014-01-08 14:13:24.000000000 +0100
@@ -23,6 +23,7 @@
typedef Grid<Element> Board;
Coord m_size;
Board m_board;
+ bool m_allow_adjacent_ships;
unsigned int m_ships;
inline int convert(const Coord& c) const { return c.x + m_size.x * c.y; }
@@ -35,10 +36,10 @@
const Element& get(const Coord& pos) const;
void set(const Coord& pos, const Element& e);
- void add(const Coord& pos, Ship* ship);
+ void add(Ship* ship);
void add(int n);
void addBorder(const Coord& pos);
- bool canAddShip(const Coord& pos, unsigned int size, Ship::Direction direction, const bool allow_adjacent_ships) const;
+ bool canAddShip(const Coord& pos, unsigned int size, Ship::Direction direction) const;
HitInfo hit(const Coord& pos);
void forceHit(const Coord& pos, const HitInfo& info);
const Element& at(const Coord& c) const;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/battlefieldview.cpp new/knavalbattle-4.12.1/src/battlefieldview.cpp
--- old/knavalbattle-4.12.0/src/battlefieldview.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/battlefieldview.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -177,18 +177,18 @@
sprite->setPos(m_renderer->toReal(c));
scene()->addItem(sprite);
- sprite->stackBefore(m_screen);
}
-void BattleFieldView::add(const Coord& c, Ship* ship)
+void BattleFieldView::add(Ship* ship)
{
Sprite* sprite = m_factory.createShip(ship);
- addSprite(c, sprite);
+ addSprite(ship->position(), sprite);
// fading preview in
+ Animation* a = new FadeAnimation(sprite, PREVIEW_OPACITY, 1, 1000);
+ Animator::instance()->add(a);
+
if (ship == m_preview.ship) {
- Animation* a = new FadeAnimation(sprite, PREVIEW_OPACITY, 1, 1000);
- Animator::instance()->add(a);
cancelPreview();
}
else if (!ship->alive()) {
@@ -197,12 +197,12 @@
}
}
-void BattleFieldView::sink(const Coord& c, Ship* ship)
+void BattleFieldView::sink(Ship* ship)
{
m_last_hit = 0;
Sprite* ship_sprite = 0;
- Coord p = c;
+ Coord p = ship->position();
for (unsigned int i = 0;
i < ship->size();
i++, p += ship->increment()) {
@@ -213,7 +213,7 @@
else if (s->spriteKey().startsWith("hit")) {
s->setSpriteKey("hit-end");
s->refresh(m_renderer);
- s->stackBefore(m_screen);
+ s->setZValue(BACKGROUND);
s->setOpacity(0.5);
}
}
@@ -227,6 +227,7 @@
{
removeImpact();
m_last_hit = m_factory.createHit();
+ m_last_hit->setZValue(BACKGROUND);
addSprite(c, m_last_hit);
}
@@ -234,6 +235,7 @@
{
removeImpact();
m_impact = m_factory.createImpact();
+ m_impact->setZValue(BACKGROUND);
addSprite(c, m_impact);
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/battlefieldview.h new/knavalbattle-4.12.1/src/battlefieldview.h
--- old/knavalbattle-4.12.0/src/battlefieldview.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/battlefieldview.h 2014-01-08 14:13:24.000000000 +0100
@@ -38,6 +38,11 @@
QGraphicsLineItem *hlines[11];
QGraphicsLineItem *vlines[11];
+ enum Planes {
+ BACKGROUND = 1,
+ FOREGROUND = 2
+ };
+
WelcomeScreen* m_screen;
KBSRenderer* m_renderer;
SpriteFactory m_factory;
@@ -74,17 +79,18 @@
void setPreview(const QPointF& pos, Ship* ship);
void cancelPreview();
- void add(const Coord& c, Ship* ship);
+ void add(Ship* ship);
void hit(const Coord& c);
void miss(const Coord& c);
void removeImpact();
- void sink(const Coord& c, Ship* ship);
+ void sink(Ship* ship);
void clear();
void setDelegate(Delegate *c);
void setPlayer(Sea::Player player);
-
+
WelcomeScreen* screen() const;
+
protected:
void drawGrid();
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/button.h new/knavalbattle-4.12.1/src/button.h
--- old/knavalbattle-4.12.0/src/button.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/button.h 2014-01-08 14:13:24.000000000 +0100
@@ -78,7 +78,6 @@
Button* m_button;
int m_brightness;
static double m_speed;
- double m_current;
int m_last;
public:
ButtonAnimation(Button* button, int brightness);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/controller.cpp new/knavalbattle-4.12.1/src/controller.cpp
--- old/knavalbattle-4.12.0/src/controller.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/controller.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -43,26 +43,25 @@
return entity;
}
-AIEntity* Controller::createAI(Sea::Player player)
+AIEntity* Controller::createAI(Sea::Player player, SeaView* view)
{
kDebug() << "created ai entity";
m_has_ai = true;
- AIEntity* e = new AIEntity(player, m_sea);
+ AIEntity* e = new AIEntity(player, m_sea, view);
e->setNick(i18n("Computer"));
setupEntity(e);
-
+
return e;
}
-NetworkEntity* Controller::createRemotePlayer(Sea::Player player, Protocol* protocol, bool client)
+NetworkEntity* Controller::createRemotePlayer(Sea::Player player, SeaView* view, Protocol* protocol, bool client)
{
- NetworkEntity* e = new NetworkEntity(player, m_sea, protocol, client);
+ NetworkEntity* e = new NetworkEntity(player, m_sea, view, protocol, client);
setupEntity(e);
connect(e, SIGNAL(restartRequested()), this, SIGNAL(restartRequested()));
if (client) {
m_sea->switchTurn();
}
-
return e;
}
@@ -80,19 +79,19 @@
this, SLOT(nick(int,QString)));
connect(entity, SIGNAL(compatibility(int)),
this, SIGNAL(compatibility(int)));
-
+
foreach (Entity* e, m_entities) {
connect(e, SIGNAL(compatibility(int)),
entity, SLOT(setCompatibilityLevel(int)));
connect(entity, SIGNAL(compatibility(int)),
e, SLOT(setCompatibilityLevel(int)));
-
+
connect(e, SIGNAL(abortGame()),
entity, SLOT(notifyAbort()));
connect(entity, SIGNAL(abortGame()),
e, SLOT(notifyAbort()));
}
-
+
m_entities.append(entity);
}
@@ -216,11 +215,16 @@
void Controller::finalizeGame(Sea::Player winner)
{
+ // first, every entity will notify the other entity its ships
+ foreach (Entity* entity, m_entities) {
+ entity->notifyShips(winner);
+ }
+ // then, it will notify the end of the game
foreach (Entity* entity, m_entities) {
entity->notifyGameOver(winner);
}
emit gameOver(winner);
-}
+ }
Entity* Controller::findEntity(Sea::Player player) const
{
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/controller.h new/knavalbattle-4.12.1/src/controller.h
--- old/knavalbattle-4.12.0/src/controller.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/controller.h 2014-01-08 14:13:24.000000000 +0100
@@ -44,17 +44,18 @@
friend class Shot;
public:
- explicit Controller(QObject* parent, AudioPlayer* player = 0, const bool allow_adjacent_ships = false);
+ explicit Controller(QObject* parent, AudioPlayer* audioPlayer = 0, const bool allow_adjacent_ships = false);
PlayerEntity* createPlayer(Sea::Player player, SeaView* view,
ChatWidget* chat, const QString& nick);
- AIEntity* createAI(Sea::Player player);
- NetworkEntity* createRemotePlayer(Sea::Player player, Protocol* protocol, bool client);
+ AIEntity* createAI(Sea::Player player, SeaView* view);
+ NetworkEntity* createRemotePlayer(Sea::Player player, SeaView* view, Protocol* protocol, bool client);
bool start(SeaView* view, bool ask = false);
Entity* findEntity(Sea::Player) const;
Sea::Player turn() const;
bool hasAI() const;
+ inline Sea* getSea() const { return m_sea; }
public slots:
void shoot(int player, const Coord& c);
void ready(int player);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/coord.h new/knavalbattle-4.12.1/src/coord.h
--- old/knavalbattle-4.12.0/src/coord.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/coord.h 2014-01-08 14:13:24.000000000 +0100
@@ -20,7 +20,7 @@
int y;
Coord(int x, int y);
- Coord() { }
+ Coord():x(0),y(0) { }
Coord operator+(const Coord& other) const;
Coord operator-(const Coord& other) const;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/entity.cpp new/knavalbattle-4.12.1/src/entity.cpp
--- old/knavalbattle-4.12.0/src/entity.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/entity.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -10,8 +10,9 @@
#include "entity.h"
-Entity::Entity(Sea::Player player)
+Entity::Entity(Sea::Player player, SeaView* seaview)
: m_player(player)
+, m_seaview(seaview)
, m_level(COMPAT_KBS4)
{
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/entity.h new/knavalbattle-4.12.1/src/entity.h
--- old/knavalbattle-4.12.0/src/entity.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/entity.h 2014-01-08 14:13:24.000000000 +0100
@@ -12,6 +12,7 @@
#include <QObject>
#include "sea.h"
+#include "seaview.h"
#include "stats.h"
class Shot;
@@ -28,11 +29,13 @@
};
protected:
Sea::Player m_player;
+ SeaView* m_seaview;
QString m_nick;
CompatibilityLevel m_level;
Stats m_stats;
+
public:
- Entity(Sea::Player player);
+ Entity(Sea::Player player, SeaView* seaview);
virtual ~Entity();
virtual void notify(Sea::Player player, const Coord& c, const HitInfo& info) = 0;
virtual void notifyChat(const Entity* entity, const QString& text) = 0;
@@ -41,6 +44,7 @@
virtual void start(bool) = 0;
virtual void startPlaying() { }
virtual void notifyReady(Sea::Player) { }
+ virtual void notifyShips(Sea::Player) { }
virtual void notifyGameOver(Sea::Player) { }
Stats* stats();
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/networkentity.cpp new/knavalbattle-4.12.1/src/networkentity.cpp
--- old/knavalbattle-4.12.0/src/networkentity.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/networkentity.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -13,18 +13,20 @@
#include "shot.h"
#include "protocol.h"
#include "settings.h"
+#include "seaview.h"
#include <KIcon>
#include
#include
-NetworkEntity::NetworkEntity(Sea::Player player, Sea* sea, Protocol* protocol, bool client)
-: Entity(player)
+NetworkEntity::NetworkEntity(Sea::Player player, Sea* sea, SeaView* seaview, Protocol* protocol, bool client)
+: Entity(player, seaview)
, m_sea(sea)
+, m_protocol(protocol)
, m_pending_shot(0)
, m_client(client)
+, m_winner(false)
{
- m_protocol = protocol;
}
NetworkEntity::~NetworkEntity()
@@ -52,14 +54,27 @@
}
}
-void NetworkEntity::notifyGameOver(Sea::Player)
+void NetworkEntity::notifyShips(Sea::Player player)
{
- m_protocol->send(MessagePtr(new GameOverMessage));
+ m_winner= player == m_player ;
+
+ GameOverMessage* msg=new GameOverMessage();
+ if (!m_winner) {
+ foreach (Ship* ship, m_sea->myShips()) {
+ if (ship->alive()) {
+ msg->addShip(ship->position(), ship->size(), ship->direction());
+ }
+ }
+ }
+ m_protocol->send(MessagePtr(msg));
}
-void NetworkEntity::startPlaying()
+void NetworkEntity::notifyGameOver(Sea::Player player)
{
+}
+void NetworkEntity::startPlaying()
+{
}
void NetworkEntity::notify(Sea::Player player, const Coord& c, const HitInfo& info)
@@ -67,7 +82,7 @@
if (info.type == HitInfo::INVALID) {
return;
}
-
+
if (player == m_player) {
bool hit = info.type == HitInfo::HIT;
bool death = info.shipDestroyed != 0;
@@ -172,7 +187,7 @@
int size = abs(delta.x) + abs(delta.y) + 1;
Ship::Direction direction = delta.x == 0 ? Ship::TOP_DOWN : Ship::LEFT_TO_RIGHT;
Coord shipPos = (delta.x < 0 || delta.y < 0) ? msg.stop() : msg.start();
- Ship* ship = new Ship(size, direction);
+ Ship* ship = new Ship(size, direction, shipPos);
info.shipDestroyed = ship;
info.shipPos = shipPos;
@@ -189,9 +204,14 @@
}
}
-void NetworkEntity::visit(const GameOverMessage&)
+void NetworkEntity::visit(const GameOverMessage& msg)
{
-
+ {
+ // receive the ships and add them to the board
+ foreach (GameOverMessage::ShipInfo ship, msg.ships()) {
+ m_seaview->add(m_sea->turn(), new Ship(ship.size, ship.direction, ship.pos));
+ }
+ }
}
void NetworkEntity::visit(const RestartMessage&)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/networkentity.h new/knavalbattle-4.12.1/src/networkentity.h
--- old/knavalbattle-4.12.0/src/networkentity.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/networkentity.h 2014-01-08 14:13:24.000000000 +0100
@@ -14,6 +14,7 @@
#include "message.h"
class Sea;
+class SeaView;
class Protocol;
class NetworkEntity : public Entity, private MessageVisitor
@@ -23,19 +24,22 @@
Protocol* m_protocol;
Shot* m_pending_shot;
bool m_client;
+ bool m_winner;
+
public:
- NetworkEntity(Sea::Player player, Sea* sea, Protocol* device, bool client);
+ NetworkEntity(Sea::Player player, Sea* sea, SeaView* seaview, Protocol* device, bool client);
~NetworkEntity();
-
+
virtual void notify(Sea::Player player, const Coord& c, const HitInfo& info);
virtual void notifyChat(const Entity* entity, const QString& text);
virtual void notifyNick(Sea::Player player, const QString& nick);
virtual void start(bool ask);
virtual void startPlaying();
virtual void notifyReady(Sea::Player player);
+ virtual void notifyShips(Sea::Player winner);
virtual void notifyGameOver(Sea::Player winner);
virtual void hit(Shot* shot);
-
+
virtual KIcon icon() const;
private slots:
void received(MessagePtr msg);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/playerentity.cpp new/knavalbattle-4.12.1/src/playerentity.cpp
--- old/knavalbattle-4.12.0/src/playerentity.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/playerentity.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -34,6 +34,7 @@
Ship* PlayerEntity::canAddShip(const Coord& c)
{
Ship* ship = nextShip();
+ ship->setPosition(c);
Q_ASSERT(ship);
if (m_sea->canAddShip(m_player, c, ship->size(), ship->direction())) {
@@ -46,26 +47,26 @@
}
}
}
-
return ship;
- }
-
+ }
return 0;
}
+
void PlayerEntity::action(Sea::Player player, const Coord& c)
{
if (nextShip()) {
if (player == m_player) {
// placing ships
+ // First check if the ship can be placed anywhere
Ship* ship = canAddShip(c);
if (ship) {
// remove ship from the list
m_ships.removeFirst();
// add ship to the sea
- m_sea->add(m_player, c, ship);
- m_view->add(m_player, c, ship);
+ m_sea->add(m_player, ship);
+ m_seaview->add(m_player, ship);
if (!nextShip()) {
emit ready(m_player);
@@ -83,13 +84,15 @@
void PlayerEntity::start(bool ask)
{
- m_ships.append(new Ship(1, Ship::LEFT_TO_RIGHT));
- m_ships.append(new Ship(2, Ship::LEFT_TO_RIGHT));
- m_ships.append(new Ship(3, Ship::LEFT_TO_RIGHT));
- m_ships.append(new Ship(4, Ship::LEFT_TO_RIGHT));
-
+ Coord origin(0, 0);
+
+ m_ships.append(new Ship(1, Ship::LEFT_TO_RIGHT, origin));
+ m_ships.append(new Ship(2, Ship::LEFT_TO_RIGHT, origin));
+ m_ships.append(new Ship(3, Ship::LEFT_TO_RIGHT, origin));
+ m_ships.append(new Ship(4, Ship::LEFT_TO_RIGHT, origin));
+
UIEntity::start(ask);
- m_view->setDelegate(this);
+ m_seaview->setDelegate(this);
}
void PlayerEntity::hit(Shot* shot)
@@ -114,7 +117,7 @@
Ship* next = nextShip();
if (next) {
next->changeDirection();
- m_view->cancelPreview();
+ m_seaview->cancelPreview();
}
}
}
@@ -126,6 +129,7 @@
return 0;
}
if (m_sea->canAddShip(player, c, next->size(), next->direction())) {
+ next->setPosition(c);
return next;
}
else {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/playfield.cpp new/knavalbattle-4.12.1/src/playfield.cpp
--- old/knavalbattle-4.12.0/src/playfield.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/playfield.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -40,8 +40,8 @@
setMinimumSize(static_cast<int>(MINIMUM_HEIGHT * 1.6), MINIMUM_HEIGHT);
QVBoxLayout* layout = new QVBoxLayout;
- m_sea = new SeaView(this);
- layout->addWidget(m_sea, 1);
+ m_seaView = new SeaView(this);
+ layout->addWidget(m_seaView, 1);
m_chat = new ChatWidget(this);
m_chat->hide();
@@ -80,22 +80,23 @@
this, SLOT(changeTurn(int)));
connect(controller, SIGNAL(playerReady(int)),
this, SLOT(playerReady(int)));
+
return controller;
}
void PlayField::setupController()
{
Animator::instance()->restart();
- m_sea->clear();
+ m_seaView->clear();
m_chat->hide();
// remove welcome screen
- m_sea->screen(Sea::Player(0))->fadeOut();
- m_sea->screen(Sea::Player(1))->fadeOut();
+ m_seaView->screen(Sea::Player(0))->fadeOut();
+ m_seaView->screen(Sea::Player(1))->fadeOut();
delete m_controller;
m_controller = createController();
- m_menu->setupController(m_controller, 0, m_sea, m_chat, false);
+ m_menu->setupController(m_controller, 0, m_seaView, m_chat, false);
startGame();
}
@@ -110,8 +111,7 @@
// create new controller
m_controller = createController();
m_menu->setupController(m_controller, old_opponent,
- m_sea, m_chat, ask);
-
+ m_seaView, m_chat, ask);
delete old_opponent;
startGame();
@@ -122,7 +122,7 @@
Animator::instance()->restart();
delete m_controller;
m_controller = 0;
- m_sea->clear();
+ m_seaView->clear();
}
void PlayField::newGame()
@@ -133,10 +133,10 @@
Kg::difficulty()->setGameRunning(false);
m_chat->hide();
- m_sea->screen(Sea::Player(0))->show();
- m_sea->screen(Sea::Player(1))->show();
+ m_seaView->screen(Sea::Player(0))->show();
+ m_seaView->screen(Sea::Player(1))->show();
- m_menu = new SimpleMenu(this, m_sea->screen(Sea::Player(0)));
+ m_menu = new SimpleMenu(this, m_seaView->screen(Sea::Player(0)));
connect(m_menu, SIGNAL(done()), this, SLOT(setupController()));
emit welcomeScreen();
}
@@ -144,7 +144,7 @@
void PlayField::restart(bool ask)
{
Animator::instance()->restart();
- m_sea->clear();
+ m_seaView->clear();
resetupController(ask);
}
@@ -254,7 +254,7 @@
void PlayField::updateNick(int player, const QString& nick)
{
- m_sea->setNick(Sea::Player(player), nick);
+ m_seaView->setNick(Sea::Player(player), nick);
}
void PlayField::changeTurn(int player)
@@ -346,12 +346,12 @@
void PlayField::toggleLeftGrid(bool show)
{
- m_sea->toggleLeftGrid(show);
+ m_seaView->toggleLeftGrid(show);
}
void PlayField::toggleRightGrid(bool show)
{
- m_sea->toggleRightGrid(show);
+ m_seaView->toggleRightGrid(show);
}
#include "playfield.moc"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/playfield.h new/knavalbattle-4.12.1/src/playfield.h
--- old/knavalbattle-4.12.0/src/playfield.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/playfield.h 2014-01-08 14:13:24.000000000 +0100
@@ -24,14 +24,14 @@
class PlayField : public QWidget
{
Q_OBJECT
- SeaView* m_sea;
+ SeaView* m_seaView;
Controller* m_controller;
AudioPlayer* m_player;
ChatWidget* m_chat;
SimpleMenu* m_menu;
QStatusBar* m_status_bar;
bool m_show_endofgame_message;
-
+
void startGame();
void endGame();
void resetupController(bool ask = false);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/protocol.cpp new/knavalbattle-4.12.1/src/protocol.cpp
--- old/knavalbattle-4.12.0/src/protocol.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/protocol.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -214,12 +214,12 @@
}
case GameOverMessage::MSGTYPE:
{
- GameOverMessage* msg = new GameOverMessage;
+ GameOverMessage* msg = new GameOverMessage();
QDomNodeList nodes = main.childNodes();
for (int i = 0; i < nodes.count(); i++) {
QDomElement element = nodes.item(i).toElement();
if (!element.isNull() && element.tagName().startsWith("ship")) {
- int size = element.tagName().mid(4).toInt() + 1;
+ int size = element.tagName().mid(4).toInt();
QStringList data = element.text().split(' ');
if (data.size() != 3) {
continue;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/sea.cpp new/knavalbattle-4.12.1/src/sea.cpp
--- old/knavalbattle-4.12.0/src/sea.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/sea.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -32,12 +32,19 @@
if (m_status != PLACING_SHIPS) {
return false;
}
- return m_fields[p]->canAddShip(pos, size, direction, m_allow_adjacent_ships);
+ return m_fields[p]->canAddShip(pos, size, direction);
}
-void Sea::add(Player p, const Coord& pos, Ship* ship)
+void Sea::add(Player p, Ship* ship)
{
- m_fields[p]->add(pos, ship);
+ if(p == PLAYER_B) {
+ m_enemyShips.append(ship);
+ }
+ else {
+ m_myShips.append(ship);
+ }
+
+ m_fields[p]->add(ship);
}
void Sea::add(Player p, int n)
@@ -136,5 +143,15 @@
return m_fields[p]->isNearShip(pos);
}
+const QList Sea::enemyShips() const
+{
+ return m_enemyShips;
+}
+
+const QList Sea::myShips() const
+{
+ return m_myShips;
+}
+
#include "sea.moc"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/sea.h new/knavalbattle-4.12.1/src/sea.h
--- old/knavalbattle-4.12.0/src/sea.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/sea.h 2014-01-08 14:13:24.000000000 +0100
@@ -10,7 +10,9 @@
#ifndef Sea_H
#define Sea_H
+#include <QList>
#include <QObject>
+
#include "ship.h"
#include "hitinfo.h"
@@ -37,6 +39,8 @@
Coord m_size;
Player m_turn;
BattleField* m_fields[2];
+ QList m_enemyShips;
+ QList m_myShips;
Status m_status;
bool m_allow_adjacent_ships;
@@ -50,7 +54,7 @@
bool canAddShip(Player p, const Coord& pos, int size, Ship::Direction direction) const;
void add(Player p, int n);
- void add(Player p, const Coord& pos, Ship* ship);
+ void add(Player p, Ship* ship);
void addBorder(Player p, const Coord& pos);
bool canHit(Player p, const Coord& pos) const;
HitInfo hit(const Coord& pos);
@@ -62,6 +66,9 @@
void switchTurn();
bool isNearShip(Sea::Player, const Coord& pos) const;
void allowAdjacentShips(const bool allow_adjacent_ships);
+
+ const QList enemyShips() const;
+ const QList myShips() const;
inline Status status() const { return m_status; }
inline Player turn() const { return m_turn; }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/seaview.cpp new/knavalbattle-4.12.1/src/seaview.cpp
--- old/knavalbattle-4.12.0/src/seaview.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/seaview.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -179,9 +179,9 @@
updatePreview(m_last_preview);
}
-void SeaView::add(Sea::Player p, const Coord& c, Ship* ship)
+void SeaView::add(Sea::Player p, Ship* ship)
{
- m_fields[p]->add(c, ship);
+ m_fields[p]->add(ship);
}
void SeaView::hit(Sea::Player p, const Coord& c)
@@ -194,9 +194,9 @@
m_fields[p]->miss(c);
}
-void SeaView::sink(Sea::Player p, const Coord& c, Ship* ship)
+void SeaView::sink(Sea::Player p, Ship* ship)
{
- m_fields[p]->sink(c, ship);
+ m_fields[p]->sink(ship);
}
void SeaView::clear()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/seaview.h new/knavalbattle-4.12.1/src/seaview.h
--- old/knavalbattle-4.12.0/src/seaview.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/seaview.h 2014-01-08 14:13:24.000000000 +0100
@@ -52,10 +52,10 @@
void setDelegate(Delegate* c);
void cancelPreview();
- void add(Sea::Player p, const Coord& c, Ship* ship);
+ void add(Sea::Player p, Ship* ship);
void hit(Sea::Player p, const Coord& c);
void miss(Sea::Player p, const Coord& c);
- void sink(Sea::Player p, const Coord& c, Ship* ship);
+ void sink(Sea::Player p, Ship* ship);
void clear();
void setStats(Sea::Player p, const QString& icon,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/ship.cpp new/knavalbattle-4.12.1/src/ship.cpp
--- old/knavalbattle-4.12.0/src/ship.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/ship.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -10,13 +10,24 @@
#include "ship.h"
#include
-Ship::Ship(unsigned int size, Direction direction)
+Ship::Ship(unsigned int size, Direction direction, Coord position)
: m_size(size)
+, m_position(position)
, m_direction(direction)
{
m_life = size;
}
+const Coord Ship::position() const
+{
+ return m_position;
+}
+
+void Ship::setPosition(const Coord & position)
+{
+ m_position = position;
+}
+
void Ship::changeDirection()
{
m_direction = m_direction == TOP_DOWN ? LEFT_TO_RIGHT : TOP_DOWN;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/ship.h new/knavalbattle-4.12.1/src/ship.h
--- old/knavalbattle-4.12.0/src/ship.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/ship.h 2014-01-08 14:13:24.000000000 +0100
@@ -23,23 +23,30 @@
};
private:
unsigned int m_size;
+ Coord m_position;
Direction m_direction;
int m_life;
public:
- Ship(unsigned int size, Direction direction);
+ Ship(unsigned int size, Direction direction, Coord position);
+ void decLife();
+ void setPosition(const Coord & position);
void changeDirection();
+
+ const Coord position() const;
Coord increment() const;
Coord decrement() const;
Coord incrementPerpendicular() const;
Coord decrementPerpendicular() const;
+
static Coord increment(Direction);
static Coord decrement(Direction);
static Coord incrementPerpendicular(Direction);
static Coord decrementPerpendicular(Direction);
+
inline unsigned int size() const { return m_size; }
inline Direction direction() const { return m_direction; }
- void decLife();
+
bool alive() const;
};
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/simplemenu.cpp new/knavalbattle-4.12.1/src/simplemenu.cpp
--- old/knavalbattle-4.12.0/src/simplemenu.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/simplemenu.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -110,7 +110,7 @@
case DONE_LOCAL_GAME: {
m_player1 = controller->createPlayer(Sea::Player(0), sea, chat, m_nickname);
sea->setStats(Sea::Player(0), "score_mouse", m_nickname, m_player1->stats());
- m_player2 = controller->createAI(Sea::Player(1));
+ m_player2 = controller->createAI(Sea::Player(1), sea);
sea->setStats(Sea::Player(1), "score_ai",
"Computer", m_player2->stats());
chat->hide();
@@ -121,7 +121,7 @@
m_player1 = controller->createPlayer(Sea::Player(0), sea, chat, m_nickname);
sea->setStats(Sea::Player(0), "score_mouse",
m_nickname, m_player1->stats());
- m_player2 = controller->createRemotePlayer(Sea::Player(1), m_protocol, false);
+ m_player2 = controller->createRemotePlayer(Sea::Player(1), sea, m_protocol, false);
if (old_opponent) {
m_player1->setCompatibilityLevel(old_opponent->compatibilityLevel());
m_player2->setCompatibilityLevel(old_opponent->compatibilityLevel());
@@ -138,7 +138,7 @@
m_player1 = controller->createPlayer(Sea::Player(0), sea, chat, m_nickname);
sea->setStats(Sea::Player(0), "score_mouse",
m_nickname, m_player1->stats());
- m_player2 = controller->createRemotePlayer(Sea::Player(1), m_protocol, true);
+ m_player2 = controller->createRemotePlayer(Sea::Player(1), sea, m_protocol, true);
if (old_opponent) {
m_player1->setCompatibilityLevel(old_opponent->compatibilityLevel());
m_player2->setCompatibilityLevel(old_opponent->compatibilityLevel());
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/uientity.cpp new/knavalbattle-4.12.1/src/uientity.cpp
--- old/knavalbattle-4.12.0/src/uientity.cpp 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/uientity.cpp 2014-01-08 14:13:24.000000000 +0100
@@ -10,19 +10,20 @@
#include "uientity.h"
#include "seaview.h"
#include "shot.h"
+#include "ship.h"
#include <KIcon>
+#include <QList>
UIEntity::UIEntity(Sea::Player player, Sea* sea, SeaView* view)
-: Entity(player)
+: Entity(player, view)
, m_sea(sea)
-, m_view(view)
{
}
UIEntity::~UIEntity()
{
- m_view->setDelegate(0);
+ m_seaview->setDelegate(0);
}
void UIEntity::notify(Sea::Player player, const Coord& c, const HitInfo& info)
@@ -30,9 +31,14 @@
drawShoot(Sea::opponent(player), c, info);
}
+void UIEntity::notifyGameOver(Sea::Player winner)
+{
+ drawHiddenShips(winner);
+}
+
void UIEntity::start(bool)
{
- m_view->clear();
+ m_seaview->clear();
}
void UIEntity::hit(Shot* shot)
@@ -40,15 +46,26 @@
shot->execute(HitInfo::INVALID);
}
+void UIEntity::drawHiddenShips(Sea::Player winner)
+{
+ QList enemyShips = m_sea->enemyShips();
+
+ foreach (Ship * ship, enemyShips) {
+ if (ship->alive()) {
+ m_seaview->add(winner, ship);
+ }
+ }
+}
+
void UIEntity::drawShoot(Sea::Player player, const Coord& c, const HitInfo& info)
{
switch (info.type) {
case HitInfo::HIT:
- m_view->hit(player, c);
+ m_seaview->hit(player, c);
// registerHit(player, c);
break;
case HitInfo::MISS:
- m_view->miss(player, c);
+ m_seaview->miss(player, c);
// registerMiss(player, c);
break;
default:
@@ -60,10 +77,10 @@
if (shipPos.valid()) {
// show destroyed opponent ship
if (player != m_player) {
- m_view->add(player, shipPos, info.shipDestroyed);
+ m_seaview->add(player, info.shipDestroyed);
}
-
- m_view->sink(player, shipPos, info.shipDestroyed);
+
+ m_seaview->sink(player, info.shipDestroyed);
}
}
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/knavalbattle-4.12.0/src/uientity.h new/knavalbattle-4.12.1/src/uientity.h
--- old/knavalbattle-4.12.0/src/uientity.h 2013-11-28 20:12:01.000000000 +0100
+++ new/knavalbattle-4.12.1/src/uientity.h 2014-01-08 14:13:24.000000000 +0100
@@ -19,14 +19,15 @@
Q_OBJECT
protected:
Sea* m_sea;
- SeaView* m_view;
-
+
void drawShoot(Sea::Player player, const Coord& c, const HitInfo& info);
+ void drawHiddenShips(Sea::Player winner);
public:
UIEntity(Sea::Player player, Sea*, SeaView* view);
virtual ~UIEntity();
virtual void notify(Sea::Player player, const Coord& c, const HitInfo& info);
+ virtual void notifyGameOver(Sea::Player winner);
virtual void notifyChat(const Entity*, const QString&) { }
virtual void notifyNick(Sea::Player, const QString&) { }
virtual void start(bool);
--
To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse-commit+help@opensuse.org