我无法在我的刽子手游戏中将破折号切换为猜测字母。以下是我所拥有的,但它不起作用。
const fs = require('fs');
json = {
one: 1,
two: 2
}
json = JSON.stringify(json);
fs.writeFile('./foo.json', json, (err) => {
if (!err) {
console.log('done');
}
});
答案 0 :(得分:0)
Hangman对于学习任何类型的编程来说都是一款非常棒的游戏。这是开始的事情:
Option Explicit
Sub TestMe()
Dim secretWord As String
Dim currentResult As String
secretWord = "stackoverflow"
currentResult = "__a__o_____o_"
currentResult = TryToHang(secretWord, "s", currentResult)
currentResult = TryToHang(secretWord, "t", currentResult)
currentResult = TryToHang(secretWord, "c", currentResult)
Debug.Print currentResult
End Sub
Public Function TryToHang(secretWord, guess, currentResult) As String
Dim cnt As Long
For cnt = 1 To Len(secretWord)
If Mid(secretWord, cnt, 1) = guess Then
Mid(currentResult, cnt, 1) = guess
End If
Next cnt
TryToHang = currentResult
End Function
运行TestMe()
后,您将在控制台上获得stac_o_____o_
。在接下来的步骤中,创建一些字符串构建器,它会生成与给定单词__________
一样长的初始当前结果字符串。
并且可能会重写While(True)
循环中的所有内容,在挂起完成之前请求输入。