diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-02-17 15:35:18 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-02-17 15:35:18 -0500 |
commit | 006e76d24c1d6ea465fef2a5958133b712a7ca3d (patch) | |
tree | 8b59d3a530941a944500fe2c1b92b57f254ecd4a /src | |
parent | b80b3ab6838595aa016b285c4d5f77c15a5446f6 (diff) | |
download | fourpuzzle-006e76d24c1d6ea465fef2a5958133b712a7ca3d.tar.gz fourpuzzle-006e76d24c1d6ea465fef2a5958133b712a7ca3d.tar.bz2 fourpuzzle-006e76d24c1d6ea465fef2a5958133b712a7ca3d.zip |
Engine: Abstracted Comparsion
Diffstat (limited to 'src')
3 files changed, 78 insertions, 20 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java index ab8d977..c3016e0 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java | |||
@@ -33,13 +33,8 @@ public class VariableNumberPrecondition implements Precondition { | |||
33 | { | 33 | { |
34 | int n1 = Game.getSaveFile().getVariables().get(variableID); | 34 | int n1 = Game.getSaveFile().getVariables().get(variableID); |
35 | int n2 = number; | 35 | int n2 = number; |
36 | 36 | ||
37 | switch (comparison) | 37 | return comparison.compare(n1, n2); |
38 | { | ||
39 | case Less: return (n1 < n2); | ||
40 | case Greater: return (n1 > n2); | ||
41 | case Equal: return (n1 == n2); | ||
42 | } | ||
43 | } | 38 | } |
44 | 39 | ||
45 | return false; | 40 | return false; |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java index 91a31ba..da16d09 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java | |||
@@ -31,14 +31,12 @@ public class VariableVariablePrecondition implements Precondition { | |||
31 | { | 31 | { |
32 | if (Game.getSaveFile().getVariables().containsKey(variableID)) | 32 | if (Game.getSaveFile().getVariables().containsKey(variableID)) |
33 | { | 33 | { |
34 | int n1 = Game.getSaveFile().getVariables().get(variableID); | 34 | if (Game.getSaveFile().getVariables().containsKey(variableID2)) |
35 | int n2 = Game.getSaveFile().getVariables().get(variableID2); | ||
36 | |||
37 | switch (comparison) | ||
38 | { | 35 | { |
39 | case Less: return (n1 < n2); | 36 | int n1 = Game.getSaveFile().getVariables().get(variableID); |
40 | case Greater: return (n1 > n2); | 37 | int n2 = Game.getSaveFile().getVariables().get(variableID2); |
41 | case Equal: return (n1 == n2); | 38 | |
39 | return comparison.compare(n1, n2); | ||
42 | } | 40 | } |
43 | } | 41 | } |
44 | 42 | ||
diff --git a/src/com/fourisland/fourpuzzle/util/Comparison.java b/src/com/fourisland/fourpuzzle/util/Comparison.java index 9e5ef54..79bcb28 100755 --- a/src/com/fourisland/fourpuzzle/util/Comparison.java +++ b/src/com/fourisland/fourpuzzle/util/Comparison.java | |||
@@ -1,20 +1,85 @@ | |||
1 | package com.fourisland.fourpuzzle.util; | ||
2 | |||
3 | /* | 1 | /* |
4 | * To change this template, choose Tools | Templates | 2 | * To change this template, choose Tools | Templates |
5 | * and open the template in the editor. | 3 | * and open the template in the editor. |
6 | */ | 4 | */ |
7 | 5 | ||
8 | 6 | package com.fourisland.fourpuzzle.util; | |
9 | 7 | ||
10 | /** | 8 | /** |
11 | * | 9 | * |
12 | * @author hatkirby | 10 | * @author hatkirby |
13 | */ | 11 | */ |
14 | public enum Comparison { | 12 | public enum Comparison { |
15 | 13 | /** | |
16 | Less, | 14 | * A comparision that returns true if param a is less than param b. |
17 | Greater, | 15 | */ |
16 | Less | ||
17 | { | ||
18 | public boolean compare(int a, int b) | ||
19 | { | ||
20 | return (a < b); | ||
21 | } | ||
22 | }, | ||
23 | /** | ||
24 | * A comparision that returns true if param a is greater than param b. | ||
25 | */ | ||
26 | Greater | ||
27 | { | ||
28 | public boolean compare(int a, int b) | ||
29 | { | ||
30 | return (a > b); | ||
31 | } | ||
32 | }, | ||
33 | /** | ||
34 | * A comparision that returns true if param a is equal to param b. | ||
35 | */ | ||
18 | Equal | 36 | Equal |
37 | { | ||
38 | public boolean compare(int a, int b) | ||
39 | { | ||
40 | return (a == b); | ||
41 | } | ||
42 | }, | ||
43 | /** | ||
44 | * A comparision that returns true if param a is greater than or equal to | ||
45 | * param b. | ||
46 | */ | ||
47 | Above | ||
48 | { | ||
49 | public boolean compare(int a, int b) | ||
50 | { | ||
51 | return (a >= b); | ||
52 | } | ||
53 | }, | ||
54 | /** | ||
55 | * A comparision that returns true if param a is less than or equal to | ||
56 | * param b. | ||
57 | */ | ||
58 | Below | ||
59 | { | ||
60 | public boolean compare(int a, int b) | ||
61 | { | ||
62 | return (a <= b); | ||
63 | } | ||
64 | }, | ||
65 | /** | ||
66 | * A comparison that returns true if param a is not equal to param b. | ||
67 | */ | ||
68 | Inequal | ||
69 | { | ||
70 | public boolean compare(int a, int b) | ||
71 | { | ||
72 | return (a != b); | ||
73 | } | ||
74 | }; | ||
75 | |||
76 | /** | ||
77 | * Compares both parameters | ||
78 | * | ||
79 | * @param a The first number to compare | ||
80 | * @param b The second number to compare | ||
81 | * @return true if <code>a COMPARE b</code> is true, otherwise false | ||
82 | */ | ||
83 | public abstract boolean compare(int a, int b); | ||
19 | 84 | ||
20 | } | 85 | } |