How to Develop an iPad Board Game App: Part 1/2
10 posts
• Page 1 of 1
How to Develop an iPad Board Game App: Part 1/2
This is the official thread to discuss the following blog post: How to Develop an iPad Board Game App: Part 1/2
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1780
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Re: How to Develop an iPad Board Game App: Part 1/2
Finally! I've been waiting for this tutorial for a long time! 
Thanks a lot!
Thanks a lot!
- wdflu
- Hacker
- Posts: 10
- Joined: Sun Nov 27, 2011 12:06 pm
- Has thanked: 0 time
- Been thanked: 0 time
Re: How to Develop an iPad Board Game App: Part 1/2
Very nice! I'm sorry, but could you elaborate more on how the navigation functions work, and more about the moveSurroundsCountersForColumn: method? My C-programming kung-fu is weak as I came to Objective-C from a Ruby background, so I don't really fully comprehend typedefs and blocks.. But fantastic tutorial anyway! Learnt loads. By the way I'm @sg_gabriel here
------
Get your app on the App Store in the shortest time. No designers needed.
Beautiful iPhone design templates with reusable sliced image assets and PSD files you can customize. Focus on your coding, leave the design to us.
http://www.getappninja.com
Twitter: https://twitter.com/sg_gabriel
------
Get your app on the App Store in the shortest time. No designers needed.
Beautiful iPhone design templates with reusable sliced image assets and PSD files you can customize. Focus on your coding, leave the design to us.
http://www.getappninja.com
Twitter: https://twitter.com/sg_gabriel
-

PenguinGab - Baby Hacker
- Posts: 7
- Joined: Sat Apr 07, 2012 7:43 pm
- Has thanked: 0 time
- Been thanked: 1 time
Re: How to Develop an iPad Board Game App: Part 1/2
PenguinGab wrote:Very nice! I'm sorry, but could you elaborate more on how the navigation functions work, and more about the moveSurroundsCountersForColumn: method? My C-programming kung-fu is weak as I came to Objective-C from a Ruby background, so I don't really fully comprehend typedefs and blocks.. But fantastic tutorial anyway! Learnt loads. By the way I'm @sg_gabriel here
Let's see if I can make it a bit more clear.
Blocks are an Obj-C language feature that allow you to define distinct segments of code that can be passed around just like variables. A block has a 'signature'just like any other method, which details its return value and any arguments that are passed to it. The typedef is simply used to create an alias for a particular signature. This is all that typedefs do - alias things.
The moveSurroundsCountersForColumn takes a BoardNavigationFunction, which is a block. In other words, you can pass a segment of code to this method which dictates how it moves from one cell to the next. I practice, this is one of the 8 navigation functions declared at the top of the file.
Within moveSurroundsCountersForColumn the passed BoardNavigationFunction is invoked on each iteration. As an example, let's say BoardNavigationFunctionRight was passed to this function. When invoked, this function will increment the value of the column variable that was passed to it. This results in one move to the function moving one cell to the right. Note, this also makes use of C-style programming where the address of a variable is passed then de-referenced in order to increment / decrement it. You can probably ignore this!
I hope this makes sense. If I were you I would read a few tutorials and just give blocks a go!
Colin E.
-

ColinEberhardt - iOS Tutorial Team Member
- Posts: 32
- Joined: Sat Nov 03, 2012 2:17 pm
- Has thanked: 3 times
- Been thanked: 10 times
Re: How to Develop an iPad Board Game App: Part 1/2
Thank you for the very good tutorial!!!
I have a question on 'moveSurroundsCountersForColumn' unit testing.
I have no idea how I can ensure that I have full branch coverage.
Is there any suggestions how to think about algorithms?
I have a question on 'moveSurroundsCountersForColumn' unit testing.
I have no idea how I can ensure that I have full branch coverage.
Is there any suggestions how to think about algorithms?
- nafu
- n00b
- Posts: 1
- Joined: Tue Feb 26, 2013 10:06 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: How to Develop an iPad Board Game App: Part 1/2
nafu wrote:I have a question on 'moveSurroundsCountersForColumn' unit testing.
I have no idea how I can ensure that I have full branch coverage.
Is there any suggestions how to think about algorithms?
Good question! in the absence of dedicated code coverage tools, this basically just takes discipline. In the past I have added comments in my code that indicate the various code paths then added unit test that refer to each of these. This makes it easier to audit your code visually in order to test for coverage.
However, this is pretty tedious!
If you really care about getting full coverage of branches or conditions, you are going to need tools. I've used code coverage tools within Eclipse and Visual Studio before - ones the visually highlight the code that has been covered as well as report metrics are the best.
I haven't tried this in Xcode yet, but it does appear that it is possible:
http://www.infinite-loop.dk/blog/2011/0 ... it-all-up/
Regards, Colin E.
-

ColinEberhardt - iOS Tutorial Team Member
- Posts: 32
- Joined: Sat Nov 03, 2012 2:17 pm
- Has thanked: 3 times
- Been thanked: 10 times
Re: How to Develop an iPad Board Game App: Part 1/2
I think you have the "r" variable increment/decrement for BoardNavigationFunctionLeftUp and BoardNavigationFunctionLeftDown reversed. For BoardNavigationFunctionLeftUp, shouldn't it be (*r)--, and BoardNavigationFunctionLeftDown (*r)++? As in...
- Code: Select all
BoardNavigationFunction BoardNavigationFunctionLeftUp = ^(NSInteger* c, NSInteger* r) {
(*c)--;
(*r)--;
};
BoardNavigationFunction BoardNavigationFunctionLeftDown = ^(NSInteger* c, NSInteger* r) {
(*c)--;
(*r)++;
};
Re: How to Develop an iPad Board Game App: Part 1/2
First off: great tutorial.
I have a question about your use of blocks.
I tried changing the block signature from NSInteger to int, so that rather than defining it as you did:
I did this:
I changed the typedef accordingly, got everything to compile and run and found that it did not work. The columns and rows do not get altered as they did with the objects. I am still new to blocks, so I wanted to know if this was a scoping issue? It actually seems to me that the int behavior makes more sense since the values passed in are supposed to be copied into the block and should not change the originals. Are you circumventing that behavior in your code by the deference?
What am I missing?
Thanks.
P.S. I ran some coding tests. It looks like this has nothing to do with primitives vs. objects but rather about the fact that you are doing a deference in the block. That is what allows you to change the values of column and row. This seems to go against the idea that blocks have their own protected scope -- on the other hand it does work...
I guess technically you are not changing the value of the parameters, they always point to the same thing, you just change the value that is being pointed at. So I think I have answered my own question.
Thanks again!
I have a question about your use of blocks.
I tried changing the block signature from NSInteger to int, so that rather than defining it as you did:
- Code: Select all
BoardNavigationFunction BoardNavigationFunctionRight = ^(NSInteger* c, NSInteger* r) {
(*c)++;
};
I did this:
- Code: Select all
BoardNavigationFunction BoardNavigationFunctionRight = ^(int c, int r) {
c++;
};
I changed the typedef accordingly, got everything to compile and run and found that it did not work. The columns and rows do not get altered as they did with the objects. I am still new to blocks, so I wanted to know if this was a scoping issue? It actually seems to me that the int behavior makes more sense since the values passed in are supposed to be copied into the block and should not change the originals. Are you circumventing that behavior in your code by the deference?
What am I missing?
Thanks.
P.S. I ran some coding tests. It looks like this has nothing to do with primitives vs. objects but rather about the fact that you are doing a deference in the block. That is what allows you to change the values of column and row. This seems to go against the idea that blocks have their own protected scope -- on the other hand it does work...
Thanks again!
- zenwar
- n00b
- Posts: 1
- Joined: Thu Mar 07, 2013 2:55 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: How to Develop an iPad Board Game App: Part 1/2
jieuryli wrote:I think you have the "r" variable increment/decrement for BoardNavigationFunctionLeftUp and BoardNavigationFunctionLeftDown reversed.
Ooops - well spotted! Fortunately this doesn't actually have an impact on the gameplay.
Colin E.
-

ColinEberhardt - iOS Tutorial Team Member
- Posts: 32
- Joined: Sat Nov 03, 2012 2:17 pm
- Has thanked: 3 times
- Been thanked: 10 times
Re: How to Develop an iPad Board Game App: Part 1/2
zenwar wrote:I tried changing the block signature from NSInteger to int
NSInteger and int are interchangeable, however ... you have swapped an NSInteger* for int - the first (NSInteger*) is a pointer to an integer, whereas the second (int) is an integer.
Primitive / value types are passed by value rather than passed by reference. In order to allow the block to update the rows / columns, you have to pass a pointer to the value, which is then de-referenced and updated.
Hope that helps!
Colin E.
-

ColinEberhardt - iOS Tutorial Team Member
- Posts: 32
- Joined: Sat Nov 03, 2012 2:17 pm
- Has thanked: 3 times
- Been thanked: 10 times
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: Exabot [Bot] and 7 guests