That would work if the buttons and the game logic were in the same
class, but they aren't. I have a GameBoard class with all of the
buttons set up in there, and then I have a Game class with the game
logic. The game logic method looks a little like this:

        public void runGame() {
                while(!gameOver) {
                        if(/*button clicked*/) {
                                if(detectWin(turn ? 
PLAYER1_SYMBOL:PLAYER2_SYMBOL)) {
                                        gameOver = true;
                                        if(turn)
                                                winMessage.setMessage("Player 1 
won!");
                                        else
                                                winMessage.setMessage("Player 2 
won!");
                                        continue;
                                }
                                else
                                        turn = !turn;
                        }
                }

                winMessage.show();
        }

On Jun 10, 8:33 am, Mark Murphy <mmur...@commonsware.com> wrote:
> Use setOnClickListener() or android:onClick.
>
>
>
>
>
>
>
>
>
> On Thu, Jun 9, 2011 at 1:18 PM, c0dege3k <c0deg...@gmail.com> wrote:
> > I'm writing a simple tic-tac-toe game, with regular buttons making up
> > the grid. What I want to happen is for when one button is clicked, for
> > the "turn" boolean to switch. There doesn't seem to be a detect-click
> > method built-in, so I was wondering if there was an easy way to solve
> > this problem.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android 3.0 Programming Books:http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to