package mug13; public class Eat implements Verb { //feilds WorldBuilder worldOps; //constructor public Eat(WorldBuilder _worldOps) { this.worldOps = _worldOps; } //methods //use as (insert verb here).perform(Person, Object) //needs to return an array of length three with two strings to broadcast, first to the subject and second to everyone else, and the third value a string "false" for a verb that changes nothing (broadcast only) and "true" for a verb that changes something. public String[] execute(String subject, String object) { //creating necesary variables String[] action = {"default", "default"}; try { Person actor = worldOps.mapPerson(subject); Thing food = worldOps.mapThing(object); int perform = food.checkVerb("eat").intValue(); if(perform == -1) { action[0] = "This action cannot be taken on this object"; action[1] = null; } else if (perform == 0) { action[0] = "You bite the " + food.getName() + "."; action[1] = actor.getName() + " bites the " + food.getName() + "."; return action; } else if (perform == 1) { //changes to person here //changes to object double parts = food.getNumberAttribute("parts"); if (parts == 1.0) { action[0] = "You finish the " + food.getName() + "."; action[1] = actor.getName() + " finishes the " + food.getName() + "."; //remove object from the world worldOps.removeThing(food.getName()); //remove from the place try { worldOps.mapPlace(food.getWordAttribute("location")).removeThing(food.getName()); } catch(Exception e) { action[0] = "this is in a place that does not exist"; action[1] = null; return action; } } else { food.changeNumberAttribute("parts", new Double(parts - 1.0)); action[0] = "You eat from the the " + food.getName() + "."; action[1] = actor.getName() + " eats from the " + food.getName() + "."; } //return the stuff } return action; } catch (Exception e) { action[0] = "You can only eat things."; action[1] = null; return action; } } } /* //changes to the object double parts = food.getNumberAttribute("parts"); if (parts == 1) { action[0] = "You finish the " + object.getName() + "."; action[1] = actor.getName() + " finishes the " + food.getName() + "."; //remove object from the world realworld.remove(object); food.getWordAttribute("location").removeThing(object.getName()); } else { food.changeNumberAttribute("parts", parts - 1); } */