开发者

android -- wait for user input

开发者 https://www.devze.com 2023-04-08 06:44 出处:网络
I\'m creating a spades app with 1 human player and 3 computer players. The problem that I am having is, the play must happen sequentially (clockwise) and I need my program to wait on the player input

I'm creating a spades app with 1 human player and 3 computer players.

The problem that I am having is, the play must happen sequentially (clockwise) and I need my program to wait on the player input. I can't use wait() 开发者_如何学Pythonand notify(). I have tried while loops to check whether the user has selected a card but those stop the program from running. I've tried recursive methods that won't return anything until the player has chosen a card. That too does not work. So what do I do? I'm stuck.

My method goes like this (leaving out the non-pertinent code)

private void game(){
   while(there are more tricks to be played)
      while(each player has not played){
         if(human turn)
            get input from player
         else
            computer plays
      }
}


Maybe you should change a little bit your game controller. Instead of waiting for anything, have your program continuously paint the screen. If user inputs nothing, same screen is paint all the time.

Once he presses a key (or clicks a card or whatever events you have), simply modify the paint method's argument (the screen to be painted). Thus you will separate painting the screen and input handling. It's a common technique called MVC model.

Maybe this will help (it's my game creating blog, and the links inside it are also helpful): http://m3ph1st0s.blogspot.ro/2012/12/create-games-with-libgdx-library-in.html

You don't need to adapt all your game to the game described there, only the technique of separating input from painting. As a general technique, you should NOT have input determine painting.

Hope it helps. Don't hesitate to request further help.


You can try to add Event Handlers. It will try triger a event every time the user selects a card.


Try this.

Create one thread and in that threat call sleep(1000);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号