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. Titipan Lowongan Kerja untuk Tabulet PC

Dear all,

Ada titipan lowongan pekerjaan nih buat jadi programmer Android untuk
Tabulet PC. Lokasi kerjanya di Jakarta dan full time.

Syaratnya, cukup sederhana, tertarik dengan Android (khususnya dalam urusan
oprek mengoprek) dan bisa programming Android (ga harus jago).

Untuk lebih jelasnya atau berminat, bisa langsung hubungi h...@tabuletpc.com

Terima kasih, hatur nuhun sadayana. :)

-- 
Ibnu Sina
just call me Ibun
twitter: @iboen

http://bit.ly/anw5Yz

-- 
===============
"

2. Using NetworkUtils to add a new route

Hi,

We implemented a system applciation that must add a route to one of
the existing network interfaces in the phone. We tried to use
NetworkUtils.addHostRoute() but we get "Operation Not Permited".
We see that MobileDataStateTracker uses it; from our understanding the
tracker is running within ConnectivityService which runs in the
SystemServer.
We also believe that SystemServer does not run as root.
We'd like to know what we have to do to make our system app able to
call addHostRoute().

Thanks and regards,

--

3. Paid app from UK.pls help

4. Android source

5. When will GoogleMap "3D" API be released?

6. hapus contact

7. Android Market buat ngeblank NJ