Snake Demo Question

by Mike » Wed, 03 Mar 2010 04:22:46 GMT


Sponsored Links
 My first post here...hello!

Can anyone tell me what is to prevent the Snake demo from putting 2
apples in the same location?
When the game starts, it populates 2 apples.

Here is the relevant method;

private void addRandomApple() {
        Coordinate newCoord = null;
        boolean found = false;
        while (!found) {
            // Choose a new location for our apple
            int newX = 1 + RNG.nextInt(mXTileCount - 2);
            int newY = 1 + RNG.nextInt(mYTileCount - 2);
            newCoord = new Coordinate(newX, newY);

            // Make sure it's not already under the snake
            boolean collision = false;
            int snakelength = mSnakeTrail.size();
            for (int index = 0; index < snakelength; index++) {
                if (mSnakeTrail.get(index).equals(newCoord)) {
                    collision = true;
                }
            }
            // if we're here and there's been no collision, then we
have
            // a good location for an apple. Otherwise, we'll circle
back
            // and try again
            found = !collision;
        }
        if (newCoord == null) {
            Log.e(TAG, "Somehow ended up with a null newCoord!");
        }
        mAppleList.add(newCoord);
    }

--



Snake Demo Question

by Justin Anderson » Tue, 09 Mar 2010 09:52:46 GMT


 Sure, just write some simple code that makes sure newCoord is not already in
mAppleList...  put it right after the check for colliding with the snake
location.

----------------------------------------------------------------------
There are only 10 types of people in the world...
Those who know binary and those who don't.
----------------------------------------------------------------------





>


Sponsored Links


Snake Demo Question

by Mike » Thu, 11 Mar 2010 04:39:39 GMT


 Thanks for the response!  Takes about 3 weeks to get a post and
response on here! Wow....

I am really just getting up to speed on formatting issue....crawling
right now.
I'm a noob, so this may seem obvious to veterans but...after digging a
little deeper into the demo, I found this;

 /**
     * Draws some apples.
     *
     */
    private void updateApples() {
        for (Coordinate c : mAppleList) {
            setTile(YELLOW_STAR, c.x, c.y);
        }

And

map.putIntArray("mAppleList", coordArrayListToArray(mAppleList));

And cross referencing with the developers documentation;

"Normally, Lists allow duplicate elements, as compared to Sets, where
elements have to be unique. "

So, it looks like the answer to my question is that nothing is
preventing the second apple being drawn over the first. Unless I am
missing something here....








> >



Snake Demo Question

by Justin Anderson » Thu, 11 Mar 2010 05:38:53 GMT


 > Thanks for the response!  Takes about 3 weeks to get a post and response
on here! Wow....*

It was 10 days... about a week and a half. And all of us are reading
through these posts and answering on our own personal time.

*> So, it looks like the answer to my question is that nothing is preventing
the second apple being drawn over the first. Unless I am missing something
here....*

Yes... and I misunderstood your original question. I was telling you
where/how to add the code to put that check in.

Good luck with Android! It's a great platform...

----------------------------------------------------------------------
There are only 10 types of people in the world...
Those who know binary and those who don't.
----------------------------------------------------------------------


On Wed, Mar 10, 2010 at 1:39 PM, Mike <baronbo...@gmail.com> wrote:

> > >



Other Threads

1. Learn how to develop android apps

If you have what to learn how develop android apps but
keep getting frustrated by advanced tutorials that leave
beginners out. Check out my list of tutorial web sites for
beginners.

Tutorial sites are very important for beginners,
check out my lists of good tutorial sites found

.... http://bit.ly/aDxGrG

-- 

2. VFY: arbitrarily rejecting large method

After building my project with Java debug information, I get the
following "warning" from dalvikvm when launching my application:

VFY: arbitrarily rejecting large method

It seems the Dalvik VM's verifier is rejecting one of my methods. The
method is named in the warning, and it is indeed very large,
consisting of a long switch statement. I'd like to avoid breaking it
up if I can.

Is there a way to get the verifier to accept this method, including
debug information?

-- 

3. Corrupted SharedPreference file

4. How do you copy a SQLite database from the device to your PC

5. Call Recording.

6. 2 ListViews in one Activity?

7. Voice conferencing in Android2.1