-rw-r--r-- | noncore/games/backgammon/backgammon.cpp | 16 | ||||
-rw-r--r-- | noncore/games/backgammon/moveengine.cpp | 2 | ||||
-rw-r--r-- | noncore/games/bounce/bounce.pro | 5 | ||||
-rw-r--r-- | noncore/games/bounce/game.cpp | 15 | ||||
-rw-r--r-- | noncore/games/go/go.pro | 15 | ||||
-rw-r--r-- | noncore/games/go/gowidget.cpp | 9 | ||||
-rw-r--r-- | noncore/games/kpacman/kpacman.pro | 4 | ||||
-rw-r--r-- | noncore/games/kpacman/kpacmanwidget.cpp | 5 | ||||
-rw-r--r-- | noncore/games/kpacman/status.cpp | 5 | ||||
-rw-r--r-- | noncore/games/mindbreaker/mindbreaker.cpp | 2 | ||||
-rw-r--r-- | noncore/games/oyatzee/oyatzee.cpp | 50 | ||||
-rw-r--r-- | noncore/games/oyatzee/oyatzee.pro | 2 | ||||
-rw-r--r-- | noncore/games/wordgame/wordgame.cpp | 2 |
13 files changed, 75 insertions, 57 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp index 51020a0..bdb1c78 100644 --- a/noncore/games/backgammon/backgammon.cpp +++ b/noncore/games/backgammon/backgammon.cpp @@ -1,177 +1,181 @@ #include "backgammon.h" - #include "aidialog.h" #include "filedialog.h" #include "playerdialog.h" #include "rulesdialog.h" #include "themedialog.h" +/* OPIE */ +#include <opie2/odebug.h> +#include <qpe/qpeapplication.h> +#include <qpe/config.h> +#include <qpe/resource.h> +using namespace Opie::Core; + +/* QT */ #include <qfile.h> #include <qlayout.h> #include <qmessagebox.h> #include <qtimer.h> -#include <qpe/qpeapplication.h> -#include <qpe/config.h> #include <qmenubar.h> -#include <qpe/resource.h> #include <stdlib.h> BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { if (!name) setName("BackGammon"); setCaption(tr( "Backgammon") ); setIcon( Resource::loadPixmap( "backgammon" ) ); //general counter varaible int a=0; //the game engine move=new MoveEngine(); //load the default theme Config conf("backgammon"); if(!conf.isValid()) { - qDebug("config file does not exist"); + odebug << "config file does not exist" << oendl; conf.setGroup("general"); conf.writeEntry("theme","default"); conf.setGroup("rules"); conf.writeEntry("move_with_pieces_out",false); conf.writeEntry("nice_dice",false); conf.setGroup("display"); conf.writeEntry("small",false); conf.writeEntry("warning",true); conf.setGroup("ai"); conf.writeEntry("rescue",6); conf.writeEntry("eliminate",4); conf.writeEntry("expose",1); conf.writeEntry("protect",5); conf.writeEntry("safe",3); conf.writeEntry("empty",2); } conf.setGroup("general"); theme_name=conf.readEntry("theme","default"); QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; //the rules conf.setGroup("rules"); rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false); rules.generous_dice=conf.readBoolEntry("nice_dice",false); move->setRules(rules); //get the AI settings AISettings ai; conf.setGroup("ai"); ai.rescue=conf.readNumEntry("rescue",6); ai.eliminate=conf.readNumEntry("eliminate",4); ai.expose=conf.readNumEntry("expose",1); ai.protect=conf.readNumEntry("protect",5); ai.safe=conf.readNumEntry("safe",3); ai.empty=conf.readNumEntry("empty",2); move->setAISettings(ai); //get the theme component names Config theme(theme_file,Config::File); if(!theme.isValid()) { - qDebug("theme file does not exist"); + odebug << "theme file does not exist" << oendl; theme.setGroup("theme"); theme.writeEntry("board","casino_board_1"); theme.writeEntry("pieces1","casino_pieces_blue"); theme.writeEntry("pieces2","casino_pieces_white"); theme.writeEntry("dice1","casino_dice"); theme.writeEntry("dice2","casino_dice"); theme.writeEntry("table","casino_table_green"); theme.writeEntry("odds","casino_odds"); } theme.setGroup("theme"); board_name=theme.readEntry("board","casino_board_1"); piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); diceA_name=theme.readEntry("dice1","casino_dice"); diceB_name=theme.readEntry("dice2","casino_dice"); table_name=theme.readEntry("table","casino_table_green"); odds_name=theme.readEntry("odds","casino_odds"); //the menu QMenuBar* menuBar = new QMenuBar(this); QPopupMenu* gamemenu= new QPopupMenu(this); gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); gamemenu->insertSeparator(); gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); gamemenu->insertSeparator(); gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); menuBar->insertItem(tr( "Game" ),gamemenu); QPopupMenu* thememenu= new QPopupMenu(this); thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); thememenu->insertSeparator(); thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); thememenu->insertSeparator(); thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); menuBar->insertItem(tr( "Theme" ),thememenu); QPopupMenu* optionmenu=new QPopupMenu(this); optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); optionmenu->insertSeparator(); optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); menuBar->insertItem(tr( "Options"),optionmenu); QWidget* mainarea=new QWidget(this); setCentralWidget(mainarea); //the main area QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); area=new QCanvas(235,235); boardview=new BackGammonView(area,mainarea); boardview->setMaximumHeight(240); layout->addWidget(boardview); connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); //status bar message=new QLabel("<b>Backgammon</b>",mainarea); message->setAlignment(AlignHCenter); layout->addWidget(message); //the marker marker_current=new QCanvasRectangle(area); marker_current->setBrush(QColor(0,0,255)); marker_current->setSize(15,5); marker_current->setZ(1); for(a=0;a<4;a++) { marker_next[a]=new QCanvasRectangle(area); marker_next[a]->setBrush(QColor(0,255,0)); marker_next[a]->setSize(15,5); marker_next[a]->setZ(1); } connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); connect(move,SIGNAL(nomove()),this,SLOT(nomove())); connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); //the pieces p1=new CanvasImageItem*[15]; p1_side=new CanvasImageItem*[15]; QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); QImage piece_1_front=piece_1_all.copy(0,0,15,15); QImage piece_1_side=piece_1_all.copy(0,15,15,5); p2=new CanvasImageItem*[15]; p2_side=new CanvasImageItem*[15]; QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); QImage piece_2_front=piece_2_all.copy(0,0,15,15); QImage piece_2_side=piece_2_all.copy(0,15,15,5); diff --git a/noncore/games/backgammon/moveengine.cpp b/noncore/games/backgammon/moveengine.cpp index 7de7147..a4145cc 100644 --- a/noncore/games/backgammon/moveengine.cpp +++ b/noncore/games/backgammon/moveengine.cpp @@ -364,193 +364,193 @@ void MoveEngine::setRules(Rules rules) int MoveEngine::getPossibleMoves() { int homezone[]={0,25,0}; int lastToHomeZone=abs(last_piece[player]-homezone[player]); for(int field=0;field<26;field++) { for(int b=0;b<4;b++) { int dice_tmp=dice[b]; if(dice[b]!=7 && dice[b]> lastToHomeZone) dice_tmp=lastToHomeZone; int nextfield=(player==1) ? field+dice_tmp : field-dice_tmp; if(nice_dice) { if(player==1 && nextfield>homezone[1]) nextfield=homezone[1]; else if(player==2 && nextfield<homezone[2]) nextfield=homezone[2]; } moves[field].weight[b]=0; moves[field].to[b]=nextfield; int out_of_board[]={-1,0,25}; if(!move_with_pieces_out && field!=out_of_board[player] && pieces_out[player]) { continue; } if(dice[b]!=7 && fieldColor(field)==player ) //player can only move his own pieces { if((player==1 && nextfield > homezone[1]) || (player==2 && nextfield < homezone[2])) { moves[field].weight[b]=0; //movement would be far out of board } else if(nextfield==homezone[player] && !allclear[player]) { moves[field].weight[b]=0; //can not rescue pieces until all are in the endzone } else if(nextfield==homezone[player] && allclear[player]) { moves[field].weight[b]=ai.rescue; //rescue your pieces : nuff said ;-) } else if(fieldColor(nextfield)==otherplayer) { if(abs(population[nextfield].total)>1) //can not move to this field moves[field].weight[b]=0; else if(abs(population[nextfield].total)==1) //eliminate opponent : very nice moves[field].weight[b]=ai.eliminate; } else if(fieldColor(nextfield)==player) //nextfield already occupied by player { if(abs(population[field].total)==2) //expose own piece : not diserable moves[field].weight[b]=ai.expose; else if(abs(population[nextfield].total)>1) //own pices already there : safe moves[field].weight[b]=ai.safe; else if(abs(population[nextfield].total)==1) //protect own piece : most importatnt moves[field].weight[b]=ai.protect; } else if(population[nextfield].total==0) //nextfield empty { if(abs(population[field].total)==2) //expose own piece : not diserable moves[field].weight[b]=ai.expose; else moves[field].weight[b]=ai.empty; } else moves[field].weight[b]=0; //default. } else moves[field].weight[b]=0; //dice already used or field not used by player } } int total=0; for(int field=0;field<26;field++) { total+=moves[field].weight[0]+moves[field].weight[1]+moves[field].weight[2]+moves[field].weight[3]; } return total; } void MoveEngine::move(const int& from, int to, const int& dice) { - //qDebug("%d moves from %d to %d (%d) with dice %d",player,from,to,to-from,dice); + //odebug << "" << player << " moves from " << from << " to " << to << " (" << to-from << ") with dice " << dice << "" << oendl; if(player==1 && to==25) to=26; if(player==2 && to==0) to=27; //if space is occupied by enemy move pieces to startzone if(fieldColor(to)==otherplayer) { population[to].total=0; if(otherplayer==1) population[0].total++; else population[25].total--; } if(player==1) { population[from].total--; population[to].total++; } else //player=2 { population[from].total++; population[to].total--; } if(dice==1) emit done_dice1(); else if(dice==2) emit done_dice2(); else if(dice==3) emit done_dice3(); else emit done_dice4(); if(abs(population[26].total)==15) emit player_finished(1); if(abs(population[27].total)==15) emit player_finished(2); } void MoveEngine::checkstate() { //check if pieces are out pieces_out[1]=(population[0].total>0) ? true : false; pieces_out[2]=(population[25].total<0) ? true : false; //check if all pieces are in the endzones allclear[1]=true; allclear[2]=true; last_piece[1]=25; bool found_last_piece1=false; last_piece[2]=0; for(int a=0;a<26;a++) { if(a<19 && population[a].total>0) allclear[1]=false; if(a>6 && population[a].total<0) allclear[2]=false; if(population[a].total>0 && !found_last_piece1) { last_piece[1]=a; found_last_piece1=true; } if(population[a].total<0) last_piece[2]=a; } } void MoveEngine::nomarker(Marker& marker) { marker.visible_current=false; marker_current=-1; for(int a=0;a<4;a++) { marker.x_next[a]=0; marker.y_next[a]=0; marker_next[a]=-1; marker.visible_next[a]=false; } } int MoveEngine::fieldColor(const int& index) const { if(population[index].total>0) return 1; else if(population[index].total<0) return 2; else return 0; } diff --git a/noncore/games/bounce/bounce.pro b/noncore/games/bounce/bounce.pro index ba745c8..56a325c 100644 --- a/noncore/games/bounce/bounce.pro +++ b/noncore/games/bounce/bounce.pro @@ -1,10 +1,9 @@ -#CONFIG = qt warn_on -CONFIG = qt warn_on quick-app +CONFIG = qt warn_on quick-app HEADERS = game.h kbounce.h SOURCES = game.cpp kbounce.cpp main.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe -lopiecore2 +LIBS += -lqpe -lopiecore2 TARGET = bounce include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/games/bounce/game.cpp b/noncore/games/bounce/game.cpp index 1f1f8cd..bbd3d0b 100644 --- a/noncore/games/bounce/game.cpp +++ b/noncore/games/bounce/game.cpp @@ -1,120 +1,127 @@ /* * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <stdlib.h> -#include <qtimer.h> +#include "game.h" + +/* OPIE */ +#include <opie2/odebug.h> #include <qpe/qpeapplication.h> +using namespace Opie::Core; -#include "game.h" +/* QT */ +#include <qtimer.h> + +/* STD */ +#include <stdlib.h> #define TILE_SIZE 9 #define TILE_FIRST ((FIELD_WIDTH-2)*(FIELD_HEIGHT-2)) #define TILE_FREE (TILE_FIRST + 0) #define TILE_BORDER (TILE_FIRST + 1) #define TILE_WALLEND (TILE_FIRST + 2) #define TILE_WALLUP (TILE_FIRST + 3) #define TILE_WALLDOWN (TILE_FIRST + 4) #define TILE_WALLLEFT (TILE_FIRST + 5) #define TILE_WALLRIGHT (TILE_FIRST + 6) #define GAME_DELAY 15 #define BALL_ANIM_DELAY 60 #define WALL_DELAY 100 #define MS2TICKS( ms ) ((ms)/GAME_DELAY) Arrow::Arrow(QCanvasPixmapArray* array, QCanvas* canvas) : QCanvasSprite( array, canvas ) { m_vertical = true; move(3,3); } void Arrow::update() { if ( m_vertical ) setFrame( 0 ); else setFrame( 1 ); } void Arrow::changeDirection() { m_vertical = ! m_vertical; update(); } Ball::Ball(QCanvasPixmapArray* array, QCanvas* canvas) : QCanvasSprite( array, canvas ), m_animDelay( 0 ), m_soundDelay( MS2TICKS(BALL_ANIM_DELAY)/2 ) { } void Ball::update() { m_animDelay--; if ( m_animDelay<=0 ) { m_animDelay = MS2TICKS(BALL_ANIM_DELAY); int frameNum = frame(); frameNum++; if ( frameNum>=frameCount() ) frameNum = 0; setFrame( frameNum ); } } void Ball::advance(int stage) { bool reflectX = false; bool reflectY = false; // check for collisions if ( collide(xVelocity(), 0) ) reflectX = true; if ( collide(0, yVelocity()) ) reflectY = true; if ( !reflectX && !reflectY && collide(xVelocity(), yVelocity()) ) reflectX = reflectY = true; // emit collision QRect r = boundingRect(); r.moveBy( xVelocity(), yVelocity() ); JezzField* field = (JezzField *)canvas(); int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); if ( ul!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.top() / TILE_SIZE, ul ); else if ( ur!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.top() / TILE_SIZE, ur ); else if ( bl!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.bottom() / TILE_SIZE, bl ); else if ( br!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.bottom() / TILE_SIZE, br ); // apply reflection if ( reflectX ) setXVelocity( -xVelocity() ); if ( reflectY ) setYVelocity( -yVelocity() ); // update field update(); QCanvasSprite::advance( stage ); } bool Ball::collide( double dx, double dy ) { QRect r = boundingRect(); @@ -274,193 +281,193 @@ void JezzView::viewportMouseReleaseEvent( QMouseEvent *ev ) } void JezzView::changeCursor() { m_vertical = !m_vertical; if ( m_vertical ) { setCursor( sizeVerCursor ); } else { setCursor( sizeHorCursor ); } } /*************************************************************************/ JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name ) : QWidget( parent, name ), m_wall1( 0 ), m_wall2( 0 ), m_text( 0 ), m_running( false ), m_percent( 0 ), m_pictured( false ) { QString path = QPEApplication::qpeDir()+"pics/bounce/"; // load gfx m_ballPixmaps = new QCanvasPixmapArray( path + "ball%1.png", 25 ); for ( unsigned n=0; n < m_ballPixmaps->count(); n++ ) m_ballPixmaps->image(n)->setOffset( 0, 0 ); m_arrowPixmaps = new QCanvasPixmapArray( path + "arrow%1.png", 2 ); for ( unsigned n=0; n < m_arrowPixmaps->count(); n++ ) m_arrowPixmaps->image(n)->setOffset( 0, 0 ); QPixmap tiles( path + "tiles.png" ); // create field m_field = new JezzField( tiles, this, "m_field" ); m_field->resize( TILE_SIZE*FIELD_WIDTH, TILE_SIZE*FIELD_HEIGHT ); for ( int x=0; x<FIELD_WIDTH; x++ ) m_field->setTile( x, 0, TILE_BORDER ); for ( int y=1; y<FIELD_HEIGHT-1; y++ ) { m_field->setTile( 0, y, TILE_BORDER ); for ( int x=1; x<FIELD_WIDTH-1; x++ ) m_field->setTile( x, y, TILE_FREE ); m_field->setTile( FIELD_WIDTH-1, y, TILE_BORDER ); } for ( int x=0; x<FIELD_WIDTH; x++ ) m_field->setTile( x, FIELD_HEIGHT-1, TILE_BORDER ); connect( m_field, SIGNAL(ballCollision(Ball*,int,int,int)), this, SLOT(ballCollision(Ball*,int,int,int)) ); // create view m_view = new JezzView( m_field, this, "m_view" ); m_view->move( 0, 0 ); m_view->adjustSize(); connect( m_view, SIGNAL(buildWall(int,int,bool)), this, SLOT(buildWall(int,int,bool)) ); // create balls for ( int n=0; n<ballNum; n++ ) { Ball *ball = new Ball( m_ballPixmaps, m_field ); m_balls.append( ball ); ball->setVelocity( ((rand() & 1)*2-1)*2, ((rand() & 1)*2-1)*2 ); ball->setFrame( rand() % 25 ); ball->move( 4*TILE_SIZE + ( rand() - 50 ) % ( (FIELD_WIDTH-8)*TILE_SIZE ), 4*TILE_SIZE + rand() % ( (FIELD_HEIGHT-8)*TILE_SIZE ) ); ball->show(); } // create arrow arrow = new Arrow( m_arrowPixmaps, m_field ); arrow->show(); // create text label m_text = new QCanvasText( m_field ); // create game clock m_clock = new QTimer( this ); connect( m_clock, SIGNAL(timeout()), this, SLOT(tick()) ); m_clock->start( GAME_DELAY ); // setup geometry setFixedSize( m_view->size() ); } JezzGame::~JezzGame() { m_balls.clear(); delete m_view; delete m_field; delete m_ballPixmaps; } void JezzGame::display( QString text, int size ) { - qDebug("This function \"display\" shouldn't be called!!!"); + odebug << "This function \"display\" shouldn't be called!!!" << oendl; if ( !text.isEmpty() ) { QFont font( "Helvetica", size, QFont::Bold ); font.setStyleHint( QFont::Helvetica ); m_text->setFont( font ); m_text->setText( text ); QRect size = m_text->boundingRect(); m_text->move( ( FIELD_WIDTH*TILE_SIZE - size.width() ) / 2, ( FIELD_HEIGHT*TILE_SIZE - size.height() ) / 2 ); m_text->show(); } else { m_text->hide(); } } void JezzGame::start() { m_running = true; } void JezzGame::stop() { m_running = false; } void JezzGame::makeBlack() { // copy current field into buffer for ( int y=0; y<FIELD_HEIGHT; y++ ) for ( int x=0; x<FIELD_WIDTH; x++ ) m_buf[x][y] = m_field->tile( x, y ); // fill areas that contains a ball for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) fill( ball->x()/TILE_SIZE, ball->y()/TILE_SIZE ); // areas still free can be blacked now for ( int y=0; y<FIELD_HEIGHT; y++ ) for ( int x=0; x<FIELD_WIDTH; x++ ) { if ( m_buf[x][y]==TILE_FREE ) m_field->setGameTile( x, y, true ); } m_field->update(); m_view->repaint(); // count percent value of occupied area int p = percent(); if ( p!=m_percent ) { m_percent = p; emit newPercent( m_percent ); } } int JezzGame::percent() { int notFree = 0; for ( int y=1; y<FIELD_HEIGHT-1; y++ ) for ( int x=1; x<FIELD_WIDTH-1; x++ ) { if ( m_field->tile(x,y)!=TILE_FREE ) notFree++; } return 100 * notFree / ( (FIELD_WIDTH-1) * (FIELD_HEIGHT-1) ); } void JezzGame::fill( int x, int y ) { if ( m_buf[x][y]!=TILE_FREE) return; // go left int _x=x; for ( ; m_buf[_x][y]==TILE_FREE; _x-- ) m_buf[_x][y] = TILE_BORDER; int stopx = _x; // fill above for ( _x=x; _x>stopx; _x-- ) if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); // fill below for ( _x=x; _x>stopx; _x-- ) if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); // go right for ( _x=x+1; m_buf[_x][y]==TILE_FREE; _x++ ) m_buf[_x][y] = TILE_BORDER; stopx = _x; diff --git a/noncore/games/go/go.pro b/noncore/games/go/go.pro index b73bbb0..72425a5 100644 --- a/noncore/games/go/go.pro +++ b/noncore/games/go/go.pro @@ -1,19 +1,18 @@ -CONFIG = qt warn_on quick-app +CONFIG = qt warn_on quick-app HEADERS = amigo.h \ go.h \ goplayutils.h \ gowidget.h SOURCES = amigo.c \ - goplayer.c \ - goplayutils.c \ - killable.c \ - gowidget.cpp \ - main.cpp -INCLUDEPATH += $(OPIEDIR)/include + goplayer.c \ + goplayutils.c \ + killable.c \ + gowidget.cpp \ + main.cpp +INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -lopiecore2 TARGET = go - include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/games/go/gowidget.cpp b/noncore/games/go/gowidget.cpp index d134540..ec03c1d 100644 --- a/noncore/games/go/gowidget.cpp +++ b/noncore/games/go/gowidget.cpp @@ -1,131 +1,132 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "gowidget.h" +/* OPIE */ +#include <opie2/odebug.h> #include <qpe/config.h> #include <qpe/resource.h> +using namespace Opie::Core; +/* QT */ #include <qpainter.h> #include <qtoolbar.h> #include <qmenubar.h> #include <qaction.h> #include <qapplication.h> //processEvents() #include <qlabel.h> -//#include <stdio.h> - - static const enum bVal computer_color = BLACK; static int current_handicap = 1; static QBrush *goBrush; //static QImage *newBlackStone; //static QImage *blackStone; //static QImage *whiteStone; static QPixmap *newBlackStone; static QPixmap *blackStone; static QPixmap *whiteStone; static bool smallStones = FALSE; GoMainWidget::GoMainWidget( QWidget *parent, const char* name, WFlags fl) : QMainWindow( parent, name, fl ) { setToolBarsMovable( FALSE ); GoWidget *go = new GoWidget(this); setCentralWidget(go); toolbar = new QToolBar(this); toolbar->setHorizontalStretchable( TRUE ); addToolBar(toolbar); QMenuBar *mb = new QMenuBar( toolbar ); mb->setMargin(0); QPopupMenu *file = new QPopupMenu( this ); QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); a->addTo( file ); a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); a->addTo( file ); a->addTo( toolbar ); a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), go, SLOT( resign() ) ); a->addTo( file ); a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 ); a->setToggleAction( TRUE ); connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) ); a->addTo( file ); mb->insertItem( tr( "Game" ), file ); QLabel *turnLabel = new QLabel( toolbar ); turnLabel->setBackgroundMode( PaletteButton ); connect( go, SIGNAL(showTurn(const QPixmap&)), turnLabel, SLOT(setPixmap(const QPixmap&)) ); QLabel * scoreLabel = new QLabel( toolbar ); scoreLabel->setBackgroundMode( PaletteButton ); connect( go, SIGNAL(showScore(const QString&)), scoreLabel, SLOT(setText(const QString&)) ); toolbar->setStretchableWidget( scoreLabel ); go->readConfig(); } void GoMainWidget::resizeEvent( QResizeEvent * ) { //### this won't work because of the text label... /* if ( width() > height() ) moveToolBar( toolbar, Left ); else moveToolBar( toolbar, Top ); */ } GoWidget *GoWidget::self = 0; GoWidget::GoWidget( QWidget *parent, const char* name) : QWidget( parent, name ) { if ( self ) fatal( "Only one Go widget allowed" ); self = this; twoplayer = FALSE; d = bx = by = 1; QPixmap pix = Resource::loadPixmap( "go/pine" ); goBrush = new QBrush( black, pix ); /* QString fn = Resource::findPixmap("Go-black"); blackStone = new QImage( fn ); fn = Resource::findPixmap("Go-black-highlight"); @@ -355,106 +356,106 @@ void GoWidget::doComputerMove() } } void GoWidget::mousePressEvent( QMouseEvent *me ) { if ( !gameActive ) return; int x = x2board(me->x()); int y = y2board(me->y()); showStone(x,y,currentPlayer); } void GoWidget::mouseMoveEvent( QMouseEvent *me ) { if ( !gameActive ) return; int x = x2board(me->x()); int y = y2board(me->y()); if ( x != newX || y != newY ) showStone(x,y,currentPlayer); } void GoWidget::showStone( int x, int y, enum bVal c ) { if ( newX > -1 ) { refresh( newX, newY ); newY = newX = -1; } if ( x < 0 || x > 18 || y < 0 || y > 18 ) { newX = newY = -1; return; } if ( board[x][y] == -1 && !Suicide( c, x, y ) ) { newX = x; newY = y; refresh(x,y); } } void GoWidget::mouseReleaseEvent( QMouseEvent * ) { if ( gameActive && newX > -1 ) doMove( newX, newY ); newX = newY = -1; } void GoWidget::refresh( int x, int y ) { update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 ); } void GoWidget::removeStone(short x, short y) { board[x][y]=-1; refresh( x, y ); } void GoWidget::placeStone (enum bVal c, short x, short y ) { board[x][y]=c; refresh( x, y ); } void GoWidget::reportPrisoners( int blackcnt, int whitecnt ) { QString s = tr( "Prisoners: black %1, white %2" ).arg(blackcnt).arg(whitecnt); emit showScore( s ); } void GoWidget::setTwoplayer( bool b ) { twoplayer = b; } void GoWidget::setHandicap( int h ) { current_handicap = h; } extern "C" { void removestone(short x, short y) { GoWidget::self->removeStone(x,y); } void placestone (enum bVal c, short x, short y ) { GoWidget::self->placeStone(c,x,y); } void intrMoveReport(enum bVal c ,char *coord ,char *reason ) { - qDebug( "intrMoveReport colour %d, %s %s", c, coord, reason ); + odebug << "intrMoveReport colour " << c << ", " << coord << " " << reason << "" << oendl; } void intrPrisonerReport( short blackcnt, short whitecnt ) { GoWidget::self->reportPrisoners(blackcnt,whitecnt); } } diff --git a/noncore/games/kpacman/kpacman.pro b/noncore/games/kpacman/kpacman.pro index 8453f78..45314f9 100644 --- a/noncore/games/kpacman/kpacman.pro +++ b/noncore/games/kpacman/kpacman.pro @@ -1,41 +1,39 @@ TEMPLATE = app -#CONFIG = qt warn_on CONFIG = qt warn_on -#TMAKE_CXXFLAGS += HEADERS = kpacmanwidget.h \ referee.h \ status.h \ painter.h \ score.h \ pacman.h \ monster.h \ keys.h \ fruit.h \ energizer.h \ board.h \ bitfont.h \ kpacman.h \ bitmaps.h \ colors.h \ portable.h SOURCES = kpacmanwidget.cpp \ referee.cpp \ status.cpp \ painter.cpp \ score.cpp \ pacman.cpp \ monster.cpp \ keys.cpp \ fruit.cpp \ energizer.cpp \ board.cpp \ bitfont.cpp \ kpacman.cpp \ main.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe +LIBS += -lqpe -lopiecore2 DESTDIR = $(OPIEDIR)/bin TARGET = kpacman include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/games/kpacman/kpacmanwidget.cpp b/noncore/games/kpacman/kpacmanwidget.cpp index 9631495..b59dd02 100644 --- a/noncore/games/kpacman/kpacmanwidget.cpp +++ b/noncore/games/kpacman/kpacmanwidget.cpp @@ -1,153 +1,154 @@ #include "portable.h" #if defined( KDE2_PORT ) #include <kapp.h> #include <kconfig.h> #include <kstddirs.h> #include <kpacmanwidget.h> #include <kpacmanwidget.moc> #elif defined( QPE_PORT ) #include <qpe/qpeapplication.h> #include <qpe/config.h> #include "kpacmanwidget.h" #endif - +#include <opie2/odebug.h> +using namespace Opie::Core; KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name) : QWidget( parent, name ) { score = 0l; referee = 0l; status = 0l; bitfont = NULL; fontName = ""; scheme = mode = -1; confScheme(); score = new Score(this, name, scheme, mode, bitfont); referee = new Referee( this, name, scheme, mode, bitfont); status = new Status(this, name, scheme, mode); setBackgroundColor( black ); } KpacmanWidget::~KpacmanWidget() { } void KpacmanWidget::confMisc(bool defGroup) { APP_CONFIG_BEGIN( cfg ); //KStandardDirs *dirs = KGlobal::dirs(); QString findPath; if (defGroup || cfg->hasKey("Font")) { fontName = cfg->readEntry("Font"); if (fontName.left(1) != "/" && fontName.left(1) != "~") fontName.insert(0, "fonts/"); if (fontName.right(1) == "/") fontName.append("font.xbm"); //findPath = dirs->findResource("appdata", fontName); findPath = FIND_APP_DATA( fontName ); if (!findPath.isEmpty()) fontName = findPath; bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e); bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f); } APP_CONFIG_END( cfg ); } void KpacmanWidget::confScheme() { APP_CONFIG_BEGIN( cfg ); QString lastFontName = fontName; SAVE_CONFIG_GROUP( cfg, oldgroup ); QString newgroup; // if not set, read mode and scheme from the configfile if (mode == -1 && scheme == -1) { scheme = cfg->readNumEntry("Scheme", -1); mode = cfg->readNumEntry("Mode", -1); // if mode is not set in the defGroup-group, lookup the scheme group if (scheme != -1 || mode == -1) { newgroup.sprintf("Scheme %d", scheme); cfg->setGroup(newgroup); mode = cfg->readNumEntry("Mode", -1); RESTORE_CONFIG_GROUP( cfg, oldgroup ); } } confMisc(); if (mode != -1) { newgroup.sprintf("Mode %d", mode); cfg->setGroup(newgroup); confMisc(FALSE); } if (scheme != -1) { newgroup.sprintf("Scheme %d", scheme); cfg->setGroup(newgroup); confMisc(FALSE); } if (lastFontName != fontName) { if (bitfont != 0) delete bitfont; bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar); if (bitfont->width() == 0 || bitfont->height() == 0) { QString msg = tr("The bitfont could not be contructed.\n\n" "The file '@FONTNAME@' does not exist,\n" "or is of an unknown format."); msg.replace(QRegExp("@FONTNAME@"), fontName); // QMessageBox::critical(this, tr("Initialization Error"), msg); printf("%s\n", msg.data()); } } RESTORE_CONFIG_GROUP( cfg, oldgroup ); APP_CONFIG_END( cfg ); } void KpacmanWidget::setScheme(int Scheme, int Mode) { mode = Mode; scheme = Scheme; confScheme(); score->setScheme(Scheme, Mode, bitfont); referee->setScheme(Scheme, Mode, bitfont); status->setScheme(Scheme, Mode); score->repaint(FALSE); referee->repaint(FALSE); status->repaint(FALSE); } void KpacmanWidget::resizeEvent( QResizeEvent * ) { - qWarning("Resize"); + owarn << "Resize" << oendl; referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); referee->setBackgroundColor(BLACK); if(!status ) return; status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(), status->height()); status->setBackgroundColor(BLACK); score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height()); score->setBackgroundColor(BLACK); } diff --git a/noncore/games/kpacman/status.cpp b/noncore/games/kpacman/status.cpp index 02ff63d..db6938e 100644 --- a/noncore/games/kpacman/status.cpp +++ b/noncore/games/kpacman/status.cpp @@ -1,119 +1,122 @@ #include "portable.h" #if defined( KDE2_PORT ) #include <kapp.h> #include <klocale.h> #include <kstddirs.h> #include <status.h> #include <status.moc> #elif defined( QPE_PORT ) #include <qpe/qpeapplication.h> #include <qpe/config.h> #include "status.h" #endif +#include <opie2/odebug.h> +using namespace Opie::Core; + #include <qbitmap.h> #include <qmsgbox.h> #include <qfileinfo.h> Status::Status( QWidget *parent, const char *name, int Scheme, int Mode ) : QWidget( parent, name ) { - qWarning("Status::Status"); + owarn << "Status::Status" << oendl; actualLifes = 0; actualLevel = 0; lifesPix = NULL; levelPix = NULL; scheme = Scheme; mode = Mode; level = 0; confScheme(); } QList<QPixmap> *Status::loadPixmap(QWidget *parent, QString pixmapName, QList<QPixmap> *pixmaps) { if (pixmaps == NULL) { pixmaps = new QList<QPixmap>; pixmaps->setAutoDelete(TRUE); } if (!pixmaps->isEmpty()) pixmaps->clear(); QPixmap PIXMAP(pixmapName); if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { QString msg = tr("The pixmap could not be contructed.\n\n" "The file '@PIXMAPNAME@' does not exist,\n" "or is of an unknown format."); msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); QMessageBox::information(parent, tr("Initialization Error"), (const char *) msg); return 0; } int height = PIXMAP.height(); int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); QBitmap BITMAP; QBitmap MASK; BITMAP = *PIXMAP.mask(); MASK.resize(width, height); for (int x = 0; x < PIXMAP.width()/width; x++) { QPixmap *pixmap = new QPixmap(width, height); pixmaps->append(pixmap); bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, CopyROP, TRUE); bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, CopyROP, TRUE); pixmap->setMask(MASK); } return pixmaps; } void Status::paintEvent( QPaintEvent *) { for (int x = 0; x < actualLifes && !lifesPix->isEmpty(); x++) bitBlt(this, lifesPix->at(0)->width()+(lifesPix->at(0)->width()*x), (height()-lifesPix->at(0)->height())/2, lifesPix->at(0), 0, 0, lifesPix->at(0)->width(), lifesPix->at(0)->height()); for (int x = 0; x < actualLevel && !levelPix->isEmpty(); x++) { erase((width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]), (height()-levelPix->at(x)->height())/2, levelPix->at(x)->width(), levelPix->at(x)->height()); bitBlt(this, (width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]), (height()-levelPix->at(x)->height())/2, levelPix->at(x), 0, 0, levelPix->at(x)->width(), levelPix->at(x)->height()); } } void Status::initPixmaps() { if (lastLifesPixmapName != lifesPixmapName.at(level)) { lifesPix = loadPixmap(this, lifesPixmapName.at(level), lifesPix); lastLifesPixmapName = lifesPixmapName.at(level); } if (lastLevelPixmapName != levelPixmapName.at(level)) { levelPix = loadPixmap(this, levelPixmapName.at(level), levelPix); lastLevelPixmapName = levelPixmapName.at(level); } } QString Status::decodeHexOctString(QString s) { QString value; QString valids; int pos, xpos = 0, opos = 0; int v, len, leadin; const char *ptr; uchar c; while (((xpos = s.find(QRegExp("\\\\x[0-9a-fA-F]+"), xpos)) != -1) || diff --git a/noncore/games/mindbreaker/mindbreaker.cpp b/noncore/games/mindbreaker/mindbreaker.cpp index 2b924c6..1f554d2 100644 --- a/noncore/games/mindbreaker/mindbreaker.cpp +++ b/noncore/games/mindbreaker/mindbreaker.cpp @@ -1,189 +1,189 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "mindbreaker.h" #include <qtopia/resource.h> #include <qtopia/config.h> #include <qtopia/qpeapplication.h> #include <qtoolbar.h> #include <qtoolbutton.h> #include <qmessagebox.h> #include <qlayout.h> #include <qtimer.h> #include <stdlib.h> #include <sys/time.h> #include <unistd.h> static int pegRTTI = 3393393; static int adjusted_panel_height; static int adjusted_panel_width; static int adjusted_bin_margin; static int adjusted_peg_size; static int adjusted_answerpeg_size; static int adjusted_title_height; static int adjusted_title_width; static int adjusted_first_peg_x_diff; static int adjusted_first_peg_y_diff; static int adjusted_peg_spacing; static int adjusted_answerpegx; static int adjusted_answerpegy; static int adjusted_answerpeg_xdiff; static int adjusted_answerpeg_ydiff; static int adjusted_board_height; static int adjusted_board_width; static void setupBoardSize(int w, int h) { adjusted_panel_width = w * 3/4; adjusted_title_width = w * 3/4; adjusted_title_height = h/10; adjusted_panel_height = (h-adjusted_title_height)/9; adjusted_bin_margin = w * 10/240; adjusted_peg_size = adjusted_panel_height*3/4; adjusted_answerpeg_size = QMIN(adjusted_panel_width*15/180,adjusted_panel_height*15/25); // looks a bit dodgy on larger sizes if ( adjusted_peg_size > 40 ) adjusted_peg_size = 40; adjusted_first_peg_x_diff = w * 31/240-adjusted_peg_size/2; adjusted_first_peg_y_diff = (adjusted_panel_height - adjusted_peg_size)/2; adjusted_peg_spacing = w * 30/240; // looks a bit dodgy on larger sizes (still does though, but not as much...) if ( adjusted_answerpeg_size > 22 ) adjusted_answerpeg_size = 22; adjusted_answerpegx = adjusted_panel_width * 159/180 - adjusted_answerpeg_size/2; adjusted_answerpegy = adjusted_panel_height/3 - adjusted_answerpeg_size/2; adjusted_answerpeg_xdiff = adjusted_panel_width * 10/180; adjusted_answerpeg_ydiff = adjusted_panel_height * 9/25; adjusted_board_height = adjusted_title_height + (adjusted_panel_height * 9); adjusted_board_width = adjusted_panel_width + (adjusted_bin_margin * 2) + adjusted_peg_size; -// qDebug("Adjusted width %d height %d", adjusted_board_width, adjusted_board_height); +// odebug << "Adjusted width " << adjusted_board_width << " height " << adjusted_board_height << "" << oendl; } /* helper class, */ class Peg : public QCanvasRectangle { public: Peg(QCanvas *canvas, int type, int go = -1, int pos = -1); int rtti() const {return pegRTTI; } void advance(int phase); bool hit( const QPoint &) const; /* a placed peg is one that has been set down on the board correctly and should not be moved, only copied */ bool placed() const; void setPlaced(bool); int pegGo() const; int pegPos() const; void setPegPos(int); int type() const; static void buildImages(); static QImage imageForType(int t); static int eggLevel; protected: void drawShape(QPainter &); private: static QVector<QImage> normalPegs; static QVector<QImage> specialPegs; bool isplaced; int pegtype; int peg_go; int peg_pos; int aniStep; }; int Peg::eggLevel = 0; QVector<QImage> Peg::normalPegs; QVector<QImage> Peg::specialPegs; void Peg::buildImages() { QImage pegs = Resource::loadImage("mindbreaker/pegs"); int x = 0; int y = 0; int i; eggLevel = 0; normalPegs.resize(10); for (i = 0; i < 6; i++) { normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size). smoothScale(adjusted_peg_size, adjusted_peg_size) )); x += peg_size; } specialPegs.resize(5); for (i = 0; i < 5; i++) { specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size). smoothScale(adjusted_peg_size, adjusted_peg_size) )); x += peg_size; } QImage image = Resource::loadImage("mindbreaker/mindbreaker"); /* copy from master image to functional images */ x = 0; y = panel_height; normalPegs.insert(8, new QImage( image.copy(x, y, panel_width, panel_height). smoothScale( adjusted_panel_width, adjusted_panel_height) )); y += panel_height; y += title_height; normalPegs.insert(9, new QImage(image.copy(x, y, title_width, title_height). smoothScale( adjusted_title_width, adjusted_title_height) )); y += title_height; x = 6 * peg_size; normalPegs.insert(6, new QImage(image.copy(x, y, answerpeg_size, answerpeg_size). smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) )); x += answerpeg_size; normalPegs.insert(7, new QImage(image.copy(x, y, answerpeg_size, answerpeg_size). smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) )); } QImage Peg::imageForType(int t) { if (eggLevel > t ) { if( t < 5) { diff --git a/noncore/games/oyatzee/oyatzee.cpp b/noncore/games/oyatzee/oyatzee.cpp index a55aa73..27c0a9f 100644 --- a/noncore/games/oyatzee/oyatzee.cpp +++ b/noncore/games/oyatzee/oyatzee.cpp @@ -1,490 +1,496 @@ #include "oyatzee.h" +/* OPIE */ +#include <opie2/odebug.h> +using namespace Opie::Core; + +/* QT */ #include <qmessagebox.h> #include <qpushbutton.h> #include <qpainter.h> #include <qlayout.h> +/* STD */ #include <stdlib.h> OYatzee::OYatzee( QWidget *parent , const char *name, WFlags fl ) : QMainWindow( parent , name , fl ) { QWidget *thing = new QWidget( this ); setCentralWidget( thing ); setCaption( tr( "OYatzee" ) ); setPlayerNumber( 4 ); setRoundsNumber( 1 ); lastPlayerFinished = false; currentPlayer = 1; ps.append( new Player( "Carsten" ) ); ps.append( new Player( "Julia" ) ); ps.append( new Player( "Christine" ) ); ps.append( new Player( "Stephan" ) ); QVBoxLayout *vbox = new QVBoxLayout( thing ); sb = new Scoreboard( ps, thing , "sb" ); connect( sb->pb , SIGNAL( item(int) ), this , SLOT( slotEndRound(int) ) ); dw = new DiceWidget( thing , "dw" ); dw->setMaximumHeight( this->height()/4 ); connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) ); vbox->addWidget( sb ); vbox->addWidget( dw ); } void OYatzee::slotEndRound( int item ) { - qDebug( "Der User hat Nummer %d ausgewählt" , item ); + odebug << "Der User hat Nummer " << item << " ausgewählt" << oendl; /* * if the user clicked on Total, Bonus or Score and thus not on a * selectable item return and do nothing */ if ( item == 7 || item == 8 || item == 16 ) return; /* * check if the user can really click on that item */ if ( posibilities.find( item ) == posibilities.end() ) return; QValueListInt numbers; Dice *d = dw->diceList.first(); for ( ; d != 0 ; d = dw->diceList.next() ) { numbers.append( d->hasValue() ); } int points = 0; switch ( item ) { case Ones: points = getPoints( 1 , numbers ); break; case Twos: points = getPoints( 2 , numbers ); break; case Threes: points = getPoints( 3 , numbers ); break; case Fours: points = getPoints( 4 , numbers ); break; case Fives: points = getPoints( 5 , numbers ); break; case Sixes: points = getPoints( 6 , numbers ); break; case ThreeOfAKind: points = oakPoints; break; case FourOfAKind: points = oakPoints; break; case FullHouse: points = 25; break; case SStraight: points = 30; break; case LStraight: points = 40; break; case Yatzee: points = 50; break; case Chance: points = getPoints ( Chance , numbers ); } sb->nextRB(currentPlayer-1)->updateMap( item , points ); nextPlayer(); - qDebug( "Punkte: %d" , points ); + odebug << "Punkte: " << points << "" << oendl; } void OYatzee::nextPlayer() { currentPlayer++; if ( currentPlayer > numOfPlayers ) { currentPlayer = 1; } ps.at(currentPlayer-1)->turn = 0; } int OYatzee::getPoints( const int num , QValueListInt l) { QValueListInt::Iterator it = l.begin(); int c = 0; if ( num != Chance ) { for ( ; it != l.end() ; ++it ) { if ( *it == num ) c++; } return c * num; } else { for ( ; it != l.end() ; ++it ) { c += *it; } return c; } } OYatzee::~OYatzee() { } void OYatzee::detectPosibilities() { posibilities.clear(); - qDebug( "running detectPosibilities()" ); + odebug << "running detectPosibilities()" << oendl; Dice *d = dw->diceList.first(); QValueListInt numbers; for ( ; d != 0 ; d = dw->diceList.next() ) { numbers.append( d->hasValue() ); } //the 6 numbers QValueListInt::Iterator it; for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6 { bool cont = false; it = numbers.begin(); for ( ; it != numbers.end() ; ++it ) { if ( cont ) continue; if ( numbers.find( i ) != numbers.end() ) { posibilities.append( i ); cont = true; } } } //3er, 4er, Yatzee it = numbers.begin(); int count; int temp; int countFH = 0; //for the full-house-check for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6 at least 3 times { count = 0; temp = 0; it = numbers.begin(); for ( ; it != numbers.end() ; ++it ) { if ( *it == i ) { count++; temp++; } if ( temp == 2 ) countFH = temp; } if ( count >= 3 ) { posibilities.append( 9 ); //now we check if it is a full house if ( count == 3 && countFH == 2 ) //aka Full House posibilities.append( 11 ); if ( count >= 4 ) posibilities.append( 10 ); if ( count == 5 ) //Yatzee posibilities.append( 14 ); oakPoints = count * i; } } //S-Straight if ( numbers.find( 3 ) != numbers.end() && numbers.find( 4 ) != numbers.end() ) { bool isLong = false; bool isShort = true; //L-Straight if ( numbers.find( 2 ) != numbers.end() && numbers.find( 5 ) != numbers.end() ) { isShort = true; //12345 or 23456 if ( numbers.find( 1 ) != numbers.end() || numbers.find( 6) != numbers.end() ) isLong = true; } //1234 if ( numbers.find( 1 ) != numbers.end() && numbers.find( 2 ) != numbers.end() ) isShort = true; //3456 if ( numbers.find( 5 ) != numbers.end() && numbers.find( 6 ) != numbers.end() ) isShort = true; if ( isShort ) posibilities.append( 12 ); if ( isLong ) posibilities.append( 13 ); } posibilities.append( 13 ); //Chance, well, this is allways possible displayPossibilites(); } void OYatzee::displayPossibilites() { //X for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it ) //X { -//X qDebug( QString::number( *it ) ); +//X odebug << QString::number( *it ) << oendl; //X switch ( *it ) //X { //X case Ones: -//X qDebug( "1er" ); +//X odebug << "1er" << oendl; //X break; //X case Twos: -//X qDebug( "2er" ); +//X odebug << "2er" << oendl; //X break; //X case Threes: -//X qDebug( "3er" ); +//X odebug << "3er" << oendl; //X break; //X case Fours: -//X qDebug( "4er" ); +//X odebug << "4er" << oendl; //X break; //X case Fives: -//X qDebug( "5er" ); +//X odebug << "5er" << oendl; //X break; //X case Sixes: -//X qDebug( "6er" ); +//X odebug << "6er" << oendl; //X break; //X case ThreeOfAKind: -//X qDebug( "3oaK" ); +//X odebug << "3oaK" << oendl; //X break; //X case FourOfAKind: -//X qDebug( "4oaK" ); +//X odebug << "4oaK" << oendl; //X break; //X case FullHouse: -//X qDebug( "Full House" ); +//X odebug << "Full House" << oendl; //X break; //X case SStraight: -//X qDebug( "Short S" ); +//X odebug << "Short S" << oendl; //X break; //X case LStraight: -//X qDebug( "Long S" ); +//X odebug << "Long S" << oendl; //X break; //X case Yatzee: -//X qDebug( "Yatzee!" ); +//X odebug << "Yatzee!" << oendl; //X break; //X case Chance: -//X qDebug( "Chance" ); +//X odebug << "Chance" << oendl; //X break; //X } //X } sb->pb->setIntlist( posibilities ); sb->pb->update(); } void OYatzee::startGame() { /* * TODO */ } void OYatzee::stopGame(){} void OYatzee::setPlayerNumber( const int num ) { numOfPlayers = num; } void OYatzee::setRoundsNumber( const int num ) { numOfRounds = num; } void OYatzee::slotStartGame() { } void OYatzee::slotRollDices() { - qDebug( "Roll nummer: %d" , ps.at( currentPlayer-1 )->turn ); + odebug << "Roll nummer: " << ps.at( currentPlayer-1 )->turn << "" << oendl; if ( ps.at( currentPlayer-1 )->turn == 3 ) { QMessageBox::information( this, "OYatzee", tr( "Only three rolls per turn allowed." ) ); return; } Dice *d = dw->diceList.first(); for ( ; d != 0 ; d = dw->diceList.next() ) { if ( !d->isSelected ) d->roll(); } -// qDebug( "Roll nummer (vorher): %d" , ps.at( currentPlayer-1 )->turn ); +// odebug << "Roll nummer (vorher): " << ps.at( currentPlayer-1 )->turn << "" << oendl; ps.at(currentPlayer-1)->turn++; -// qDebug( "Roll nummer (nachher): %d" , ps.at( currentPlayer-1 )->turn ); +// odebug << "Roll nummer (nachher): " << ps.at( currentPlayer-1 )->turn << "" << oendl; detectPosibilities(); } /* * Scoreboard */ Scoreboard::Scoreboard( playerList ps, QWidget *parent, const char *name ) : QWidget( parent , name ) { ps_ = ps; pb = new Possibilityboard( this , "pb" ); createResultboards( 4 ); QHBoxLayout *hbox = new QHBoxLayout( this ); hbox->addWidget( pb ); hbox->addSpacing( 25 ); Resultboard *r = rbList.first(); for ( ; r != 0 ; r = rbList.next() ) { hbox->addWidget( r ); } } Resultboard* Scoreboard::nextRB( int currentPlayer ) { Resultboard *b; b = rbList.at( currentPlayer ); - qDebug( "Anzahl: %d" , rbList.count() ); + odebug << "Anzahl: " << rbList.count() << "" << oendl; return b; } void Scoreboard::createResultboards(const int num) { Player *p = ps_.first(); for ( int i = 0 ; i < num ; ++i , p = ps_.next() ) { QString n = p->playerName; rbList.append( new Resultboard( n , this ) ); } } void Scoreboard::paintEvent( QPaintEvent * ) { //X QPainter p; //X p.begin( this ); //X //X p.drawRect( 0,0, this->width() , this->height() ); } /* * Dice */ Dice::Dice( QWidget *parent , const char *name ) : QFrame( parent , name ) { QTime t = QTime::currentTime(); // set random seed srand(t.hour()*12+t.minute()*60+t.second()*60); connect( this , SIGNAL( selected() ), this , SLOT( slotSelected() ) ); } void Dice::slotSelected() { if ( isSelected ) isSelected = false; else isSelected = true; update(); } const int Dice::hasValue() const { return Value; } void Dice::roll() { Value = rand()%6; Value += 1; update(); } void Dice::mousePressEvent( QMouseEvent* /*e*/ ) { emit selected(); } void Dice::paintEvent( QPaintEvent * ) { QPainter p; p.begin( this ); p.drawRect( 0,0, this->width() , this->height() ); if ( isSelected ) p.drawRect( 20,20, 10,10 ); paintNumber( &p ); } void Dice::paintNumber( QPainter *p ) { p->setBrush( Qt::black ); int w = this->width(); int h = this->height(); int r = this->width(); r /= 10; switch ( Value ) { case 1: p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ; break; case 2: p->drawEllipse( (int)( 0.3*w - r ) , (int)( 0.3*h - r ) , r , r ) ; p->drawEllipse( (int)( 0.7*w - r ) , (int)( 0.7*h - r ) , r , r ) ; break; case 3: p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ; p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ; p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ; break; @@ -515,173 +521,173 @@ void Dice::paintNumber( QPainter *p ) /* * DiceWidget */ DiceWidget::DiceWidget( QWidget *parent , const char *name ) : QWidget( parent , name ) { rollButton = new QPushButton( tr( "Roll" ) , this ) ; for ( int i = 0 ; i < 5 ; i++ ) { //appending the 5 dices of the game diceList.append( new Dice( this, "wuerfel" ) ); } QHBoxLayout *hbox = new QHBoxLayout( this ); Dice *d = diceList.first(); for ( ; d != 0 ; d = diceList.next() ) { hbox->addWidget( d ); } hbox->addWidget( rollButton ); } /* * Player */ Player::Player( QString name ) { playerName = name; setupResultList(); turn = 0; } void Player::setupResultList() { for ( int i = 1 ; i < 14 ; ++i ) { pResults.append( 0 ); } } /* * TODO: muss noch genutzt werden */ void Player::updateTotalPoints( pointMap m ) { pointMap::Iterator it = m.begin(); for ( ; it != m.end() ; ++it ) { totalPoints += it.data(); } } void Player::setResults( const int cat , const int points ) { QValueListInt::Iterator it = pResults.at( cat ); *it = points; } /* * Board */ Board::Board( QWidget *parent , const char* name ) : QWidget ( parent , name ) { } void Board::mousePressEvent( QMouseEvent *e ) { emit clicked( e->pos() ); } /* * Resultboard */ Resultboard::Resultboard( QString playerName , QWidget *parent , const char* name ) : Board ( parent , name ) { pName = playerName; } void Resultboard::paintEvent( QPaintEvent* ) { QPainter p; p.begin( this ); const int cell_width = this->width(); const int cell_height = this->height()/17; pointMap::Iterator it = pMap.begin(); for ( ; it != pMap.end() ; ++it ) { int i = it.key(); - qDebug( "ok: %d , %d" , i , it.data() ); + odebug << "ok: " << i << " , " << it.data() << "" << oendl; p.drawText( 0, i*cell_height , cell_width , cell_height , Qt::AlignCenter , QString::number( it.data() ) ); } p.drawText( 0,0,cell_width,cell_height, Qt::AlignCenter , pName ); //Playername } void Resultboard::updateMap( int item , int points ) { pMap.insert( item , points ); update(); } /* * Possibilityboard */ Possibilityboard::Possibilityboard( QWidget *parent , const char* name ) : Board ( parent , name ) { begriffe.append( "1er" ); begriffe.append( "2er" ); begriffe.append( "3er" ); begriffe.append( "4er" ); begriffe.append( "5er" ); begriffe.append( "6er" ); begriffe.append( "Total" ); begriffe.append( "Bonus" ); begriffe.append( "3oaK" ); begriffe.append( "4oaK" ); begriffe.append( "Full House" ); begriffe.append( "Short S" ); begriffe.append( "Long S" ); begriffe.append( "Yatzee!" ); begriffe.append( "Chance" ); begriffe.append( "Score" ); connect( this , SIGNAL( clicked(QPoint) ), this , SLOT( slotClicked(QPoint) ) ); } void Possibilityboard::slotClicked( QPoint p) { emit item( p.y()/(this->height()/17) ); } void Possibilityboard::paintEvent( QPaintEvent* ) { QPainter p; p.begin( this ); const int cell_width = this->width(); const int cell_height = this->height()/17; p.setBrush( Qt::blue ); QValueListInt::Iterator listIt = list.begin(); for ( ; listIt != list.end() ; ++listIt ) { p.drawRect( 0 , (*listIt) * cell_height , cell_width , cell_height ); } p.setBrush( Qt::black ); p.setBrush( Qt::NoBrush ); QStringList::Iterator begriffeIt = begriffe.begin(); for ( int i = 1 ; i < 18 ; ++i ) { p.drawText( 0 , i*cell_height , cell_width , cell_height , Qt::AlignCenter , *begriffeIt ); ++begriffeIt; } } void Possibilityboard::setIntlist( QValueListInt &l ) { list = l; } diff --git a/noncore/games/oyatzee/oyatzee.pro b/noncore/games/oyatzee/oyatzee.pro index 754abd2..f505c66 100644 --- a/noncore/games/oyatzee/oyatzee.pro +++ b/noncore/games/oyatzee/oyatzee.pro @@ -1,11 +1,11 @@ TEMPLATE = app CONFIG = qt warn_on DESTDIR = $(OPIEDIR)/bin HEADERS = oyatzee.h SOURCES = main.cpp oyatzee.cpp TARGET = oyatzee INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe +LIBS += -lqpe -lopiecore2 include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp index a80bd35..47d6725 100644 --- a/noncore/games/wordgame/wordgame.cpp +++ b/noncore/games/wordgame/wordgame.cpp @@ -582,193 +582,193 @@ bool ComputerPlayer::step() uchar nletter[4095]; // QDawg only handles 0..4095 memset(nletter,0,4096); for (int i=0; i<rack->count(); i++) { const Tile* r = rack->tileRef(i); if ( r->isBlank() ) nletter[0]++; else nletter[r->text()[0].unicode()]++; } Tile blankvalues[99]; // ### max blanks findBest(current, d, root, 0, nletter, tiles, 0, blankvalues, 0); if ( ++current.rx() == board->xTiles() ) { current.rx() = 0; if ( ++current.ry() == board->yTiles() ) { if ( across ) { if ( dict == 1 ) { if ( best_score >= 0 ) { rack->arrangeTiles(best,best_n); rack->setBlanks(best_blankvalues); board->scoreTurn(best_start, best_n, best_dir); board->showTurn(); } return FALSE; } dict++; across = FALSE; current = QPoint(0,0); } else { across = TRUE; current = QPoint(0,0); } } } return TRUE; } void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar* nletter, const Tile** tiles, int n, Tile* blankvalues, int blused) { if ( !node ) return; QChar l = node->letter(); const Tile* cur = board->tile(at); if ( cur ) { if ( cur->text()[0] == l ) { bool nextok = board->contains(at+d); if ( node->isWord() && n && (!nextok || !board->tile(at+d)) ) noteChoice(tiles,n,d,blankvalues,blused); if ( nextok ) findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); // #### text()[1]... } } else { if ( nletter[l.unicode()] || nletter[0] ) { int rc = rack->count(); ulong msk = 1; for ( int x=0; x<rc; x++ ) { if ( !(used&msk) ) { const Tile* t = rack->tileRef(x); if ( t->isBlank() || t->text() == l ) { // #### multi-char value()s bool nextok = board->contains(at+d); tiles[n++] = t; if ( t->isBlank() ) blankvalues[blused++] = Tile(l,0); if ( node->isWord() && (!nextok || !board->tile(at+d)) ) noteChoice(tiles,n,d,blankvalues,blused); used |= msk; // mark nletter[t->text()[0].unicode()]--; if ( nextok ) findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); n--; nletter[t->text()[0].unicode()]++; if ( t->isBlank() ) { // keep looking blused--; used &= ~msk; // unmark } else { break; } } } msk <<= 1; } } // #### text()[1]... } findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused); } void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused) { int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0); /* if (s>0 || current==QPoint(5,1)){ QString st; for ( int i=0; i<n; i++ ) st += tiles[i]->text(); -qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s); +odebug << "" << current.x() << "," << current.y() << ": " << st.latin1() << " (" << n << ") for " << s << "" << oendl; } */ if ( s > best_score ) { int i; for ( i=0; i<n; i++ ) best[i] = tiles[i]; for ( i=0; i<blused; i++ ) best_blankvalues[i] = blankvalues[i]; best_n = n; best_blused = blused; best_score = s; best_dir = d; best_start = current; } } int TileItem::smallWidth() { return tile_smallw; } int TileItem::smallHeight() { return tile_smallh; } int TileItem::bigWidth() { return tile_bigw; } int TileItem::bigHeight() { return tile_bigh; } void TileItem::setState( State state ) { hide(); s = state; show(); // ### use update() in Qt 3.0 } void TileItem::setTile(const Tile& tile) { hide(); t = tile; show(); // ### use update() in Qt 3.0 } void TileItem::setBig(bool b) { big = b; } void TileItem::drawShape(QPainter& p) { static QFont *value_font=0; static QFont *big_font=0; static QFont *small_font=0; if ( !value_font ) { value_font = new QFont("helvetica",8); if ( TileItem::bigWidth() < 20 ) { big_font = new QFont("helvetica",12); small_font = new QFont("helvetica",8); } else { big_font = new QFont("smoothtimes",17); small_font = new QFont("smoothtimes",10); } } QRect area(x(),y(),width(),height()); p.setBrush(s == Floating ? yellow/*lightGray*/ : white); p.drawRect(area); if ( big ) { p.setFont(*value_font); QString n = QString::number(t.value()); int w = p.fontMetrics().width('1'); int h = p.fontMetrics().height(); w *= n.length(); QRect valuearea(x()+width()-w-1,y()+height()-h,w,h); p.drawText(valuearea,AlignCenter,n); p.setFont(*big_font); area = QRect(x(),y()+tile_btweak,width()-4,height()-1); } else { p.setFont(*small_font); area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3); } if ( t.value() == 0 ) p.setPen(darkGray); p.drawText(area,AlignCenter,t.text().upper()); } Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), parent) |