Watchers

From Gardenwiki

Jump to: navigation, search

Watching a game in progress is one way to learn how to play it. However, unless you like watchers making moves on the board, you need to explicitly forbid it.

Keeping Watchers from Making Moves

If your BoardView class allows players to make moves using a mouse click event, then in the mouseClicked method you can use the following lines. Assume that your GameObject is stored in _myobj.

       boolean skipAction = false;
       // check for just watching
       if (_myobj.getPlayerIndex(_ctx.getUsername()) == -1)
           skipAction = true;
 
       // ..... lines snipped here
 
       if (!skipAction) {
               MyController.postAction(
                       MyBoardView.this,  MyController.SUBMIT_WORD, word);
           }

If your Panel class includes button click events or textfields, then you will want to include a similar check.

The GameManager class can also check for whether a signal comes from a watcher, but normally it is better to handle this at the client level.

Hiding Chat from Watchers

Sometimes players want to chat privately while they play, or want to prevent watchers from kibbutzing or otherwise distracting them from the game. Here is how to hide the chat window from all watchers.

Assume that in our Panel class we have named the chat panel "chat". In the willEnterPlace() method, add these lines:

       if (_myobj.getPlayerIndex(_ctx.getUsername()) == -1)
       {   // hide the chat box            
           chat.getParent().remove(chat);        
       }

This will hide the chat window from all watchers. A checkbox can be added to the lobby to deny chat to watchers, in which case the GameManager class would initialize a boolean variable in the GameObject, and that boolean would be checked in the condition of the above if statement, as well as checking whether the person is a player or a watcher.

Personal tools