-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTakeCommand.java
42 lines (38 loc) · 1.15 KB
/
TakeCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* TakeCommand Class
*
* @author Alexandre Boursier and Nolan Potier
* @version 2011.10.24
*/
public class TakeCommand extends Command
{
/**
* Constructor for objects of class GoCommand
*/
public TakeCommand() {}
/**
* Try to take an item if present into the room
* We have to be in the good room
* Returns always 'false'.
*/
@Override
public boolean execute(Player player)
{
if(player.getCurrentRoom().getItem() == null) {
System.out.println("There is nothing to take there !");
}
else if (!hasSecondWord()) {
System.out.println("take what?");
}
else if (! getSecondWord().equals(player.getCurrentRoom().getItem().getName().toLowerCase())){
System.out.println("There is nothing like that to take !");
}
else
{
System.out.println("You've just found " + player.getCurrentRoom().getItem().getName() + " ! :) ");
System.out.println(player.getCurrentRoom().getItem().getDescription());
player.addItem(player.getCurrentRoom().takeItem());
}
return false;
}
}