⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reversi.cpp

📁 Siemens 的SIMpad是一个多媒体设备
💻 CPP
字号:
/* * Copyright (C) 2002 Robert Ernst <robert.ernst@linux-solutions.at> * * This file may be distributed and/or modified under the terms of the * GNU General Public License version 2 as published by the Free Software * Foundation and appearing in the file LICENSE.GPL included in the * packaging of this file. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * See COPYING for GPL licensing information. * */#include <qpe/qpemenubar.h>#include <qpe/config.h>#include <qapplication.h>#include <qmainwindow.h>#include <qpopupmenu.h>#include <qtimer.h>#include "PlayField.h"#include "Reversi.h"#include <stdlib.h>#include <time.h>Reversi::Reversi(QWidget *parent, const char *name, WFlags f) :    QMainWindow(parent, name, f){    /* initialize random number generator */    srand(::time(0));    /* set window style and caption */    setCaption(tr("Reversi"));    /* create the play field as the central widget */    m_field = new PlayField(this);    setCentralWidget(m_field);    m_field->show();    /* create the game/strength submenu */    m_strengthMenu = new QPopupMenu(0, "strength_menu");    connect(m_strengthMenu, SIGNAL(activated(int)), this, SLOT(updateStrength(int)));    connect(m_strengthMenu, SIGNAL(activated(int)), m_field, SLOT(updateStrength(int)));    m_strengthMenu->setCheckable(true);    m_strengthMenu->insertItem(tr("Easy"), 2);    m_strengthMenu->insertItem(tr("Normal"), 4);    m_strengthMenu->insertItem(tr("Difficult"), 6);    m_strengthMenu->insertItem(tr("Hard"), 8);    m_strengthMenu->insertItem(tr("Insane"), 10);    /* create the game/animations submenu */    m_animationsMenu = new QPopupMenu(0, "animations_menu");    connect(m_animationsMenu, SIGNAL(activated(int)), this, SLOT(updateAnimations(int)));    connect(m_animationsMenu, SIGNAL(activated(int)), m_field, SLOT(updateAnimations(int)));    m_animationsMenu->setCheckable(true);    m_animationsMenu->insertItem(tr("No"), 0);    m_animationsMenu->insertItem(tr("Yes"), 1);    /* create the game/computer_begins submenu */    m_computerBeginsMenu = new QPopupMenu(0, "computer_begins_menu");    connect(m_computerBeginsMenu, SIGNAL(activated(int)), this, SLOT(updateComputerBegins(int)));    connect(m_computerBeginsMenu, SIGNAL(activated(int)), m_field, SLOT(updateComputerBegins(int)));    m_computerBeginsMenu->setCheckable(true);    m_computerBeginsMenu->insertItem(tr("Player"), 0);    m_computerBeginsMenu->insertItem(tr("Computer"), 1);    /* create the game submenu */    QPopupMenu *gameMenu = new QPopupMenu(0, "game_menu");    gameMenu->insertItem(tr("New"), m_field, SLOT(start()));    gameMenu->insertItem(tr("Back"), m_field, SLOT(back()));    gameMenu->insertItem(tr("Hint"), m_field, SLOT(hint()));    gameMenu->insertSeparator();    gameMenu->insertItem(tr("Strength"), m_strengthMenu);    gameMenu->insertItem(tr("Animations"), m_animationsMenu);    gameMenu->insertItem(tr("Beginner"), m_computerBeginsMenu);    gameMenu->insertSeparator();    gameMenu->insertItem(tr("Close"), this, SLOT(close()));    /* create the menu */    QPEMenuBar *menu = new QPEMenuBar(this);    menu->insertItem(tr("Game"), gameMenu);    /* read the configuration file */    readConfig();    /* check the menu entries of game submenus */    m_strengthMenu->setItemChecked(m_strength, true);    m_animationsMenu->setItemChecked(m_animations, true);    m_computerBeginsMenu->setItemChecked(m_computerBegins, true);}Reversi::~Reversi(){    writeConfig();}void Reversi::readConfig(void){    Config cfg("Reversi");    cfg.setGroup("Settings");    int strength = cfg.readNumEntry("Strength", 4);    if (strength <= 2) {	m_strength = 2;    } else if (strength <= 4) {	m_strength = 4;    } else if (strength <= 6) {	m_strength = 6;    } else if (strength <= 8) {	m_strength = 8;    } else {	m_strength = 10;    }    m_field->updateStrength(m_strength);    m_animations = cfg.readNumEntry("Animations", 1) ? true : false;    m_computerBegins = cfg.readNumEntry("Beginner", 0) ? true : false;    m_field->updateComputerBegins(m_computerBegins);}void Reversi::writeConfig(void){    Config cfg("Reversi");    cfg.setGroup("Settings");    cfg.writeEntry("Strength", m_strength);    cfg.writeEntry("Animations", m_animations);    cfg.writeEntry("Beginner", m_computerBegins);}void Reversi::updateStrength(int strength){    m_strengthMenu->setItemChecked(m_strength, false);    m_strength = strength;    m_strengthMenu->setItemChecked(m_strength, true);    writeConfig();}void Reversi::updateAnimations(int animations){    m_animationsMenu->setItemChecked(m_animations, false);    m_animations = animations ? true : false;    m_animationsMenu->setItemChecked(m_animations, true);    writeConfig();}void Reversi::updateComputerBegins(int computerBegins){    m_computerBeginsMenu->setItemChecked(m_computerBegins, false);    m_computerBegins = computerBegins ? true : false;    m_computerBeginsMenu->setItemChecked(m_computerBegins, true);    writeConfig();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -