-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6e1281
commit afbf37c
Showing
33 changed files
with
621 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
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); | ||
} |
This file contains 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
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; | ||
} | ||
} |
This file contains 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
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"); | ||
} | ||
} |
This file contains 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
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); | ||
} |
This file contains 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
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(); | ||
} | ||
} | ||
} |
This file contains 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
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); | ||
} | ||
} |
Oops, something went wrong.