Admob Interstitial ad shows after three end games - xcode

How do i limit Admob interstitial ads to show only once after my game session has ended three times? I am try to limit amount of the ads annoying players. I am using Xcode, thanks.

Just set a counter that keeps track of the number of time a game is played, then on every 3 times, present it and reset counter
pseudo code
init:
adMobCounter = 3;
gameEnd:
adMobCounter--;
if(adMobCounter == 0)
{
adMobInterstitialPresent();
adMobCounter = 3;
}

Related

Better way to show iAd interstitial ads

Is there a better way to show interstitial ads than just picking a random number between 0-4 and if its 3 show the ad?
This method has its downsides because sometimes ads wont show for awhile and other times they will show 3 times in a row which is very annoying. Any help would be appreciated!
Why generate a random number at all? There is no requirement for you to implement your interstitials in this manner. How often do you want to show your ads? You can just increment an index and show your interstitial once it reaches a certain amount. For example:
// Create an Int to increment
var index = 0
// Call this func after an event
func showInterstitial() {
index++
if (index == 5) {
// Show ad
// Reset index
index = 0
}
}

How to keep panning only if id exists?

I'm trying to pan through a list of elements to confirm that the set minimum number of elements is there on the screen. The problem I'm running into is that 'pan' will keep going and the test will pass even if I set the minimum to a high number (greater than what's actually there on the page).
When /^I swipe through my list of chat suggestion cards I should see the minimum$/ do
i = 0
while i < 12
i += 1
wait_for_element_exists("* id:'itemContainer'")
pan("* id:'itemContainer'", :left)
end
end
Is there anyway to check if the number of id: 'itemContainer' is actually there, to make it fail if the minimum number doesn't exist?
Query will only return the elements that are currently on the screen, so you will have to swipe across to make all of the cards visible to calabash and check for them. Assuming that query("* id:'itemContainer'") would only find one at a time, i.e. the cards are a whole screen in size,
12.times do
card_before_panning = query("* id:'itemContainer'")
pan("* id:'itemContainer'", :left)
card_after_panning = query("* id:'itemContainer'")
assert_not_equal card_before_panning, card_after_panning
end
If more than one of the cards can be visible on the screen at a time then you will have to do an additional check. Assuming that there could be two visible at the time
11.times do
card_before_panning = query("* id:'itemContainer' index:0")
pan("* id:'itemContainer'", :left)
card_after_panning = query("* id:'itemContainer' index:0")
assert_not_equal card_before_panning, card_after_panning
end
# Then check that there are two visible on the final screen.
assert_equal 2, query("* id:'itemContainer'").size
Note that this will only work if the cards appear differently in your app, i.e. they have different content. If query("* id:'itemContainer'") has identical results for each of the cards then calabash will not be able to tell them apart to see if anything has changed.

How would I save "coins" in my game in Swift SpriteKit?

I have this game where the user collects coins and I want them to be able to save them and use the coins for in app purchaces. How would I do this? Could I use NSUserDefaults for this or is it something else? Thanks! I used this for saving the highScore:
EDITED
var coinDefaults = NSUserDefaults()
var coinScore = defaults.integerForKey("coinScore")
if(coins > 0)
{
coinDefaults.setInteger(coins, forKey: "coinScore")
}
var showCoins = coinDefaults.integerForKey("coinScore")
coinLabel.text = String(showCoins)
}
Reseting the coinScore
NSUserDefaults.standardUserDefaults().removeObjectForKey("coinScore")
loading the saved score
var coinScore = NSUserDefaults.standardUserDefaults().integerForKey("coinScore")
var coins = 5
updating the coinScore
if coins > coinScore {
coinScore = coins
NSUserDefaults().setInteger(coinScore, forKey: "coinScore")
}
println( NSUserDefaults().integerForKey("coinScore").description )
coins += 20
if coins > coinScore {
coinScore = coins
NSUserDefaults().setInteger(coinScore, forKey: "coinScore")
}
println( NSUserDefaults().integerForKey("coinScore").description )
yes, you have different options to save data : nsuserdefaults, write to a file and store the file, coredata, or use a webserver with a database.
If someone knows how to hack your app, he will use what is inside your app (the 3 first methods), this is why many big games use internet (webserver) to check against what was bought by the user.
But, it is not so often that someone hack your game, if he does though, he would never pay anyway. So stay with nsuserdefaults, it is simple and good enough in my opinion.

1-2-3 star level awards algorithm

What I am trying to do is to have individual star counts per level based on player performance. (1-2-3 star awards.) This will be based on what region the player reaches. I know how to award the stars but keeping track of it all is throwing me problems. First lets say a player plays level 2 and receives 1 star for their performance. Then at a later time, s/he returns to the level and gets a 2 star. I would like the star count for that specific scene to update to two stars, while only adding 1 star ( The one extra s/he got this time) to the totalStarCount.
My initial plan was to have variables:
OldStarCount
NewStarCount
TotalStarCount
Then when a player reaches say region1, and is awarded one star, then NewStarCount would be set to one, then
TotalStarCount = TotalStarCount + (NewStarCount - OldStarCount);
Then update OldStarCount = NewStarCount;
Set NewStarCount = 0;
Move On to next Scene;
Am I approaching this the correct way? Any help would be greatly appreciated.
You could have something like this
int result = 0;
int totalStars = 0;
int[] starCounts = new int[NumberOfRegions};
...
currentRegion = 42;
result = play(currentRegion);
if(result > starCounts[currentRegion]){
totalStars += result - starCounts[currentRegion];
starCounts[currentRegion] = result;
}
This is just an example of what you could do. There are obvious scalability issues with this (what happens when you want to add new regions, etc), but you get the gist.

How to end a game after an interval of time(in XNA)

I have created a game using XNA Game Studio. It consists of a square randomly moving anywhere and on clicking it, the score increases by one.
Now, what I want to do is, I want to end it after a time interval of, say, 100 seconds. So how do I do it? And where should I write that part of the code? That is, in which method? I am very new to XNA. Its just two days since I have started learning it.
In your update loop check the elapsed game time greater than 100 seconds:
int counter = 0;
protected override void Update(GameTime gameTime)
{
counter += gameTime.ElapsedGameTime.TotalSeconds;
if ( counter > 100 )
{
//end the game...
}
}
If you want the total game time since the game started, you can use the TotalGameTime property instead, then you won't need the counter.

Resources