Guest User

Untitled

a guest
Jan 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. - (void) reportScore: (int64_t) score forCategory: (NSString*) category
  2. {
  3. GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
  4. scoreReporter.value = score;
  5. [scoreReporter reportScoreWithCompletionHandler: ^(NSError *error)
  6. {
  7. [self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error];
  8. }];
  9. }
  10.  
  11. GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
  12. request.minPlayers = 1;
  13. request.maxPlayers = 1;
  14.  
  15. [[GKMatchmaker sharedMatchmaker] findMatchForRequest:request
  16. withCompletionHandler:^(GKMatch *match, NSError *error) {
  17. if (error || !match) {
  18. // handle the error
  19. }
  20. else if (match != nil){
  21. // match found
  22. }}];
  23.  
  24. /*GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
  25. request.minPlayers = 1;
  26. request.maxPlayers = 1;
  27. GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
  28. mmvc.matchmakerDelegate = self;
  29. currentMatch.delegate=self;
  30. [self presentModalViewController:mmvc animated:YES];*/
  31. //[mmvc release];
  32. }
  33. - (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state {
  34. switch (state){
  35. case GKPlayerStateConnected:
  36. if (match.expectedPlayerCount == 0) {
  37. // start the match
  38. }
  39. break;
  40. case GKPlayerStateDisconnected:
  41. // remove the player from the match, notify other players, etc
  42. break;
  43. }
  44. }
  45. - (void)matchmakerViewControllerWasCancelled:(GKMatchmakerViewController *)viewController{}
  46.  
  47. // Matchmaking has failed with an error
  48. - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFailWithError:(NSError *)error{
  49. }
  50.  
  51.  
  52. // A peer-to-peer match has been found, the game should start
  53. - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match{
  54. }
  55.  
  56. // Players have been found for a server-hosted game, the game should start
  57. - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindPlayers:(NSArray *)playerIDs{
  58. }
  59.  
  60. // An invited player has accepted a hosted invite. Apps should connect through the hosting server and then update the player's connected state (using setConnected:forHostedPlayer:)
  61. - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didReceiveAcceptFromHostedPlayer:(NSString *)playerID {
  62. }
  63. - (void) sendPosition
  64. {
  65. NSError *error;
  66. NSString* str = @"teststring";
  67. NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
  68. // NSData *packet = [NSData dataWithBytes:&msg length:sizeof(PositionPacket)];
  69. [currentMatch sendDataToAllPlayers: data withDataMode: GKMatchSendDataUnreliable error:&error];
  70. if (error != nil)
  71. {
  72. // Handle the erro.r
  73. }
  74. }
Add Comment
Please, Sign In to add comment