1
Created the methods Above(), Below(), Highest(), Lowest(), Evens(), Odds(), Matching(), Repeating(), Unique()
...
I need to create a structure/implement these methods inside each other, as if they were organized in directories, within a class Roll()
.
The goal is that those who try to use the class Roll
, can bring their code as close to human language:
ApplyDamage (Physical (Roll (5,d6).Sum.OnlyEvens.Above(2)), ChosenTarget);
Example:
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class Roll
{
List<int> scores;
int maxRange;
public void Roll(int amountOfDices, int maxRange)
{
this.maxRange = maxRange;
for (int i = 0; i < amountOfDices; i++)
{
scores.Add(Random.Range(1,maxRange));
}
}//Construtor
public int Sum (scores)//este é o MEU Sum
{
public int OnlyEvens(scores){
public int Above(scores, int threshold)
{
return(Evens(Above(scores)).Sum());
}
public int Below(scores, int threshold)
{
return(Evens(Below(scores)).Sum());
}
return(Evens(scores).Sum());
}
return(scores.Sum());//este Sum() é proveniente do System.Linq
}
}
In what language? And this OOP is a little strange because in the examples the methods are not members of any object (
ApplyDamage()
instead ofmyInstance.ApplyDamage()
). I couldn’t get it right.– rodorgas
probably meant to be
chosenTarget.ApplyDamage(.....)
– Pablo Almeida
I’m sorry, I rephrased my question, and I hope it’s made clearer, thank you for your help with defining the problem.
– Ivan garcia filho
What is the type of the 1st Physical() parameter? It is a list(Ienumerable)?
– ramaral
Pablo, actually "Applydamage" is a function that instantiates a "Damage" (no, Damage is not a variable in the software I’m developing) : public void Applydamage(Damage inDamageType, int inAmount, List<Gameobject> targets) {
 Damage tempDamage = new Damage(inDamageType,inAmount);
 foreach(var item in Listeners){
 BroadcastMessage("BeforeApplyDamage",this);
 }
 ChosenTarget.BroadcastMessage("ApplyDamage", this);
 foreach(var item in Listeners){ Broadcastmessage("Afterapplydamage", this); } }
– Ivan garcia filho
Ramaral, positive, "Physical" is a Ienumerable
– Ivan garcia filho