本文整理汇总了C++中mazewarinstance::Ptr::myRatId方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::myRatId方法的具体用法?C++ Ptr::myRatId怎么用?C++ Ptr::myRatId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mazewarinstance::Ptr
的用法示例。
在下文中一共展示了Ptr::myRatId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makePacket
void makePacket(MW244BPacket *p, char status, int killed, bool UpdateSeqNo)
{
strncpy(p->Name,M->myName_,NAMESIZE );
p-> ID = M->myRatId().value();
cout << "ID from packet: " << M->myRatId().value() << endl;
if (UpdateSeqNo) ++my_seq_no;
p-> sequence_number = my_seq_no;
p -> tagged_rat = killed;
p->score = M->score().value();
p->x_pos = MY_X_LOC;
p->y_pos = MY_Y_LOC;
p-> dir = MY_DIR;
p-> status = status;
p-> globalID = GLOBAL_ID;
p -> time = start_time;
}
示例2: ratStates
void ratStates()
{
/* In our sample version, we don't know about the state of any rats over
the net, so this is a no-op */
for (int i = 0; i < 8 ; i++)
if (i != M->myRatId().value() && participants[i] == 0 && M->mazeRats_[Mapping_idToIndex.find(i)->second].playing)// no packet from this dude
{ cout << i << endl;
//M->mazeRats_[Mapping_idToIndex.find(i)->second].playing = false;
rat_array[Mapping_idToIndex.find(i)->second] = NULL;
RatIndexType ratId( Mapping_idToIndex.find(i)->second);
ClearRatPosition(ratId);
}
for (int i = 0; i < 8; i++)
cout << "bool" << M->mazeRats_[i].playing << endl;
if (!( M->mazeRats_[1].playing || M->mazeRats_[2].playing || M->mazeRats_[3].playing || M->mazeRats_[4].playing || M->mazeRats_[5].playing || M->mazeRats_[6].playing || M->mazeRats_[7].playing)) // this means that there are no other players :O
{
M->myRatIdIs(0);
M->scoreIs(0);
SetMyRatIndexType(0);
Mapping_idToIndex.clear();
Mapping_indexToId.clear();
play();//main(0,NULL); // start over
}
}
示例3: shoot
void shoot()
{
mw_score_t score;
mws_fire_missile(M->state, M->local_id);
/* XXX: Should check return code in case of error. */
mws_get_rat_score(M->state, M->local_id, &score);
M->scoreIs(score);
UpdateScoreCard(M->myRatId().value());
}
示例4: return
/* This is just for the sample version, rewrite your own */
char *GetRatName(RatIndexType ratId)
{
if (ratId.value() == M->myRatId().value())
{ return(M->myName_); }
else { return ("Dummy"); }
}
示例5: GetRatScore
/* This is just for the sample version, rewrite your own */
Score GetRatScore(RatIndexType ratId)
{
if (ratId.value() == M->myRatId().value())
{ return(M->score()); }
else { return (0); }
}
示例6: processPacket
void processPacket (MWEvent *eventPacket)
{
MW244BPacket *p = new MW244BPacket ;
p = eventPacket->eventDetail;
/*cout << p->ID<< endl;
cout << p->sequence_number<< endl;
cout << p->score<< endl;
cout << p->x_pos<< endl;
cout << p->y_pos<< endl;
cout << p->dir<< endl;
cout << p->tagged_rat<< endl;
cout << p->globalID<< endl;
ConvertIncoming(p);
cout << p->ID<< endl;
cout << p->sequence_number<< endl;
cout << p->score<< endl;
cout << p->x_pos<< endl;
cout << p->y_pos<< endl;
cout << p->dir<< endl;
cout << p->tagged_rat<< endl;
cout << p->globalID<< endl;
exit(0);*/
cout << "PP " << p->ID << endl;
if (myPacket(p, &eventPacket->eventSource) && join)// BECAUSE WHILE YOU ARE STILL 0, you will get packets with ID 0
{
return;
}
else {
if (!join && expected_seqno[p->ID] <= p->sequence_number){
if (p->globalID == 7) // What if there is only player with global ID 7? :/
{
cout << "You are one player too many :(" << endl;
cout << "Please try again later." << endl;
exit(0);
}
else
{ for (int i = 0; i < 100; i++)
cout << "Incrementing for no reason" << endl;
join = true;
GLOBAL_ID = p->globalID+1;
M->myRatIdIs(GLOBAL_ID);
setMapping();
UpdateScoreCard(0);
MW244BPacket q;
makePacket(&q,'h',-1, updateSeqNo);
sendPacketToPlayers(q);
participants[p->ID]++;
Rat r;
r.playing = 1;
cout << "NEW " << p->ID << endl;
r.x=p->x_pos;
r.y=p->y_pos;
r.dir=(p->dir);
M->mazeRats_[Mapping_idToIndex.find(p->ID)->second] = r;
rat_array[p-> ID]=new MW244BPacket;
rat_array[Mapping_idToIndex.find(p->ID)->second]=p;
Loc x(p->x_pos);
Loc y(p->y_pos);
Direction dir(p-> dir);
RatIndexType ratId(Mapping_idToIndex.find(p->ID)->second);
SetRatPosition(ratId, x, y, dir);
UpdateScoreCard(Mapping_idToIndex.find(p-> ID)->second);
expected_seqno[p->ID] = p->sequence_number + 1;
return;
}
}
if (GLOBAL_ID < p->globalID && expected_seqno[p->ID] <= p->sequence_number )
GLOBAL_ID = p->globalID;
if (p->status == 'a' && p->tagged_rat == M->myRatId().value())
{ // cannot discard expected_seqno[p->ID] <= p->sequence_number
// because we're getting this packet because the other side didn't get b :(
// MUST send b
MW244BPacket q;
makePacket(&q,'b',-1, updateSeqNo);
sendPacketToPlayers(q);
cout<<p->sequence_number<<"Seq number"<<endl;
cout<<prevseq_a[p->ID]<<"Previous Seq number"<<endl;
if (p->sequence_number > prevseq_a[p->ID])
{ // dealing with duplicates
DrawString("You have been tagged!",21,200,250);
M->scoreIs( M->score().value()-5 );
UpdateScoreCard(0);
NewPosition(M);
}
prevseq_a[p->ID] = p->sequence_number;
}
else if (p->status == 'a' && expected_seqno[p->ID] <= p->sequence_number){
//RatIndexType ratId(p-> ID);
//ClearRatPosition(ratId);
RatIndexType ratId( Mapping_idToIndex.find(p->ID)->second);
ClearRatPosition(ratId);
//.........这里部分代码省略.........
示例7: myPacket
bool myPacket(MW244BPacket *p, Sockaddr *remote) {
return Mapping_idToIndex.find(p->ID)->second == Mapping_idToIndex.find(M->myRatId().value())->second && p->time == start_time;
}
示例8: setMapping
void setMapping()
{
participation = 0;
if (M->myRatId().value() == 7)
{
Mapping_idToIndex.insert(pair<int, int>(7,0));
for(int i = 0; i < 7 ; i++)
Mapping_idToIndex.insert(pair<int, int>(i,i+1));
Mapping_indexToId.insert(pair<int, int>(0,7));
Mapping_indexToId.insert(pair<int, int>(1,0));
Mapping_indexToId.insert(pair<int, int>(2,1));
Mapping_indexToId.insert(pair<int, int>(3,2));
Mapping_indexToId.insert(pair<int, int>(4,3));
Mapping_indexToId.insert(pair<int, int>(5,4));
Mapping_indexToId.insert(pair<int, int>(6,5));
Mapping_indexToId.insert(pair<int, int>(7,6));
}
else if (M->myRatId().value() == 6)
{
Mapping_idToIndex.insert(pair<int, int>(6,0));
Mapping_idToIndex.insert(pair<int, int>(7,1));
for(int i = 0; i < 6; i++)
Mapping_idToIndex.insert(pair<int, int>(i,i+2));
Mapping_indexToId.insert(pair<int, int>(0,6));
Mapping_indexToId.insert(pair<int, int>(1,7));
Mapping_indexToId.insert(pair<int, int>(2,0));
Mapping_indexToId.insert(pair<int, int>(3,1));
Mapping_indexToId.insert(pair<int, int>(4,2));
Mapping_indexToId.insert(pair<int, int>(5,3));
Mapping_indexToId.insert(pair<int, int>(6,4));
Mapping_indexToId.insert(pair<int, int>(7,5));
}
else if (M->myRatId().value() == 5)
{
Mapping_idToIndex.insert(pair<int, int>(5,0));
Mapping_idToIndex.insert(pair<int, int>(6,1));
Mapping_idToIndex.insert(pair<int, int>(7,2));
for(int i = 0; i < 5; i++)
Mapping_idToIndex.insert(pair<int, int>(i,i+3));
Mapping_indexToId.insert(pair<int, int>(0,5));
Mapping_indexToId.insert(pair<int, int>(1,6));
Mapping_indexToId.insert(pair<int, int>(2,7));
Mapping_indexToId.insert(pair<int, int>(3,0));
Mapping_indexToId.insert(pair<int, int>(4,1));
Mapping_indexToId.insert(pair<int, int>(5,2));
Mapping_indexToId.insert(pair<int, int>(6,3));
Mapping_indexToId.insert(pair<int, int>(7,4));
}
else if (M->myRatId().value() == 4)
{
Mapping_idToIndex.insert(pair<int, int>(4,0));
Mapping_idToIndex.insert(pair<int, int>(5,1));
Mapping_idToIndex.insert(pair<int, int>(6,2));
Mapping_idToIndex.insert(pair<int, int>(7,3));
for(int i = 0; i < 4; i++)
Mapping_idToIndex.insert(pair<int, int>(i,i+4));
Mapping_indexToId.insert(pair<int, int>(0,4));
Mapping_indexToId.insert(pair<int, int>(1,5));
Mapping_indexToId.insert(pair<int, int>(2,6));
Mapping_indexToId.insert(pair<int, int>(3,7));
Mapping_indexToId.insert(pair<int, int>(4,0));
Mapping_indexToId.insert(pair<int, int>(5,1));
Mapping_indexToId.insert(pair<int, int>(6,2));
Mapping_indexToId.insert(pair<int, int>(7,3));
}
else if (M->myRatId().value() == 3)
{
Mapping_idToIndex.insert(pair<int, int>(3,0));
Mapping_idToIndex.insert(pair<int, int>(4,1));
Mapping_idToIndex.insert(pair<int, int>(5,2));
Mapping_idToIndex.insert(pair<int, int>(6,3));
Mapping_idToIndex.insert(pair<int, int>(7,4));
for(int i = 0; i < 3; i++)
Mapping_idToIndex.insert(pair<int, int>(i,i+5));
Mapping_indexToId.insert(pair<int, int>(0,3));
Mapping_indexToId.insert(pair<int, int>(1,4));
Mapping_indexToId.insert(pair<int, int>(2,5));
Mapping_indexToId.insert(pair<int, int>(3,6));
Mapping_indexToId.insert(pair<int, int>(4,7));
Mapping_indexToId.insert(pair<int, int>(5,0));
Mapping_indexToId.insert(pair<int, int>(6,1));
Mapping_indexToId.insert(pair<int, int>(7,2));
}
else if (M->myRatId().value() == 2)
{
Mapping_idToIndex.insert(pair<int, int>(2,0));
Mapping_idToIndex.insert(pair<int, int>(3,1));
Mapping_idToIndex.insert(pair<int, int>(4,2));
Mapping_idToIndex.insert(pair<int, int>(5,3));
Mapping_idToIndex.insert(pair<int, int>(6,4));
Mapping_idToIndex.insert(pair<int, int>(7,5));
for(int i = 0; i < 2; i++)
Mapping_idToIndex.insert(pair<int, int>(i,i+6));
Mapping_indexToId.insert(pair<int, int>(0,2));
Mapping_indexToId.insert(pair<int, int>(1,3));
Mapping_indexToId.insert(pair<int, int>(2,4));
Mapping_indexToId.insert(pair<int, int>(3,5));
Mapping_indexToId.insert(pair<int, int>(4,6));
Mapping_indexToId.insert(pair<int, int>(5,7));
//.........这里部分代码省略.........