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. How do you change EditText's popup list text colour?

Hi,

Does anyone know how to change the colour of the text within the popup
list that appears when you longclick an EditText view? In my app when
I perform a long click on the EditText view I get a popup menu dialog
with Copy, Paste, Input Method appear, and I can't figure out how to
change the default text colour in this dialog.

Cheers,
Nilz.

-- 

2. Devphone discount?

Hello everyone! I am a highschool student and I really love
programming. I would love to play around with the kernel code and test
it on a dev phone. Do students get any discounts on them like some
development products have huge discounts for students? Please let me
know.

Thanks

-- 

3. Enable native IM di Cyan 4.2.11.1

4. Droid 2.1?

5. Where to find this graphic? com.android.internal.R.id.keyboardView

6. Widget android (google)

7. Altering the alpha level of MapView