Continuation of Random Game Concept
How I would build this
(As in how I would design the back end systems that handle the game mechanics)
(Also I will be talking in Java terms, dw about it)
The basic interfaces
DealType
An Enum of the different types of deals, such as giving/recieving money/resources, building roads, etc.
enum DEAL_TYPE{
BUILD_ROAD,
SEND_MONEY,
SEND_RESOURCE,
RECIEVE_MONEY,
RECIEVE_RESOURCE
}
Trait
An interface with these functions
//Evaluate the single parts (Like recieving money, dislike sending money)
int evaluateDealPart(DEAL_TYPE dealtype);
//Evaluate the entire deal (Risk takers prefer large deals, dislike small ones)
int evaluateEntireDeal(Deal deal);
//Evalue the entire agreement (Dislike working with rivals, Humble trait dislikes getting largest share)
int evaluateAgreement(Agreement agreement);
DealPart
A interface with that can contain the specific parameters for each DEAL_TYPE
For example:
interface DealPart{
DEAL_TYPE getDealType();
}
class SendMoneyDealPart implements DealPart<DEAL_TYPE.SendMoney> {
public final int amount;
SendMoneyDealPart(int amount){
this.amount = amount;
}
DEAL_TYPE getDealType(){
return DEAL_TYPE.SendMoney;
}
}
Deal
A class that contains multiple DealParts
class Deal{
List<DealPart> dealParts;
}
Agreement
A class that contains multiple Deals
Implementations
Example traits:
class RiskTakerTrait implements Trait{
int evaluateDealPart(DEAL_TYPE dealtype){
return 0; //Risk taker doesnt really care about specific parts
}
int evaluateEntireDeal(Deal deal){
//Calculate sum of evaltuations
int dealMagnitude = 0;
foreach(DealPart part : deal.dealParts){
foreach(Trait trait : charachter.traits){
int value = trait.evaluateDealPart(part);
//Make the value absolute to always increase value
dealMagnitude += absolute(value);
}
}
if(dealMagnitude < 50){
return -20; //Dislike small deals
}
if(magnitude > 200){
return 30; //Like large (risky) deals
}
}
int evaluateAgreement(Agreement agreement){
return 0; //Risk taker doesnt really care about entire agreements either (or do they? up to you)
}
}
//Base trait
class MoneyEnjoyerTrait implements Trait{
int evaluateDealPart(DealPart dealPart){
if(dealPart.getDealType() == RECIEVE_MONEY){
RecieveMoneyDealPart recieveMoneyDealPart = (RecieveMoneyDealPart)dealPart;
return recieveMonyDealPart.amount * MONEY_VALUE_MULTIPLIER;
}
if(dealPart.getDealType() == SEND_MONEY){
SendMoneyDealPart sendMoneyDealPart = (SendMoneyDealPart)dealPart;
return -SendMoneyDealPart.amount * MONEY_VALUE_MULTIPLIER; //Note, return negative value
}
}
int evaluateEntireDeal(Deal deal){
return 0;
}
int evaluateAgreement(Agreement agreement){
return 0;
}
}