-
Notifications
You must be signed in to change notification settings - Fork 0
/
Marketplace.java
201 lines (154 loc) · 4.47 KB
/
Marketplace.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package com.gameofrobots.robotcontroller1;
/**
* Created by Thomas on 2017-11-16.
*/
import java.util.Timer;
import java.util.TimerTask;
public class Marketplace<E> {
private Object[] data;
private int manyItems;
public Marketplace(){
final int INITIAL_CAPACITY = 10;
manyItems = 0;
data = new Object[INITIAL_CAPACITY];
}
public Marketplace(int initialCapacity){
if(initialCapacity< 0)
throw new IllegalArgumentException("The initialCapacity is negative: " + initialCapacity );
data = new Object[initialCapacity];
manyItems = 0;
}
public void add(Item element){
if(manyItems == data.length){
ensureCapacity((manyItems + 1) * 2);
}
data[manyItems] = element;
manyItems++;
}
public void ensureCapacity(int minimumCapacity){
Object biggerArray[];
if(data.length < minimumCapacity){
biggerArray = new Object[minimumCapacity];
System.arraycopy(data, 0, biggerArray, 0, manyItems);
data = biggerArray;
}
}
public boolean remove(Item target){
int index;
if(target == null){ //find first occurence of the target in the bag
index = 0;
while((index < manyItems) && (data[index] != null))
index++;
}
else{//find first occurrence of the target in the bag
index =0;
while((index < manyItems) && (!target.equals(data[index])))
index++;
}
if (index == manyItems) {//target was not found, nothing removed
//add something here to catch when there are no more items of a specific kind??****
return false;
}
else{//target was found at data[index]
manyItems--;
data[index] = data[manyItems];
data[manyItems] = null;
return true;
}
}
//Need to have count method to ensure there are buffs available
/* End Of Object Array Class*/
/*
methods to purchase and use buffs
*/
public void buyBuff(Item i){
add(i);
}
public void useSpeed(){
//If marketplace.count(speed) > 1
//Remove one speed
//Send Big I to robot and start timer for speed boost
new Reminder(5);
}
public void heal(){
}
}
//Bank class
/*
Not used right now but coded for future implementation of a full marketplace
*/
class Bank {
private int bank;
public Bank(){
bank = 1200;
}
public Bank(int startingBank){
bank = startingBank;
}
/*
Getters and Setters for Bank
*/
public void bank_add(int in) {
bank += in;
}
public String bank_spend(int out) {
if ((out - bank) >= 0) {
bank -= out;
return "Payment Successful";
} else {
return "Error!: Not Enough Cash!!";
}
}
public int getBank() {
return bank;
}
//End of Getters and Setters for Bank
}
class Item {
int type;
int length;
private final int MAX_BOOST = 10;
String name;
/*
Boost can be one of three types
Type is int to allow for expansion into more "types of boosts
Quick guide
1 = Speed; (Speed up robot for 10 seconds)
2 = heal; (Gain a set amount of health
3 = invinc = invincibility (Cannot be shot for 10 seconds)
??Future Boosts??
Point multiplier
Auto Shoot
IR Receiver immunity (Sheild?)
*/
public Item(int type){
if(type == 1){
name = "Speed Boost";
length = 10;
}
else if(type == 2){
name = "Heal";
}
else if(type == 3){
name = "Sheild";
}
}
public void speedBoost(){
}
public void healRobot(){
}
}
//may need to be public
class Reminder {
Timer lifeSpan;
public Reminder(int seconds){
lifeSpan = new Timer();
lifeSpan.schedule(new RemindTask(), seconds*1000);
}
class RemindTask extends TimerTask{
public void run(){
System.out.println("Times Up!");
lifeSpan.cancel();
}
}
}