Hi,

aus Langeweile habe ich Fifty! geschrieben (Konsolenanwendung), vielleicht auch etwas unnötig (kompliziert) geschrieben, da Langeweile.

Was kann es?
- Würfel rollen
- benutzte Würfel werden entfernt
- Würfel werden geprüft
- 3x Eingabe (auch wenn's eine falsche Eingabe war), danach werden die Würfel wieder neu gesetzt

Dice.cs:
PHP-Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 
Fifty {
    public 
struct Dice
    
{
        private 
int countnum;

        public 
int Count
        
get { return count; } }
        public 
int Num
        
get { return num; } }

        public 
Dice(int[] args)
        {
            if (
args != null && args.Length == 2)
            {
                
count args[0];
                
num args[1];
            }
            else
            {
                
count = -1;
                
num = -1;
            }
        }
    }

FiftyDice.cs:
PHP-Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 
Fifty
{
    class 
FiftyDice
    
{
        public 
Dice[] userDices getset; }
        private 
readonly int[] numscounts;

        public 
FiftyDice()
        {
            
nums = new int[] { 468101220 };
            
counts = new int[] { 32211};

            
userDices = new Dice[nums.Length];
            for (
int i 0nums.Lengthi++)
                
userDices[i] = new Dice(new int[] { counts[i], nums[i] });
        }
    }

Program.cs:
PHP-Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 
Fifty
{
    class 
Program
    
{
        static 
void Main(string[] args)
        {
            
Console.Title "Fifty!";

            
FiftyDice f = new FiftyDice();

            while (
true)
            {
                for (
int r 03r++)
                {
                    
Console.Write("Eingabe: ");
                    
String eingabe Console.ReadLine();
                    
Dice[] dices Utility.Parse(eingabe);

                    if (
dices.Any<Dice>(delegate(Dice n) { return n.Num == -1; }))
                    {
                        
Console.WriteLine("INVALID INPUT!");
                        continue;
                    }

                    
Console.Write("Benutzte Würfel: ");

                    for (
int i 0dices.Lengthi++)
                    {
                        
Dice d dices[i];

                        if (
d.Count 1)
                            
Console.Write(d.Count);

                        
Console.Write('W');
                        
Console.Write(d.Num);

                        if (
dices.Length 1)
                            
Console.Write(" + ");
                    }

                    
Console.Write("\n");
                    
KeyValuePair<boolDice[]> valid Utility.IsValid(dicesf.userDices);
                    if (
valid.Value != null)
                        
f.userDices valid.Value;

                    
Console.Write("{0}VALID DICES!\n", (!valid.Key "IN" String.Empty));
                    
Console.Write("Now: ");

                    for (
int i 0f.userDices.Lengthi++)
                    {
                        if (
f.userDices[i].Count 1)
                            
Console.Write(f.userDices[i].Count);

                        
Console.Write('W');
                        
Console.Write(f.userDices[i].Num);

                        if (
f.userDices.Length 1)
                            
Console.Write(" + ");
                    }

                    
Console.Write("\n");

                    if (
valid.Key)
                    {
                        
KeyValuePair<intstringrollDices Utility.RollDices(dices);
                        
Console.WriteLine("Du würfelst mit {0}"rollDices.Value);
                    }

                    
Console.Write("\n");
                }

                
= new FiftyDice();
                
Console.WriteLine("3x used, init new dices...");
                
Console.WriteLine();
            }
        }
    }

Utility.cs:
PHP-Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 
Fifty {
    public class 
Utility
    
{
        public static 
KeyValuePair<intstringRollDices(Dice[] parsedDices)
        {
            
StringBuilder builder = new StringBuilder();
            
StringBuilder diced = new StringBuilder();
            
Random r = new Random();
            
int total 0;

            for (
int i 0parsedDices.Lengthi++)
            {
                
Dice p parsedDices[i];
                if (
p.Count 1)
                    
builder.Append(p.Count);

                
builder.Append('W');
                
builder.Append(p.Num);

                if (
parsedDices.Length 1)
                    
builder.Append(" + ");

                for (
int j 1<= p.Countj++)
                {
                    
int randomized r.Next(1p.Num 1);
                    
total += randomized;

                    
diced.Append(randomized);
                    while (
randomized == p.Num)
                    {
                        
randomized r.Next(1p.Num 1);
                        
total += randomized;

                        
diced.Append("> ");
                        
diced.Append(randomized);
                    }

                    if (
p.Count)
                        
diced.Append(", ");
                }

                if (
parsedDices.Length 1)
                    
diced.Append(" + ");
            }

            
diced.Append(" = ");
            
diced.Append(total);
            
diced.Append(".");

            
builder.Append(": ");
            
builder.Append(diced.ToString());

            return new 
KeyValuePair<intstring>(totalbuilder.ToString());
        }

        public static 
KeyValuePair<boolDice[]> IsValid(Dice[] parsedDicesDice[] userDices)
        {
            List<
DicelistedUserDices userDices.ToList<Dice>();
            foreach (
Dice p in parsedDices)
            {
                
Dice found listedUserDices.Find(delegate(Dice u) { return u.Num == p.Num; });
                if (
found.Count == -1)
                    return new 
KeyValuePair<boolDice[]>(falsenull);

                if (
p.Count found.Count)
                    return new 
KeyValuePair<boolDice[]>(falsenull);

                
int index listedUserDices.FindIndex(0listedUserDices.Countdelegate(Dice u) { return u.Num == p.Num; });
                if (
index != -1) {
                    
listedUserDices[index] = new Dice(new int[] { listedUserDices[index].Count p.Countp.Num });

                    if (
listedUserDices[index].Count <= 0)
                        
listedUserDices.RemoveAt(index);
                }
            }

            return new 
KeyValuePair<boolDice[]>(truelistedUserDices.ToArray());
        }

        public static 
Dice[] Parse(string s)
        {
            List<
Dicedices = new List<Dice>();

            if (
s.StartsWith("/d "))
                
s.Substring(3);

            
string[] diceParams s.Split('+');
            for (
int i 0diceParams.Lengthi++)
            {
                
Dice dice ParseString(diceParams[i]);
                
bool changed false;

                foreach (
Dice d in dices)
                {
                    if (
d.Num == dice.Num)
                    {
                        
int index dices.FindIndex(0dices.Countdelegate(Dice find) { return find.Num == d.Num; });
                        if (
index != -1)
                        {
                            
dices[index] = new Dice(new int[] { d.Count dice.Countd.Num });
                            
changed true;
                        }

                        break;
                    }
                }

                if (!
changed)
                    
dices.Add(dice);
            }

            
Dice[] arrDices dices.ToArray();
            
arrDices Sort(arrDices);

            return 
arrDices;
        }

        private static 
Dice[] Sort(Dice[] toSort)
        {
            List<
intnums = new List<int>();

            foreach (
Dice d in toSort)
                
nums.Add(d.Num);

            
nums.Sort();

            List<
DicesortedDices = new List<Dice>();

            foreach (
int num in nums)
                
sortedDices.Add(new Dice(new int[] { GetCount(numtoSort), num }));

            return 
sortedDices.ToArray();
        }

        private static 
int GetCount(int numDice[] dices)
        {
            
Dice found dices.ToList<Dice>().Find(delegate(Dice d) { return d.Num == num; });
            return 
found.Count;
        }


        private static 
Dice ParseString(string s)
        {
            
s.Trim().ToLower();
            if (
String.IsNullOrEmpty(s))
                return new 
Dice(null);

            if (
s[0] == 'w')
                
s.Substring(1);

            if (!
s.Contains("w"))
            {
                
int num;
                if (
int.TryParse(sout num))
                    return new 
Dice(new int[] { 1num });
                else
                    return new 
Dice(null);
            }
            else
            {
                
string[] sParams s.Split('w');
                
int countnum;
                if (
int.TryParse(sParams[0], out count) && int.TryParse(sParams[1], out num))
                    return new 
Dice(new int[] { countnum });
                else
                    return new 
Dice(null);
            }
        }
    }

Fragen? Dann fragt.

MfG