挂人代码 [英] Hang man code

查看:69
本文介绍了挂人代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编码非常陌生,我正在尝试做一个< g class =" gr_ gr_105 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del"数据-GR-ID =" 105" id =" 105"> hang man< / g>码。到目前为止,这是我有
但我不知道如何编写用户有三条生命的代码。非常简单的编码会很好< g class =" gr_ gr_432 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del"数据-GR-ID =" 432" id =" 432"> so
< g class =" gr_ gr_443 gr-alert gr_tiny gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling multiReplace"数据-GR-ID =" 443" ID = QUOT; 443" I标记< / g取代;< / g取代;可以理解它 



使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Text;

使用System.Threading.Tasks;



namespace ConsoleApp2

{

  &NBSP;课程计划

  &NBSP; {

  &NBSP; &NBSP; &NBSP; static void Main(string [] args)

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine(" Welcome to< g class =" gr_ gr_26 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id =" 26" id =" 26"> hangan< / g>!
< g class =" gr_ gr_27 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id =" 27" id =" 27"> Lets< / g> begin。 ");)


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string [] arrayofwords = {" blue"," black"," yellow"," orange"," green"," purple"," red"" pink""" maroon" ,"黄金" };
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Random ran = new Random();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string mywords = arrayofwords [ran.Next(0,arrayofwords.Length)];

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine("类别为颜色");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; char [] guess = new char [mywords.Length];

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; for(int p = 0; p< mywords.Length; p ++)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;猜[p] ='*';

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;而(真实)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine("请写下你的猜测");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; char Playerguess = char.Parse(Console.ReadLine());



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; for(int j = 0; j< mywords.Length; j ++)



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(Playerguess == mywords [j])

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;猜[j] = mywords [j];



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;否则 

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine("你猜错了");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine(guess);




  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


$


$
  &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; }


}


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP;
  &NBSP;  

解决方案

请使用编辑器中的"插入代码块"工具发布代码。我们无法阅读直接在论坛中发布的代码,因为它被破坏了。


跟踪"生命"的数量。使用"livesAvailable"每次用户"死亡"时,变量从3开始。将值减1。如果它们变为零则会丢失。

 int livesRemaining = 3; 

while(livesRemaining> 0&&!won)
{
//游戏逻辑

//如果用户"丢失" ;生命
--livesRemaining;
};

if(livesRemaining == 0)
// Lost


I am very new to coding and I am trying to do a <g class="gr_ gr_105 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" data-gr-id="105" id="105">hang man</g> code. this is what I have so far but I don't know how to code that the user has three lives. Very simple coding would be nice <g class="gr_ gr_432 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" data-gr-id="432" id="432">so <g class="gr_ gr_443 gr-alert gr_tiny gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling multiReplace" data-gr-id="443" id="443">i</g></g> can understand it 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to <g class="gr_ gr_26 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="26" id="26">hangan</g>! <g class="gr_ gr_27 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="27" id="27">Lets</g> begin. ");

            string[] arrayofwords = { "blue", "black", "yellow", "orange", "green", "purple", "red", "pink", "maroon", "gold" };
            Random ran = new Random();
            string mywords = arrayofwords[ran.Next(0, arrayofwords.Length)];
            Console.WriteLine("Category is colours");
            char[] guess = new char[mywords.Length];
            for (int p = 0; p < mywords.Length; p++)
                guess[p] = '*';
            while (true)
            {
                Console.WriteLine("please write your guess");
                char Playerguess = char.Parse(Console.ReadLine());

                for (int j = 0; j < mywords.Length; j++)

                {

                    if (Playerguess == mywords[j])
                        guess[j] = mywords[j];

                    else 
                    {
                        Console.WriteLine("you guessed wrong");
                    }
                }

                Console.WriteLine(guess);


            }




        }
    }

}

                                                                             

解决方案

Please use the Insert Code Block tool in the editor to post code. We cannot read code posted directly in the forums as it gets mangled.

To track the number of "lives" use a "livesAvailable" variable that starts at 3. Each time the user "dies" decrement the value by one. If they get to zero they lose.

int livesRemaining = 3;

while (livesRemaining > 0 && !won)
{
   //Game logic

   //If the user "loses" a life
   --livesRemaining;
};

if (livesRemaining == 0)
   //Lost


这篇关于挂人代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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