/* fonction principale */ int main(int argc,char *argv[]) { Window window; Display *display; Visual *visual; XEvent event; XImage *ximage; GC gc; int process_fils; int depth,done; long event_mask; char buffer; /* creation de la fenetre de l'application */ CreateMainWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Pong"); /* recuperation des variables */ window=GetAppWindow(); display=GetAppDisplay(); /* affichage de la fenetre */ XMapWindow(display,window); while(TRUE) Pong(); return 0; }
int main(void) { Game Pong(1024,768,"Speedball"); Pong.start(); return 0; }
int main(int argc, char* argv[]) { max_iteration = abs(atoi(argv[1])); iter = 1; if (setjmp(Main) == 0) Ping(); if (setjmp(Main) == 0) Pong(); longjmp(PointA, 1); return 0; }
int main() { std::cout << "Ready… Set… Go!\n"; std::thread Ping(ping); std::thread Pong(pong); Ping.join(); Pong.join(); std::cout << "Done!\n"; return 0; }
int CInputAuth::Analyze(LPDESC d, BYTE bHeader, const char * c_pData) { if (!g_bAuthServer) { sys_err ("CInputAuth class is not for game server. IP %s might be a hacker.", inet_ntoa(d->GetAddr().sin_addr)); d->DelayedDisconnect(5); return 0; } int iExtraLen = 0; if (test_server) sys_log(0, " InputAuth Analyze Header[%d] ", bHeader); switch (bHeader) { case HEADER_CG_PONG: Pong(d); break; case HEADER_CG_LOGIN3: Login(d, c_pData); break; //2012.07.19 OpenID : 김용욱 case HEADER_CG_LOGIN5_OPENID: if (openid_server) LoginOpenID(d, c_pData); else sys_err("HEADER_CG_LOGIN5_OPENID : wrong client access"); break; case HEADER_CG_PASSPOD_ANSWER: PasspodAnswer(d, c_pData); break; case HEADER_CG_HANDSHAKE: break; default: sys_err("This phase does not handle this header %d (0x%x)(phase: AUTH)", bHeader, bHeader); break; } return iExtraLen; }
int main() { //Create the rendering window sf::RenderWindow Pong(sf::VideoMode(1200, 600, 32), "Pong"); //Load the sprite image from a file sf::Image PaddleImage; if (!PaddleImage.LoadFromFile("paddle.png")) return EXIT_FAILURE; sf::Image BallImage; if (!BallImage.LoadFromFile("ball.png")) return EXIT_FAILURE; //Create the Sprites sf::Sprite PaddleSpriteLeft(PaddleImage); PaddleSpriteLeft.SetPosition(20.f, 250.f); sf::Sprite PaddleSpriteRight(PaddleImage); PaddleSpriteRight.SetPosition(1150.f, 250.f); sf::Sprite BallSprite(BallImage); BallSprite.SetPosition(570.f, 250.f); float VelocityX = 200.f; float VelocityY = 100.f; int ScoreLeft = 0; int ScoreRight = 0; //position the initial Score sf::String Score; Score.SetText("Score: 0 | 0"); Score.SetFont(sf::Font::GetDefaultFont()); Score.SetPosition(530.f, 10.f); sf::SoundBuffer Buffer; if (!Buffer.LoadFromFile("bip.ogg")) { // Do nothing - the game is playable without sound } sf::Sound Beep; Beep.SetBuffer(Buffer); while (Pong.IsOpened()) { sf::Event Event; while (Pong.GetEvent(Event)) { //Close window : exit if (Event.Type == sf::Event::Closed) Pong.Close(); //Escape key : exit if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)) Pong.Close(); } //Get elapsed time float ElapsedTime = Pong.GetFrameTime(); //Move the left paddle if (Pong.GetInput().IsKeyDown(sf::Key::W)) if (PaddleSpriteLeft.GetPosition().y > 0) PaddleSpriteLeft.Move(0, -250 * ElapsedTime); if (Pong.GetInput().IsKeyDown(sf::Key::S)) if (PaddleSpriteLeft.GetPosition().y < 500) PaddleSpriteLeft.Move(0, 250 * ElapsedTime); //Move the right paddle if (Pong.GetInput().IsKeyDown(sf::Key::Up)) if (PaddleSpriteRight.GetPosition().y > 0) PaddleSpriteRight.Move(0, -250 * ElapsedTime); if (Pong.GetInput().IsKeyDown(sf::Key::Down)) if (PaddleSpriteRight.GetPosition().y < 500) PaddleSpriteRight.Move(0, 250 * ElapsedTime); //Move the ball with collision detection BallSprite.Move(VelocityX * ElapsedTime, VelocityY * ElapsedTime); if (BallSprite.GetPosition().x < 1) { ScoreRight++; std::stringstream stream; stream << "Score: " << ScoreLeft << " | " << ScoreRight; std::string result = stream.str(); Score.SetText(result); sf::Sleep(0.7f); BallSprite.SetPosition(570.f, 250.f); VelocityX = 200.f; VelocityY = -100.f; } if (BallSprite.GetPosition().x >1170) { ScoreLeft++; std::stringstream stream (std::stringstream::in | std::stringstream::out); stream << "Score: " << ScoreLeft << " | " << ScoreRight; std::string result = stream.str(); Score.SetText(result); sf::Sleep(0.7f); BallSprite.SetPosition(570.f, 250.f); VelocityX = -200.f; VelocityY = 100.f; } if (BallSprite.GetPosition().y < 0 || BallSprite.GetPosition().y > 570) { VelocityY *= -1.; Beep.Play(); } if (BallSprite.GetPosition().x < 48 && BallSprite.GetPosition().x > 20 && BallSprite.GetPosition().y > PaddleSpriteLeft.GetPosition().y && BallSprite.GetPosition().y < PaddleSpriteLeft.GetPosition().y + 100) { VelocityX *= -1.2; Beep.Play(); } if (BallSprite.GetPosition().x > 1122 && BallSprite.GetPosition().x < 1150 && BallSprite.GetPosition().y > PaddleSpriteRight.GetPosition().y && BallSprite.GetPosition().y < PaddleSpriteRight.GetPosition().y + 100) { VelocityX *= -1.2; Beep.Play(); } //Clear the screen Pong.Clear(); Pong.Draw(PaddleSpriteLeft); Pong.Draw(PaddleSpriteRight); Pong.Draw(BallSprite); Pong.Draw(Score); Pong.Display(); } std::cout << "Final Score: " << ScoreLeft << " | " << ScoreRight << std::endl; return EXIT_SUCCESS; }
void menu(void) { struct Solid cursor; char selection = 0; displayMenu(&cursor); StartTimer(0, 200); StartTimer(1, 200); for (;;) { if (CheckTimer(0)) { if (GetUp()) { if (selection > 0) { solid_moveLocation(&cursor, cursor.x - 22, cursor.y); selection--; StartTimer(0, 200); } } else if (GetDown()) { if (selection < 7) { solid_moveLocation(&cursor, cursor.x + 22, cursor.y); selection++; StartTimer(0, 200); } } } if (CheckTimer(1)) { if (GetTopLeft()) { if (selection == 0) { StarBattle(); displayMenu(&cursor); selection = 0; } else if (selection == 1) { BrickBreaker(); displayMenu(&cursor); selection = 0; } else if (selection == 2) { Debris(); displayMenu(&cursor); selection = 0; } else if (selection == 3) { Pong(); displayMenu(&cursor); selection = 0; } else if (selection == 4) { Draw(); displayMenu(&cursor); selection = 0; } StartTimer(1, 200); } } } }
void Ponger::OnUpdatedEntity(const Safir::Dob::EntityProxy entityProxy) { Pong(entityProxy); }
void Ponger::OnNewEntity(const Safir::Dob::EntityProxy entityProxy) { Pong(entityProxy); }
void JabberProtocol::OnTag(XMLEntity *entity) { char buffer[4096]; // general buffer space static int seen_streams = 0; if (entity->IsCompleted() && !strcasecmp(entity->Name(), "iq")) { // handle roster retrival if (entity->Child("query") && entity->Child("query")->Attribute("xmlns") && !strcasecmp(entity->Child("query")->Attribute("xmlns"),"jabber:iq:roster")) { ParseRosterList(entity); return; } // handle session retrival if (entity->Attribute("id") && entity->Attribute("type") && !strcasecmp(entity->Attribute("type"), "result") && !strcasecmp(entity->Attribute("id"), "sess_1")) { release_sem(logged); mainWindow->Lock(); mainWindow->PostMessage(JAB_LOGGED_IN); mainWindow->Unlock(); return; } // handle binding retrival if (entity->Attribute("id") && entity->Attribute("type") && !strcasecmp(entity->Attribute("type"), "result") && !strcasecmp(entity->Attribute("id"), "bind_0")) { jid = BString(entity->Child("bind")->Child("jid")->Data()); fprintf(stderr, "JID: %s.\n", jid.String()); Session(); return; } if (entity->Attribute("type") && entity->Child("query") && !strcasecmp(entity->Attribute("type"), "result") && entity->Child("query", "xmlns", "jabber:iq:register")) { Authorize(); return; } if (entity->Attribute("type") && entity->Attribute("id") && !strcasecmp(entity->Attribute("type"), "result") && !strcasecmp(entity->Attribute("id"), "request_room_info")) { BMessage msg(JAB_PREFERENCES_DATAFORM); msg.AddPointer("XMLEntity", entity); MessageRepeater::Instance()->PostMessage(&msg); return; } if (entity->Attribute("type") && entity->Attribute("id") && !strcasecmp(entity->Attribute("type"), "error")) { if (!strcasecmp(entity->Attribute("id"), "storage_request")) { _storage_supported = false; return; } else if (!strcasecmp(entity->Attribute("id"), "save_conferences")) { _storage_supported = false; sprintf(buffer, "Storage XEP-0049 is not supported on server. Cannot save conferences.\n\nNext time will try save to roster."); ModalAlertFactory::Alert(buffer, "Pity", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); return; } else if (!strcasecmp(entity->Attribute("id"), "request_room_info")) { if (entity->Child("error") && entity->Child("error")->Child("text") && entity->Child("error")->Attribute("code")) sprintf(buffer, "Error %s:\n\n%s", entity->Child("error")->Attribute("code"), entity->Child("error")->Child("text")->Data()); else sprintf(buffer, "Error %s", entity->Child("error")->Attribute("code")); ModalAlertFactory::Alert(buffer, "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); return; } if (entity->Child("error") && entity->Child("error")->Child("text") && entity->Child("error")->Attribute("code")) sprintf(buffer, "Error %s:\n\n%s", entity->Child("error")->Attribute("code"), entity->Child("error")->Child("text")->Data()); else sprintf(buffer, "Error %s", entity->Child("error")->Attribute("code")); ModalAlertFactory::Alert(buffer, "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); Disconnect(); return; } if (entity->Attribute("id") && entity->Child("query") && entity->Child("query")->Attribute("xmlns") && entity->Attribute("type") && !strcasecmp(entity->Attribute("id"), "storage_request") && !strcasecmp(entity->Attribute("type"), "result") && !strcasecmp(entity->Child("query")->Attribute("xmlns"), "jabber:iq:private")) { if (entity->Child("query")->Child("storage")) ParseStorage(entity->Child("query")->Child("storage")); return; } if (entity->Attribute("type") && !strcasecmp(entity->Attribute("type"), "get")) { BString iq_from; BString iq_id; if (entity->Attribute("from")) { iq_from = BString(entity->Attribute("from")); } if (entity->Attribute("id")) { iq_id = BString(entity->Attribute("id")); } // handle version request XMLEntity *query = entity->Child("query"); if (query && query->Attribute("xmlns")) { if (!strcasecmp(query->Attribute("xmlns"), "jabber:iq:version")) { ProcessVersionRequest(iq_id, iq_from); } } // handle version request query = entity->Child("ping"); if (query && query->Attribute("xmlns")) { if (!strcasecmp(query->Attribute("xmlns"), "urn:xmpp:ping")) { Pong(iq_id, iq_from); } } return; } fprintf(stderr, "Unknown IQ message.\n"); return; } // handle authorization success if (entity->IsCompleted() && !strcasecmp(entity->Name(), "success")) { InitSession(); return; } // handle presence messages if (entity->IsCompleted() && !strcasecmp(entity->Name(), "presence")) { ProcessPresence(entity); return; } // handle stream error if (entity->IsCompleted() && !strcasecmp(entity->Name(), "stream:error")) { sprintf(buffer, "An stream error has occurred."); ModalAlertFactory::Alert(buffer, "Sorry", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); Disconnect(); return; } // handle stream error if (entity->IsCompleted() && !strcasecmp(entity->Name(), "stream:features")) { mainWindow->Lock(); int wantRegister = mainWindow->_login_new_account->Value(); mainWindow->Unlock(); if (wantRegister == B_CONTROL_ON) { if (entity->Child("register")) { mainWindow->Lock(); mainWindow->_login_new_account->SetValue(B_CONTROL_OFF); mainWindow->Unlock(); SendUserRegistration(user, pass, "haiku"); } else { sprintf(buffer, "Registration not supported on this server."); ModalAlertFactory::Alert(buffer, "Sorry", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); Disconnect(); } } else if (entity->Child("mechanisms")) Authorize(); else if (entity->Child("bind")) Bind(); else if (entity->Child("session")) Session(); return; } // handle failures if (entity->IsCompleted() && !strcasecmp(entity->Name(), "failure")) { if (entity->Child("not-authorized") != NULL) sprintf(buffer, "Not authorized failure."); else if (entity->Child("invalid-mechanism") != NULL) sprintf(buffer, "Invalid mechanism failure."); else if (entity->Child("invalid-authzid") != NULL) sprintf(buffer, "Invalid authorization Id."); else sprintf(buffer, "An failure occured."); ModalAlertFactory::Alert(buffer, "Sorry", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); Disconnect(); return; } // handle disconnection if (entity->IsCompleted() && !strcasecmp(entity->Name(), "stream:stream")) { ++seen_streams; if (seen_streams % 2 == 1) Disconnect(); return; } // handle incoming messages if (entity->IsCompleted() && !strcasecmp(entity->Name(), "message")) { //TalkManager::Instance()->Lock(); TalkManager::Instance()->ProcessMessageData(entity); //TalkManager::Instance()->Unlock(); return; } //delete entity; }