Saturday, July 11, 2009

The adventures of a Pythonista in Schemeland

http://www.artima.com/weblogs/viewpost.jsp?thread=238789

Beginning F#: Card Tricks

http://www.devx.com/dotnet/Article/40537/1954

Mastermind F# WPF Game Sample

http://www.trelford.com/blog/post/Mastermind-F-WPF-Game-Sample.aspx

How to Write XNA Game Studio Express Games

http://grammerjack.spaces.live.com/blog/cns!F2629C772A178A7C!156.entry

Learning WPF through F#, and vice versa, by John Liao

http://blogs.msdn.com/dsyme/archive/2008/01/05/learning-wpf-through-f-and-vice-versa-by-john-liao.aspx

Exploring F# with Conway’s Game of Life

http://blogs.vertigo.com/personal/rtaylor/Blog/Lists/Posts/Post.aspx?ID=8

Simple F# Game using WPF

http://blogs.msdn.com/chrsmith/archive/2008/09/04/simple-f-game-using-wpf.aspx

F# FOR GAME DEVELOPMENT

http://sharp-gamedev.blogspot.com/2008/09/hello-world.html

Tuesday, July 7, 2009

How to Design Programs

http://www.htdp.org/2003-09-26/Book/curriculum.html

Factory Pattern in C#

I wanted to access the fields of the created classes.
Here is the code I've implemented, feel free to comment


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FactoryPattern
{

    interface Base
    {      
    }
    
    class Factory
    {
        Base derived;

        public Base GetObject(int selector)
        {
            switch (selector)
            {
                case 1:
                    derived = new Derived1();
                    break;
                case 2:
                    derived = new Derived2();
                    break;
            }
            return derived;
        }
    }


    class Derived1 : Base
    {
        public string origin = "Derived1";      
    }


    public class Derived2 : Base
    {
        public string origin = "Derived2";
        public int value = 145;
    }

    class Program
    {
        public static object GetFieldValue(string nameField, object obj)
        {
            return obj.GetType().GetField(nameField).GetValue(obj);
        }

        static void Main(string[] args)
        {
            Base obj;
            Factory f = new Factory();
            obj = f.GetObject(2);          
            var origin =  GetFieldValue("value", obj);
            System.Console.WriteLine(String.Format("{0}",origin));
            Console.ReadLine();          
        }
    }
}