did some work on it, it should work in this config i think

This commit is contained in:
2024-09-08 01:01:39 +02:00
parent 09f5d17a59
commit 4a31cbc8d0
13 changed files with 288 additions and 19 deletions
+21
View File
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "entrypoint",
"request": "launch",
"mainClass": "entrypoint",
"projectName": "magic_system_prototype_5c3adcf6"
}
]
}
-9
View File
@@ -1,9 +0,0 @@
// import java.lang.reflect.Method;
import java.util.*;
public class Main {
public static Stack<Stackitem<?>> S = new Stack<>();
public static void main(String[] args){
// S.push(new Stackitem<Double>("Double",4));
}
}
+9
View File
@@ -0,0 +1,9 @@
package a_utils;
public class Effect {
String name;
Integer time;
public Effect(String n, Integer t){
name = n; time = t;
}
}
+26
View File
@@ -0,0 +1,26 @@
package a_utils;
import java.util.ArrayList;
public class Player {
public Double maxHealth;
public Double health;
public Double maxMagicka;
public Double magicka;
public Double speed;
public ArrayList<Effect> effects = new ArrayList<>();
public Player(Double mh, Double h, Double mm, Double m, Double s){
maxHealth = mh;
health = h;
maxMagicka = mm;
magicka = m;
speed = s;
}
public Player(Double h, Double m){
maxHealth = h;
health = h;
maxMagicka = m;
magicka = m;
speed = 1.0;
}
}
@@ -1,3 +1,4 @@
package a_utils;
public class Stackitem<T> {
public String type;
public T value;
+85
View File
@@ -0,0 +1,85 @@
// import java.lang.reflect.Method;
import java.util.*;
import a_utils.Stackitem;
import functions.ChangeHealth;
import a_utils.Player;
import operators.*;
public class entrypoint {
public static Stack<Stackitem<?>> S = new Stack<>();
public static Player player = new Player(20.0,20.0,200.0,200.0,1.0);
public static void main(String[] args){
// String[] args = {"2", "4", "2", "4", "2", "4", "+"};
for (int i = 0; i < args.length; i++) {
System.out.print(args[i] + " ");
}System.out.println();
for(int i = 0; i < args.length; i++){
try {
int numberval;
numberval = Integer.parseInt(args[i]);
S.push(new Stackitem<Double>("Double",(double)numberval));
}catch(Exception e){}
switch (args[i]) {
case "+":
new Plus(S);
break;
case "-":
new Minus(S);
break;
case "*":
new Multiply(S);
break;
case "/":
new Divide(S);
break;
case "p":
S.push(new Stackitem<Player>("Player",player));
break;
case "c":
new ChangeHealth(S);
break;
default:
break;
}
}
// for (int i = 0; i < args.length; i++) {
// System.out.println(args[i]);
// }
System.out.println("Stack size : " + S.size());
int size = S.size();
for (int o = 0; o < size; o++) {
switch(S.peek().type){
case "Double":
System.out.println(S.pop().value);
break;
case "Player":
Player p1 = (Player)S.pop().value;
System.out.println("Emily: \n - Health: " + p1.health + "/" + p1.maxHealth + "\n - Magicka: " + p1.magicka + "/" + p1.maxMagicka);
break;
}
}
// S.push(new Stackitem<Double>("Double",Double.parseDouble("4")));
// S.push(new Stackitem<Double>("Double",Double.parseDouble("2")));
}
}
// 18 * (8 + 2)
+32
View File
@@ -0,0 +1,32 @@
package functions;
import a_utils.Stackitem;
import a_utils.Player;
import java.util.Stack;
// player value
public class ChangeHealth {
public ChangeHealth(Stack<Stackitem<?>> S){
if(S.size() >= 2){
try {
Stackitem<?> t1;
Player t2;
if(S.peek().type == "Double"){
t1 = S.pop();
}else{System.out.println("Expected a Number : " + S.peek().type);return;}
if(S.peek().type == "Player"){
t2 = (Player)S.pop().value;
}else{System.out.println("Expected a Number : " + S.peek().type);return;}
t2.health = t2.health + (Double)t1.value;
} catch (Exception e) {
System.out.println("Expected 2 numbers");
}
}else{
System.out.println("Expected two values");
}
}
}
-5
View File
@@ -1,5 +0,0 @@
package functions;
public class NumberCreate {
}
+1 -1
View File
@@ -2,6 +2,6 @@ package operators;
public class And {
public And(Boolean first, Boolean second){
}
}
+31
View File
@@ -0,0 +1,31 @@
package operators;
import a_utils.Stackitem;
import java.util.Stack;
public class Divide {
public Divide(Stack<Stackitem<?>> S){
if(S.size() >= 2){
try {
Stackitem<?> t1;
Stackitem<?> t2;
if(S.peek().type == "Double"){
t1 = S.pop();
}else{System.out.println("Expected 2 Numbers, got 0 : " + S.peek().type);return;}
if(S.peek().type == "Double"){
t2 = S.pop();
}else{System.out.println("Expected 2 Numbers, got 1 : " + S.peek().type);return;}
S.push(new Stackitem<Double>("Double", (double)t1.value / (double)t2.value));
} catch (Exception e) {
System.out.println("Expected 2 numbers");
}
}else{
System.out.println("Expected two values");
}
}
}
+26 -2
View File
@@ -1,7 +1,31 @@
package operators;
public class Minus {
public Minus(Double first, Double second){
import a_utils.Stackitem;
import java.util.Stack;
public class Minus {
public Minus(Stack<Stackitem<?>> S){
if(S.size() >= 2){
try {
Stackitem<?> t1;
Stackitem<?> t2;
if(S.peek().type == "Double"){
t1 = S.pop();
}else{System.out.println("Expected 2 Numbers, got 0 : " + S.peek().type);return;}
if(S.peek().type == "Double"){
t2 = S.pop();
}else{System.out.println("Expected 2 Numbers, got 1 : " + S.peek().type);return;}
S.push(new Stackitem<Double>("Double", (double)t1.value - (double)t2.value));
} catch (Exception e) {
System.out.println("Expected 2 numbers");
}
}else{
System.out.println("Expected two values");
}
}
}
+31
View File
@@ -0,0 +1,31 @@
package operators;
import a_utils.Stackitem;
import java.util.Stack;
public class Multiply {
public Multiply(Stack<Stackitem<?>> S){
if(S.size() >= 2){
try {
Stackitem<?> t1;
Stackitem<?> t2;
if(S.peek().type == "Double"){
t1 = S.pop();
}else{System.out.println("Expected 2 Numbers, got 0 : " + S.peek().type);return;}
if(S.peek().type == "Double"){
t2 = S.pop();
}else{System.out.println("Expected 2 Numbers, got 1 : " + S.peek().type);return;}
S.push(new Stackitem<Double>("Double", (double)t1.value * (double)t2.value));
} catch (Exception e) {
System.out.println("Expected 2 numbers");
}
}else{
System.out.println("Expected two values");
}
}
}
+25 -2
View File
@@ -1,7 +1,30 @@
package operators;
import a_utils.Stackitem;
import java.util.Stack;
public class Plus {
public double Plus(Double first, Double second){
return first + second;
public Plus(Stack<Stackitem<?>> S){
if(S.size() >= 2){
try {
Stackitem<?> t1;
Stackitem<?> t2;
if(S.peek().type == "Double"){
t1 = S.pop();
}else{System.out.println("Expected 2 Numbers, got 0 : " + S.peek().type);return;}
if(S.peek().type == "Double"){
t2 = S.pop();
}else{System.out.println("Expected 2 Numbers, got 1 : " + S.peek().type);return;}
S.push(new Stackitem<Double>("Double", (double)t1.value + (double)t2.value));
} catch (Exception e) {
System.out.println("Expected 2 numbers");
}
}else{
System.out.println("Expected two values");
}
}
}