zoukankan      html  css  js  c++  java
  • 纪念一下なぞなぞゲーム

    俺用c#做出来的第一个程序
    尽管是没有画面的
    好歹也算实现了
    废话很多
    但是先不改了吧
    这样才能展现从最初开始的思想全貌

    using System;
    public class nazonazogame
    {
        public static void Main()
        {
            Console.WriteLine("***かぞかぞゲーム(三つの数字があります)***");
            Console.WriteLine("三つの数字をそれぞれ入力してください!");
           
            //乱数a,b,cを得る
            Random r1 = new Random();
            int[] ans = new int[3];
            ans[0] = r1.Next(0, 9);

            for (int i = 1; i < 3; i++)
            {
                bool chk;
                do
                {
                    ans[i] = r1.Next(0, 9);
                    chk = false;
                    for (int j = 0; j < i; j++)
                    {
                        if (ans[i] == ans[j])
                        {
                            chk = true;
                        }

                    }
                }
                while (chk);
            }
            //Console.WriteLine(ans[0]);
            //Console.WriteLine(ans[1]);
            //Console.WriteLine(ans[2]);

            //結果を判断する
            int count = 0;
            int[] res = new int[3];
            while(count != 3)
            {
                //データを入力する
                int[] a = new int[3];
                string[] s = new string[3];
                s[0] = Console.ReadLine();
                a[0] = Int32.Parse(s[0]);
                s[1] = Console.ReadLine();
                a[1] = Int32.Parse(s[1]);
                s[2] = Console.ReadLine();
                a[2] = Int32.Parse(s[2]);

                //入力データと乱数をチェック、マークをつける
               
                for (int j = 0; j < 3; j++)
                {               
                    res[j] = -1;
                   
                    for (int i = 0; i < 3; i++)
                    {
                        if (a[j] == ans[i])
                        {
                            if (i == j)
                            {
                                res[j] = 1;
                            }
                            else
                            {
                                if (a[j] == ans[j])
                                {
                                    res[j] = 1;
                                }
                                else
                                {
                                    res[j] = 0;
                                }
                            }
                        }
                    }
                                   
                }
                count = 0;
                for (int j = 0; j < 3; j++)
                {
                    if (res[j] == 1)
                    {
                        count++;
                    }
                }


                //結果を表示する

                for (int j = 0; j < 3; j++)
                {

                    switch (res[j])
                    {
                        case 1:
                            Console.WriteLine("○");
                            break;
                        case 0:
                            Console.WriteLine("△");
                            break;
                        case -1:
                            Console.WriteLine("×");
                            break;
                    }
                }
            }
                Console.WriteLine("正解です!おめでとうございます!");
           
        }
                   
               
    }
              
    今天争取根据这个把带画面的做出来!

  • 相关阅读:
    09.Java数据算法
    08.Java反射问题
    07.Java类加载问题
    占位
    占位
    占位
    占位
    HTML与CSS粗浅摘要
    JavaScript(4):模态对话框、隐藏二级菜单及多选框的实现
    JavaScript(3):DOM选择器
  • 原文地址:https://www.cnblogs.com/loverain/p/1006684.html
Copyright © 2011-2022 走看看