=Updated Roll Output

It pretty... er
This commit is contained in:
Alex Stewart
2019-07-26 00:19:48 -07:00
parent c9fdea2979
commit d908751119
+24 -10
View File
@@ -1,9 +1,13 @@
package commands.general;
import java.awt.Color;
import java.util.Random;
import java.util.Stack;
import core.*;
import core.Command;
import core.LocStrings;
import dataStructures.KittyChannel;
import dataStructures.KittyEmbed;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
@@ -23,7 +27,15 @@ public class CommandRoll extends Command
{
try
{
res.send(rollDice(input.args));
KittyEmbed embed = new KittyEmbed();
embed.title = user.name +"'s roll!";
embed.descriptionText = rollDice(input.args);
Random numGen = new Random(user.name.hashCode());
float hue = numGen.nextFloat();
float sat = .7f;
float bright = .7f;
embed.color = Color.getHSBColor(hue, sat, bright);
res.send(embed);
}
catch(Exception e)
{
@@ -35,6 +47,7 @@ public class CommandRoll extends Command
{
Stack<Integer> values = new Stack<Integer>();
Stack<Character> operators = new Stack<Character>();
String steps = "";
for(int i = 0; i < thing.length(); i ++)
{
char current = thing.charAt(i);
@@ -49,7 +62,7 @@ public class CommandRoll extends Command
operators.add(current);
else
{
calculate(values, operators);
steps += "\n" + calculate(values, operators);
operators.add(current);
}
@@ -65,7 +78,7 @@ public class CommandRoll extends Command
else
{
i --;
calculate(values, operators);
steps += "\n" + calculate(values, operators);
}
continue;
@@ -73,7 +86,7 @@ public class CommandRoll extends Command
if(operators.isEmpty() || operators.peek() == '(' || !hasPrecendence(operators.peek(), current))
operators.add(current);
else
calculate(values, operators);
steps += "\n" + calculate(values, operators);
continue;
case ' ':
@@ -114,19 +127,20 @@ public class CommandRoll extends Command
while(operators.size() > 0)
{
calculate(values, operators);
steps += "\n" + calculate(values, operators);
}
return "" + values.pop();
return "Roll```" + thing + "```" + "Steps```" + steps + "```" + "Final value ```" + values.pop() +"```";
}
private void calculate(Stack<Integer> nums, Stack<Character> operators)
private String calculate(Stack<Integer> nums, Stack<Character> operators)
{
int second = nums.pop();
int first = nums.pop();
int value = 0;
char op = operators.pop();
switch(operators.pop())
switch(op)
{
case '+':
value = first + second;
@@ -143,8 +157,8 @@ public class CommandRoll extends Command
case 'd':
value = roll(first, second);
}
nums.add(value);
return (first + "" + op + "" + second + "=" + value);
}
private int roll(int first, int second)