示例#1
0
void
play(void)
{
	MWEvent		event;
	MW244BPacket	incoming;

	event.eventDetail = &incoming;

	while (TRUE) {
		NextEvent(&event, M->theSocket());
		if (!M->peeking())
			switch(event.eventType) {
			case EVENT_A:
				aboutFace();
				break;

			case EVENT_S:
				leftTurn();
				break;

			case EVENT_D:
				forward();
				break;

			case EVENT_F:
				rightTurn();
				break;

			case EVENT_BAR:
				backward();
				break;

			case EVENT_LEFT_D:
				peekLeft();
				break;

			case EVENT_MIDDLE_D:
				shoot();
				break;

			case EVENT_RIGHT_D:
				peekRight();
				break;

			case EVENT_NETWORK:
				processPacket(&event);
				break;

			case EVENT_INT:
				quit(0);
				break;

			}
		else
			switch (event.eventType) {
			case EVENT_RIGHT_U:
			case EVENT_LEFT_U:
				peekStop();
				break;

			case EVENT_NETWORK:
				processPacket(&event);
				break;
			}

		ratStates();		/* clean house */

		manageMissiles();

		DoViewUpdate();

		mws_update(M->state);

		/* Any info to send over network? */

	}
}
示例#2
0
/* ----------------------------------------------------------------------- */
void play(void)
{	// initialisation
	cout << "Starting Play" << endl;
	//SetRatPosition(7,1,5,0);
	proj.present = false;
	proj.prev_x = proj.prev_y = proj.x = proj.y = 1;
	int turn = 0;
	
	updateSeqNo = true;
	join = false;
	
	for (int k = 0; k < 8; k++)
		participants[k] = prevseq_a[k] = 0;
	for (int k = 0; k < 8; k++)
		expected_seqno[k] = k+1;
	GLOBAL_ID = 0;
	checking = 1;
	checkingzero=1;
	MWEvent		event;
	MW244BPacket	incoming;

	event.eventDetail = &incoming;

	while (TRUE) {
		turn ++;
		NextEvent(&event, M->theSocket());
		if (!M->peeking())
			switch(event.eventType) {
				case EVENT_A:
					aboutFace();
					break;

				case EVENT_S:
					leftTurn();
					break;

				case EVENT_D:
					forward();
					break;

				case EVENT_F:
					rightTurn();
					break;


				case EVENT_LEFT_D:
					peekLeft();
					break;

				case EVENT_BAR:
					shoot();
					break;

				case EVENT_RIGHT_D:
					peekRight();
					break;

				case EVENT_NETWORK:
					processPacket(&event);
					break;

				case EVENT_TIMEOUT:

					checking = (++checking) % 25;					
					if (checking == 0 && !join){
						cout << "Setting ID to zero" << endl;
						join = true;
						setMapping();
					}		
					else {cout << "TIMEOUT"  << endl;
						participation = (++participation) % 30;
						manageMissiles();
						if (participation == 29)
						{ ratStates(); /* clean house */
							for (int i = 0 ; i < 8 ; i++)
								participants[i] = 0;
						}
					}
					break;

				case EVENT_INT:
					quit(0);
					break;

			}
		else
			switch (event.eventType) {
				case EVENT_RIGHT_U:
				case EVENT_LEFT_U:
					peekStop();
					break;
				case EVENT_NETWORK:
					processPacket(&event);
					break;
			}
		DoViewUpdate();
		checking ++;

		manageMissiles();
		if (join && checkingzero == 0)
		{	
			MW244BPacket p;
			makePacket(&p,'a',kills, updateSeqNo);
			sendPacketToPlayers(p);
		}

		else if (join && turn % 2 == 0)
		{
			MW244BPacket p;
			makePacket(&p,'t',-1, updateSeqNo);
			sendPacketToPlayers(p);
		}

	}
}