Rev | Line | |
---|
[253] | 1 | package onetomany.bargainingchipsgame;
|
---|
[233] | 2 |
|
---|
[236] | 3 | import java.util.Random;
|
---|
[233] | 4 |
|
---|
[264] | 5 | import java.awt.Color;
|
---|
| 6 |
|
---|
[233] | 7 | /**
|
---|
[264] | 8 | * Chip is the fundamental element in Bargaining Chips.
|
---|
| 9 | * A chip could be assumed as any item at any scenario, e.g. Paracetamol in pharmaceutical market,
|
---|
| 10 | * a chair in furniture market, or a Red Dot.
|
---|
[233] | 11 | * A chip=(color, unit price), where color is the id of the chip.
|
---|
| 12 | */
|
---|
| 13 | public class Chip
|
---|
[264] | 14 | {
|
---|
[233] | 15 | private String color;
|
---|
| 16 | private double price;
|
---|
| 17 |
|
---|
| 18 | public Chip()
|
---|
| 19 | {
|
---|
[264] | 20 | setRandomColor();
|
---|
| 21 | setRandomPrice(0, 10);
|
---|
[233] | 22 | }
|
---|
| 23 |
|
---|
| 24 | public Chip(String c, double p)
|
---|
| 25 | {
|
---|
[264] | 26 | color = c;
|
---|
| 27 | price = p;
|
---|
[233] | 28 | }
|
---|
[236] | 29 |
|
---|
[233] | 30 | /**
|
---|
| 31 | * @return the color
|
---|
| 32 | */
|
---|
| 33 | public String getColor()
|
---|
| 34 | {
|
---|
| 35 | return color;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * @return the price
|
---|
| 40 | */
|
---|
| 41 | public Double getPrice()
|
---|
| 42 | {
|
---|
| 43 | return price;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[236] | 46 |
|
---|
[233] | 47 | @Override
|
---|
| 48 | public String toString()
|
---|
| 49 | {
|
---|
[264] | 50 | return "("+getColor()+", $"+getPrice().floatValue()+")";
|
---|
[233] | 51 | }
|
---|
[236] | 52 |
|
---|
[263] | 53 | public boolean hasSameColorAs(Stack s)
|
---|
| 54 | {
|
---|
| 55 | return getColor().equals(s.getColor());
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[264] | 58 | public Color getRGBcolor()
|
---|
[236] | 59 | {
|
---|
[264] | 60 | return Color.decode(color);
|
---|
[236] | 61 | }
|
---|
| 62 |
|
---|
[264] | 63 | private void setRandomColor()
|
---|
[236] | 64 | {
|
---|
[264] | 65 | String [] colors = new String [] {"Black", "Blue", "Cyan", "darkGray", "Gray", "lightGray", "Green", "Magenta", "Orange", "Pink", "Red", "White", "Yellow"};
|
---|
| 66 | int rnd = new Random().nextInt(colors.length);
|
---|
| 67 | color = colors[rnd];
|
---|
| 68 | }
|
---|
[236] | 69 |
|
---|
[264] | 70 | public void setRandomPrice(double p1, double p2)
|
---|
[236] | 71 | {
|
---|
[264] | 72 | this.price = p1 + (p2 - p1) * new Random().nextDouble();
|
---|
[236] | 73 | }
|
---|
[233] | 74 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.