-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCycleAbility.java
More file actions
56 lines (48 loc) · 1.73 KB
/
CycleAbility.java
File metadata and controls
56 lines (48 loc) · 1.73 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package Crazy8;
import java.util.ArrayList;
import java.util.Random;
/**
* The Cycle ability allows a character to discard randomly from their hand onto the pile and draw a card.
*/
public class CycleAbility implements Ability
{
private Player owner;
public String name = "Cycle";
/**
* @param player The player that 'owns' this skill.
*/
public CycleAbility(Player player)
{
this.owner = player;
}
/**
* Cycle is supposed to end your turn right away, so its uses doesn't matter.
*/
public int uses() { return 2;}
public String name() { return this.name; }
public boolean endTurn() { return true; }
/**
* A description of Cycle. Call ability.name instead for its name.
*/
public String toString()
{
return "Cycle a card from your hand into the discard pile, and draw a card from the deck. End your turn.\n\n\n\n";
}
/**
* Generate a random integer to select from the hand, discard it, draw a card.
* @param deck Refer to interface documentation.
* @param discardPile Refer to interface documentation.
* @param players Refer to interface documentation.
*/
public void use(Deck deck, DiscardPile discardPile, ArrayList<Player> players)
{
Random randomIndexGenerator = new Random();
int randomIndex = randomIndexGenerator.nextInt(owner.hand.size());
Card discard = owner.hand.remove(randomIndex);
System.out.println(owner + " used 'Cycle!'");
System.out.println(owner + " discarded a " + discard + " onto the pile.");
discardPile.push(discard);
System.out.println(owner + " drew a card.");
owner.hand.add(deck.pop());
}
}