Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
PenguRengu authored Jun 26, 2020
1 parent b6e1281 commit afbf37c
Show file tree
Hide file tree
Showing 33 changed files with 621 additions and 0 deletions.
Binary file added bin/com/pengu/pengulu/ColorTheme.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/EnemyTemplate.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/Game$1.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/Game.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/InputListener.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/InventoryManager.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/ItemTemplate.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/Node.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/UniversalChoiceListener.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/testrun/Cave.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/testrun/Coal.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/testrun/Cobblestone.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/testrun/Forest.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/testrun/Log.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/testrun/Mountains.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/testrun/Plains.class
Binary file not shown.
Binary file added bin/com/pengu/pengulu/testrun/TestRun.class
Binary file not shown.
43 changes: 43 additions & 0 deletions src/com/pengu/pengulu/ColorTheme.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.pengu.pengulu;

import java.awt.*;

public class ColorTheme {
private Color background;
private Color foreground;
private Color inputBackground;
private Color inputForeground;
private Color caretColor;

public ColorTheme(Color background, Color foreground, Color inputBackground, Color inputForeground, Color caretColor) {
this.background = background;
this.foreground = foreground;
this.inputBackground = inputBackground;
this.inputForeground = inputForeground;
this.caretColor = caretColor;
}

public Color getBackground() {
return background;
}

public Color getForeground() {
return foreground;
}

public Color getInputBackground() {
return inputBackground;
}

public Color getInputForeground() {
return inputForeground;
}

public Color getCaretColor() {
return caretColor;
}

public static final ColorTheme monochrome = new ColorTheme(Color.BLACK, Color.GRAY, Color.DARK_GRAY, Color.LIGHT_GRAY, Color.WHITE);
public static final ColorTheme mist = new ColorTheme(new Color(137, 143, 142), new Color(190, 190, 190), new Color(161, 173, 171), new Color(240, 240, 240), Color.WHITE);
public static final ColorTheme ocean = new ColorTheme(new Color(0, 20, 80), new Color(0, 140, 150), new Color(0, 100, 200), new Color(0, 200, 200), Color.CYAN);
}
29 changes: 29 additions & 0 deletions src/com/pengu/pengulu/EnemyTemplate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.pengu.pengulu;

public class EnemyTemplate {
private int damage;
private int health;
private String id;

public EnemyTemplate(int damage, int health, String id) {
this.damage = damage;
this.health = health;
this.id = id;
}

public String getId() {
return id;
}

public int getDamage() {
return damage;
}

public boolean takeDamage(int damage) {
this.health -= damage;
if (health <= 0) {
return true;
}
return false;
}
}
152 changes: 152 additions & 0 deletions src/com/pengu/pengulu/Game.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.pengu.pengulu;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.basic.BasicScrollBarUI;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

public class Game extends JFrame implements ActionListener {

private static JTextArea displayArea;
private static JTextField inputField;
private static JButton submitButton;
private static JScrollPane scrollPane;
private static ColorTheme colorTheme = ColorTheme.monochrome;

private static Node currentNode;
private static ArrayList<Node> nodes = new ArrayList<Node>();

public void start() {
setDefaultCloseOperation(EXIT_ON_CLOSE);

makeGui();

currentNode.request();

setSize(1000, 800);
setVisible(true);
}

private void makeGui() {
displayArea = new JTextArea();
displayArea.setEditable(false);
displayArea.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 25));

scrollPane = new JScrollPane(displayArea);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);


getContentPane().add(scrollPane, BorderLayout.CENTER);

JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new BorderLayout());

inputField = new JTextField();
inputField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20));
inputField.addActionListener(this);


bottomPanel.add(inputField, BorderLayout.CENTER);

submitButton = new JButton("Submit");
submitButton.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 20));
submitButton.addActionListener(this);
bottomPanel.add(submitButton, BorderLayout.EAST);

getContentPane().add(bottomPanel, BorderLayout.SOUTH);

updateColors();

}

private static void updateColors() {
displayArea.setBackground(colorTheme.getBackground());
displayArea.setForeground(colorTheme.getForeground());
displayArea.setSelectedTextColor(colorTheme.getForeground());
displayArea.setSelectionColor(colorTheme.getInputBackground());

scrollPane.getVerticalScrollBar().setBackground(colorTheme.getBackground());
scrollPane.getHorizontalScrollBar().setBackground(colorTheme.getBackground());
setScrollBarColor(scrollPane.getVerticalScrollBar(), colorTheme.getForeground());
setScrollBarColor(scrollPane.getHorizontalScrollBar(), colorTheme.getForeground());

inputField.setBackground(colorTheme.getInputBackground());
inputField.setForeground(colorTheme.getInputForeground());
inputField.setSelectedTextColor(colorTheme.getInputBackground());
inputField.setSelectionColor(colorTheme.getInputForeground());
inputField.setCaretColor(colorTheme.getCaretColor());
inputField.setBorder(new LineBorder(colorTheme.getInputBackground(), 0, false));

submitButton.setBackground(colorTheme.getInputBackground());
submitButton.setForeground(colorTheme.getInputForeground());
submitButton.setBorder(new LineBorder(colorTheme.getInputForeground(), 2, false));
}

private static void setScrollBarColor(JScrollBar bar, Color color) {
bar.setUI(new BasicScrollBarUI() {
@Override
protected void configureScrollBarColors() {
this.thumbColor = color;
}
});
}

@Override
public void actionPerformed(ActionEvent e) {
displayln("> " + inputField.getText());
if (currentNode.getInputRequested()) {
currentNode.setInputRequested(false);
currentNode.respondToInput(inputField.getText());
} else {
if (currentNode.respondToUniversalChoice(inputField.getText())) {
currentNode.runAgain();
} else {
currentNode.respond(inputField.getText());
}

}
inputField.setText("");

}

public static void setCurrentNode(Node node) {
if (currentNode != null) {
Node.setPreviousNodeId(currentNode.getId());
}

currentNode = node;
}
static Node getCurrentNode() {
return currentNode;
}
public static void addNode(Node node) {
nodes.add(node);
}
public static Node getNodeById(String id) {
for (int i = 0; i < nodes.size(); i++) {
if (nodes.get(i).getId().equals(id)) {
return nodes.get(i);
}
}
return currentNode;
}

public static void setColorTheme(ColorTheme colorTheme) {
Game.colorTheme = colorTheme;
updateColors();
}

public static void display(String message) {
displayArea.append(message);
displayArea.setCaretPosition(displayArea.getDocument().getLength());
}
public static void displayln(String message) {
display(message + "\n");
}
public static void displayln() {
display("\n");
}
}
5 changes: 5 additions & 0 deletions src/com/pengu/pengulu/InputListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pengu.pengulu;

public interface InputListener {
public void onInput(String inputText);
}
58 changes: 58 additions & 0 deletions src/com/pengu/pengulu/InventoryManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.pengu.pengulu;

import java.util.ArrayList;

public class InventoryManager {
private static ArrayList<ItemTemplate> items = new ArrayList<ItemTemplate>();

public static void addItem(ItemTemplate item) {
items.add(item);
}

public static ItemTemplate getItemById(String id) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i).getId().equals(id)) {
return items.get(i);
}
}
return null;
}

public static int getItemCount(ItemTemplate item) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i).getId().equals(item.getId())) {
return items.get(i).getCount();
}
}
return -1;
}

public static void incrementItem(ItemTemplate item, int amount) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i).getId().equals(item.getId())) {
items.get(i).incrementCount(amount);
}
}
}
public static void incrementItem(ItemTemplate item) {
incrementItem(item, item.getCount());
}

public static boolean decrementItem(ItemTemplate item, int amount) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i).getId().equals(item.getId())) {
return items.get(i).decrementCount(amount);
}
}
return false;
}
public static boolean decrementItem(ItemTemplate item) {
return decrementItem(item, item.getCount());
}

public static void display() {
for (int i = 0; i < items.size(); i++) {
items.get(i).display();
}
}
}
33 changes: 33 additions & 0 deletions src/com/pengu/pengulu/ItemTemplate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.pengu.pengulu;

public class ItemTemplate {
private int count;
private String id;

public ItemTemplate(int count, String id) {
this.count = count;
this.id = id;
}

public int getCount() {
return count;
}
public void incrementCount(int amount) {
count += amount;
}
public boolean decrementCount(int amount) {
if (count - amount < 0) {
return false;
}
count -= amount;
return true;
}

public String getId() {
return id;
}

public void display() {
Game.displayln(id + ": " + count);
}
}
Loading

0 comments on commit afbf37c

Please sign in to comment.