有人可以帮我解决Hangman游戏(C#控制台) [英] Can someone help me out with my HangMan Game (C# Console)

查看:59
本文介绍了有人可以帮我解决Hangman游戏(C#控制台)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用系统;

命名空间Hangman
{
   课程计划
    {
       静态void Main(string [] args)
        {

            Console.WriteLine("Welcome to Hangman!");
            Console.WriteLine(您有6条生命.");
            Console.WriteLine("GOOOOOOOOOOOOOOOOOOOOOOOOOO");

            string [] wordBank = new string [20];
            wordBank [0] ="librarycard";
            wordBank [1] ="head";
            wordBank [2] ="ihateprogramming";
            wordBank [3] =七个";
            wordBank [4] =西瓜";
            wordBank [5] ="peak";
            wordBank [6] =皮革";
            wordBank [7] =菠萝";
            wordBank [8] ="lost";
            wordBank [9] ="starwars";
            wordBank [10] ="apple";
            wordBank [11] ="stevecarrell";
            wordBank [12] ="kevinspacey";
            wordBank [13] ="carlgrimes";
            wordBank [14] =古生物学家";
            wordBank [15] ="hangman";
            wordBank [16] ="thereisamanridingahorseontopofmychest";
            wordBank [17] ="mathewperry";
            wordBank [18] ="newski";
            wordBank [19] ="cheekysherwin";
           随机randGen =新的Random();
            var spot = randGen.Next(0,20);
           字符串mysteryWord = wordBank [spots];

            char [] guess = new char [mysteryWord.Length];

            for(int p = 0; p< mysteryWord.Length; p ++)
                guess [p] ='*';

           寿命= 6;

           而(true)
            {

                for(int x = 0; x< mysteryWord.Length; x ++)
                {
                    int j;
                    Console.Write("请输入您的猜测:");
                    char playerGuess = char.Parse(Console.ReadLine());
                    for(j = 0; j< mysteryWord.Length; j ++)
                    {
                       如果(playerGuess == mysteryWord [j])
                        {
                            guess [j] = playerGuess;
                        }

                    }
                   如果(playerGuess!= mysteryWord [x])
                    {
                       生命=生命-1;
                       如果(生命== 0)
                        {
                            Console.WriteLine(您输了!");
                            Console.WriteLine(单词为(" + mysteryWord +"))");
                            Console.ReadLine();
                            Environment.Exit(0);
                        }
                    }
                    Console.WriteLine(guess);
                    Console.WriteLine(您拥有:" +生活+生活".);
                }
            } 
        }
    }
}

using System;

namespace Hangman
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Welcome to Hangman!");
            Console.WriteLine("You have 6 Lives.");
            Console.WriteLine("GOOOOOOOOOOOOOOOOOOOOOOOO");

            string[] wordBank = new string[20];
            wordBank[0] = "librarycard";
            wordBank[1] = "head";
            wordBank[2] = "ihateprogramming";
            wordBank[3] = "seven";
            wordBank[4] = "watermelon";
            wordBank[5] = "peak";
            wordBank[6] = "leather";
            wordBank[7] = "pineapple";
            wordBank[8] = "lost";
            wordBank[9] = "starwars";
            wordBank[10] = "apple";
            wordBank[11] = "stevecarrell";
            wordBank[12] = "kevinspacey";
            wordBank[13] = "carlgrimes";
            wordBank[14] = "paleontologist";
            wordBank[15] = "hangman";
            wordBank[16] = "thereisamanridingahorseontopofmychest";
            wordBank[17] = "mathewperry";
            wordBank[18] = "newski";
            wordBank[19] = "cheekysherwin";
            Random randGen = new Random();
            var spots = randGen.Next(0, 20);
            string mysteryWord = wordBank[spots];

            char[] guess = new char[mysteryWord.Length];

            for (int p = 0; p < mysteryWord.Length; p++)
                guess[p] = '*';

            int life = 6;

            while (true)
            {

                for (int x = 0; x < mysteryWord.Length; x++)
                {
                    int j;
                    Console.Write("Please enter your guess: ");
                    char playerGuess = char.Parse(Console.ReadLine());
                    for (j = 0; j < mysteryWord.Length; j++)
                    {
                        if (playerGuess == mysteryWord[j])
                        {
                            guess[j] = playerGuess;
                        }

                    }
                    if (playerGuess != mysteryWord[x])
                    {
                        life = life - 1;
                        if (life == 0)
                        {
                            Console.WriteLine("You Lost!");
                            Console.WriteLine("The word was ( " + mysteryWord + " )");
                            Console.ReadLine();
                            Environment.Exit(0);
                        }
                    }
                    Console.WriteLine(guess);
                    Console.WriteLine("You have: " + life + " live(s).");
                }
            } 
        }
    }
}

有人可以告诉我我的程序是怎么回事,也许可以帮忙解决它

Can someone tell me what is going on with my program and maybe help fix it please

推荐答案

Dan,

这是Microsoft Project(项目管理计划产品)的论坛.请重新发布到论坛获取c#.从这里开始:

This is a forum for Microsoft Project - a project management scheduling product.  Please re-post to the forum for c#.  Start here:

http://social.msdn.microsoft.com/Forums/zh-CN/csharpgeneral/threads

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/threads


这篇关于有人可以帮我解决Hangman游戏(C#控制台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆