I am implementing checkers as a game for Android. I am able to move with my pieces and with "computer" pieces. I am going to add AI for 开发者_如何学Ccomputer somehow, but now I am stuck with Threading. This is my game activity for checkers (Game.java):
private SachovniceView sachovniceView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
chessboardView = new chessboardView(this);
setContentView(chessboardView);
chessboardView.requestFocus();
}
in chessboardView I draw in Canvas chessboard and I have here method for drawing mine and my opponent's game pieces and method (both in @Override protected void onDraw(Canvas canvas) method) for moving my pieces. I am storing position of gamepieces in [][] field, when I move with my stone, I invalidate() chesssboard for redrawing. And Here is the thing - how to implement Threads in my game? I am absolutely lost. I think I have to give away method for moving stones and make it alone as a class with name human_turn, then I have to make the same with computer (like computer_turn) and somehow implement Thread logic. My turn, opponent thread is stopped, I finish my move, opponent thread is going to alive, my thread is stopping and so on. I have spent whole day on the internet, but I didn't get the Thread thing in my head :-( Help would be appreciated. Thanks
Hmyzak
精彩评论