Skip to content

Commit

Permalink
Engine: Groundwork for effects
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveWillowby committed Nov 18, 2016
1 parent 856b0e6 commit 120534f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 8 deletions.
9 changes: 6 additions & 3 deletions engine/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ static public void Main()
Object o = new Object("pizza");
Console.WriteLine ("Pizza for lunch. Pizza for dinner.");
Console.WriteLine (o.type);
Func<int> returnsNumber = test1(3);
Console.WriteLine ("" + test1(5)());
Console.WriteLine ("" + returnsNumber());
int passIn = 3;
Func<int> returnsNumber = test1(passIn);
passIn = 8;

Console.WriteLine ("" + test1(5)()); //prints out 10
Console.WriteLine ("" + returnsNumber()); //prints out 6
}
}
12 changes: 7 additions & 5 deletions engine/instantiations/Effect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@

public class Effect
{
protected int numObjects;
//protected int numObjects;
protected Action<Object[]> affector;

public void affect(Object[] o)
public void Affect(Object[] o)
{
/*
if(o.Length != numObjects)
{
return;
}
*/
affector(o);
}

public Effect()
{
numObjects = 1;
//numObjects = 1;
affector = o => {};
}

public Effect(Action<Object[]> a, int n)
public Effect(Action<Object[]> a /*, int n*/)
{
numObjects = n;
//numObjects = n;
affector = a;
}
}
76 changes: 76 additions & 0 deletions engine/parsing/EffectParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* Parses a requirement line */
using System;

public class EffectParser
{
public enum Type
{
Put
, Remove
, Create
, Delete
, Distribute
, Disown
, Players
, SetTimer
};

protected static char[] dot = {'.'};

public Effect Parse(Line header, Line line)
{
Action<Object[]> affector = o => {};

string t = line.tokens[1].val;
Type type = ParseType(t);

if(type == Type.Put)
{
}
else if(type == Type.Remove)
{
}
else if(type == Type.Delete)
{
}
else if(type == Type.Distribute)
{
}
else if(type == Type.Disown)
{
}
else if(type == Type.Players)
{
}
else if(type == Type.SetTimer)
{
}

return new Effect(affector);
}

protected static Type ParseType(string t)
{
switch(t)
{
case "put":
return Type.Put;
case "remove":
return Type.Remove;
case "create":
return Type.Create;
case "delete":
return Type.Delete;
case "distribute":
return Type.Distribute;
case "disown":
return Type.Disown;
case "players":
return Type.Players;
case "settimer":
return Type.SetTimer;
default:
throw new Exception("Invalid requirement type " + t);
}
}
}
2 changes: 2 additions & 0 deletions engine/parsing/RequirementParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ protected static Type ParseType(string t)
return Type.RIn;
case "contains":
return Type.Contains;
case "rcontains":
return Type.RContains;
default:
throw new Exception("Invalid requirement type " + t);
}
Expand Down

0 comments on commit 120534f

Please sign in to comment.