Help in mobile phone keys commands needed

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

Help in mobile phone keys commands needed

Postby thebestdesign » Sat Nov 24, 2007 3:35 pm

Hi,
i'm creating a sudoku puzzle, I used a tiledlayer called 'board' which represent the puzzle.
I applied the keyPressed method below to read the numbers entered by the user and place them
to the appropriate place in the board. the program works fine in the Sun WTK emulator, But when i install the application in my mobile phone i found that when i press:
- '2': number 2 prints in the correct position then the cursor moves one position to the top.
- '4': number 4 printed in the correct position then the cursor moved one position to the left.
- '6': number 6 printed and cursor moved one position to the right.
- '8': number 8 printed and cursor moved one position down.
- anyother number: the program behaves correctly.

protected void keyPressed(int keyCode)
{

try{
String keyText = getKeyName(keyCode);
int keyNumber = Integer.parseInt(keyText);
int value = board.getCell(positionX, positionY);
if(value<= 10)
{
board.setCell(positionX, positionY, keyNumber);

}
}
catch(Exception e){}

}
Basically i don't have any problem to move around the board, i'm using the mobile phone's joystick to move from one cell to another, so i want to disable the functionality of movements used by the numbers '2,4,6,8' and use them only for input like the other buttons '1,3,7,9'.
is there anyway how to do it? because i found other sudoku mobile games on the internet they use the same concept, the mobile phone joystick is used to move between cells, and the numbers '1,2,...9' are used for board input only.

Please do you know any solution for this problem?

Thank you.
thebestdesign
 
Posts: 10
Joined: Sat Nov 24, 2007 2:23 pm

Re: Help in mobile phone keys commands needed

Postby DevelopmentTeam » Mon Nov 26, 2007 4:24 am

The problem is clear that the bug is obvious. If you use 2,4,6,8 for navigation and also for number input, then this problem is obvious. There are 2 ways in which sudoku games work.

1) Joystick is used for navigation and numbers keys are for input.
2) Joystick and 2,4,6,8 are both used for navigtion to support old phones without joystick also. In this case you have to press select button or any softkeys to enter an input. Once you press select the number keys are converted into input mode.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Help in mobile phone keys commands needed

Postby thebestdesign » Mon Nov 26, 2007 8:29 pm

Hi codetiger,
thank you for the reply, basically that's what i'm looking for, option number 1:
1) Joystick is used for navigation and numbers keys are for input.
how to do it? i don't want the keys '2,4,6,8' to be used for any movements, i want them for input ONLY.
I hope to hear from you soon.
thebestdesign
 
Posts: 10
Joined: Sat Nov 24, 2007 2:23 pm

Re: Help in mobile phone keys commands needed

Postby DevelopmentTeam » Tue Nov 27, 2007 3:55 am

Instead of trying out the keyvalue conversion and stuff, just check the keycode like here

these are the values keypressed and keyreleased functions will bring when you check their value.

KEY_UP : -1
KEY_DOWN : -2
KEY_LEFT : -3
KEY_RIGHT : -4
KEY_SELECT : -5
KEY_CLEAR : -8
KEY_SEND : -10
KEY_END : 11
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Help in mobile phone keys commands needed

Postby thebestdesign » Tue Nov 27, 2007 12:02 pm

Hi,
i still didn't understand what do you mean, can you please explain it in more details? i'm still a beginner, not a professional.
Thanks.
thebestdesign
 
Posts: 10
Joined: Sat Nov 24, 2007 2:23 pm

Re: Help in mobile phone keys commands needed

Postby DevelopmentTeam » Tue Nov 27, 2007 12:19 pm

Code: Select all
protected void keyPressed(int keyCode)
{
  if(keyCode == -1) {
      // upkey pressed
  } else if(keyCode == -2) {
      // downkey pressed
  } else if(keyCode == -3) {
      // leftkey pressed
  } else if(keyCode == -4) {
      // rightkey pressed
  }
}
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Help in mobile phone keys commands needed

Postby thebestdesign » Tue Nov 27, 2007 4:36 pm

Thank you very much, the code is working perfectly now..
Many thanks :-)
thebestdesign
 
Posts: 10
Joined: Sat Nov 24, 2007 2:23 pm

Re: Help in mobile phone keys commands needed

Postby DevelopmentTeam » Wed Nov 28, 2007 3:18 am

Congratulations... :)
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India


Return to J2ME Games

Who is online

Users browsing this forum: No registered users and 2 guests

cron