01: package poker.business;
02:
03: import poker.data.other.Fortune;
04: import java.util.Vector;
05: import poker.spec.*;
06:
07: /**
08: *
09: * EnhyDraw!, beta 4, 5/21/99
10: *
11: * Copyright 1999, Larry Wolcot & Daryl Tempesta
12: * ALL rights reserved. Not for commercial use
13: * without written permission from both authors.
14: *
15: */
16: public class FortuneManagerImpl implements FortuneManager,
17: java.io.Serializable {
18:
19: private Vector fortuneList = new Vector(0);
20: private int lastFortuneNumber;
21:
22: public void addFortune(String fortune) {
23:
24: int num = 1;
25: if (fortuneList.size() > 1) {
26: Fortune lastFortune = (Fortune) fortuneList.lastElement();
27: num = lastFortune.getFortuneNumber() + 1;
28: }
29:
30: Fortune newFortune = new Fortune(num, fortune);
31: newFortune.setHasBeenUsed(false);
32: fortuneList.addElement(newFortune);
33: }
34:
35: public String getFortune() {
36: String fortune = "";
37: if (fortuneList.size() == 0) {
38: fortune = "";
39: } else {
40: Fortune nextFortune = (Fortune) fortuneList
41: .elementAt(lastFortuneNumber);
42: fortune = nextFortune.getFortune();
43: lastFortuneNumber++;
44: }
45:
46: if (lastFortuneNumber >= fortuneList.size()) {
47: lastFortuneNumber = 0;
48: }
49:
50: return fortune;
51: }
52:
53: }
|