예제 #1
0
파일: data.hpp 프로젝트: blaf/ditchers
/**
Sets the game client is going to participate in by its ID.
*/
bool Client::setGame(int gameid){
    if (gameid == 0){
        Game* gm = 0;
        setGame(gm);
        return true;
    }else if ((games.find(gameid) != games.end()) && (!games[gameid]->started)){
        setGame(games[gameid]);
        return true;
    }else return false;
}
예제 #2
0
void MainWindow::restart()
{

    itemList.clear();
    setparam();
    setGame();


}
예제 #3
0
void SelectLevel::init(Game* game)
{
	// Important to set the game for changeState() to work!
	setGame(game);

	mMenu = new Menu("SelectLevelMenu", NavigationType::MOUSE, HOR); 
	mMenu->setSize(600, 400, 256, 512);

	// [NOTE] It's actually World that should deletes the spawners, but since theres no World in the menu we have to do it manually.
	// Very poorly structured...
	gLevelHandler->deleteSpawners();
	gLevelHandler->loadLevels();

	for(int i = 0; i < gLevelHandler->getNumLevels(); i++) {
		string name = gLevelHandler->getLevel(i)->getName();
		LevelItem* item = new LevelItem(name, "data/imgs/buttons/level_standard_text.png", "data/imgs/buttons/level_glow_text.png", "data/imgs/buttons/level_invalid_text.png");
		item->waves = gLevelHandler->getLevel(i)->getNumWaves();
		item->completedWaves = gLevelHandler->getLevel(i)->getCompletedWaves();

		// Not the first level.
		if(i != 0) {
			Level* lastLevel = gLevelHandler->getLevel(i-1);
			if(lastLevel->getCompletedWaves() < lastLevel->getNumWaves())
				item->state = INACTIVE;
		}

		mMenu->addMenuItem(item);
	}

	mMenu->buildMenu(128*1.2, 70*1.2);
	mMenu->connect(&SelectLevel::menuMessage, this);

	// Side menu.
	mSideMenu = new Menu("SideMenu", NavigationType::MOUSE, HOR); 
	mSideMenu->setSize(1000, 700, 256, 512);
	MenuItem* item = new MenuItem("MainMenu", "data/imgs/buttons/back_standard.png", "data/imgs/buttons/back_glow.png");
	mSideMenu->addMenuItem(item);
	mSideMenu->buildMenu(116*1.5, 50*1.5);
	mSideMenu->connect(&SelectLevel::menuMessage, this);

	// Create the world.
	mWorld = new World();
	mLight = new Light(D3DXVECTOR3(0, 25, 0), D3DXVECTOR3(0, -1, 0), Material(WHITE, 0), 32, 1600.0f);
	mWorld->addLight(mLight); 
	mWorld->addAmbientLight(D3DCOLOR_ARGB(200, 100, 100, 100));

	// Set the graphics light list.
	gGraphics->setLightList(mWorld->getLights());

	mLogo = gGraphics->loadTexture("data/imgs/logo.png");

	// Setup the camera.
	gCamera->setPosition(D3DXVECTOR3(0, 5000, 0));
	gCamera->setDirection(D3DXVECTOR3(0, -0.6, 0.4));
}
예제 #4
0
void MainWindow::showEvent(QShowEvent *)
{
    setparam();
    setGame();
    // Timer
    connect(&timer,SIGNAL(timeout()),this,SLOT(tick()));
    connect(this,SIGNAL(quitGame()),this,SLOT(QUITSLOT()));
    timer.start(100/6);


}
예제 #5
0
LRESULT CGreedySnakeView::OnGoodbye(WPARAM wParam, LPARAM lParam)
{
	m_bClose = FALSE;
	m_pDlg->DestroyWindow();
	setGame();

	//Manager::theManager()->refreshBlocks();
	//Invalidate(FALSE);
	SetTimer(TIMER1, TIME_RUN_INTERVAL, NULL);
	SetTimer(TIMER2, TIME_SWITCH_MAP, NULL);
	return 0L;
}
예제 #6
0
void PlayingOnline::init(Game* game)
{
	// important!
	setGame(game);

	mPeer			= new Peer();
	mBkgd			= gGraphics->loadTexture("imgs\\bkgd.bmp");
	mPlayer			= new OnlinePlayer(WHITE);
	mGui			= new GUI();
	mChangeState	= false;

	mGui->setPlayer(mPlayer);
	mPeer->setPlayer(mPlayer);
	mPeer->setGui(mGui);
	mPlayer->setGui(mGui);
}
예제 #7
0
void MainMenu::init(Game* game)
{
	// Important to set the game for changeState() to work!
	setGame(game);

	// Create the menu.
	mMenu = new Menu("MainMenu", NavigationType::MOUSE, HOR); 
	mMenu->setSize(880, 700, 256, 512);
	mMenu->addMenuItem(new MenuItem("SelectLevel", "data/imgs/buttons/play_standard.png", "data/imgs/buttons/play_glow.png"));
	mMenu->addMenuItem(new MenuItem("About", "data/imgs/buttons/about_standard.png", "data/imgs/buttons/about_glow.png"));
	mMenu->addMenuItem(new MenuItem("Quit", "data/imgs/buttons/quit_standard.png", "data/imgs/buttons/quit_glow.png"));
	mMenu->buildMenu(116*1.5, 50*1.5);
	mMenu->connect(&MainMenu::menuMessage, this);

	// Side menu.
	mAboutMenu = new Menu("SideMenu", NavigationType::MOUSE, HOR); 
	mAboutMenu->setSize(1000, 700, 256, 512);
	MenuItem* item = new MenuItem("Back", "data/imgs/buttons/back_standard.png", "data/imgs/buttons/back_glow.png");
	mAboutMenu->addMenuItem(item);
	mAboutMenu->buildMenu(116*1.5, 50*1.5);
	mAboutMenu->connect(&MainMenu::menuMessage, this);

	// Create the world.
	mWorld = new World();
	mLight = new Light(D3DXVECTOR3(0, 25, 0), D3DXVECTOR3(0, -1, 0), Material(WHITE, 0), 32, 1600.0f);
	mWorld->addLight(mLight); 
	mWorld->addAmbientLight(D3DCOLOR_ARGB(200, 100, 100, 100));

	mLogo = gGraphics->loadTexture("data/imgs/logo.png");
	mAboutTexture = gGraphics->loadTexture("data/imgs/about.png");

	// Set the graphics light list.
	gGraphics->setLightList(mWorld->getLights());

	// Setup the camera.
	gCamera->setPosition(D3DXVECTOR3(0, 5000, 0));
	gCamera->setDirection(D3DXVECTOR3(0, -0.6, 0.4));

	ShowCursor(true);

	gSound->muteMusic(false);
	gSound->playMusic("data/sound/menu_loop.wav", true, 0);
	gSound->setVolume(0.15f);

	mShowingAbout = false;
}
예제 #8
0
파일: GameScene.cpp 프로젝트: woodpile/Mine
//创建一个新的游戏
void GameScene::createNewGame(void)
{
    int width = 5, heigh = 5;
    
    //初始化游戏地图
    if (nullptr != _map)
    {
        delete _map;
        _map = nullptr;
    }
    _map = new MMap(width, heigh);
    _map->setBombProbability(2000);
    _map->randRefresh();
    
    //计算地图边界
    auto mapsize = _backgroud->getContentSize();
    
    auto boxsize = Director::getInstance()->getTextureCache()->getTextureForKey("blue.png")->getContentSize();
    int edgew = ((int)(mapsize.width - width * boxsize.width) / 2) + (int)(boxsize.width) / 2;
    int edgeh = ((int)(mapsize.height - heigh * boxsize.height) /2) -
                (int)(boxsize.height) / 2 + heigh * boxsize.height;
    log("edge w %d, h %d", edgew, edgeh);
    
    //根据地图画出格子
    for (int h = 0; h < heigh; h++)
    {
        for (int w = 0; w < width; w++)
        {
            //创建一个格子
            auto box = MBox::create();
            box->setPosition(edgew + boxsize.width * w, edgeh - boxsize.height * h);
            auto boxid = GameScene::BASE_BOX_ID + h * width + w;
            _backgroud->addChild(box, 1, boxid);
            //设置格子的属性
            box->setBoxId(boxid);
            box->setMPos(w, h);
            auto boxAttrib = _map->getDate(w, h);
            box->setAttr(boxAttrib.num, (MBombType)boxAttrib.bomb);
            //设置关联
            box->setGame(this);
        }
    }
    
    return;
}
예제 #9
0
void LobbyState::init(Game* game)
{
	// Important!
	setGame(game);

	mServerList = NULL;
	
	mBkgd = gGraphics->loadTexture("imgs\\bkgd.bmp");
	mLogo = gGraphics->loadTexture("imgs\\logo.bmp");

	// Prompt the login dialog.
	DialogBox(gGame->getAppInst(), MAKEINTRESOURCE(IDD_DIALOG1), gGame->getMainWnd(), (DLGPROC)DlgProc);
		
	if(!changedState)	{
		mServerList = new ServerList(345, 240, 400, 400);
	}
	else
		changedState = false;
}
예제 #10
0
KReversiView::KReversiView(KReversiGame* game, QWidget *parent, KgThemeProvider *provider) :
    KgDeclarativeView(parent), m_delay(ANIMATION_SPEED_NORMAL), m_game(0),
    m_showLastMove(false), m_showLegalMoves(false),
    m_showLabels(false), m_provider(provider)
{
    m_provider->setDeclarativeEngine("themeProvider", engine());

    qmlRegisterType<ColorScheme>("ColorScheme", 1, 0, "ColorScheme");

    QString path =
        KStandardDirs::locate("appdata", QLatin1String("qml/Table.qml"));
    setSource(QUrl::fromLocalFile(path));

    m_qml_root = (QObject*) rootObject();
    rootContext()->setContextProperty("container", this);

    connect(m_qml_root, SIGNAL(cellClicked(int,int)),
            this, SLOT(onPlayerMove(int,int)));
    setGame(game);
}
예제 #11
0
파일: LocalState.cpp 프로젝트: fobnn/Banzai
void LocalState::init(Game* game)
{
	// important!
	setGame(game);

	mBkgd			= gGraphics->loadTexture("imgs\\bkgd.bmp");
	mGreyBkgd		= gGraphics->loadTexture("imgs\\grey_bkgd.bmp");

	mBoard			= new Board(80);
	mActivePlayer	= new LocalPlayer(WHITE);
	mPlayer2		= new LocalPlayer(BLACK);
	mPiecesCaptured = new PiecesCaptured(700, 40);

	// Both players uses the same board
	mActivePlayer->setBoard(mBoard);
	mPlayer2->setBoard(mBoard);
	mSelectedPiece	= NULL;

	// Create the status text
	mStatusText		=	StatusText("Invalid position!", 675, 220, 0.0f);
	gSound->playEffect(NEW_GAME_SOUND);
}
예제 #12
0
void CGreedySnakeView::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (m_bClose == FALSE && nIDEvent == TIMER1)
	{
		if(!Manager::theManager()->isAllDead())
		{
			Manager::theManager()->refresh();
			Invalidate(FALSE);
		}
		else
		{
			m_bClose = TRUE;
			drawGameOver();
			/*if(Manager::theManager()->initialGame())
			{
				setGame();
				Invalidate(FALSE);
			}*/
		}
	}
	else if(m_bClose == FALSE && nIDEvent == TIMER2)
	{
		if(Manager::theManager()->initialGame())
		{
			setGame();
			Invalidate(FALSE);
		}
		else
		{
			m_bClose = TRUE;
			drawGameOver();
		}
	}

	CView::OnTimer(nIDEvent);
}
예제 #13
0
void CampaignLevelState::init(Game* game)
{
	// important!
	setGame(game);

	// create the menu
	//mCampaignLevelMenu = new Menu("CustemLevelMenu", MOUSE, true, 4, 4);
	mCampaignLevelMenu = new Menu("CustemLevelMenu", MOUSE, VER, 2, true, 4, 4);
	mCampaignLevelMenu->setMenuBackground("none", 700, 450, 256, 350);		// mCampaignLevelMenu->setMenuBackground("misc\\textures\\menu_bkgd.bmp", 700, 450, 256, 350);

	// get the files in the map folder
	std::vector<string> levelList = getLevels();

	// load the campaign progress
	mProgress.loadProgress("levels\\campaign\\campaign_progress.txt");

	// add menu items, each level
	for(int i = 0; i < levelList.size(); i++)
	{
		// remove .txt
		if(levelList[i].find(".txt") != string::npos || levelList[i].find(".TXT") != string::npos)
			levelList[i].erase(levelList[i].end()-4,levelList[i].end()); 

		if(mProgress.getProgress(levelList[i]).playable == 0)	{
			mCampaignLevelMenu->addMenuItem(levelList[i], (char*)GRAY_BUTTON_NORMAL_SOURCE.c_str(), (char*)GRAY_BUTTON_HOOVER_SOURCE.c_str());
			mCampaignLevelMenu->setPressable(levelList[i], false);
		}
		else
			mCampaignLevelMenu->addMenuItem(levelList[i], "misc\\textures\\level_menu_normal.bmp", "misc\\textures\\level_menu_hoover.bmp");
	}

	// build the menu
	mCampaignLevelMenu->buildMenu2();
	mCampaignLevelMenu->connect(&CampaignLevelState::menuHandler, this);

	mBackgroundTexture = gGraphics->loadTexture("misc\\textures\\epic_bkgd.bmp");
}
예제 #14
0
KReversiView::~KReversiView()
{
    setGame(0);
}
예제 #15
0
파일: grid.cpp 프로젝트: nkgeorgiev/FMI
void Grid::openMine(int id){
    int i=id/n;
    int j=id%n;
    if(cnt==0){
       *grid=generateMines(i,j,x,*grid);
    }
    QAbstractButton *current=button[i][j];
    QString text=QString::number(numberOfMines(i,j,grid));
    if(arr[i][j]==0){
        if(grid->at(i)[j]==0){
            if(text=="0"){
                 openZeroes(i,j,grid);

            } else {
                arr[i][j]=1;
                cnt++;
                current->setText(text);
                setColor(i,j,text);

                //current->setDisabled(true);
            }
        }
        else{
            //Lose

            for(int i=0;i<m;i++){
                for(int j=0;j<n;j++){
                    if(arr[i][j]!=1){
                        if(grid->at(i)[j]==0){
                            arr[i][j]=1;                          
                            button[i][j]->setText(QString::number(numberOfMines(i,j,grid)));
                            setColor(i,j,QString::number(numberOfMines(i,j,grid)));

                            //button[i][j]->setDisabled(true);
                       } else
                        button[i][j]->setIcon(QIcon("mine_logo.gif"));
}
                }
            }
            QDialog *Qlose=new QDialog();
            Ui_DialogLose *lose=new Ui_DialogLose();
            lose->setupUi(Qlose);
            Qlose->show();
            QObject::connect(Qlose,SIGNAL(accepted()),this,SLOT(setGame()));

        }
        //Win
        if(cnt==m*n-x){
            QDialog *Qwin=new QDialog();
            Ui_DialogWin *win=new Ui_DialogWin();
            win->setupUi(Qwin);
            Qwin->show();

            QObject::connect(Qwin,SIGNAL(accepted()),this,SLOT(setGame()));
        }
    }
    else if(arr[i][j]==1){
        int count=0;
        for(int a=i-1;a<=i+1;a++){
            for(int b=j-1;b<=j+1;b++){
                if(!(a<0 || a>=m || b<0 || b>=n) && arr[a][b]==2){
                    count++;
                }
            }
        }
        /*
        std::cout<<count<<endl;
        for(int p=0;p<m;p++){
            for(int q=0;q<n;q++)
                cout<<arr[p][q]<<" ";
            cout<<endl;
        }
        */

        if(QString::number(count)==button[i][j]->text()){
            for(int a=i-1;a<=i+1;a++)
                for(int b=j-1;b<=j+1;b++)
                    if(!(a<0 || a>=m || b<0 || b>=n) && arr[a][b]==0)
                        openMine(a*n+b);
        }
    }

}
예제 #16
0
CommentView::CommentView(QWidget *parent, SgfGame* gm) :
    QPlainTextEdit(parent)
{
	m_game = 0;
	setGame(gm);
}
예제 #17
0
Game::Game( int& numberPlayers, const string yourName, const bool automatic )
  : indexToBid(-1), indexBidder(0), kingFound(false), chelemAnnounced(false), addDogAtTheEnd(false), toSwap(false), foolGiver(nullptr), foolReceiver(nullptr)
{
  setGame( numberPlayers, yourName, automatic );
}