标签云

微信群

扫码加入我们

WeChat QR Code

I have a little game written in C#. It uses a database as back-end. It's a trading card game, and I wanted to implement the function of the cards as a script.What I mean is that I essentially have an interface, ICard, which a card class implements (public class Card056: ICard) and which contains function that is called by the game.Now, to make the thing maintainable/moddable, I would like to have the class for each card as source code in the database and essentially compile it on first use. So when I have to add/change a card, I'll just add it to the database and tell my application to refresh, without needing any assembly deployment (especially since we would be talking about 1 assembly per card which means hundreds of assemblies).Is that possible? Register a class from a source file and then instantiate it, etc.ICard Cards[current] = new MyGame.CardLibrary.Card056();Cards[current].OnEnterPlay(ref currentGameState);The language is C# but extra bonus if it's possible to write the script in any .NET language.


That's funny, me and a friend were thinking of writing a trading card game in C# a while back, don't suppose you still have the source for this? Interested on how you'd approached this.

2019年08月19日12分10秒

mattytommo No, don't have anything left, it was in the really early stages and essentially was just working like I outlined above. Nowadays, I would look into Roslyn to do C# compilation: blogs.msdn.com/b/csharpfaq/archive/2011/10/19/… - Alternatively, JavaScript using Jint - jint.codeplex.com

2019年08月19日12分10秒

ah thanks, but I was looking more for the implementation of the trading card game itself and the structure you'd used, as opposed to the scripting engine. Thanks anyway :)

2019年08月19日12分10秒

By the way, I've chosen this as the accepted answer because I wanted to loo at Python and IronPython anyway, so the IronPython approach works best for me.

2019年08月19日12分10秒

LuaInterface is a lua interpreter that works fantastic as well.

2019年08月19日12分10秒

I implemented C# Script in a workflow system in Nov 09.It has performed really well for us.

2019年08月19日12分10秒

(No need to flag this; while this should be a comment/answer update, but is grandfathered in from before those were options)

2019年08月19日12分10秒

I believe this refers to Roslyn? en.wikipedia.org/wiki/Microsoft_Roslyn

2019年08月19日12分10秒

Yes. Although Roslyn is still on the horizon, Mono.CSharp (available on NuGet) packs all the same functionality.

2019年08月19日12分10秒

Adding an update to keep the options relevant: The .NET Compiler Platform ("Roslyn") is available. So its a viable alternative to all the others mentioned. github.com/dotnet/roslyn.

2019年08月19日12分10秒