Browse files

Added the first version of the GUI, fixed a bug in the randomize() fu…

…nction of CardList and serveral API improvements.
  • Loading branch information...
1 parent bd1eb14 commit 049175fefa9d762647f3e5c466f752d4b7acc4fa domseichter committed Mar 1, 2004
Showing with 464 additions and 41 deletions.
  1. +2 −2 src/Makefile.am
  2. +89 −19 src/Makefile.in
  3. +65 −0 src/canvascard.cpp
  4. +47 −0 src/canvascard.h
  5. +2 −2 src/card.cpp
  6. +6 −4 src/cardlist.cpp
  7. +7 −1 src/game.cpp
  8. +2 −1 src/game.h
  9. +163 −0 src/gamecanvas.cpp
  10. +56 −0 src/gamecanvas.h
  11. +1 −1 src/player.cpp
  12. +1 −1 src/player.h
  13. +12 −6 src/schafkopf.cpp
  14. +11 −4 src/schafkopf.h
View
4 src/Makefile.am
@@ -2,7 +2,7 @@
INCLUDES = $(all_includes)
# these are the headers for your project
-noinst_HEADERS = schafkopf.h card.h cardlist.h player.h game.h settings.h computerplayer.h humanplayer.h
+noinst_HEADERS = schafkopf.h card.h cardlist.h player.h game.h settings.h computerplayer.h humanplayer.h gamecanvas.h canvascard.h
# let automoc handle all of the meta source files (moc)
METASOURCES = AUTO
@@ -20,7 +20,7 @@ KDE_ICON = schafkopf
bin_PROGRAMS = schafkopf
# the application source, library search path, and link libraries
-schafkopf_SOURCES = main.cpp schafkopf.cpp card.cpp cardlist.cpp player.cpp game.cpp settings.cpp computerplayer.cpp humanplayer.cpp
+schafkopf_SOURCES = main.cpp schafkopf.cpp card.cpp cardlist.cpp player.cpp game.cpp settings.cpp computerplayer.cpp humanplayer.cpp gamecanvas.cpp canvascard.cpp
schafkopf_LDFLAGS = $(KDE_RPATH) $(all_libraries)
schafkopf_LDADD = -lkdegames $(LIB_KDEUI)
View
108 src/Makefile.in
@@ -1,5 +1,5 @@
# Makefile.in generated by automake 1.7.2 from Makefile.am.
-# KDE tags expanded automatically by am_edit - $Revision: 1.1 $
+# KDE tags expanded automatically by am_edit - $Revision: 1.2 $
# @configure_input@
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
@@ -247,7 +247,7 @@ xdg_directorydir = @xdg_directorydir@
INCLUDES = $(all_includes)
# these are the headers for your project
-noinst_HEADERS = schafkopf.h card.h cardlist.h
+noinst_HEADERS = schafkopf.h card.h cardlist.h player.h game.h settings.h computerplayer.h humanplayer.h gamecanvas.h canvascard.h
# let automoc handle all of the meta source files (moc)
#>- METASOURCES = AUTO
@@ -262,7 +262,7 @@ KDE_ICON = schafkopf
bin_PROGRAMS = schafkopf
# the application source, library search path, and link libraries
-schafkopf_SOURCES = main.cpp schafkopf.cpp card.cpp cardlist.cpp
+schafkopf_SOURCES = main.cpp schafkopf.cpp card.cpp cardlist.cpp player.cpp game.cpp settings.cpp computerplayer.cpp humanplayer.cpp gamecanvas.cpp canvascard.cpp
schafkopf_LDFLAGS = $(KDE_RPATH) $(all_libraries)
schafkopf_LDADD = -lkdegames $(LIB_KDEUI)
@@ -280,26 +280,46 @@ bin_PROGRAMS = schafkopf$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS)
am_schafkopf_OBJECTS = main.$(OBJEXT) schafkopf.$(OBJEXT) card.$(OBJEXT) \
- cardlist.$(OBJEXT)
+ cardlist.$(OBJEXT) player.$(OBJEXT) game.$(OBJEXT) \
+ settings.$(OBJEXT) computerplayer.$(OBJEXT) \
+ humanplayer.$(OBJEXT) gamecanvas.$(OBJEXT) canvascard.$(OBJEXT)
#>- schafkopf_OBJECTS = $(am_schafkopf_OBJECTS)
-#>+ 5
+#>+ 8
schafkopf_final_OBJECTS = schafkopf.all_cpp.o
schafkopf_nofinal_OBJECTS = main.$(OBJEXT) schafkopf.$(OBJEXT) card.$(OBJEXT) \
- cardlist.$(OBJEXT)
+ cardlist.$(OBJEXT) player.$(OBJEXT) game.$(OBJEXT) \
+ settings.$(OBJEXT) computerplayer.$(OBJEXT) \
+ humanplayer.$(OBJEXT) gamecanvas.$(OBJEXT) canvascard.$(OBJEXT)\
+card.moc.o
@KDE_USE_FINAL_FALSE@schafkopf_OBJECTS = $(schafkopf_nofinal_OBJECTS)
@KDE_USE_FINAL_TRUE@schafkopf_OBJECTS = $(schafkopf_final_OBJECTS)
schafkopf_DEPENDENCIES =
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/admin/depcomp
am__depfiles_maybe = depfiles
-#>- @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/card.Po ./$(DEPDIR)/cardlist.Po \
-#>- @AMDEP_TRUE@ ./$(DEPDIR)/main.Po ./$(DEPDIR)/schafkopf.Po
-#>+ 4
-@AMDEP_TRUE@@KDE_USE_FINAL_TRUE@DEP_FILES = $(DEPDIR)/schafkopf.all_cpp.P ./$(DEPDIR)/card.Po ./$(DEPDIR)/cardlist.Po \
-@AMDEP_TRUE@@KDE_USE_FINAL_TRUE@ @AMDEP_TRUE@ ./$(DEPDIR)/main.Po ./$(DEPDIR)/schafkopf.Po
-@AMDEP_TRUE@@KDE_USE_FINAL_FALSE@DEP_FILES = ./$(DEPDIR)/card.Po ./$(DEPDIR)/cardlist.Po \
-@AMDEP_TRUE@@KDE_USE_FINAL_FALSE@ @AMDEP_TRUE@ ./$(DEPDIR)/main.Po ./$(DEPDIR)/schafkopf.Po
+#>- @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/canvascard.Po ./$(DEPDIR)/card.Po \
+#>- @AMDEP_TRUE@ ./$(DEPDIR)/cardlist.Po \
+#>- @AMDEP_TRUE@ ./$(DEPDIR)/computerplayer.Po ./$(DEPDIR)/game.Po \
+#>- @AMDEP_TRUE@ ./$(DEPDIR)/gamecanvas.Po \
+#>- @AMDEP_TRUE@ ./$(DEPDIR)/humanplayer.Po ./$(DEPDIR)/main.Po \
+#>- @AMDEP_TRUE@ ./$(DEPDIR)/player.Po ./$(DEPDIR)/schafkopf.Po \
+#>- @AMDEP_TRUE@ ./$(DEPDIR)/settings.Po
+#>+ 14
+@AMDEP_TRUE@@KDE_USE_FINAL_TRUE@DEP_FILES = $(DEPDIR)/card.moc.P $(DEPDIR)/schafkopf.all_cpp.P ./$(DEPDIR)/canvascard.Po ./$(DEPDIR)/card.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_TRUE@ @AMDEP_TRUE@ ./$(DEPDIR)/cardlist.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_TRUE@ @AMDEP_TRUE@ ./$(DEPDIR)/computerplayer.Po ./$(DEPDIR)/game.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_TRUE@ @AMDEP_TRUE@ ./$(DEPDIR)/gamecanvas.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_TRUE@ @AMDEP_TRUE@ ./$(DEPDIR)/humanplayer.Po ./$(DEPDIR)/main.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_TRUE@ @AMDEP_TRUE@ ./$(DEPDIR)/player.Po ./$(DEPDIR)/schafkopf.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_TRUE@ @AMDEP_TRUE@ ./$(DEPDIR)/settings.Po
+@AMDEP_TRUE@@KDE_USE_FINAL_FALSE@DEP_FILES = $(DEPDIR)/card.moc.P ./$(DEPDIR)/canvascard.Po ./$(DEPDIR)/card.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_FALSE@ @AMDEP_TRUE@ ./$(DEPDIR)/cardlist.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_FALSE@ @AMDEP_TRUE@ ./$(DEPDIR)/computerplayer.Po ./$(DEPDIR)/game.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_FALSE@ @AMDEP_TRUE@ ./$(DEPDIR)/gamecanvas.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_FALSE@ @AMDEP_TRUE@ ./$(DEPDIR)/humanplayer.Po ./$(DEPDIR)/main.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_FALSE@ @AMDEP_TRUE@ ./$(DEPDIR)/player.Po ./$(DEPDIR)/schafkopf.Po \
+@AMDEP_TRUE@@KDE_USE_FINAL_FALSE@ @AMDEP_TRUE@ ./$(DEPDIR)/settings.Po
#>- CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
#>- $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
#>+ 2
@@ -380,10 +400,17 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/canvascard.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/card.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cardlist.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/computerplayer.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/game.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gamecanvas.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/humanplayer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/player.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/schafkopf.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/settings.Po@am__quote@
distclean-depend:
-rm -rf ./$(DEPDIR)
@@ -644,18 +671,53 @@ messages: rc.cpp
.NOEXPORT:
#>+ 3
+card.moc.cpp: $(srcdir)/card.h
+ $(MOC) $(srcdir)/card.h -o card.moc.cpp
+
+#>+ 2
+mocs: card.moc.cpp
+
+#>+ 3
schafkopf.moc: $(srcdir)/schafkopf.h
$(MOC) $(srcdir)/schafkopf.h -o schafkopf.moc
#>+ 2
mocs: schafkopf.moc
#>+ 3
+game.moc: $(srcdir)/game.h
+ $(MOC) $(srcdir)/game.h -o game.moc
+
+#>+ 2
+mocs: game.moc
+
+#>+ 3
+canvascard.moc: $(srcdir)/canvascard.h
+ $(MOC) $(srcdir)/canvascard.h -o canvascard.moc
+
+#>+ 2
+mocs: canvascard.moc
+
+#>+ 3
+settings.moc: $(srcdir)/settings.h
+ $(MOC) $(srcdir)/settings.h -o settings.moc
+
+#>+ 2
+mocs: settings.moc
+
+#>+ 3
+gamecanvas.moc: $(srcdir)/gamecanvas.h
+ $(MOC) $(srcdir)/gamecanvas.h -o gamecanvas.moc
+
+#>+ 2
+mocs: gamecanvas.moc
+
+#>+ 3
clean-metasources:
- -rm -f schafkopf.moc
+ -rm -f card.moc.cpp schafkopf.moc game.moc canvascard.moc settings.moc gamecanvas.moc
#>+ 2
-KDE_DIST=schafkopf.desktop schafkopf.lsm hi16-app-schafkopf.png cardlist_interface.h hi64-app-schafkopf.png hi32-app-schafkopf.png
+KDE_DIST=schafkopf.desktop schafkopf.lsm hi16-app-schafkopf.png hi64-app-schafkopf.png hi32-app-schafkopf.png schafkopf
#>+ 2
docs-am:
@@ -704,11 +766,11 @@ bcheck-am:
#>+ 11
-schafkopf.all_cpp.cpp: $(srcdir)/Makefile.in $(srcdir)/main.cpp $(srcdir)/schafkopf.cpp $(srcdir)/card.cpp $(srcdir)/cardlist.cpp schafkopf.moc
+schafkopf.all_cpp.cpp: $(srcdir)/Makefile.in $(srcdir)/main.cpp $(srcdir)/schafkopf.cpp $(srcdir)/card.cpp $(srcdir)/cardlist.cpp $(srcdir)/player.cpp $(srcdir)/game.cpp $(srcdir)/settings.cpp $(srcdir)/computerplayer.cpp $(srcdir)/humanplayer.cpp $(srcdir)/gamecanvas.cpp $(srcdir)/canvascard.cpp $(srcdir)/card.moc.cpp game.moc schafkopf.moc canvascard.moc gamecanvas.moc settings.moc
@echo 'creating schafkopf.all_cpp.cpp ...'; \
rm -f schafkopf.all_cpp.files schafkopf.all_cpp.final; \
echo "#define KDE_USE_FINAL 1" >> schafkopf.all_cpp.final; \
- for file in main.cpp schafkopf.cpp card.cpp cardlist.cpp ; do \
+ for file in main.cpp schafkopf.cpp card.cpp cardlist.cpp player.cpp game.cpp settings.cpp computerplayer.cpp humanplayer.cpp gamecanvas.cpp canvascard.cpp card.moc.cpp ; do \
echo "#include \"$$file\"" >> schafkopf.all_cpp.files; \
test ! -f $(srcdir)/$$file || egrep '^#pragma +implementation' $(srcdir)/$$file >> schafkopf.all_cpp.final; \
done; \
@@ -743,8 +805,16 @@ cvs-clean:
kde-rpo-clean:
-rm -f *.rpo
-#>+ 5
+#>+ 13
+schafkopf.lo: schafkopf.moc
+canvascard.o: canvascard.moc
+settings.o: settings.moc
nmcheck:
+game.lo: game.moc
schafkopf.o: schafkopf.moc
+canvascard.lo: canvascard.moc
+gamecanvas.o: gamecanvas.moc
nmcheck-am: nmcheck
-schafkopf.lo: schafkopf.moc
+gamecanvas.lo: gamecanvas.moc
+settings.lo: settings.moc
+game.o: game.moc
View
65 src/canvascard.cpp
@@ -0,0 +1,65 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Dominik Seichter *
+ * domseichter@web.de *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include "canvascard.h"
+#include "card.h"
+
+#include <qpixmap.h>
+#include <qwmatrix.h>
+
+CanvasCard::CanvasCard(Card* card,QCanvas*c)
+ : QCanvasRectangle(c), m_rotation(0)
+{
+ m_card = card;
+ show();
+}
+
+
+CanvasCard::~CanvasCard()
+{
+}
+
+void CanvasCard::draw( QPainter & p )
+{
+ QPixmap* pixmap = m_visible ? m_card->pixmap() : Card::backgroundPixmap();
+
+ setSize( pixmap->width(), pixmap->height() );
+
+ // this code handles already matrix transformations
+ QWMatrix wm = p.worldMatrix();
+ QPoint point( (int)x(), (int)y() );
+ point = wm * point;
+
+ wm.rotate( (double)m_rotation );
+
+ QPixmap pix = pixmap->xForm( wm );
+ bitBlt( p.device(), point.x(), point.y(), &pix );
+}
+
+void CanvasCard::setFrontVisible( bool b )
+{
+ m_visible = b;
+}
+
+void CanvasCard::setRotation( int d )
+{
+ m_rotation = d;
+}
+
+#include "canvascard.moc"
View
47 src/canvascard.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Dominik Seichter *
+ * domseichter@web.de *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef CANVASCARD_H
+#define CANVASCARD_H
+
+#include <qcanvas.h>
+#include <qpainter.h>
+
+class Card;
+
+class CanvasCard : public QCanvasRectangle
+{
+ public:
+ CanvasCard(Card* card,QCanvas*c);
+ ~CanvasCard();
+
+ Card* card() const { return m_card; }
+
+ void setFrontVisible( bool b );
+ void setRotation( int d );
+
+ private:
+ void draw( QPainter & p );
+
+ bool m_visible;
+ int m_rotation;
+ Card* m_card;
+};
+
+#endif
View
4 src/card.cpp
@@ -34,7 +34,6 @@ Card::Card( const enum type t, const enum color c )
m_pixmap = 0;
m_card = t;
m_color = c;
-
switch( m_card ) {
case ASS:
m_points = 11; break;
@@ -76,7 +75,7 @@ QPixmap* Card::pixmap()
QPixmap* Card::backgroundPixmap()
{
if( !m_background ) {
- QString deck = Settings::instance()->cardDeck();
+ QString deck = Settings::instance()->cardBackground();
m_background = new QPixmap( deck );
}
@@ -86,6 +85,7 @@ QPixmap* Card::backgroundPixmap()
void Card::cardChanged()
{
delete m_pixmap;
+ m_pixmap = NULL;
if( m_background ) {
delete m_background;
m_background = NULL;
View
10 src/cardlist.cpp
@@ -28,8 +28,8 @@ CardList::CardList()
void CardList::init()
{
- clear();
setAutoDelete( true );
+ clear();
for( int i = 0; i < CARD_CNT ; i += 4 )
for( int z = Card::EICHEL; z <= Card::SCHELLEN; z++ )
@@ -53,7 +53,7 @@ void CardList::randomize()
init();
for(i=0;i<CARD_CNT;i++)
{
- rval=KApplication::random()%32;
+ rval=KApplication::random()%CARD_CNT;
for(a=0;a<i;a++)
{
if(rnd[a]==rval)
@@ -66,7 +66,9 @@ void CardList::randomize()
}
for(i=0;i<CARD_CNT;i++)
append(at(rnd[i]));
- for(i=0;i<CARD_CNT;i++)
- remove(first()); // we always remove the first item
+ while(count() > CARD_CNT )
+ (void)take(0); // we always remove the first item
+ // Do not use remove(), as autoDeletion is
+ // enabled!!!
}
View
8 src/game.cpp
@@ -104,11 +104,17 @@ const Game::game_info *Game::gameInfo() const
return &m_gameinfo;
}
-Player* Game::findId( unsigned int id )
+Player* Game::findId( unsigned int id ) const
{
for( unsigned int i = 0; i < PLAYERS; i++)
if( id == m_players[i]->id() )
return m_players[i];
+ return 0;
+}
+
+Player* Game::findIndex( unsigned int index ) const
+{
+ return ( index < PLAYERS ? m_players[index] : 0 );
}
bool Game::istTrumpf(Card *card)
View
3 src/game.h
@@ -49,7 +49,8 @@ class Game : public QObject
const CardList *currStich() const;
const Game::game_info *gameInfo() const;
- Player* findId( unsigned int id );
+ Player* findId( unsigned int id ) const;
+ Player* findIndex( unsigned int index ) const;
bool istTrumpf(Card *card);
View
163 src/gamecanvas.cpp
@@ -0,0 +1,163 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Dominik Seichter *
+ * domseichter@web.de *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include "gamecanvas.h"
+
+#include "card.h"
+#include "canvascard.h"
+#include "player.h"
+#include "settings.h"
+
+/** Uncomment this line to make all cards
+ * user visible, this is useful for debuggin
+ * and improving the AI.
+ * But it might cause problems in network mode for cheaters!!
+ */
+#define CHEAT
+
+#ifdef CHEAT
+ #warning "CHEATING ENABLED!!!"
+#endif
+
+#define NUMCARDS 8
+// DISTANCE from the border
+#define DIST 20
+
+GameCanvas::GameCanvas(QCanvas* c, QWidget *parent, const char *name)
+ : QCanvasView(c,parent, name)
+{
+ m_game = NULL;
+
+ canvas()->setBackgroundColor( Qt::darkGreen );
+ update();
+
+ connect( this, SLOT(redrawAll()), Settings::instance(), SLOT(cardChanged()));
+}
+
+
+GameCanvas::~GameCanvas()
+{
+ // TODO: delete m_items, crashes for some reeson MEMORY LEAK!!!
+ // for( unsigned int i = 0; i < PLAYERS; i++ )
+ // delete m_items[i];
+}
+
+void GameCanvas::setGame( Game* game )
+{
+ // no need to delete m_game, because it is a QObject
+ m_game = game;
+ createCards();
+}
+
+void GameCanvas::createCards()
+{
+ for( unsigned int i = 0; i < PLAYERS; i++ )
+ m_items[i] = new QCanvasItemList();
+
+ for( unsigned int i = 0; i < PLAYERS; i++ ) {
+ Player* player = m_game->findIndex( i );
+ for( unsigned int z = 0; z < player->cards()->count(); z++ ) {
+ CanvasCard *c = new CanvasCard( player->cards()->at(z), canvas() );
+
+ if(i==1)
+ c->setRotation(90);
+ else if(i==3)
+ c->setRotation(270);
+#ifdef CHEAT
+ c->setFrontVisible( true );
+#else
+ c->setFrontVisible( player->rtti() == Player::HUMAN );
+#endif
+ m_items[i]->append( c );
+
+ }
+ }
+
+ lineupCards();
+}
+
+void GameCanvas::lineupCards()
+{
+ int w = canvas()->width()-DIST;
+ int h = canvas()->height()-DIST;
+ int cardw = Card::backgroundPixmap()->width();
+ int cardh = Card::backgroundPixmap()->height();
+
+ for( unsigned int i = 0; i < PLAYERS; i++ ) {
+ int x = 0, y = 0;
+ QCanvasItemList* list = m_items[i];
+
+ if(i==1||i==3)
+ qSwap( cardw, cardh );
+
+ switch( i ) {
+ case 0:
+ x=(w-cardw*NUMCARDS)/2;
+ y=h-cardh;
+ break;
+ case 1:
+ x=w-cardw;
+ y=(h-((cardh/2)*(NUMCARDS-1)+cardh))/2;
+ break;
+ case 2:
+ x=(w-((cardw/2)*(NUMCARDS-1)+cardw))/2;
+ y=DIST;
+ break;
+ case 3:
+ default:
+ x=DIST;
+ y=(h-((cardh/2)*(NUMCARDS-1)+cardh))/2;
+ break;
+ }
+
+ for( unsigned int z = 0; z < list->count(); z++ ) {
+ CanvasCard* card = static_cast<CanvasCard*>((*list)[z]);
+ card->move( x, y );
+ if(i==0)
+ x += cardw;
+ else if(i==2)
+ x += (cardw/2);
+ else
+ y += (cardh/2);
+ }
+
+ // swap them back
+ if(i==1||i==3)
+ qSwap( cardw, cardh );
+ }
+
+ canvas()->update();
+}
+
+void GameCanvas::resizeEvent( QResizeEvent * r )
+{
+// TODO: remove this constants...
+ canvas()->resize( this->width() -20, this->height()-20 );
+ QCanvasView::resizeEvent( r );
+
+ lineupCards();
+}
+
+void GameCanvas::redrawAll()
+{
+ canvas()->setAllChanged();
+ canvas()->update();
+}
+
+#include "gamecanvas.moc"
View
56 src/gamecanvas.h
@@ -0,0 +1,56 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Dominik Seichter *
+ * domseichter@web.de *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef GAMECANVAS_H
+#define GAMECANVAS_H
+
+#include <qcanvas.h>
+#include "game.h"
+
+class QCanvasItemList;
+class QResizeEvent;
+
+class GameCanvas : public QCanvasView
+{
+ Q_OBJECT
+ public:
+ GameCanvas(QCanvas* c,QWidget *parent = 0, const char *name = 0);
+ ~GameCanvas();
+
+ void setGame( Game* game );
+
+ private slots:
+ void redrawAll();
+
+ private:
+ /** Create QCanvasItem's for all Cards
+ */
+ void createCards();
+ /** Position the cards on the screen correctly
+ */
+ void lineupCards();
+
+ void resizeEvent( QResizeEvent *r );
+
+ QCanvasItemList* m_items[PLAYERS];
+
+ Game* m_game;
+};
+
+#endif
View
2 src/player.cpp
@@ -28,7 +28,7 @@ void Player::setName( const QString & n )
m_name = n;
}
-const CardList *Player::cards() const
+CardList *Player::cards() const
{
return m_cards;
}
View
2 src/player.h
@@ -20,7 +20,7 @@ class Player
const QString & name() const;
void setName( const QString & n );
- const CardList *cards() const;
+ CardList *cards() const;
void setCards( CardList *cards);
const CardList* stiche() const;
void addStich( CardList stich );
View
18 src/schafkopf.cpp
@@ -18,8 +18,12 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "schafkopf.h"
-#include "card.h"
#include "settings.h"
+#include "gamecanvas.h"
+// TODO: either move the game object into
+// GameCanvas as member variable or
+// maybe make GameCanvas a subclasse of Game
+#include "game.h"
#include <qlabel.h>
#include <qpixmap.h>
@@ -38,12 +42,14 @@ SchafKopf::SchafKopf()
: KMainWindow( 0, "SchafKopf" )
{
QVBox* w = new QVBox( this );
- QLabel* label = new QLabel( "HI", w );
-
setCentralWidget( w );
- Card c( Card::SIEBEN, Card::SCHELLEN );
- label->setPixmap( *c.pixmap() );
-
+
+ m_game = new Game();
+ m_canvas = new QCanvas( this, "canvas" );
+ m_canvasview = new GameCanvas( m_canvas, w, "canvasview" );
+ m_canvasview->setGame( m_game );
+ //m_game->gameLoop();
+
setupActions();
}
View
15 src/schafkopf.h
@@ -27,6 +27,9 @@
#include <kmainwindow.h>
+class QCanvas;
+class GameCanvas;
+class Game;
/**
* @short Application Main Window
* @author Dominik Seichter <domseichter@web.de>
@@ -38,14 +41,18 @@ class SchafKopf : public KMainWindow
public:
SchafKopf();
~SchafKopf();
-
- private:
- void setupActions();
-
+
private slots:
/** Configure the carddeck to be used
*/
void carddecks();
+
+ private:
+ void setupActions();
+
+ Game* m_game;
+ GameCanvas* m_canvasview;
+ QCanvas* m_canvas;
};
#endif // _SCHAFKOPF_H_

0 comments on commit 049175f

Please sign in to comment.