source: src/main/java/onetomany/bargainingchipsgame/Chip.java@ 263

Last change on this file since 263 was 263, checked in by Faria Nassiri Mofakham, 5 years ago

Offer class updated; Message enum created; parapoloid tried in GUI; some small changes in some previous classes (Bundle, stack,.. ); UF_Silly renamed to UF_Crazy; started to add role to UF classes...

File size: 2.7 KB
Line 
1/**
2 * Chip class
3 */
4package onetomany.bargainingchipsgame;
5
6import java.awt.Color;
7import java.util.Arrays;
8import java.util.List;
9import java.util.Random;
10
11/**
12 * Chip is the fundamental element of the market domain in Bargaining Chips Game.
13 * Chip could be assumed as any item at any scenario, e.g. Paracetamol in pharmaceutical market, a chair in furniture market, or a Red Dot.
14 * A chip=(color, unit price), where color is the id of the chip.
15 *
16 * @author Faria Nassiri-Mofakham
17 */
18
19public class Chip
20{
21
22 private String color;
23 private double price;
24
25 public Chip()
26 {
27 setColor(null);
28 setPrice(-1);
29 }
30
31 public Chip(String c, double p)
32 {
33 setColor(c);
34 setPrice(p);
35 }
36
37 /**
38 * @param c the color to set
39 */
40
41 public void setColor(String c)
42 {
43 this.color = c;
44 }
45
46 /**
47 * @param p the price to set
48 */
49 public void setPrice(double p)
50 {
51 this.price = p;
52 }
53
54 public void setRandomPrice(double p1, double p2)
55 {
56 this.price = p1 + (p2 - p1) * new Random().nextDouble();
57 }
58
59 /**
60 * @return the color
61 */
62 public String getColor()
63 {
64 return color;
65 }
66
67 /**
68 * @return the price
69 */
70 public Double getPrice()
71 {
72 return price;
73 }
74
75
76 @Override
77 public String toString()
78 {
79 return "("+getColor()+","+getPrice().floatValue()+"$)";
80 // other representations
81 //return this.getClass().getSimpleName()+"("+getColor()+","+getPrice().floatValue()+"$)";
82 // // return getColor()+" "+this.getClass().getSimpleName()+" for "+getPrice()+"$";
83 }
84
85 public boolean hasSameColorAs(Stack s)
86 {
87 return getColor().equals(s.getColor());
88 }
89
90 public Color getRGBcolor(String s) // to be able to pass colors in RGB hex strings
91 {
92 return Color.decode(s);
93 }
94
95 public void setColorRandomRGB()
96 {
97 this.color = new Color((int)(Math.random()*255+1),(int)(Math.random()*255+1),(int)(Math.random()*255+1)).toString();
98 }
99
100 public void setRandomColor()
101 {
102 int i = (int)(Math.random()*13);
103 switch(i)
104 {
105 case 0:
106 this.color="Black";
107 break;
108 case 1:
109 this.color="Blue";
110 break;
111 case 2:
112 this.color="Cyan";
113 break;
114 case 3:
115 this.color="darkGray";
116 break;
117 case 4:
118 this.color="Gray";
119 break;
120 case 5:
121 this.color="lightGray";
122 break;
123 case 6:
124 this.color="Green";
125 break;
126 case 7:
127 this.color="Magenta";
128 break;
129 case 8:
130 this.color="Orange";
131 break;
132 case 9:
133 this.color="Pink";
134 break;
135 case 10:
136 this.color="Red";
137 break;
138 case 11:
139 this.color="White";
140 break;
141 case 12:
142 this.color="Yellow";
143 break;
144
145 default:
146 System.out.println(i+" Undefined color!");
147 }
148 }
149}
Note: See TracBrowser for help on using the repository browser.