Questions about snake sample code

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Questions about snake sample code

Postby jru » Sun Feb 06, 2011 8:26 pm

I have been playing with the snake sample code and feel that I have come to a brick wall. I feel
that my problems could easily be solved.

1. When the app runs, you are given the option to press up to play. Where in the code, does the action
of pressing up run the game?

2. I believe that if I recreate SnakeView with another name, using another key, I could run this as
another mode. Am I trying to complicate the process?

Thanks for any time and efforts.

Jru
jru
Freshman
Freshman
 
Posts: 3
Joined: Sun Feb 06, 2011 8:07 pm

Top

Re: Questions about snake sample code

Postby blundell » Tue Feb 08, 2011 2:20 pm

Post a link to the code you talk about
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Questions about snake sample code

Postby jru » Thu Feb 10, 2011 5:48 am

http://developer.android.com/resources/ ... index.html

The sample code I am playing with...
jru
Freshman
Freshman
 
Posts: 3
Joined: Sun Feb 06, 2011 8:07 pm

Re: Questions about snake sample code

Postby eyespyus » Thu Feb 10, 2011 6:06 pm

Jru,

Look in the SnakeView.java source for the section that checks for onKeyDown. Here is the part of the code that checks for DPAD up and restarts game:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.    public boolean onKeyDown(int keyCode, KeyEvent msg) {
  2.  
  3.         if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
  4.             if (mMode == READY | mMode == LOSE) {
  5.                 /*
  6.                  * At the beginning of the game, or the end of a previous one,
  7.                  * we should start a new game.
  8.                  */
  9.                 initNewGame();
  10.                 setMode(RUNNING);
  11.                 update();
  12.                 return (true);
  13.  ....
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
User avatar
eyespyus
Freshman
Freshman
 
Posts: 7
Joined: Fri Mar 05, 2010 9:31 pm

Re: Questions about snake sample code

Postby jru » Tue Feb 15, 2011 9:44 pm

Thank you, I copied SnakeView and made a SnakeViewb. I changed that to run from DPAD down. It doesn't run and I am thinking I need to add code to Snake.java. I am not sure what I need to add and any help is appreciated.


Note: The changing I have done is correct, it runs fine as SnakeView, but cannot get it to run as SnakeViewb.

Jru
jru
Freshman
Freshman
 
Posts: 3
Joined: Sun Feb 06, 2011 8:07 pm

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 1 guest