Esempio n. 1
0
/*
    increments the player score by the specified value
*/
void Player::incrementScore(int value){
    score+=value;

    //resets the score to 0 if the score is a negative value
    if (score < 0)
        resetScore();
}
Esempio n. 2
0
void QtTDContext::resetMap() {
        removeAllEnemies();
        clearTowers();
        setCredits(creditsStart);
        setInterest(interestStart, interestIncrease);
        resetLives(livesStart);
        resetBonus();
        resetScore();
        resetWaves();
        gameTime = 0;
        //mainApp.resetMap();
}
Esempio n. 3
0
Server::Server(void *surf, const Configuration& conf)
 : Framework(surf, conf, UNINITIALIZED), ballouttimer(-1), ballspeed(6.0)
{
	ball.push_back(Ball(this));
	player.push_back(new Player(this, "Mr. Wand", BACK, field.getLength()/2.0f));
	// Mr. Wand is cheating!
	player[0]->setSize(3.5, 3.5); // *****************
	player[0]->run();
	resetScore();
	output.addMessage(Interface::WAITING_FOR_OPPONENT);

	server = initNetwork(conf.version, conf.playername, conf.port);
	loopback = Client::initNetwork(conf.version, "localhost", conf.port, conf.playername);

	if (server == -1 || loopback == -1)
		shutdown();

	loop();
}
Esempio n. 4
0
void Server::startGame()
{
	output.removeMessage(Interface::WAITING_FOR_OPPONENT);
	resetScore();

	// it could be we are serving at this moment
	output.removeMessage(Interface::YOU_SERVE);
	player[0]->detachBall(0.0);

	// create new players
	delete player[0];	delete player[1];
	player.clear();

	for (std::map<grapple_user, Peer>::iterator i = peer.begin(); i != peer.end(); ++i)
	{
		Side side = (i->first == localid ? FRONT : BACK);
		i->second.player = new Player(this, i->second.name, side, field.getLength()/2.0f);
		player.push_back(i->second.player);
		i->second.player->run();
	}

	// now we are up & ..
	state = RUNNING;
	sendSimplePacket(READY);

	// reset ball in a cool way
	output.addMessage(Interface::FLASH_GAME_STARTED);
	ballouttimer = addTimer(10, BALLOUT, this);

	// tell pause state
	if (paused)
		sendSimplePacket(PAUSE_REQUEST);
	else
		sendSimplePacket(RESUME_REQUEST);

	// tell our initial position
	Vec2f pos = peer[localid].player->getPosition();
	Buffer sbuf(PADDLEPOSITION);
	sbuf.pushId(localid);
	sbuf.pushDouble(pos.y);
	sbuf.pushDouble(pos.x);
	sendPacket(sbuf, false);
}
Esempio n. 5
0
//---------------------------------------------------------------
void newNetGame(LPARAM lP)
{
	TnetGameSettings *b= (TnetGameSettings*)lP;
	killBrains();
	players[0].isComp= players[1].isComp= 0;
	width=b->width;
	height=b->height;
	newGame(b->begin ? 1-NET_PLAYER : NET_PLAYER, false);
	if(ruleFive!=b->rule5){
		ruleFive=b->rule5;
		wrLog(b->rule5==2? lng(988, "rule renju"):(b->rule5 ? lng(655, "Exactly five in a row win") : lng(654, "Five or more in a row win")));
	}
	if(continuous!=b->cont){
		continuous=b->cont;
		wrLog(b->cont ? lng(657, "Continuous game") : lng(656, "Single game"));
	}
	wrLog(b->begin ? lng(872, "You begin") : lng(873, "The other player begins"));
	resetScore();
}
Esempio n. 6
0
ScoreManager::ScoreManager()
{
	setHighscore(getHighscoreFromFile());
	resetScore();
}
Esempio n. 7
0
File: goals.c Progetto: fishr/6.270
void resetRound(int randomSeed) {
    resetScore();
    reseedRandom(randomSeed);
    pickNewGoal();
}
Esempio n. 8
0
void ScoreManager::gameOver() {
	gameOverB = true;
	// gameOverOverlay->setText(gameOverText);
	// showGameOver();
	resetScore();
}
Esempio n. 9
0
void recv_data(void *arg)
{
   player_t *client = (player_t *)arg;
   char buffer[BUFSIZ];
   unsigned int echolen;
   
   rt_task_suspend(NULL); //will wait on main to signal

   for(;;){
      memset(buffer,0,sizeof(buffer));
      int status;

      if((status = recv(client->socket, buffer, BUFSIZ, 0)) < 0)
         rt_err("recv()");
    
     /* player cannot start until the given time */
      if(!strcmp(buffer,"START")){
        start(); 
        /* score initialization from start()*/
        echolen = strlen(gameData);
        if(send(client->vsocket, gameData, echolen, 0) != echolen)
     		rt_err("send()");

        /*2 View mode case*/
        if(viewMode > 1){
		if(send(viewSocket2, gameData, echolen, 0) != echolen)
     			rt_err("send()");
	}

	/* Ball initial position */
	echolen = strlen(ballData);
	if(send(client->vsocket, ballData, echolen, 0) != echolen)
		rt_err("send()");

	
	/*2 View mode case*/
        if(viewMode > 1){
		if(send(viewSocket2, ballData, echolen, 0) != echolen)
     			rt_err("send()");
	}


       	/* ball Thread can now run */
	if(rt_task_resume(&ballThread))	
	   rt_err("rt_task_resume()");
  	continue;
      }

      else if(!strcmp(buffer,"RESET")){
	resetScore();
        echolen = strlen(gameData);
	if(send(client->vsocket, gameData, echolen, 0) != echolen)
	      rt_err("send()");

	/*2 View mode case*/
        if(viewMode > 1){
		if(send(viewSocket2, gameData, echolen, 0) != echolen)
     			rt_err("send()");
	}

	continue;
      }
      else if(!strcmp(buffer, "ADD")){
        addPong();
        echolen = strlen(pongData[0]);
	if(send(client->vsocket, pongData[0],echolen, 0) != echolen)
     		rt_err("send()");
    
	/*2 View mode case*/     
        if(viewMode > 1){
		if(send(viewSocket2, pongData[0], echolen, 0) != echolen)
     			rt_err("send()");
	}
 
        echolen = strlen(pongData[1]);
	if(send(client->vsocket, pongData[1],echolen, 0) != echolen) 
     		rt_err("send()");

	
	/*2 View mode case*/
        if(viewMode > 1){
		if(send(viewSocket2, pongData[1], echolen, 0) != echolen)
     			rt_err("send()");
	}


	continue;
      }

      /* parsing L(k) and R(k) */ 
      if(client->socket == initSock){
        if(!strcmp(buffer, "LEFT") || !strcmp(buffer, "RIGHT")){
	    move(buffer[0]); //either 'L' or 'R' -> {L/R1}
            echolen = strlen(moveData[0]);
	    if(send(client->vsocket, moveData[0],echolen, 0) != echolen)
     		rt_err("send()");
            /*2 View mode case*/
            if(viewMode > 1){
		if(send(viewSocket2, moveData[0], echolen, 0) != echolen)
     			rt_err("send()");
	    }
        }
      }

      else if(client->socket != initSock){
        if(!strcmp(buffer,"LEFT") || !strcmp(buffer, "RIGHT")){
	    opponentMovement(buffer[0]); // {L/R2}
            echolen = strlen(moveData[1]);
	    if(send(client->vsocket, moveData[1],echolen, 0) != echolen)
     		rt_err("send()");
              /*2 View mode case*/
            if(viewMode > 1){
		if(send(viewSocket2, moveData[1], echolen, 0) != echolen)
     			rt_err("send()");
	    }
	}
      }
      
      /* TODO Cases to think about 
         1. need 2 alert other players about P(X) exiting
         2. close this socket, potentially alert main that another client can connect
         3. ^ if possible pause game save state -> MILESTONE 3 
      */    
     if(!strcmp(buffer,"EXIT")){
		
	
        		char data[1024];
                           printf("%d","A");
	
       		 	//recv(client->vsocket,data,sizeof(data),0);
	
		
        		kill(mThreadPid, SIGKILL);
     }
	
		
   
    }
}
Esempio n. 10
0
void Scoreboard::resetAll() 
{ 
	for(int num = 1; num <= numPlayers; ++num)
		resetScore(num);
	highScore = 0;
}