File indexing completed on 2024-11-24 03:43:17
0001 /******************************************************************* 0002 * 0003 * Copyright 2009 Pelladi Gabor <pelladigabor@gmail.com> 0004 * 0005 * Bovo is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2, or (at your option) 0008 * any later version. 0009 * 0010 * Bovo is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with Bovo; see the file COPYING. If not, write to 0017 * the Free Software Foundation, 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 * 0020 ********************************************************************/ 0021 0022 0023 /** 0024 * @file aifactory.cc implementing the AiFactory class 0025 */ 0026 0027 #include "aifactory.h" 0028 #include "ai.h" 0029 #include "aron/aiaron.h" 0030 #include "gabor/aigabor.h" 0031 0032 0033 /** namespace for AI stuff */ 0034 namespace ai { 0035 0036 AiFactory::AiFactory() { 0037 m_aiList.append(QStringLiteral("Gabor")); 0038 m_aiList.append(QStringLiteral("Aron")); 0039 m_ai = 0; 0040 } 0041 0042 AiFactory::~AiFactory() = default; 0043 0044 Ai* AiFactory::createAi(const Dimension& dimension, KGameDifficultyLevel::StandardLevel skill, 0045 Player player, DemoMode demoMode) const { 0046 if (demoMode == Demo) { 0047 return new AiAron(dimension, skill, player); 0048 } else { 0049 if (m_ai == 0) { 0050 return new AiGabor(dimension, skill, player); 0051 } else if (m_ai == 1) { 0052 return new AiAron(dimension, skill, player); 0053 } else { 0054 qFatal("Invalid AI!"); 0055 return nullptr; 0056 } 0057 } 0058 } 0059 0060 const QStringList& AiFactory::aiList() const { 0061 return m_aiList; 0062 } 0063 0064 int AiFactory::ai() const { 0065 return m_ai; 0066 } 0067 0068 void AiFactory::changeAi(int ai) { 0069 if (0 <= ai && ai < m_aiList.size()) { 0070 m_ai = ai; 0071 } 0072 } 0073 0074 } /* namespace ai */ 0075 0076 #include "moc_aifactory.cpp"