1 | /******************************************************************* |
2 | * |
3 | * Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com> |
4 | * Copyright 2013 Denis Kuplyakov <dener.kup@gmail.com> |
5 | * |
6 | * This file is part of the KDE project "KReversi" |
7 | * |
8 | * KReversi is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2, or (at your option) |
11 | * any later version. |
12 | * |
13 | * KReversi is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with KReversi; see the file COPYING. If not, write to |
20 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
21 | * Boston, MA 02110-1301, USA. |
22 | * |
23 | ********************************************************************/ |
24 | #include <commondefs.h> |
25 | |
26 | #include <KLocale> |
27 | |
28 | |
29 | static QString chipPrefixString[2] = {"chip_bw" , "chip_color" }; |
30 | |
31 | QString Utils::chipPrefixToString(ChipsPrefix prefix) { |
32 | return chipPrefixString[prefix]; |
33 | } |
34 | |
35 | ChipColor Utils::opponentColorFor(ChipColor color) |
36 | { |
37 | if (color == NoColor) |
38 | return NoColor; |
39 | else |
40 | return (color == White ? Black : White); |
41 | } |
42 | |
43 | |
44 | QString Utils::colorToString(const ChipColor &color) |
45 | { |
46 | if (Preferences::useColoredChips()) |
47 | return (color == Black ? i18n("Blue" ) : i18n("Red" )); |
48 | return (color == Black ? i18n("Black" ) : i18n("White" )); |
49 | } |
50 | |
51 | QString Utils::moveToString(const KReversiMove& move) |
52 | { |
53 | QString moveString = colorToString(move.color); |
54 | |
55 | const char labelsHor[] = "ABCDEFGH" ; |
56 | const char labelsVer[] = "12345678" ; |
57 | |
58 | moveString += QLatin1Char(' '); |
59 | moveString += QLatin1Char(labelsHor[move.col]); |
60 | moveString += QLatin1Char(labelsVer[move.row]); |
61 | |
62 | return moveString; |
63 | } |
64 | |
65 | int Utils::difficultyLevelToInt() |
66 | { |
67 | |
68 | for (int i = 0; i < Kg::difficulty()->levels().size(); i++) |
69 | if (Kg::difficultyLevel() |
70 | == Kg::difficulty()->levels()[i]->standardLevel()) |
71 | return i; |
72 | |
73 | return -1; |
74 | } |
75 | |
76 | const KgDifficultyLevel *Utils::intToDifficultyLevel(int skill) |
77 | { |
78 | return Kg::difficulty()->levels()[skill]; |
79 | } |
80 | |