/* * Copyright (c) 1996-2002 Nicolas HADACEK (hadacek@kde.org) * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "bfield.h" using namespace KGrid2D; BaseField::BaseField(long seed) : _nbUncovered(0), _nbMarked(0), _nbUncertain(0), _random(seed) {} CoordList BaseField::coveredNeighbours(const Coord &p) const { CoordList n; CoordList tmp = neighbours(p); for (CoordList::const_iterator it=tmp.begin(); it!=tmp.end(); ++it) if ( state(*it)!=Uncovered ) n.append(*it); return n; } uint BaseField::nbMinesAround(const Coord &p) const { uint nb = 0; CoordList n = neighbours(p); for (CoordList::const_iterator it=n.begin(); it!=n.end(); ++it) if ( hasMine(*it) ) nb++; return nb; } void BaseField::reset(uint width, uint height, uint nbMines) { _firstReveal = true; _nbMarked = 0; _nbUncertain = 0; _nbUncovered = 0; _nbMines = nbMines; Case tmp; tmp.mine = false; tmp.state = Covered; resize(width, height); fill(tmp); } bool BaseField::checkField(uint w, uint h, uint nb, const TQString &s) { if ( s.length()!=w*h ) return false; uint n = 0; unsigned int strLength(s.length()); for (uint i=0; i