[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-bugs-dist
Subject:    [Bug 90720] game doesn't end after losing
From:       Henrique Pinto <henrique.pinto () kdemail ! net>
Date:       2006-11-13 23:18:38
Message-ID: 20061113231838.12680.qmail () ktown ! kde ! org
[Download RAW message or body]

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
         
http://bugs.kde.org/show_bug.cgi?id=90720         
henrique.pinto kdemail net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From henrique.pinto kdemail net  2006-11-14 00:18 -------
SVN commit 604721 by henrique:

 * Display a message when there are no more moves left.
   FEATURE: 90720


 M  +64 -4     board.cpp  
 M  +3 -0      board.h  


--- trunk/KDE/kdegames/ksame/board.cpp #604720:604721
 @ -2,6 +2,7  @
  *
  * Copyright (C) 1997-1998  Marcus Kreutzberger
  * Copyright (C) 2006 Henrique Pinto <henrique.pinto kdemail net>
+ * Copyright (C) 2006 Stephan Kulow <coolo kde org>
  * 
  * This file is part of the KDE project
  *
 @ -25,11 +26,10  @
 
 #include <KStandardDirs>
 #include <KRandomSequence>
+#include <KLocale>
 #include <kdebug.h>
 
 #include <QResizeEvent>
-#include <QGraphicsItem>
-#include <QtDebug>
 
 KSame::Stone::Stone( KSame::Board *board, int x, int y, QGraphicsItem *parent )
 	: QGraphicsPixmapItem( parent, board ), m_x( x ), m_y( y ), m_board( board )
 @ -79,6 +79,10  @
 	  m_score( 0 ), m_changed( false ), m_boardData( 0 )
 {
 	m_elementsSize = QSize( 64, 64 );
+	m_gameOverOverlay = new QGraphicsPixmapItem;
+	addItem( m_gameOverOverlay );
+	m_gameOverOverlay->setZValue( 20000 );
+	m_gameOverOverlay->hide();
 }
 
 void KSame::Board::drawBackground( QPainter *painter, const QRectF& )
 @ -100,6 +104,7  @
 	m_markedStones.clear();
 	initializeBoardData();
 	createItems();
+	m_gameOverOverlay->hide();
 	emit newGameStarted( m_boardNumber, m_colorCount );
 }
 
 @ -110,6 +115,11  @
 	setSceneRect( 0, 0, size.width(), size.height() );
 	m_renderer.setBackgroundSize( size );
 
+	if ( m_changed && isGameOver() )
+	{
+		generateGameOverPixmap( won() );
+	}
+
 	m_renderer.setElementSize( m_elementsSize );
 	createItems();
 }
 @ -293,14 +303,18  @
 		m_score += 1000;
 	}
 
-	emit scoreChanged( m_score );
-	emit stonesRemoved( m_markedStones.count() );
 
 	if ( isGameOver() )
 	{
+		m_undoList.clear();
+		generateGameOverPixmap( won() );
+		m_gameOverOverlay->show();
 		emit gameOver();
 	}
 
+	emit scoreChanged( m_score );
+	emit stonesRemoved( m_markedStones.count() );
+
 	m_markedStones.clear();
 	emit newCountOfMarkedStones( m_markedStones.count() );
 	m_changed = true;
 @ -361,10 +375,56  @
 	m_boardData   = lastState.m_boardData;
 
 	createItems();
+	m_gameOverOverlay->hide();
 	m_markedStones.clear();
 	emit newCountOfMarkedStones( m_markedStones.count() );
 	emit scoreChanged( lastState.m_score );
 	return true;
 }
 
+void KSame::Board::generateGameOverPixmap( bool won )
+{
+	kDebug() << k_funcinfo << endl;
+
+	int itemWidth  = qRound( 0.8*sceneRect().width()  );
+	int itemHeight = qRound( 0.6*sceneRect().height() );
+
+	QPixmap px( itemWidth, itemHeight );
+	kDebug() << "Pixmap Size:" << px.size() << endl;
+	px.fill( QColor( 0, 0, 0, 0 ) );
+
+	QPainter p( &px );
+	p.setPen( QColor( 0, 0, 0, 0 ) );
+	p.setBrush( QBrush( QColor( 188, 202, 222, 155 ) ) );
+	p.setRenderHint( QPainter::Antialiasing );
+	p.drawRoundRect( 0, 0, itemWidth, itemHeight, 25 );
+
+	QString text;
+	if ( won )
+		text = i18n( "You won.\nYou even removed the last stone, great job!\n Your score \
was %1.", m_score ); +	else
+		text = i18n( "Game over.\nThere are no more removable stones.\n Your score was \
%1.", m_score ); +
+	QFont font;
+	font.setPointSize( 28 );
+	p.setFont( font );
+	int textWidth = p.boundingRect( p.viewport(), Qt::AlignCenter|Qt::AlignVCenter, \
text ).width(); +	int fontSize = 28;
+	while ( ( textWidth > itemWidth * 0.95 ) && ( fontSize > 12 ) )
+	{
+		fontSize--;
+		font.setPointSize( fontSize );
+		p.setFont( font );
+		textWidth = p.boundingRect( p.viewport(), Qt::AlignCenter|Qt::AlignVCenter, text \
).width(); +	}
+
+	p.setPen( QColor( 0, 0, 0, 255 ) );
+	p.drawText( p.viewport(), Qt::AlignCenter|Qt::AlignVCenter, text );
+	p.end();
+
+	m_gameOverOverlay->setPixmap( px );
+	m_gameOverOverlay->setPos( ( sceneRect().width() - itemWidth )/2, ( \
sceneRect().height() - itemHeight )/2 ); +
+}
+
 #include "board.moc"
--- trunk/KDE/kdegames/ksame/board.h #604720:604721
 @ -34,6 +34,7  @
 #include <QStack>
 #include <QPair>
 
+
 namespace KSame
 {
 	class Board;
 @ -117,6 +118,7  @
 		private:
 			void initializeBoardData();
 			void createItems();
+			void generateGameOverPixmap( bool won );
 			void markHelper( int x, int y, quint8 color );
 			int  map( int x, int y ) const;
 			bool validPosition( int x, int y ) const;
 @ -136,6 +138,7  @
 			QList<KSame::Coordinate> m_markedStones;
 			QStack<KSame::GameState> m_undoList;
 
+			QGraphicsPixmapItem *m_gameOverOverlay;
 	};
 
 } // namespace KSame


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic