开发者

How to handle computer player moves

开发者 https://www.devze.com 2023-03-12 18:56 出处:网络
I am writing a simple turn-based Android game which allows a player to play against the computer (i.e. phone in this case).

I am writing a simple turn-based Android game which allows a player to play against the computer (i.e. phone in this case).

What would be a good/recommended w开发者_JAVA百科ay of letting the game update the computer's move against the player during the game? One way I could think of is to make the class maintaining the board visible to the computer player (pass the instance to the AI player instance) and update it directly, but this does not seem like a "good" approach. As sometimes it may take time to compute the next move. Also in future if we want to incorporate network play it should not involve a major rewrite to handle an update from the network player.

Any help with this is much appreciated.


If computations may take a long time then I reccomend looking into AsyncTask you could notify the player that the computer is making its move then pop up a progress dialog which notifies the user that the other player is doing something? Is this sorta what you are looking for? Here are some resources:

Android Docs: http://developer.android.com/reference/android/os/AsyncTask.html

Async Template: http://jyro.blogspot.com/2009/11/android-asynctask-template.html

0

精彩评论

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