-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManager.cpp
More file actions
56 lines (48 loc) · 1.69 KB
/
GameManager.cpp
File metadata and controls
56 lines (48 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "GameManager.h"
#include <QDebug>
GameManager::GameManager(const IWordSource& wordSource)
: m_wordSource(wordSource)
, m_guessCount(0)
{
}
void GameManager::newGame()
{
m_secretWord = m_wordSource.getWord().toUpper();
m_guessCount = 0; // Her yeni oyunda tahmin sayısını sıfırla
qDebug() << "Yeni oyun basladi. Gizli kelime:" << m_secretWord;
}
QString GameManager::getSecretWord() const
{
return m_secretWord;
}
GuessResult GameManager::submitGuess(const QString& guess)
{
QString upperGuess = guess.toUpper();
GuessResult finalResult;
finalResult.letterResults.fill(LetterResult::NotInWord, GameConfig::WORD_LENGTH);
// Renk hesaplama algoritması (değişiklik yok)
QString tempSecretWord = m_secretWord;
for (int i = 0; i < GameConfig::WORD_LENGTH; ++i) {
if (upperGuess[i] == tempSecretWord[i]) {
finalResult.letterResults[i] = LetterResult::CorrectPosition;
tempSecretWord[i] = '-';
}
}
for (int i = 0; i < GameConfig::WORD_LENGTH; ++i) {
if (finalResult.letterResults[i] != LetterResult::CorrectPosition) {
int foundIndex = tempSecretWord.indexOf(upperGuess[i]);
if (foundIndex != -1) {
finalResult.letterResults[i] = LetterResult::WrongPosition;
tempSecretWord[foundIndex] = '-';
}
}
}
m_guessCount++; // Tahmin yapıldı, sayacı artır
// Kazanma/Kaybetme durumunu kontrol et
if (upperGuess == m_secretWord) {
finalResult.gameState = GameState::Won;
} else if (m_guessCount >= GameConfig::MAX_GUESSES) {
finalResult.gameState = GameState::Lost;
}
return finalResult;
}