-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdButton.java
79 lines (70 loc) · 2.08 KB
/
AdButton.java
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Andrew Z.
* Y
* Final Project
* Represents a button on the main program user interface
* AdButton.java
* 7/24/20
*/
import java.util.*;
import java.awt.*;
public class AdButton extends Button {
private double price;
/**
* constructs a button
* @param x the x coordinate of the button's top left corner
* @param y the y coordinate of the button's top left corner
* @param w the width of the button
* @param h the height of the button
* @param color the color of the button
* @param text the text that should appear on the button
* @param price the price of the ad in coins
*/
public AdButton (int x, int y, int w, int h, Color fillColor, String text, Color textColor,
double price) {
super(x,y,w,h,fillColor,text,textColor);
this.price = price;
}
/**
* draws in the text associated with the button
* @param g the graphics object
*/
@Override
public void drawText(Graphics g) {
// writes in the text
g.setFont(new Font("Dialog", Font.PLAIN, 18));
g.setColor(getTextColor());
String label;
if (AirlineMain.advertisement) {
label = "TV Ad Owned! (2x profits)";
} else {
label = getText() + ": $" + (int)price;
}
g.drawString(label, getX()+3, getY() + 3*getHeight()/4);
}
/**
* gets whether or not the ad can be bought
* @param g graphics
* @return can buy
*/
public boolean canBuy(Graphics g) {
// only allow if they don't already own
if (AirlineMain.advertisement) {
AirlineMain.dashText("You already own the TV ad!",g);
return false;
// and only if they have enough coins
} else if (AirlineMain.coins < getPrice()) {
AirlineMain.dashText("You do not have enough coins for this ad.",g);
return false;
} else {
return true;
}
}
/**
* gets the price of the ad
* @return the price
*/
public double getPrice() {
return price;
}
}