Blackberry Messenger Bedienungsanleitung Seite 9

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 11
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 8
http://cmer.uoguelph.ca 9
Now that we know how to post message to the profile, we can use this knowledge to post
more messages about the user’s progress in the game.
The next thing we’ll do is actually increase the counters when the user won, tied to lost
the game. To do this, we need to go to the alertWinner() function.
Inside the first If-statement, we can include the line of code userWins++; as the
variable winner will be equal to 1 if the user won. Inside the else-if portion, where we
check if winner is equal to 2, we can include the line of code userLoses++; as this
portion will be true if the user lost the game. Finally, if the game was a tie, we can
include userTies++; in the else statement.
Since we also need to keep track of the number of games the user played in order to
display it in their BBM profile, we also need to increment the triesCounter++;
variable at the end of the alertWinner function, as this function gets called each time the
game is over.
Now let’s work on posting to the users profile when each of these events occurs. In the
first if-statement, add the following lines of code to post to the users profile when they
won a game.
var itemText = "Beat the unbeatable Tic Tac Toe game!";
var itemIcon = "local:///thumbsup.jpg";
var itemOptions = { text: itemText, icon: itemIcon };
blackberry.bbm.platform.self.profilebox.addItem(itemOptions);
In the else-if statement which handles the event if the user lost the game, add the
following lines of code.
var itemText = "Failed to beat the unbeatable Tic Tac Toe game!";
var itemIcon = "local:///thumbsdown.jpg";
var itemOptions = { text: itemText, icon: itemIcon };
blackberry.bbm.platform.self.profilebox.addItem(itemOptions);
Finally, in the else statement which handles tied games, insert the following code.
var itemText = "Was so close to beating the unbeatable Tic Tac
Toe game, but sadly the game was tied!";
var itemIcon = "local:///thumbsdown.jpg";
var itemOptions = { text: itemText, icon: itemIcon };
blackberry.bbm.platform.self.profilebox.addItem(itemOptions);
Another good thing to have is an update if the user has not beaten the game after a certain
amount of times playing. To accomplish this, we add another if-statement to determine if
the triesCounter variable is a multiple of 5. If it is a multiple of 5, we would post a
message on the users profile letting everyone on their contact list know how many
attempts they made. To do this, we need the following lines of code at the end of the
alertWinner function.
Seitenansicht 8
1 2 3 4 5 6 7 8 9 10 11

Kommentare zu diesen Handbüchern

Keine Kommentare