Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

field.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002   field.cpp  -  description
00003   -------------------
00004 begin                : Fri May 19 2000
00005 copyright            : (C) 2000 by Roman Merzlyakov
00006 email                : roman@sbrf.barrt.ru
00007 copyright            : (C) 2000 by Roman Razilov
00008 email                : Roman.Razilov@gmx.de
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
00017  *                                                                         *
00018  ***************************************************************************/
00019 #include <stdlib.h>
00020 #include "field.h"
00021 
00022 Field::Field(QWidget* parent, const char* name)
00023         : QWidget( parent, name )
00024 {
00025         clearField();
00026 }
00027 
00028 Field::~Field()
00029 {
00030 }
00031 
00032 void Field::clearField()
00033 {
00034         for(int y=0; y<NUMCELLSH; y++)
00035                 for(int x=0; x<NUMCELLSW; x++)
00036                         field[y][x].clear();
00037 }
00038 void Field::clearAnim()
00039 {
00040         for(int y=0; y<NUMCELLSH; y++)
00041                 for(int x=0; x<NUMCELLSW; x++)
00042                         field[y][x].setAnim( ANIM_NO );
00043 }
00044 int Field::deleteAnimatedBalls()
00045 {
00046         int deleted = 0;
00047         for(int y=0; y<NUMCELLSH; y++)
00048                 for(int x=0; x<NUMCELLSW; x++)
00049                 {
00050                         if ( field[y][x].getAnim() != ANIM_NO )
00051                         {
00052                                 deleted++;
00053                                 field[y][x].clear();
00054                         }
00055                 }
00056         return deleted;
00057 }
00058 
00059 bool Field::checkBounds(int x, int y)
00060 {
00061         return (x>=0) && (x<NUMCELLSW) && (y>=0) && (y<NUMCELLSH);
00062 }
00063 
00064 void Field::putBall(int x, int y, int color)
00065 {
00066         if( checkBounds(x,y) )
00067                 field[y][x].setColor(color);
00068 }
00069 /*
00070    void Field::putBall(int x, int y, char color)
00071    {
00072    if( checkBounds(x,y) ){
00073    field[y][x].setColor(color);
00074    erase5Balls();
00075    repaint(FALSE);
00076    }
00077    }*/
00078 void Field::moveBall(int xa, int ya, int xb, int yb)
00079 {
00080         if( checkBounds(xa,ya) && checkBounds(xb,yb) &&
00081                         field[yb][xb].isFree() && ( xa != xb || ya != yb) ) {
00082                 field[yb][xb].moveBall(field[ya][xa]);
00083         }
00084 }
00085 
00086 int Field::getBall(int x, int y)
00087 {
00088         if( checkBounds(x,y) )
00089                 return field[y][x].getColor();
00090         else 
00091                 return NOBALL;
00092 }
00093 int Field::getAnim(int x, int y)
00094 {
00095         if( checkBounds(x,y) )
00096                 return field[y][x].getAnim();
00097         else 
00098                 return NOBALL;
00099 }
00100 void Field::setAnim(int x, int y, int anim)
00101 {
00102         if( checkBounds(x,y) )
00103                 field[y][x].setAnim( anim );
00104 }
00105 
00106 void Field::removeBall(int x, int y )
00107 {
00108         if( checkBounds(x,y) ) field[y][x].clear();
00109 }
00110 
00111 int Field::freeSpace()
00112 {
00113         int s = 0;
00114         for(int y=0; y<NUMCELLSH; y++)
00115                 for(int x=0; x<NUMCELLSW; x++)
00116                         if(field[y][x].isFree()) s++;
00117         return s;
00118 }
00119 void Field::saveUndo()
00120 {
00121         void clearAnim();
00122         for(int y=0; y<NUMCELLSH; y++)
00123                 for(int x=0; x<NUMCELLSW; x++)
00124                         field_undo[y][x] = field[y][x];
00125 }
00126 void Field::restoreUndo()
00127 {
00128         for(int y=0; y<NUMCELLSH; y++)
00129                 for(int x=0; x<NUMCELLSW; x++)
00130                         field[y][x] = field_undo[y][x];
00131 }

Generated on Sat Nov 5 16:17:19 2005 for OPIE by  doxygen 1.4.2