#define DEBUG_THIS_SHITT

using System;
using System.IO;

class CoolShrankClass
{
    const int SHRANK_MAX_ARTIKEL = 4;
    const string SHRANK_PFOAD = "/home/cbx/coolshrankrc";
    
    static int[] anArtikelMenge = new int[SHRANK_MAX_ARTIKEL];
    // Zuordnung der Felder wird hier hergestellt:
    static string[] astrArtikelName = new string[SHRANK_MAX_ARTIKEL] {"Bier","Wein","Cola","Pizza"};

    public static void Main(string[] args)
        {
        CoolShrankFuellen();
        
        CoolShrankLaden(SHRANK_PFOAD);

#if DEBUG_THIS_SHITT // bedingte compilierung
        for (int i = 0; i < anArtikelMenge.Length; i++)
            {
            Console.WriteLine("Füllstand {0} = {1}",astrArtikelName[i], anArtikelMenge[i]);
            }
#endif
        
        if (CoolShrankZutritt())
            {
            Console.WriteLine("Access granted");
            CoolShrankMenue();
            }
        else
            {
            Console.WriteLine("Access denied");
            }
        
        CoolShrankSpeichern(SHRANK_PFOAD);
        
        Console.WriteLine("\n\n=> Game over");
        return; 
        }

// Nennfüllstand im Shrank herstellen
    static public void CoolShrankFuellen()
        {
        anArtikelMenge[0] = 10; // Bier
        anArtikelMenge[1] = 3;  // Wein
        anArtikelMenge[2] = 5;  // Cola
        anArtikelMenge[3] = 4;  // Pizza
        } 
        
    static public void CoolShrankSpeichern(string strPfoad)
        {
        StreamWriter outStream = new StreamWriter(strPfoad);
        
        for ( int i=0; i < anArtikelMenge.Length; i++ )
            {
            outStream.WriteLine(anArtikelMenge[i]);
            }
            
        outStream.Close();
        }   

    static public void CoolShrankLaden(string strPfoad)
        {
        StreamReader inStream;
        
        try
            {
            inStream = new StreamReader(strPfoad);
            }
        catch (FileNotFoundException ex)
            {
            Console.WriteLine("No file found, refilling to defaults...");
            return;
            }
        
        for ( int i=0; i < anArtikelMenge.Length; i++ )
            {
            anArtikelMenge[i] = Convert.ToInt32(inStream.ReadLine());
            }
        
        inStream.Close();
        }
        
    static public bool CoolShrankZutritt()      
        {
        int nAt, nDot, nSpace;
        
        Console.Write ("Entern Sie Ihre E-Mailadresse: ");
        string strAdresse = Console.ReadLine();
        
        nAt = nDot = nSpace = 0;
        
        foreach (char c in strAdresse)
            {
            switch (c)
                {
                case '@':
                    nAt++;
                    break;
                case '.':
                    nDot++;
                    break;
                case ' ':
                    nSpace++;
                    break;
                }
            } //for
        
        return ((nAt == 1) && (nDot >= 1) && (nSpace == 0));
        }   

    static public void CoolShrankMenue()        
        {

        Console.WriteLine("\n\n *** Hauptmenü *** \n");
        
        for ( int i=0; i < anArtikelMenge.Length; i++ )
            {
            if (anArtikelMenge[i] > 0)
                {
                Console.WriteLine("({0})...{1} (noch {2})", 
                                   i+1, astrArtikelName[i], anArtikelMenge[i]);
                }
            }
        }
            
} // class

syntax highlighted by Code2HTML, v. 0.9.1