本文整理汇总了C++中mazewarinstance::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NewPosition
void NewPosition(MazewarInstance::Ptr m)
//void NewPosition(MazewarInstance *m)
{
Loc newX(0);
Loc newY(0);
Direction dir(0); /* start on occupied square */
while (M->maze_[newX.value()][newY.value()]) {
/* MAZE[XY]MAX is a power of 2 */
newX = Loc(random() & (MAZEXMAX - 1));
newY = Loc(random() & (MAZEYMAX - 1));
/* In real game, also check that square is
unoccupied by another rat */
}
/* prevent a blank wall at first glimpse */
if (!m->maze_[(newX.value())+1][(newY.value())]) dir = Direction(NORTH);
if (!m->maze_[(newX.value())-1][(newY.value())]) dir = Direction(SOUTH);
if (!m->maze_[(newX.value())][(newY.value())+1]) dir = Direction(EAST);
if (!m->maze_[(newX.value())][(newY.value())-1]) dir = Direction(WEST);
m->xlocIs(newX);
m->ylocIs(newY);
m->dirIs(dir);
}
示例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: DoViewUpdate
void DoViewUpdate()
{
mws_render_wipe(M->state);
mws_render_draw(M->state);
/* XXX: Hack. I don't want to deal with setting updateView in
* the mws_* methods, thus just always update view, even
* if it is unnecessary.
*/
updateView = TRUE;
if (updateView) { /* paint the screen */
/* XXX: I don't think this is necessary anymore as the
* mws_render_* functions take care of it.
ShowPosition(MY_X_LOC, MY_Y_LOC, MY_DIR);
*/
if (M->peeking())
ShowView(M->xPeek(), M->yPeek(), M->dirPeek());
else
ShowView(MY_X_LOC, MY_Y_LOC, MY_DIR);
updateView = FALSE;
}
}
示例4: 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());
}
示例5: DoViewUpdate
void DoViewUpdate()
{
if (updateView) { /* paint the screen */
ShowPosition(MY_X_LOC, MY_Y_LOC, MY_DIR);
if (M->peeking())
ShowView(M->xPeek(), M->yPeek(), M->dirPeek());
else
ShowView(MY_X_LOC, MY_Y_LOC, MY_DIR);
updateView = FALSE;
}
}
示例6: shoot
void shoot()
{
if (proj.present) return;
proj.present = true;
proj.x = M->xloc().value();
proj.y = M->yloc().value();
proj.prev_x = proj.prev_y = 0;
proj.direction = M->dir().value();
gettimeofday(&proj.shootTime, NULL);
M->scoreIs( M->score().value()-1 );
UpdateScoreCard(0);
}
示例7: main
int main(int argc, char *argv[])
{
Loc x(1);
Loc y(5);
Direction dir(0);
char *ratName;
signal(SIGHUP, quit);
signal(SIGINT, quit);
signal(SIGTERM, quit);
if (argc >= 2)
ratName = strdup(argv[1]);
else
getName("Welcome to CS244B MazeWar!\n\nYour Name", &ratName);
M = MazewarInstance::mazewarInstanceNew(string(ratName));
MazewarInstance* a = M.ptr();
strncpy(M->myName_, ratName, NAMESIZE);
free(ratName);
MazeInit(argc, argv);
mws_add_rat(M->state, &M->local_id, MY_X_LOC, MY_Y_LOC, MY_MW_DIR_T,
M->myName_);
mws_set_local_rat(M->state, M->local_id);
play();
return (0);
}
示例8: main
/* ----------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
Loc x(1);
Loc y(5);
Direction dir(0);
char *ratName;
signal(SIGHUP, quit);
signal(SIGINT, quit);
signal(SIGTERM, quit);
struct timeval zero;
struct timeval now;
gettimeofday(&now, NULL);
start_time = time_diff(now, zero);
getName("Welcome to CS244B MazeWar!\n\nYour Name", &ratName);
ratName[strlen(ratName)-1] = 0;
M = MazewarInstance::mazewarInstanceNew(string(ratName));
MazewarInstance* a = M.ptr();
strncpy(M->myName_, ratName, NAMESIZE);
free(ratName);
MazeInit(argc, argv);
NewPosition(M);
play();
return 0;
}
示例9: 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;
}
示例10: sendPacketToPlayers
void sendPacketToPlayers(MW244BPacket p)
{
ConvertOutgoing(&p);
if (sendto(M->theSocket(), &p, sizeof(MW244BPacket), 0, (struct sockaddr *)&groupAddr, sizeof(Sockaddr)) < 0)
MWError("Sample error");
}
示例11: _backward
void _backward()
{
register int tx = MY_X_LOC;
register int ty = MY_Y_LOC;
switch(MY_DIR) {
case NORTH: if (!M->maze_[tx-1][ty]) tx--; break;
case SOUTH: if (!M->maze_[tx+1][ty]) tx++; break;
case EAST: if (!M->maze_[tx][ty-1]) ty--; break;
case WEST: if (!M->maze_[tx][ty+1]) ty++; break;
default:
MWError("bad direction in Backward");
}
if ((MY_X_LOC != tx) || (MY_Y_LOC != ty)) {
M->xlocIs(Loc(tx));
M->ylocIs(Loc(ty));
updateView = TRUE;
}
}
示例12: GetRatScore
/* This is just for the sample version, rewrite your own */
Score GetRatScore(RatIndexType ratId)
{
if (ratId.value() == 0 )
{ return(M->score()); }
else
{
if(rat_array[(ratId.value())]==NULL)
return 0;
else
return rat_array[ratId.value()]->score;
}
}
示例13: peekRight
void peekRight()
{
M->xPeekIs(MY_X_LOC);
M->yPeekIs(MY_Y_LOC);
M->dirPeekIs(MY_DIR);
switch(MY_DIR) {
case NORTH: if (!M->maze_[MY_X_LOC+1][MY_Y_LOC]) {
M->xPeekIs(MY_X_LOC + 1);
M->dirPeekIs(EAST);
}
break;
case SOUTH: if (!M->maze_[MY_X_LOC-1][MY_Y_LOC]) {
M->xPeekIs(MY_X_LOC - 1);
M->dirPeekIs(WEST);
}
break;
case EAST: if (!M->maze_[MY_X_LOC][MY_Y_LOC+1]) {
M->yPeekIs(MY_Y_LOC + 1);
M->dirPeekIs(SOUTH);
}
break;
case WEST: if (!M->maze_[MY_X_LOC][MY_Y_LOC-1]) {
M->yPeekIs(MY_Y_LOC - 1);
M->dirPeekIs(NORTH);
}
break;
default:
MWError("bad direction in PeekRight");
}
/* if any change, display the new view without moving! */
if ((M->xPeek() != MY_X_LOC) || (M->yPeek() != MY_Y_LOC)) {
M->peekingIs(TRUE);
updateView = TRUE;
}
}
示例14:
void
__rightTurn(void)
{
M->dirIs(_rightTurn[MY_DIR]);
updateView = TRUE;
}
示例15: 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"); }
}