Beispiel #1
0
void AssassinWar::initJoinGameDlg()
{
    m_pJoinGameDlg = new JoinGameDlg(this);
    m_pJoinGameDlg->initialize();
    connect(m_pJoinGameDlg, SIGNAL(joinGame()), this, SLOT(joinGame()));
    connect(m_pJoinGameDlg, SIGNAL(cancelJoinGame()), this, SLOT(showMainWin()));
}
void QueryServersUserInterface::onKeyDown(U32 key)
{
   switch(key)
   {
      case ' ':
         if(lastSortColumn == sortColumn)
            sortAscending = !sortAscending;
         else
         {
            lastSortColumn = sortColumn;
            sortAscending = true;
         }
         sort();
         break;
      case '\r':
         {
            S32 currentIndex = findSelectedIndex();
            if(currentIndex == -1)
               currentIndex = 0;

            if(servers.size() > currentIndex)
            {
               // join the selected game
               joinGame(servers[currentIndex].serverAddress, servers[currentIndex].isFromMaster, false);

               // and clear out the servers, so that we don't do any more pinging
               servers.clear();
            }
         }
         break;
      case 27:
         gMainMenuUserInterface.activate();
         break;
   }
}
Beispiel #3
0
void PlayerHandler::added(int playerIndex)
{
  bz_debugMessage(3, "PlayerHandler::added");
  std::string name = format("Sample %d", playerIndex);
  setPlayerData(name.c_str(), NULL, "bot sample", eObservers);
  joinGame();
}
Beispiel #4
0
uint8_t selectGame()
{  
    int len, i, selected;
    struct packet p;
    int a = 0;
    config.channel = ANNOUNCE_CHANNEL;
    memcpy(config.mac0, ANNOUNCE_MAC, 5);
    nrf_config_set(&config);

    gamecount = 0;
    for(i=0;i<60;i++){
        len= nrf_rcv_pkt_time(30, sizeof(p), (uint8_t*)&p);
        if (len==sizeof(p)){
            if( a ) a = 0; else a = 1;
            gpioSetValue (RB_LED2, a);
            processPacket(&p);
        }
    }
    selected = 0;
    while(1){
        showGames(selected);
        int key=getInputWait();
        getInputWaitRelease();
        switch(key){
            case BTN_DOWN:
                if( selected < gamecount-1 ){
                    selected++;
                }
                break;
            case BTN_UP:
                if( selected > 0 ){
                    selected--;
                }
                break;
            case BTN_LEFT:
                return 0;
            case BTN_ENTER:
            case BTN_RIGHT:
                if( gamecount == 0 )
                    return 0;
                gameId = games[selected].gameId;
                memcpy(config.txmac, games[selected].gameMac, 5);
                memcpy(config.mac0, games[selected].gameMac, 5);
                config.mac0[4]++;
                config.channel = games[selected].gameChannel;
                interval = games[selected].interval;
                jitter = games[selected].jitter;
                flags = games[selected].gameFlags;
                nrf_config_set(&config);
                if( games[selected].gameFlags & FLAGS_MASS_GAME )
                    return 1;
                else
                    return joinGame();
        }
    }
}
Beispiel #5
0
/**
 * @brief StartWindow::StartWindow
 * @param parent
 * Constructor of the StartWindow-class
 * connects the signals of the Buttons and the LineEdit
 */
StartWindow::StartWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::StartWindow)
{
    ui->setupUi(this);
    server = new MyServer(this);
    socket = new MySocket(this);
    setW = new SetWindow(this);
    numb = 0;

    connect(ui->lineEdit, SIGNAL(editingFinished()), this, SLOT(getName()));
    connect(ui->startGameButton, SIGNAL(clicked()), this, SLOT(openGame()));
    connect(ui->joinGameButton, SIGNAL(clicked()), this, SLOT(joinGame()));
}
Beispiel #6
0
index::index(QWidget *parent) :
    QDialog(parent)
{
    pbNewGame = new QPushButton(tr("New Game"));
    pbJoinGame = new QPushButton(tr("Join Game"));
    pbQuit = new QPushButton(tr("Quit"));

    connect(pbNewGame, SIGNAL(clicked()), this, SLOT(initNewgame()));
    connect(pbJoinGame, SIGNAL(clicked()), this, SLOT(joinGame()));
    connect(pbQuit, SIGNAL(clicked()), this, SLOT(close()));

    QVBoxLayout *buttonLayout = new QVBoxLayout;
    buttonLayout->addStretch(1);
    buttonLayout->addWidget(pbNewGame);
    buttonLayout->addWidget(pbJoinGame);
    buttonLayout->addWidget(pbQuit);
    buttonLayout->addStretch(1);
    setLayout(buttonLayout);

    setWindowTitle(tr("Home Delete Game"));
}
GamesList::GamesList(QWidget *parent) : QWidget(parent)
{
    _gameList = new QTableWidget(0, 2);

    _gameList->setHorizontalHeaderItem(0, new QTableWidgetItem("Games"));
    _gameList->setHorizontalHeaderItem(1, new QTableWidgetItem("Players"));

    _joinButton.setText("Join");
    _refreshButton.setText("Refresh");
    _backButton.setText("Previous");

    _gridLayout.addWidget(_gameList, 0, 0);
    _gridLayout.addWidget(&_refreshButton, 0, 1, 1, 1, Qt::AlignTop);
    _gridLayout.addWidget(&_backButton, 1, 1, 1, 1, Qt::AlignTop);
    _gridLayout.addWidget(&_joinButton, 1, 0);

    setLayout(&_gridLayout);

    connect(&_refreshButton, SIGNAL(clicked()), this, SLOT(refresh()));
    connect(&_joinButton, SIGNAL(clicked()), this, SLOT(joinGame()));
    connect(&_backButton, SIGNAL(clicked()), this, SLOT(getBack()));
    connect(_gameList, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(joinGame()));
    connect(ListGameSlotSingleton::getInstance(), SIGNAL(newGame(UInt8,UInt8,QString)), this, SLOT(addGame(UInt8,UInt8,QString)));
}
Beispiel #8
0
void GameJoinButton::emitClicked() {
	emit(joinGame(gameid));
}
Beispiel #9
0
// ///////////////// /////////////////////////////////////////////////
// Main Front end game loop.
TITLECODE titleLoop(void)
{
	TITLECODE RetCode = TITLECODE_CONTINUE;

	pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON);
	pie_SetFogStatus(false);
	screen_RestartBackDrop();
	wzShowMouse(true);

	// When we first init the game, firstcall is true.
	if (firstcall)
	{
		firstcall = false;
		// First check to see if --host was given as a command line option, if not,
		// then check --join and if neither, run the normal game menu.
		if( hostlaunch )
		{
			ingame.bHostSetup = true;
			bMultiPlayer = true;
			bMultiMessages = true;
			game.type = SKIRMISH;		// needed?
			changeTitleMode(MULTIOPTION);
			hostlaunch = false;			// reset the bool to default state.
		}
		else if(strlen(iptoconnect) )
		{
			joinGame(iptoconnect, 0);
		}
		else
		{
			changeTitleMode(TITLE);			// normal game, run main title screen.
		}
		// Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor()
		wzSetCursor(CURSOR_DEFAULT);
	}

	if (titleMode != MULTIOPTION && titleMode != MULTILIMIT && titleMode != STARTGAME)
		screen_disableMapPreview();

	switch(titleMode) // run relevant title screen code.
	{
		// MULTIPLAYER screens
		case PROTOCOL:
			runConnectionScreen(); // multiplayer connection screen.
			break;
		case MULTIOPTION:
			runMultiOptions();
			break;
		case GAMEFIND:
			runGameFind();
			break;
		case MULTI:
			runMultiPlayerMenu();
			break;
		case MULTILIMIT:
			runLimitScreen();
			break;
		case KEYMAP:
			runKeyMapEditor();
			break;

		case TITLE:
			runTitleMenu();
			break;

		case SINGLE:
			runSinglePlayerMenu();
			break;

		case TUTORIAL:
			runTutorialMenu();
			break;

//		case GRAPHICS:
//			runGraphicsOptionsMenu();
//			break;

		case CREDITS:
			runCreditsScreen();
			break;

//		case DEMOMODE:
//			runDemoMenu();
//			break;
//	case VIDEO:
//			runVideoOptionsMenu();
//			break;
		case OPTIONS:
			runOptionsMenu();
			break;

		case GAME:
			runGameOptionsMenu();
			break;


		case GRAPHICS_OPTIONS:
			runGraphicsOptionsMenu();
			break;

		case AUDIO_OPTIONS:
			runAudioOptionsMenu();
			break;

		case VIDEO_OPTIONS:
			runVideoOptionsMenu();
			break;

		case MOUSE_OPTIONS:
			runMouseOptionsMenu();
			break;

		case QUIT:
			RetCode = TITLECODE_QUITGAME;
			break;

		case STARTGAME:
		case LOADSAVEGAME:
  			if (titleMode == LOADSAVEGAME)
			{
				RetCode = TITLECODE_SAVEGAMELOAD;
			}
			else
			{
				RetCode = TITLECODE_STARTGAME;
			}
			return RetCode;			// don't flip!

		case SHOWINTRO:
			pie_SetFogStatus(false);
	  		pie_ScreenFlip(CLEAR_BLACK);
			changeTitleMode(TITLE);
			RetCode = TITLECODE_SHOWINTRO;
			break;

		default:
			debug( LOG_FATAL, "unknown title screen mode" );
			abort();
	}
	NETflush();  // Send any pending network data.

	audio_Update();

	pie_SetFogStatus(false);
	pie_ScreenFlip(CLEAR_BLACK);//title loop

	if ((keyDown(KEY_LALT) || keyDown(KEY_RALT))
	    /* Check for toggling display mode */
	    && keyPressed(KEY_RETURN)) {
		wzToggleFullscreen();
	}
	return RetCode;
}
Beispiel #10
0
bool playGame(AI& fp,AI& sp,char* host,int&results)
{
  //cout<<"PlayGame Function Called"<<endl;
  int socket = open_server_connection(host, "19000");
  if(socket == -1)
  {
    cerr << "Unable to connect to server" << endl;
    return false;
  }
  if(!serverLogin(socket, fp.username(), fp.password()))
  {
    cerr << "Login Failed" << endl;
    return false;
  }
  socket = createGame();
  int game = getGameNumber();
  cout<<"TOP Game: "<<game<<endl;
  //cout<<"Above Fork"<<endl;
  pid_t pID = fork();
  if(pID ==0)//PLAYER 2
  {
    //cout<<"Fork Happened for Player 2"<<endl;
    socket = open_server_connection(host, "19000");
    if(socket == -1)
    {
      cerr << "Unable to connect to server" << endl;
      return false;
    }
    //cout<<"Attempting to log in"<<endl;
    if(!serverLogin(socket, sp.username(), sp.password()))
    {
      return false;
    }
    //cout<<"Joining Game"<<endl;
    socket = joinGame(game);
    //cout<<"Above while loop"<<endl;
    while(networkLoop(socket))
    {
      if(sp.startTurn())
      {
        endTurn();
      }
      else
      {
        getStatus();
      }
    }
  }
  else
  {
    //cout<<"P1 above while"<<endl;
    while(networkLoop(socket))
    {
      if(fp.startTurn())
      {
        endTurn();
      }
      else
      {
        getStatus();
      }
    }
  }

  //Wait for log
  while (networkLoop(socket)){}
  //Get the scores
  results=(fp.getWinValue());
  if(pID == 0)
  {
    close(socket);
       
    exit(0);
    //TODO Hack to kill the spawned copy
  }
  close(socket);
  cout<<"Game["<<game<<"] "<<fp.aiNum<<" VS "<<sp.aiNum<<" final score = "<<results<<endl;
  return true;
}
Beispiel #11
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    server(BUFSIZE + 1, this),
    client(BUFSIZE + 1, this)
{
    setMenuBar(new QMenuBar(this));
    QMenu *gameMenu = new QMenu("Game", menuBar());
    createAction = new QAction("Create", gameMenu);
    createAction->setIcon(QIcon(":/create.icns"));
    joinAction = new QAction("Join in", gameMenu);
    joinAction->setIcon(QIcon(":/join.icns"));
    abortAction = new QAction("Abort", gameMenu);
    abortAction->setIcon(QIcon(":/abort.icns"));
    menuBar()->addMenu(gameMenu);
    gameMenu->addAction(createAction);
    gameMenu->addAction(joinAction);
    gameMenu->addAction(abortAction);
    QToolBar *toolbar = new QToolBar(this);
    toolbar->setMovable(0);
    addToolBar(Qt::LeftToolBarArea, toolbar);
    toolbar->addAction(createAction);
    toolbar->addAction(joinAction);
    toolbar->addAction(abortAction);
    abortAction->setEnabled(0);

    setStatusBar(new QStatusBar(this));


    setCentralWidget(new QWidget(this));
    QHBoxLayout *mainLayout = new QHBoxLayout();
    centralWidget()->setLayout(mainLayout);

    chessBoard = new ChessBoard(centralWidget());
    mainLayout->addWidget(chessBoard);

    opp = new UserWidget(this);
    loc = new UserWidget(this);
    oppName = new QLabel(this);
    locName = new QLabel(this);
    QVBoxLayout *rightLayout = new QVBoxLayout();
    mainLayout->addLayout(rightLayout);

    rightLayout->addWidget(opp);
    rightLayout->addWidget(oppName);
    startButton = new QPushButton("Start", this);
    startButton->setEnabled(0);
    rightLayout->addWidget(startButton);
    tieButton = new QPushButton("Tie", this);
    tieButton->setEnabled(0);
    rightLayout->addWidget(tieButton);
    surButton = new QPushButton("Surrender", this);
    surButton->setEnabled(0);
    rightLayout->addWidget(surButton);
    rightLayout->addWidget(tieButton);

    number = new QLCDNumber(this);
    rightLayout->addWidget(number);
    rightLayout->addWidget(loc);
    rightLayout->addWidget(locName);
    tieTimer.setSingleShot(1);
    //TODO rightLayout for some information


    QObject::connect(createAction, SIGNAL(triggered()), this, SLOT(createGame()));
    QObject::connect(joinAction, SIGNAL(triggered()), this, SLOT(joinGame()));
    QObject::connect(abortAction, SIGNAL(triggered()), this, SLOT(abortLink()));
    QObject::connect(chessBoard, SIGNAL(clickPiece(QPair<int,int>)), this, SLOT(handleClick(QPair<int, int>)));
    QObject::connect(&server, SIGNAL(received(void*, int)), this, SLOT(handleReceive(void*, int)));
    QObject::connect(&server, SIGNAL(connected()), this, SLOT(handleConnected()));
    QObject::connect(&client, SIGNAL(received(void*,int)), this, SLOT(handleReceive(void*, int)));
    QObject::connect(startButton, SIGNAL(clicked()), this, SLOT(startGame()));
    QObject::connect(&tieTimer, SIGNAL(timeout()), this, SLOT(enableTie()));
    QObject::connect(tieButton, SIGNAL(clicked()), this, SLOT(handleTie()));
    QObject::connect(surButton, SIGNAL(clicked()), this, SLOT(abortLink()));
    QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeOut()));
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow){
    ui->setupUi(this);

    // Initialize Bet
    ui->GuessNumBet->setNum(Config::GuessNumBet);
    ui->BlackJackBet->setNum(Config::BlackjackBet);

    // Initialize server configs
    this->socket = -1;
    this->serverIP = ui->serverIPDisplay->text();
    this->serverPort = ui->serverPortDisplay->text().toInt();

    // Initialize games
    this->guess_num_client = new GuessNumClient(this);
    this->blackjack_client = new BlackJackClient(this);
    this->guess_num_client->setModal(true);
    this->blackjack_client->setModal(true);

    // Initialize keep alive timer
    this->keepAlive = new QTimer();
    this->keepAlive->setInterval(Config::KeepAliveFrequency);

    // Initialize dialog
    this->initializeWaitDialog();
    this->initializeGuessNumDialogs();
    this->initializeBlackjackDialogs();

    *(user.mutable_name()) = "Anomynous";
    ui->name->setText(QString("Anomynous"));
    ui->BlackJackButton->setEnabled(false);
    ui->GuessNumButton->setEnabled(false);

    // Register custom type so QObject::connect can work
    qRegisterMetaType<System::Type>("System::Type");

    QObject::connect(ui->ConfigureServerButton,     SIGNAL(clicked()),                 this, SLOT(showServerConfigDialog()));
    QObject::connect(ui->TryConnectionButton,       SIGNAL(clicked()),                 this, SLOT(tryConnect()));
    QObject::connect(this,                          SIGNAL(connectionInvalid()),       this, SLOT(warnConnection()));
    QObject::connect(this->keepAlive,               SIGNAL(timeout()),                 this, SLOT(keepAlivePokeServer()));

    QObject::connect(this->guess_num_client,        SIGNAL(waitForRival()),            this->guessnum_congrat, SLOT(exec()));
    QObject::connect(this->guess_num_client,        SIGNAL(loseGame()),                this->guessnum_loser, SLOT(exec()));
    QObject::connect(this->guess_num_client,        SIGNAL(winGame()),                 this->guessnum_winner, SLOT(exec()));
    QObject::connect(this->guess_num_client,        SIGNAL(modify_player_money(int)),  this, SLOT(increaseMoney(int)));
    QObject::connect(this->guess_num_client,        SIGNAL(finished(int)),             this->guess_num_client, SLOT(cleanUp()));

    QObject::connect(this->blackjack_client,        SIGNAL(modify_player_money(int)),  this, SLOT(increaseMoney(int)));
    QObject::connect(this->blackjack_client,        SIGNAL(waitForRival()),            this->blackjack_wait, SLOT(exec()));
    QObject::connect(this->blackjack_client,        SIGNAL(showBlackjackResult(int,int)), this->blackjack_result_dialog, SLOT(showResult(int,int)));
    QObject::connect(this->blackjack_client,        SIGNAL(finished(int)),             this->blackjack_client, SLOT(cleanUp()));

    QObject::connect(this->blackjack_result_dialog, SIGNAL(finished(int)),             this->blackjack_client, SLOT(accept()));

    QObject::connect(ui->GuessNumButton,            &QPushButton::clicked,             [this](){ joinGame(System::GUESSNUM); });
    QObject::connect(ui->BlackJackButton,           &QPushButton::clicked,             [this](){ joinGame(System::JACK); });
    QObject::connect(this->guess_num_client,        SIGNAL(rival_die()),  this, SLOT(handleGuessNumPlayerDie()));
    QObject::connect(this->blackjack_client,        SIGNAL(rival_die()),  this, SLOT(handleBlackJackPlayerDie()));

    // Prompt for change name at startup.
    changeName();
}
Beispiel #13
0
// used to handle message from a ClientConnection
// those message can be 
//     'SYSTEM_REGISTER <CONSUMER | PROVIDER> #Game [Game]' --> no answer
//     'SYSTEM_REQUEST_GAME GameKind'
//             'SYSTEM_REQUEST_GAME_REFUSED ErrorMessage'
//             'SYSTEM_REQUEST_GAME_ACCEPTED GameId #Consumer [Consumer]'
//     'SYSTEM_JOIN_GAME GameId'
//     'SYSTEM_LEAVE_GAME GameId'
//     '<gameId> MESSAGE'
void ConnectionManager::handleMessage( ClientConnectionPtr connection,
                                       const std::string& message )
{
   // log the message
   AsyncLogger::getInstance()->log( "RECEIVE FROM (" + connection->getLogin() + ") : " + message );

   // explode the message to be able to check the kind 
   std::vector< std::string > messageParts;
   if ( StringUtils::explode( message,
                              ' ',
                              messageParts,
                              2 ) == 2 )
   {
      if ( messageParts[ 0 ] == SYSTEM_REGISTER )
      {
         registerConnection( connection,
                              messageParts[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == SYSTEM_REQUEST_GAME )
      {
         requestGame( connection,
                        messageParts[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == SYSTEM_REQUEST_GAME_LIST )
      {
         requestGameList( connection,
                           messageParts[ 1 ] );
      }
      else if ( messageParts[ 0 ] == SYSTEM_JOIN_OR_REQUEST_GAME )
      {
         joinOrRequestGame( connection,
                              messageParts[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == SYSTEM_JOIN_GAME )
      {
         joinGame( connection,
                     messageParts[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == SYSTEM_LEAVE_GAME )
      {
         leaveGame( connection,
                     messageParts[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == SYSTEM_GAME_CREATION_REFUSED )
      {
         // get the relevant information
         std::vector< std::string > messageInformation;
         StringUtils::explode( messageParts[ 1 ],
                                 ' ',
                                 messageInformation,
                                 2 );

         // and close the game
         closeGame( connection,
                     messageInformation[ 0 ],
                     messageInformation[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == GAME_MESSAGE )
      {
         // get the relevant information
         std::vector< std::string > messageInformation;
         StringUtils::explode( messageParts[ 1 ],
                                 ' ',
                                 messageInformation,
                                 2 );

         // and forward the message (gameId, message)
         handleGameMessage( connection,
                              messageInformation[ 0 ],
                              message );
      }
   }
}