-
-
Save kylekellogg/f8679d0392bc58dc2d9835f1bc875fbf to your computer and use it in GitHub Desktop.
BoxOpener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.util.Random; | |
public class Box { | |
private int size; | |
private int boxPrice = 5; | |
public static Item[] items; | |
Random itempick; | |
BoxOpener b = new BoxOpener(); | |
public int getBoxPrice() { | |
return boxPrice; | |
} | |
public int getTotalBoxValue() { | |
int sum = 0; | |
for (int i = 0; i < items.length; i++) { | |
Item temp = new Item(); | |
items[i] = temp; | |
//System.out.println("This item's price is " + temp.getPrice() + "."); | |
sum += temp.getPrice(); | |
} | |
return sum; | |
}; | |
public int getSize() { | |
return this.size; | |
} | |
public Box() { | |
createSize(); | |
createItems(); | |
assignBoxPrice(); | |
itempick = new Random(); | |
} | |
//constructor; will always give int boxesOpened, and must have that argument elsewhere. | |
public void createSize() { | |
this.size = itempick.nextInt(5); | |
} | |
public void createItems() { | |
items = new Item[this.size]; | |
for (int i = 0; i < this.size; i++) { | |
Item temp = new Item(); | |
items[i] = temp; | |
} | |
} | |
public void assignBoxPrice() { | |
if(b.getBoxesOpened() >0 && (b.getBoxesOpened()%5)== 0){ | |
boxPrice += 1; | |
System.out.println("Box price: "+getBoxPrice()); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class BoxOpener { | |
private int boxesOpened = 0; | |
private int boxesRemaining = 5; | |
Box b = new Box(); | |
public int getBoxesOpened() { | |
return boxesOpened; | |
} | |
public int getBoxesRemaining() { | |
return this.boxesRemaining; | |
} | |
public BoxOpener() { | |
while (boxesRemaining>0){ | |
boxesRemaining -= 1; | |
boxesOpened += 1; | |
System.out.println("Boxes opened: "+getBoxesOpened()); | |
w.addCash(b.getBoxPrice()); | |
System.out.println("Cash: "+Wallet.getCurrentMoney()); | |
while(Wallet.getCurrentMoney()>=b.getBoxPrice()){ | |
Wallet.subtractCash(b.getBoxPrice()); | |
} | |
} | |
} | |
//this needs to move the value of box contents to wallet, keep track of boxes remaining and boxes opened, and buy boxes when wallet has enough money. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.util.Random; | |
public class Item { | |
private int itemPrice; | |
private Random pricepick; | |
public int getPrice() { | |
return this.itemPrice; | |
} | |
public Item() { | |
createItemPrice(); | |
pricepick = new Random(); | |
} | |
public void createItemPrice(){ | |
this.itemPrice = pricepick.nextInt(5); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class LootBox { | |
private boolean gameRunning = true; | |
public static void main(String[] args) { | |
long lastLoopTime = System.nanoTime(); | |
final int TARGET_FPS = 60; | |
final long OPTIMAL_TIME = 1000000000 / TARGET_FPS; | |
long lastFpsTime = 0; | |
while (gameRunning) { | |
long now = System.nanoTime(); | |
long updateLength = now - lastLoopTime; | |
lastLoopTime = now; | |
double delta = updateLength / ((double) OPTIMAL_TIME); | |
if (delta < ((double) OPTIMAL_TIME)) { | |
continue; | |
} | |
lastFpsTime += updateLength; | |
if (lastFpsTime >= 1000000000) { | |
lastFpsTime = 0; | |
} | |
// Do game update here | |
// Do game display here | |
try{ | |
final int gameTime = (lastLoopTime - System.nanoTime() + OPTIMAL_TIME) / 1000000; | |
System.out.println(gameTime); | |
Thread.sleep(gameTime); | |
}catch(Exception e){ | |
} | |
} | |
} | |
//open boxes, get x items, sell for money, buy more boxes. repeat until run out of money.*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class Wallet { | |
private static int currentMoney = 0; | |
public static int getCurrentMoney(){ | |
return currentMoney; | |
} | |
public Wallet() { | |
} | |
public static void addCash(int value){ | |
this.currentMoney += value; | |
} | |
public static void subtractCash(int value){ | |
this.currentMoney -= value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment