需要帮助创建hangman(语法帮助,不作弊) [英] Need help with creating hangman (Syntax help, not cheating)

查看:77
本文介绍了需要帮助创建hangman(语法帮助,不作弊)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我目前的任务是:

"创建一个类似于Hangman的游戏,其中玩家猜测字母试图复制隐藏的单词。在数组中至少存储八个单词,并随机选择一个作为隐藏单词。 (生成随机数所需的语句在决策和循环章节的练习中显示为
。)最初,使用星号显示隐藏的单词以表示每个字母。允许用户猜测字母以替换隐藏字中的星号,直到用户完成整个单词。
如果用户猜到隐藏字中没有的字母,则显示相应的消息。如果用户猜出隐藏字中多次出现的字母,请确保放置每个正确的字母。图6-27显示了在consolebased应用程序和GUI应用程序中正在进行的典型游戏
。将文件另存为GuessAWord.cs。提示:如果您创建了游戏的GUI版本,则可能需要包含一个"开始"按钮,用于选择随机单词并执行其他启动任务,然后再显示游戏界面的
。启动任务完成后,您可以从表单中删除"开始"按钮。"

"Create a game similar to Hangman in which a player guesses letters to try to replicate a hidden word. Store at least eight words in an array, and randomly select one to be the hidden word. (The statements needed to generate a random number are shown in the Exercises in the Decision Making and Looping chapters.) Initially, display the hidden word using asterisks to represent each letter. Allow the user to guess letters to replace the asterisks in the hidden word until the user completes the entire word. If the user guesses a letter that is not in the hidden word, display an appropriate message. If the user guesses a letter that appears multiple times in the hidden word, make sure that each correct letter is placed. Figure 6-27 shows typical games in progress in a consolebased application and in a GUI application. Save the file as GuessAWord.cs. Hint: If you create the GUI version of the game, you might want to include a Start button that selects the random word and performs other start-up tasks before you reveal the game interface. After the start-up tasks are complete, you can remove the Start button from the form."

到目前为止,我一直在搜索互联网,以便开始制定计划.....

I have been searching the internet so far for a way to even begin to formulate a plan.....

我的代码还没什么值得看的,但我想先问一下(启动这个帖子):

My code is nothing worth looking at yet, but I wanted to ask first (to get this thread started):

如何用星号替换单词中的每个字母?

How can I replace each letter in a word with an asterisk?

推荐答案

可能有很多不同的方法可以解决这个问题,但这是我可能会这样做的方式(只是大声思考)。

There are probably a gajillion different ways to go about this, but this is they way I would probably do it (just thinking out loud).

从一个单词开始供用户猜测(来自随机列表或其他)。然后创建一个要显示的字符串,该字符串具有相同的字母数并设置为所有星号。显示该字符串。得到用户的猜测。搜索单词以猜测给定字母的出现
。如果在单词中找到该字母,请用该字母替换该位置的显示字中的星号。显示字符串,获取用户的猜测等,重复直到显示字中没有星号。

Start with a word for the user to guess (from the random list or whatever). Then create a string to display, which has the same number of letters and is set to all asterisks. Display that string. Get the user's guess. Search the word to guess for occurrences of the given letter. If you find the letter in the word, replace the asterisk in the display word at that location with that letter. Display the string, get the user's guess etc. , repeating until there are no more asterisks in the display word.


这篇关于需要帮助创建hangman(语法帮助,不作弊)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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