Пример #1
0
void XeenEngine::outerGameLoop() {
	if (_loadSaveSlot != -1)
		// Loading savegame from launcher, so Skip menu and go straight to game
		_gameMode = GMODE_PLAY_GAME;

	while (!shouldQuit() && _gameMode != GMODE_QUIT) {
		GameMode mode = _gameMode;
		_gameMode = GMODE_NONE;
		assert(mode != GMODE_NONE);

		switch (mode) {
		case GMODE_STARTUP:
			showStartup();
			break;

		case GMODE_MENU:
			showMainMenu();
			break;

		case GMODE_PLAY_GAME:
			playGame();
			break;

		default:
			break;
		}
	}
}
Пример #2
0
void Game::showGameOverMenu(int player_id) {
    int n = scene->items().size();
    for(int i = 0; i < n; i++) {
        scene->items()[i]->setEnabled(false);
    }
    drawPanel(0, 0, 1024, 768, QColor(Qt::lightGray), 0.65);
    drawPanel(1024/2 - 200,200,400,400,QColor(Qt::darkGray), 0.85);
    QGraphicsTextItem *lbl_go_text = new LabelItem("Konec hry", 0, 0);
    lbl_go_text->setPos(scene->width()/2 - lbl_go_text->boundingRect().width()/2, 250);
    scene->addItem(lbl_go_text);
    QGraphicsTextItem *lbl_player_won = new LabelItem(QString("Vyhral hrac c. %1").arg(player_id), 0, 0);
    lbl_player_won->setPos(scene->width()/2 - lbl_player_won->boundingRect().width()/2, 275);
    scene->addItem(lbl_player_won);
    Button *restart_btn = new Button(QString("Hrat znovu"));
    int x = scene->width()/2 - restart_btn->boundingRect().width()/2;
    int y = 325;
    restart_btn->setPos(x, y);
    connect(restart_btn, SIGNAL(clicked()), this, SLOT(startGame()));
    scene->addItem(restart_btn);

    Button *back_to_menu_btn = new Button(QString("Vratit do menu"));
    x = scene->width()/2 - back_to_menu_btn->boundingRect().width()/2;
    y += 75;
    back_to_menu_btn->setPos(x, y);
    connect(back_to_menu_btn, SIGNAL(clicked()), this, SLOT(showMainMenu()));
    scene->addItem(back_to_menu_btn);

    Button *exit_btn = new Button(QString("Konec"));
    x = scene->width()/2 - exit_btn->boundingRect().width()/2;
    y += 75;
    exit_btn->setPos(x, y);
    connect(exit_btn, SIGNAL(clicked()), this, SLOT(close()));
    scene->addItem(exit_btn);
}
Пример #3
0
void systemTrayIcon::systemTrayIconActivated(QSystemTrayIcon::ActivationReason enActivationReason)
{
    if (Context == enActivationReason)
    {
        emit showMainMenu();
    }
    else if (DoubleClick == enActivationReason)
    {
        if (!m_strID.isEmpty())
        {
            emit showUserMessage(m_strID);
        }
    }
    else if (Trigger == enActivationReason)
    {
        if (!m_strID.isEmpty())
        {
            emit showUserMessage(m_strID);
        }
        else
        {
            emit showMainWindow();
        }
    }
}
Пример #4
0
void InterfaceLogic::leaderboardUpdate()
{
  if (leaderboardLogic.update() == LeaderboardLogic::resClose)
  {
    if (!statesStack.empty())
      goPreviousState();
    else
      showMainMenu();
  }
}
Пример #5
0
    void GuiManager::updateGui(bool paused)
    {
        if(paused)
        {
            if(currentGuiType() == TitleScreen)
            {
                static const int WAIT_TIME = 7000;

                auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch() - mStartTime.time_since_epoch()).count();
                if(duration > WAIT_TIME)
                {
                    showMainMenu();
                    mCurrentGuiType = Other;
                }
            }
            else if(currentGuiType() == Credits)
            {
                mCreditsScrollBox->update();
                if(mCreditsScrollBox->isFinished())
                {
                    showMainMenu();
                    mCurrentGuiType = Other;
                }
            }

            // Process event from queue

            if(!mStateQueue.empty())
            {
                switch(mStateQueue.front())
                {
                    case FadeIn:
                        updateFadeIn();
                        break;
                    case FadeOut:
                        updateFadeOut();
                        break;
                }
            }

        }
    }
Пример #6
0
void GameManager::clickedPlay()
{
    lobby = new Lobby;


    connect(lobby, SIGNAL(c_exit()), this, SLOT(showMainMenu()));
    connect(lobby, SIGNAL(c_go()), this, SLOT(startGame()));

    connect(lobby, SIGNAL(c_exit()), this, SLOT(removeLobby()));
    connect(lobby, SIGNAL(c_go()), this, SLOT(removeLobby()));
}
Пример #7
0
void GameManager::endGame(Bike *winner)
{
    GameOverScreen *gos = new GameOverScreen(winner?QString::fromStdString(winner->getName()):"Draw");
    MainFrame::showOverlay(gos);

    //connect cleanup
    connect(gos, SIGNAL(exit()), this, SLOT(cleanGame()));
    connect(gos, SIGNAL(rematch()), this, SLOT(cleanGame()));
    //connect action
    connect(gos, SIGNAL(exit()), this, SLOT(showMainMenu()));
    connect(gos, SIGNAL(rematch()), this, SLOT(startGame()));
}
Пример #8
0
static void doMenu()
{
	if (menuInput.attack == TRUE || input.attack == TRUE)
	{
		playSound("sound/common/click");

		showMainMenu();
	}

	memset(&menuInput, 0, sizeof(Input));
	memset(&input, 0, sizeof(Input));
}
Пример #9
0
UIManager::UIManager() {
    mainWindow = new MainWindow();
    mainMenu = new MainMenu(mainWindow);
    navigationWindow = new NavigationWindow(mainWindow);
    settingsWindow = new SettingsForm(mainWindow);

    mainWindow->layout()->addWidget(mainMenu);
    mainWindow->layout()->addWidget(navigationWindow);
    mainWindow->layout()->addWidget(settingsWindow);
    toolbox = new ToolBox(navigationWindow);

    QObject::connect(mainWindow, SIGNAL(geometryChanged(QRect)), this, SLOT(mainWindowGeometryChanged(QRect)));
    QObject::connect(navigationWindow, SIGNAL(goBack()), this, SLOT(showMainMenu()));
    QObject::connect(navigationWindow, SIGNAL(toolboxButtonClicked()), this, SLOT(toggleToolbox()));
    QObject::connect(mainMenu, SIGNAL(close()), this, SLOT(close()));
    QObject::connect(mainMenu, SIGNAL(showChart()), this, SLOT(showChartWindow()));
    QObject::connect(mainMenu, SIGNAL(showSettings()), this, SLOT(showSettingsWindow()));
    QObject::connect(settingsWindow, SIGNAL(goBack()), this, SLOT(showMainMenu()));

    connectInstruments();
    mainWindow->show();
}
Пример #10
0
void GTMenuPrivate::checkMainMenuItemState(GUITestOpStatus &os, const QStringList &itemPath, PopupChecker::CheckOption expectedState) {
    GT_CHECK(itemPath.count() > 1, QString("Menu item path is too short: { %1 }").arg(itemPath.join(" -> ")));

#ifdef Q_OS_MAC
    GTMenuPrivateMac::checkMainMenuItemState(os, itemPath, expectedState);
#else
    QStringList cuttedItemPath = itemPath;
    const QString menuName = cuttedItemPath.takeFirst();
    GTUtilsDialog::waitForDialog(os, new PopupCheckerByText(os, cuttedItemPath, expectedState, GTGlobals::UseMouse));
    showMainMenu(os, menuName, GTGlobals::UseMouse);
    GTGlobals::sleep(100);
#endif
}
Пример #11
0
void GameManager::pause()
{
    Ticker::stop();

    playArea->enableKeys(false);
    bikes.enableInput(false);
    IngameMenu *im = new IngameMenu;
    MainFrame::showOverlay(im);
    connect(im, SIGNAL(resume()), this, SLOT(resume()));
    connect(im, SIGNAL(options()), this, SLOT(clickedOptions()));

    connect(im, SIGNAL(exit()), this, SLOT(cleanGame()));
    connect(im, SIGNAL(exit()), this, SLOT(showMainMenu()));
}
Пример #12
0
Файл: jeu.c Проект: Shayli/ITD
int startMenu()
{
	int choice;
	do {
		choice = showMainMenu();
		if(choice == MENU_MAP)
		{
			int map = showMapMenu();
			play(map);
		} 
		else if(choice == MENU_HELP)
		{
			showHelpMenu();
		}
	} while(choice != MENU_EXIT);
	return 0;
}
Пример #13
0
void Game::run() {
	if (!showLicenseSplash())
		return;
	if (!showTitle())
		return;
	if (!showMainMenu())
		return;
	if (!showQuote())
		return;
	if (!showChapter1())
		return;

	_module.reset(new Module(*_console));

	runModule();

	_module.reset();
}
Пример #14
0
void Game::run() {
	if (!showLicenseSplash())
		return;
	if (!showTitle())
		return;
	if (!showMainMenu())
		return;
	if (!showQuote())
		return;
	if (!showChapter1())
		return;

	_module = new Module(*_console);

	runModule();

	delete _module;
	_module = 0;
}
Пример #15
0
void Game::showNewGameMenu(){
    scene->clear();

    QGraphicsTextItem *players_lbl = new QGraphicsTextItem(QString("Pocet hracu:"));
    players_lbl->setPos(350, 270);
    scene->addItem(players_lbl);

    players_cbox = new QComboBox;
    players_cbox->addItem(QString("2"));
    players_cbox->addItem(QString("3"));
    players_cbox->addItem(QString("4"));
    players_cbox->move(430, 270);
    scene->addWidget(players_cbox);

    QGraphicsTextItem *board_size_lbl = new QGraphicsTextItem(QString("Velikost desky:"));
    board_size_lbl->setPos(490, 270);
    scene->addItem(board_size_lbl);

    size_cbox = new QComboBox;
    size_cbox->addItem(QString("5"));
    size_cbox->addItem(QString("7"));
    size_cbox->addItem(QString("9"));
    size_cbox->addItem(QString("11"));
    size_cbox->setCurrentIndex(1);
    size_cbox->move(570, 270);
    scene->addWidget(size_cbox);


    Button *play_btn = new Button(QString("Zacit"));
    int x = scene->width()/2 - play_btn->boundingRect().width()/2;
    int y = 360;
    play_btn->setPos(x, y);
    connect(play_btn, SIGNAL(clicked()), this, SLOT(startGame()));
    scene->addItem(play_btn);

    Button *back_btn = new Button(QString("Zpet"));
    x = scene->width()/2 - back_btn->boundingRect().width()/2;
    y += 75;
    back_btn->setPos(x, y);
    connect(back_btn, SIGNAL(clicked()), this, SLOT(showMainMenu()));
    scene->addItem(back_btn);
}
Пример #16
0
static void doMenu()
{
	int xAxisMoved, yAxisMoved;

	if (menuInput.attack == TRUE || input.attack == TRUE)
	{
		playSound("sound/common/click");

		showMainMenu();
	}

	xAxisMoved = input.xAxisMoved;
	yAxisMoved = input.yAxisMoved;

	memset(&menuInput, 0, sizeof(Input));
	memset(&input, 0, sizeof(Input));

	input.xAxisMoved = xAxisMoved;
	input.yAxisMoved = yAxisMoved;
}
Пример #17
0
BoardWindow::BoardWindow(bool game, QObject *parent)
{
  this->parent = parent;
  centralWidget = new QWidget();
  this->setCentralWidget(centralWidget);
  boardLayout = new QGridLayout();
  boardLayout->setHorizontalSpacing(0);
  boardLayout->setVerticalSpacing(0);
  if (game)
  {
    mainMenuAction = this->menuBar()->addAction("Menu główne");
    connect(mainMenuAction, SIGNAL(triggered()), this, SIGNAL(showMainMenu()));

    this->timeWidget = new QLCDNumber(this);

    mainLayout = new QVBoxLayout();

    upperLayout = new QHBoxLayout();
    upperLayout->addStretch(1);
    upperLayout->addWidget(timeWidget);

    mainLayout->addLayout(upperLayout);
    mainLayout->addLayout(boardLayout);
    centralWidget->setLayout(mainLayout);
  } else
  {
    this->upperLayout = nullptr;
    this->mainLayout = nullptr;
    this->timeWidget = nullptr;

    boardLayout = new QGridLayout();
    boardLayout->setHorizontalSpacing(0);
    boardLayout->setVerticalSpacing(0);

    centralWidget->setLayout(boardLayout);
  }
}
Пример #18
0
void Game::showInGameMenu(){
    menu = true;
    int n = scene->items().size();
    for(int i = 0; i < n; i++) {
        scene->items()[i]->setEnabled(false);
    }
    drawPanel(0, 0, 1024, 768, QColor(Qt::lightGray), 0.65);
    drawPanel(1024/2 - 200,200,400,400,QColor(Qt::darkGray), 0.85);

    Button *resume_btn = new Button(QString("Vratit do hry"));
    int x = scene->width()/2 - resume_btn->boundingRect().width()/2;
    int y = 250;
    resume_btn->setPos(x, y);
    connect(resume_btn, SIGNAL(clicked()), this, SLOT(updateGame()));
    scene->addItem(resume_btn);

    Button *save_game_btn = new Button(QString("Ulozit hru"));
    x = scene->width()/2 - save_game_btn->boundingRect().width()/2;
    y += 75;
    save_game_btn->setPos(x, y);
    //connect(save_game_btn, SIGNAL(clicked()), this, SLOT(showMainMenu()));
    scene->addItem(save_game_btn);

    Button *back_to_menu_btn = new Button(QString("Vratit do menu"));
    x = scene->width()/2 - back_to_menu_btn->boundingRect().width()/2;
    y += 75;
    back_to_menu_btn->setPos(x, y);
    connect(back_to_menu_btn, SIGNAL(clicked()), this, SLOT(showMainMenu()));
    scene->addItem(back_to_menu_btn);

    Button *exit_btn = new Button(QString("Konec"));
    x = scene->width()/2 - exit_btn->boundingRect().width()/2;
    y += 75;
    exit_btn->setPos(x, y);
    connect(exit_btn, SIGNAL(clicked()), this, SLOT(close()));
    scene->addItem(exit_btn);
}
Пример #19
0
/// returns true if command is processed
bool V3DocViewWin::onCommand( int command, int params )
{
    CRLog::info("V3DocViewWin::onCommand(%d [%s], %d)", command, getCommandName(command, params), params );
    switch ( command ) {
    case MCMD_QUIT:
        getWindowManager()->closeAllWindows();
        return true;
    case MCMD_MAIN_MENU:
        showMainMenu();
        return true;
    case MCMD_SETTINGS_FONTSIZE:
        showFontSizeMenu();
        return true;
#if CR_INTERNAL_PAGE_ORIENTATION==1
    case MCMD_SETTINGS_ORIENTATION:
        showOrientationMenu();
        return true;
#endif
    case MCMD_SETTINGS:
        showSettingsMenu();
        return true;
    case MCMD_RECENT_BOOK_LIST:
        showRecentBooksMenu();
        return true;
    case MCMD_OPEN_RECENT_BOOK:
        _docview->swapToCache();
        _docview->getDocument()->updateMap();
        openRecentBook( params );
        return true;
    case MCMD_SWITCH_TO_RECENT_BOOK:
        _docview->swapToCache();
        _docview->getDocument()->updateMap();
        openRecentBook( 1 );
        return true;
    case MCMD_ABOUT:
        showAboutDialog();
        return true;
    case MCMD_CITE:
        activate_cite( _wm, this);
        return true;
    case MCMD_GO_PAGE_APPLY:
        _docview->doCommand( DCMD_GO_PAGE, params-1 );
        return true;
    case MCMD_GO_PERCENT_APPLY:
        _docview->doCommand( DCMD_GO_POS, params * _docview->GetFullHeight() / 100 );
        return true;
    case MCMD_SETTINGS_APPLY:
#if CR_INTERNAL_PAGE_ORIENTATION==1
    case mm_Orientation:
#endif
    case mm_FontSize:
        applySettings();
        saveSettings( lString16() );
        _wm->getSkin()->gc();
        return true;
    case DCMD_SAVE_HISTORY:
        saveHistory( lString16() );
        saveSettings( lString16() );
        return true;
    case DCMD_SAVE_TO_CACHE:
        _docview->swapToCache();
        _docview->getDocument()->updateMap();
        return true;
    case MCMD_BOOKMARK_LIST:
        showBookmarksMenu(false);
        return true;
    case MCMD_BOOKMARK_LIST_GO_MODE:
        showBookmarksMenu(true);
        return true;
    case DCMD_ZOOM_IN:
    case DCMD_ZOOM_OUT:
        showWaitIcon();
		CRViewDialog::onCommand( command, params );
        _props->setInt( PROP_FONT_SIZE, _docview->getFontSize() );
        saveSettings( lString16() );
        return true;
    case MCMD_HELP:
        showHelpDialog();
        return true;
    case DCMD_BOOKMARK_SAVE_N:
        _docview->doCommand( DCMD_BOOKMARK_SAVE_N, params );
        if ( _props->getBoolDef( PROP_AUTOSAVE_BOOKMARKS, true ) )
            saveHistory( lString16() );
        return true;
    default:
        // do nothing
        ;
    }
    return CRViewDialog::onCommand( command, params );
}
Пример #20
0
GameManager::GameManager()
{
    lobby = NULL;
    showMainMenu();
}
Пример #21
0
static void
mateHandleEvent (XEvent      *event)
{
	MATE_DISPLAY (&display);

	switch (event->type) {
	case KeyPress:
		if (isKeyPressEvent (event, &main_menu_key))
		{
			BananaArgument arg[2];

			arg[0].name = "root";
			arg[0].type = BananaInt;
			arg[0].value.i = event->xkey.root;

			arg[1].name = "time";
			arg[1].type = BananaInt;
			arg[1].value.i = event->xkey.time;

			showMainMenu (&arg[0], 2);
		}
		else if (isKeyPressEvent (event, &run_key))
		{
			BananaArgument arg[2];

			arg[0].name = "root";
			arg[0].type = BananaInt;
			arg[0].value.i = event->xkey.root;

			arg[1].name = "time";
			arg[1].type = BananaInt;
			arg[1].value.i = event->xkey.time;

			showRunDialog (&arg[0], 2);
		}
		else if (isKeyPressEvent (event, &run_command_screenshot_key))
		{
			BananaArgument arg[2];

			arg[0].name = "root";
			arg[0].type = BananaInt;
			arg[0].value.i = event->xkey.root;

			const BananaValue *
			option_command_screenshot = bananaGetOption (
			      bananaIndex, "command_screenshot", -1);

			arg[1].name = "command";
			arg[1].type = BananaString;
			arg[1].value.s = option_command_screenshot->s;

			runDispatch (&arg[0], 2);
		}
		else if (isKeyPressEvent (event, &run_command_window_screenshot_key))
		{
			BananaArgument arg[2];

			arg[0].name = "root";
			arg[0].type = BananaInt;
			arg[0].value.i = event->xkey.root;

			const BananaValue *
			option_command_window_screenshot = 
			     bananaGetOption (bananaIndex, "command_window_screenshot", -1);

			arg[1].name = "command";
			arg[1].type = BananaString;
			arg[1].value.s = option_command_window_screenshot->s;

			runDispatch (&arg[0], 2);
		}
		else if (isKeyPressEvent (event, &run_command_terminal_key))
		{
			BananaArgument arg[2];

			arg[0].name = "root";
			arg[0].type = BananaInt;
			arg[0].value.i = event->xkey.root;

			const BananaValue *
			option_command_terminal = bananaGetOption (
			      bananaIndex, "command_terminal", -1);

			arg[1].name = "command";
			arg[1].type = BananaString;
			arg[1].value.s = option_command_terminal->s;

			runDispatch (&arg[0], 2);
		}

	default:
		break;
	}

	UNWRAP (md, &display, handleEvent);
	(*display.handleEvent) (event);
	WRAP (md, &display, handleEvent, mateHandleEvent);
}
Пример #22
0
MainWidget::MainWidget(QWidget *parent)
    : DropShadowWidget(parent)
{
	initLocalConnection();
    setMinimumSize(900, 600);
	setWindowIcon(QIcon(":/img/safe"));

	statked_widget = new QStackedWidget();
    title_widget = new TitleWidget();
    content_widget = new ContentWidget();
	kill_mummy_widget = new KillMummyWidget();
	main_menu = new MainMenu();
	character_widget = new CharacterWidget();
	about_us_dialog = new AboutUsDialog(this);
	setting_dialog = new SettingDialog(this);
	login_dialog = new LoginDialog(this);
	register_widget = new RegisterWidget(this); 
	skin_widget = new SkinWidget(this);
	system_tray = new SystemTray(this);

	QPalette palette;
	palette.setBrush(QPalette::Window, QBrush(Qt::white));
    statked_widget->setPalette(palette);
    statked_widget->setAutoFillBackground(true);

	statked_widget->addWidget(content_widget);
	statked_widget->addWidget(kill_mummy_widget);

	QVBoxLayout *center_layout = new QVBoxLayout();
	center_layout->addWidget(statked_widget);
	center_layout->setSpacing(0);
	center_layout->setContentsMargins(0, 0, 0, 0);

    QVBoxLayout *main_layout = new QVBoxLayout();
    main_layout->addWidget(title_widget);
    main_layout->addLayout(center_layout);
	main_layout->setSpacing(0);
	main_layout->setContentsMargins(SHADOW_WIDTH, SHADOW_WIDTH, SHADOW_WIDTH, SHADOW_WIDTH);

    setLayout(main_layout);

	connect(title_widget, SIGNAL(showSkin()), this, SLOT(showSkinWidget()));
	connect(title_widget, SIGNAL(showMainMenu()), this, SLOT(showMainMenu()));
	connect(title_widget, SIGNAL(showMin()), this, SLOT(showMinimized()));
	connect(title_widget, SIGNAL(closeWidget()), this, SLOT(hide()));
	connect(title_widget, SIGNAL(turnPage(int)), this, SLOT(turnPage(int)));

	connect(main_menu, SIGNAL(showSettingDialog()), this, SLOT(showSettingDialog()));
	connect(main_menu, SIGNAL(showNewCharacter()), this, SLOT(showNewCharacter()));
	connect(main_menu, SIGNAL(showAboutUs()), this, SLOT(showAboutUs()));

	connect(content_widget, SIGNAL(showLoginDialog()), this, SLOT(showLoginDialog()));
	connect(content_widget, SIGNAL(showRegisterDialog()), this, SLOT(showRegisterDialog()));

	connect(setting_dialog, SIGNAL(changeLanguage(LANGUAGE)), this, SLOT(changeLanguage(LANGUAGE)));

	connect(skin_widget, SIGNAL(changeSkin(QString)), this, SLOT(changeSkin(QString)));

	connect(system_tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconIsActived(QSystemTrayIcon::ActivationReason)));
	connect(system_tray, SIGNAL(showWidget()), this, SLOT(showWidget()));
	
	system_tray->show();

	title_widget->turnPage("0");

	skin_name = Util::getSkinName();
	if( QString::compare(skin_name, QString("")) == 0)
	{
		this->changeSkin(DEFAULT_SKIN);
	}
}
Пример #23
0
static void doMenu()
{
	int up, down, attack, block, xAxisMoved, yAxisMoved;

	up = FALSE;
	down = FALSE;
	attack = FALSE;
	block = FALSE;

	if (menuInput.up == TRUE)
	{
		up = TRUE;
	}

	else if (menuInput.down == TRUE)
	{
		down = TRUE;
	}

	else if (menuInput.attack == TRUE)
	{
		attack = TRUE;
	}

	else if (menuInput.block == TRUE)
	{
		block = TRUE;
	}

	else if (input.up == TRUE)
	{
		up = TRUE;
	}

	else if (input.down == TRUE)
	{
		down = TRUE;
	}

	else if (input.attack == TRUE)
	{
		attack = TRUE;
	}

	else if (input.block == TRUE)
	{
		attack = TRUE;
	}

	xAxisMoved = input.xAxisMoved;
	yAxisMoved = input.yAxisMoved;

	if (attack == TRUE)
	{
		memset(&menuInput, 0, sizeof(Input));
		memset(&input, 0, sizeof(Input));

		playSound("sound/common/click");

		showMainMenu();
	}

	else if (block == TRUE)
	{
		memset(&menuInput, 0, sizeof(Input));
		memset(&input, 0, sizeof(Input));

		playSound("sound/common/click");

		showMainMenu();
	}

	else if (down == TRUE)
	{
		menu.startY += 6;

		if (menu.startY > menu.endY - menu.h)
		{
			menu.startY = menu.endY - menu.h;
		}
	}

	else if (up == TRUE)
	{
		menu.startY -= 6;

		if (menu.startY < 0)
		{
			menu.startY = 0;
		}
	}

	input.xAxisMoved = xAxisMoved;
	input.yAxisMoved = yAxisMoved;
}
Пример #24
0
int main (int argc, char *argv[])
{
	// Sema for tansmit the type
	key_t sem_type_key = ftok(PATH, TYPE);
	int sem_type = semget(sem_type_key, 1, IPC_CREAT | PERMS);
	semReset(sem_type, 0);

	key_t sem_control_key = ftok(PATH, CONTROL);
	int sem_control = semget(sem_control_key, 2, IPC_CREAT | PERMS);
	semReset(sem_control, 0);
	semReset(sem_control, 1);	
	
	// Sema for control Shared Mem Stock
	key_t sem_DispSrv_key = ftok(PATH, STOCK);
	int sem_DispSrv = semget(sem_DispSrv_key, 1, IPC_CREAT | PERMS);
	semReset(sem_DispSrv, 0);

	// Shared mem between monitor and server
	key_t shm_DispSrv_key = ftok(PATH, STOCKSHM);
	int shm_DispSrv = shmget(shm_DispSrv_key, sizeof(TSharedStock), IPC_CREAT | PERMS); // Creation com display server shm

	// File Parameters
	/* Time Function for filename definition */
	time_t now = time(NULL);
	struct tm *time = localtime(&now);
	char date_time[30];
	strftime(date_time,sizeof(date_time),"%d%m%y_%H%M%S", time);

	pid_t process_id = fork(); // Premier Fork (Server, Afficheur)
	if (process_id < 0) {
		perror("Error while attempting Fork (Server/Afficheur de Resultat)");
		exit(19);
	}

	//Afficheur (Parent)//
	else if (process_id > 0){
		int level = 0;
		showMainMenu(level, date_time);
	} 
	/*Tampon Serveur (Child)*/
	else{
		// DAEMON CODE START //
		//daemonize();
		// PROCESS NOW A DAEMON //
		//***********//
		//*SEMA INIT*//
		//***********//
		// Sema for control shared mem race
		key_t sem_mutex_key = ftok(PATH, MUTEX);
		int sem_mutex = semget(sem_mutex_key, 1, IPC_CREAT | PERMS);
		semReset(sem_mutex, 0);

		key_t sem_race_key = ftok(PATH, RACE);
	    int sem_race = semget(sem_race_key, 22, IPC_CREAT | PERMS);
	    int r;
	    for(r = 0; r < 22; r++) semReset(sem_race, r);				
		//*****************//
		//*SHARED MEM INIT*//
		//*****************//
		key_t shm_race_key = ftok(PATH, RACESHM);
		int shm_race = shmget(shm_race_key, 22*sizeof(TTabCar), IPC_CREAT | PERMS);

		//***********//
		//*FORK INIT*//
		//***********//
		process_id = fork(); // Deuxieme Fork (Server, Pilot)
		if (process_id < 0) {
			perror("Error while attempting Fork (Server/Pilot)");
			exit(19);
		}
		//Pilots (Child)//
		else if (process_id == 0) forkPilots(); // Pilot forking function
		//Server (Parent)
		else server(date_time); // Main server function

		for(r = 0; r < 22; r++){
			if(semGet(sem_race, r) != 1) semReset(sem_race, r);
		 	semctl(sem_race, r, IPC_RMID, NULL);

		 }
		if(semGet(sem_mutex, 0) != 1) semReset(sem_mutex, 0);
		semctl(sem_mutex, 0, IPC_RMID, NULL);
		if(semGet(sem_type, 0) != 1) semReset(sem_type, 0);
		semctl(sem_type, 0, IPC_RMID, NULL);
		if(semGet(sem_control, 0) != 1) semReset(sem_control, 0);
		if(semGet(sem_control, 1) != 1) semReset(sem_control, 1);
		semctl(sem_control, 0, IPC_RMID, NULL);
		semctl(sem_control, 1, IPC_RMID, NULL);
		shmctl(shm_race, IPC_RMID, NULL);
		shmctl(shm_DispSrv, IPC_RMID, NULL);
		if(semGet(sem_DispSrv, 0) != 1) semReset(sem_DispSrv, 0);
		semctl(sem_DispSrv, 0, IPC_RMID, NULL);
	}
	return EXIT_SUCCESS;
}