• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kigo

  • sources
  • kde-4.14
  • kdegames
  • kigo
  • src
  • game
score.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2008 Sascha Peilicke <sasch.pe@gmx.de>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License as
6  published by the Free Software Foundation; either version 2 of
7  the License or (at your option) version 3 or any later version
8  accepted by the membership of KDE e.V. (or its successor approved
9  by the membership of KDE e.V.), which shall act as a proxy
10  defined in Section 14 of version 3 of the license.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "score.h"
22 
23 namespace Kigo {
24 
25 Score::Score(const QString &score)
26  : m_color('?'), m_score(0), m_lowerBound(0), m_upperBound(0)
27 {
28  if (score.size() >= 2) {
29  if (score[0] == 'W') {
30  m_color = 'W';
31  } else if (score[0] == 'B') {
32  m_color = 'B';
33  }
34  int i = score.indexOf(' ');
35  m_score = score.mid(2, i - 1).toFloat();
36  QString upperBound = score.section(' ', 3, 3);
37  upperBound.chop(1);
38  m_upperBound = upperBound.toFloat();
39  QString lowerBound = score.section(' ', 5, 5);
40  lowerBound.chop(1);
41  m_lowerBound = lowerBound.toFloat();
42  }
43 }
44 
45 Score::Score(const Score &other)
46  : QObject(), m_color(other.m_color), m_score(other.m_score)
47  , m_lowerBound(other.m_lowerBound), m_upperBound(other.m_upperBound)
48 {
49 }
50 
51 Score &Score::operator=(const Score &other)
52 {
53  m_color = other.m_color;
54  m_score = other.m_score;
55  m_lowerBound = other.m_lowerBound;
56  m_upperBound = other.m_upperBound;
57  return *this;
58 }
59 
60 bool Score::isValid() const
61 {
62  return m_score >= 0 && (m_color == 'W' || m_color == 'B');
63 }
64 
65 QString Score::toString() const
66 {
67  QString ret(m_color + '+');
68  ret += QString::number(m_score) + " (" + QString::number(m_lowerBound) + " - " + QString::number(m_upperBound) + ')';
69  return ret;
70 }
71 
72 } // End of namespace Kigo
73 
74 #include "moc_score.cpp"
Kigo::Score
This class represents a Go score for either player.
Definition: score.h:38
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
Kigo::Score::toString
QString toString() const
Definition: score.cpp:65
Kigo::Score::operator=
Score & operator=(const Score &other)
Definition: score.cpp:51
QString::size
int size() const
QString::chop
void chop(int n)
QString::number
QString number(int n, int base)
QObject
QString
Kigo::Score::isValid
bool isValid() const
Definition: score.cpp:60
score.h
QString::mid
QString mid(int position, int n) const
QString::toFloat
float toFloat(bool *ok) const
QString::section
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:29 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kigo

Skip menu "kigo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal