⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guess.cs

📁 Perst开源实时数据库
💻 CS
字号:
using System;
using Perst;

public class Guess:Persistent
{
    public Guess  yes;
    public Guess  no;
    public string question;
	
    public Guess(Guess no, string question, Guess yes)
    {
        this.yes = yes;
        this.question = question;
        this.no = no;
    }
	
    internal Guess()
    {
    }
	
    internal static string input(string prompt)
    {
        while (true)
        {
            Console.Write(prompt);
            string line = Console.ReadLine().Trim();
            if (line.Length != 0) 
            { 
                return line;
            }
        }
    }
	
    internal static bool askQuestion(string question)
    {
        string answer = input(question);
        return answer.ToUpper().Equals("y".ToUpper()) || answer.ToUpper().Equals("yes".ToUpper());
    }
	
    internal static Guess whoIsIt(Guess parent)
    {
        string animal = input("What is it ? ");
        string difference = input("What is a difference from other ? ");
        return new Guess(parent, difference, new Guess(null, animal, null));
    }
	
    internal Guess dialog()
    {
        if (askQuestion("May be, " + question + " (y/n) ? "))
        {
            if (yes == null)
            {
                Console.WriteLine("It was very simple question for me...");
            }
            else
            {
                Guess clarify = yes.dialog();
                if (clarify != null)
                {
                    yes = clarify;
                    Store();
                }
            }
        }
        else
        {
            if (no == null)
            {
                if (yes == null)
                {
                    return whoIsIt(this);
                }
                else
                {
                    no = whoIsIt(null);
                    Store();
                }
            }
            else
            {
                Guess clarify = no.dialog();
                if (clarify != null)
                {
                    no = clarify;
                    Store();
                }
            }
        }
        return null;
    }
	
    static public void  Main(string[] args)
    {
        Storage db = StorageFactory.Instance.CreateStorage();
		
        db.Open("guess.dbs", 4*1024*1024, "GUESS");
        Guess root = (Guess) db.Root;
		
        while (askQuestion("Think of an animal. Ready (y/n) ? "))
        {
            if (root == null)
            {
                root = whoIsIt(null);
                db.Root = root;
            }
            else
            {
                root.dialog();
            }
            db.Commit();
        }
		
        Console.WriteLine("End of the game");
        db.Close();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -