Bug 90720 - game doesn't end after losing
Summary: game doesn't end after losing
Status: RESOLVED FIXED
Alias: None
Product: ksame
Classification: Miscellaneous
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Henrique Pinto
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-03 20:19 UTC by Michael Petrov
Modified: 2006-11-14 00:18 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Petrov 2004-10-03 20:19:30 UTC
Version:           0.51 (using KDE 3.3.0, Arch Linux)
Compiler:          gcc version 3.4.2
OS:                Linux (i686) release 2.6.8.1

I have been playing the game, and it has been quite fun!
But this time after having two balls left (blue on top of red) in the lower left corner, I never got the high score table. Now that I actually think about it I only have a score of 850 while the high score starts at ~2000. So I guess this isn't really a bug, even though I did confuse it for one. So this might be a feature request now, to have a message saying game over or something similar. Because I got no notification after the game ended and spent the last 10 minutes making a bug report and looking through old reports. So please add some simple notification of when the game is over.


Technical info: 3 colors, board: 309333 score: 852
Comment 1 Henrique Pinto 2006-11-14 00:18:36 UTC
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