private boolean processCommand(Command command) { boolean wantToQuit = false; if (command.isUnknown()) { System.out.println("I don't know what you mean..."); return false; } String commandWord = command.getCommandWord(); if (commandWord.equals("help")) { printHelp(); } else if (commandWord.equals("go")) { goRoom(command); } else if (commandWord.equals("quit")) { wantToQuit = quit(command); } else if (commandWord.equals("look")) { printLocationInfo(); } else if (commandWord.equals("items")) { player.items(); } else if (commandWord.equals("take")) { player.take(command.getSecondWord()); } else if (commandWord.equals("drop")) { player.drop(command.getSecondWord()); } else if (commandWord.equals("back")) { player.back(); } else if (commandWord.equals("guess")) { guess(command.getSecondWord()); } return wantToQuit; }
/* * Processes the player input and returns a boolean value that indicates whether the input has * been successfully processed or not. */ private boolean processInput() { String inputLetter = String.valueOf(playerInput.getText()).toUpperCase(); /* * Checks whether the input is invalid. */ if (!validInput.contains(inputLetter)) { return false; } else { /* * Appends the player input (i.e., a letter) to the word (fragment) formed thus far, * obtains the new word (fragment), and processes it. */ playerInput.setText(""); wordFormed.append(inputLetter); String word = String.valueOf(wordFormed.getText()).toLowerCase(); game.setWordFormed(word); game.guess(); return true; } }
void listen(Gamer g) { // System.out.println("GET() w listen"); String m = g.st.bm.get(); String command = unPack(m, "command"); // System.out.println("command = " + command); if (command.equals("getPlayersAndCards")) { ready++; System.out.println("Wysy�am jednemu " + jsonGetGameState(g)); g.st.send(jsonGetGameState(g)); if (ready == 3) { broadcast(jsonWhoseTurn(whoseTourn)); } } if (command.equals("guess")) { guess(m); whoseTourn++; whoseTourn %= 3; broadcast(jsonWhoseTurn(whoseTourn)); } ifEnd(); }
public void onSubmit(View view) { EditText textInput = (EditText) findViewById(R.id.editText1); String letter = textInput.getText().toString().toLowerCase(); // validate if input is filled in and not a number if (letter.length() != 1 || !Character.isLetter(letter.charAt(0))) { Toast.makeText(getApplicationContext(), R.string.toast_valid_character, Toast.LENGTH_SHORT) .show(); } else { game.guess(letter); // counts as a guess if game is not ended already. if (game.ended()) { // save the player that wins because score changed game.getPlayerObject(game.winner()).addScore(); // updates DB on score change; myDB.updatePlayer(game.getPlayerObject(game.winner())); // notify this activity of player change player1 = game.p1; player2 = game.p2; } // async save on every turn.. new AsyncSaveGame(this).execute(game); } updateView(); }