; ---------------------------Main Code Start---------------------------
; 生命次数
lives := 3
; 神秘单词, 随机选择
words := ['pizza', 'fairy', 'teeth', 'shirt', 'otter', 'plane']
secret_word := random.choice(words)
; print(secret_word)
clue := StrSplit('?????')
heart_symbol := chr(10084)
guessed_word_correctly := False
update_clue(guessed_letter, secret_word, clue)
{
index := 1
secret_word := StrSplit(secret_word)
while index <= len(secret_word)
{
if guessed_letter == secret_word[index]
clue[index] := guessed_letter
index := index + 1
}
}
while lives > 0
{
if !InStr(Join(clue, ""), "?")
{
guessed_word_correctly := True
break
}
print(Join(clue, ""))
heartNum := ""
Loop lives
heartNum .= heart_symbol
print('剩余生命次数: ' heartNum)
print('猜测字母或者是整个单词: ')
guess := input('猜测字母或者是整个单词: ')
print(guess)
if guess == secret_word
{
guessed_word_correctly := True
break
}
if inarr(guess, secret_word)
update_clue(guess, secret_word, clue)
else
{
print('错误。你丢了一条命`n')
lives := lives - 1
}
}
if guessed_word_correctly
print('你赢了! 秘密单词是 ' secret_word)
else
print('你输了! 秘密单词是 ' secret_word)
; ---------------------------Main Code End---------------------------
Inarr(element, arr)
{
if Type(arr) == "String"
return InStr(arr, element)
flag := 0
for i in arr
{
if element == i
flag := 1
}
return flag
}
Input(Prompt := "")
{
InputObj := InputBox(Prompt)
if InputObj.Result == "Cancel" || InputObj.Result == "Timeout"
Return -1
else
Return InputObj.Value
}
Join(Lst_Text, Connect := ",")
{
if Type(Lst_Text) == "String"
Lst_Text := StrSplit(Lst_Text, "")
Return_Text := ""
Loop Lst_Text.Length
Return_Text .= Lst_Text[A_Index] . Connect
Return SubStr(Return_Text, 1, StrLen(Return_Text) - StrLen(Connect))
}
Len(Object)
{
if Type(Object) == "String"
Return StrLen(Object)
else if Type(Object) == "Array"
Return Object.Length
else if Type(Object) == "Map"
Return Object.Count
else if Type(Object) == "ComObjArray"
Return Object.MaxIndex + 1
else if Type(Object) == "Object"
Return ObjOwnPropCount(Object)
}
ListCmp(Lst1, Lst2)
{
Lst1 := ToString(Lst1)
Lst2 := ToString(Lst2)
if StrCompare(Lst1, Lst2) < 0
Return -1
else if StrCompare(Lst1, Lst2) > 0
Return 1
else
Return 0
}
Print(Text*)
{
Global Print_Gui
Global Print_Edit
Print_Text := ""
Loop Text.Length
{
String_Text := ToStringPrint(Text[A_Index])
if SubStr(String_Text, -1) == "," && (Type(Text[A_Index]) == "Array" || Type(Text[A_Index]) == "List" || Type(Text[A_Index]) == "ComObjArray" || Type(Text[A_Index]) == "Numpy.NDArray" || Type(Text[A_Index]) == "Map" || Type(Text[A_Index]) == "Dict" || Type(Text[A_Index]) == "Object")
String_Text := SubStr(String_Text, 1, StrLen(String_Text) - 1)
Print_Text .= String_Text "`n"
}
Print_Text := SubStr(Print_Text, 1, StrLen(Print_Text) - 1)
if WinExist("Sinet Print")
{
WinActivate("Sinet Print")
Print_Edit.Value .= "`n" Print_Text
Return
}
Print_Gui := Gui()
Print_Gui.Title := "Sinet Print"
Print_Gui.BackColor := "87CEFA"
Print_Edit := Print_Gui.Add("Edit", "R30 W800 ReadOnly")
Print_Edit.SetFont("S12", "Arial")
Print_Edit.Value := Print_Text
Print_Gui.Show()
}
Range(start, stop)
{
tmp := []
loop stop - start
tmp.push(start + A_Index - 1)
return tmp
}
Swap(ValueX, ValueY, Object := -1)
{
if Type(Object) == "Array" || Type(Object) == "List" || Type(Object) == "Map" || Type(Object) == "Dict"
{
Temp := Object[ValueX]
Object[ValueX] := Object[ValueY]
Object[ValueY] := Temp
}
else
{
Try
{
Temp := %ValueX%
%ValueX% := %ValueY%
%ValueY% := Temp
}
Catch
MsgBox("Swap Error`nTry to Input Object")
}
}
ToString(Text)
{
if Type(Text) == "Array"
{
if Text.Length < 1
Text.InsertAt(1, "")
String_Plus := ""
String_Text := "[" . ToString(Text[1])
Loop Text.Length - 1
String_Plus .= "," . ToString(Text[A_Index + 1])
String_Text .= String_Plus
String_Text .= "]"
Return String_Text
}
else if Type(Text) == "List"
{
if Text.Length < 1
Text.InsertAt(1, "")
String_Plus := ""
String_Text := "[" . ToString(Text[0])
Loop Text.Length - 1
String_Plus .= "," . ToString(Text[A_Index])
String_Text .= String_Plus
String_Text .= "]"
Return String_Text
}
else if Type(Text) == "ComObjArray"
{
if Text.MaxIndex() < 0
{
Text := ComObjArray(VT_VARIANT:=12, 1)
Text[0] := ""
}
String_Plus := ""
String_Text := "[" . ToString(Text[0])
Loop Text.MaxIndex()
String_Plus .= "," . ToString(Text[A_Index])
String_Text .= String_Plus
String_Text .= "]"
Return String_Text
}
else if Type(Text) == "Map"
{
String_Text := "{"
For i, Value in Text
String_Text .= ToString(i) . ":" . ToString(Value) . ","
if SubStr(String_Text, -1) !== "{"
String_Text := SubStr(String_Text, 1, StrLen(String_Text) - 1)
String_Text .= "}"
Return String_Text
}
else if Type(Text) == "Integer" || Type(Text) == "Float" || Type(Text) == "String"
Return String(Text)
else if Type(Text) == "Object"
{
String_Text := "{"
For i, Value in Text.OwnProps()
String_Text .= ToString(i) . ":" . ToString(Value) . ","
if SubStr(String_Text, -1) !== "{"
String_Text := SubStr(String_Text, 1, StrLen(String_Text) - 1)
String_Text .= "}"
Return String_Text
}
else
Return "#Null#"
}
ToStringPrint(Text)
{
if Type(Text) == "Array"
{
if Text.Length < 1
Text.InsertAt(1, "")
String_Plus := ""
String_Text := "[" . ToStringPrint(Text[1])
Loop Text.Length - 1
String_Plus .= "," . ToStringPrint(Text[A_Index + 1])
String_Text .= String_Plus
String_Text .= "]"
Return String_Text
}
else if Type(Text) == "List"
{
if Text.Length < 1
Text.InsertAt(1, "")
String_Plus := ""
String_Text := "[" . ToStringPrint(Text[0])
Loop Text.Length - 1
String_Plus .= "," . ToStringPrint(Text[A_Index])
String_Text .= String_Plus
String_Text .= "]"
Return String_Text
}
else if Type(Text) == "ComObjArray"
{
if Text.MaxIndex() < 0
{
Text := ComObjArray(VT_VARIANT:=12, 1)
Text[0] := ""
}
String_Plus := ""
String_Text := "[" . ToStringPrint(Text[0])
Loop Text.MaxIndex()
String_Plus .= "," . ToStringPrint(Text[A_Index])
String_Text .= String_Plus
String_Text .= "]"
Return String_Text
}
else if Type(Text) == "Map"
{
String_Text := "{"
For i, Value in Text
String_Text .= ToStringPrint(i) . ":" . ToStringPrint(Value) . ","
if SubStr(String_Text, -1) !== "{"
String_Text := SubStr(String_Text, 1, StrLen(String_Text) - 1)
String_Text .= "}"
Return String_Text
}
else if Type(Text) == "Integer" || Type(Text) == "Float" || Type(Text) == "String"
Return Text
else if Type(Text) == "Object"
{
String_Text := "{"
For i, Value in Text.OwnProps()
String_Text .= ToStringPrint(i) . ":" . ToStringPrint(Value) . ","
if SubStr(String_Text, -1) !== "{"
String_Text := SubStr(String_Text, 1, StrLen(String_Text) - 1)
String_Text .= "},"
Return String_Text
}
else
Return "#Type: " Type(Text) "#"
}
Class List Extends Array
{
NextIdx := 0
__Enum(Number)
{
Index := this.Length
Return Fn
Fn(&idx := 0, &value := 0)
{
if IsSet(value)
{
Try
{
idx := this[this.Length - Index]
Return Index-- >= 0
}
Catch
Return 0
}
else
{
Try
{
idx := this.Length - Index
value := this[this.Length - Index]
Return Index-- >= 0
}
Catch
Return 0
}
}
}
__Item[Index]
{
Get => this.GetMethod(Index)
Set => this.SetMethod(Index, Value)
}
Append(Object*)
{
Loop Object.Length
this.Push(Object[A_Index])
}
Count(Object)
{
Return_Count := 0
For i in this
{
if !ListCmp(i, Object)
Return_Count++
}
Return Return_Count
}
Extend(Extend_Lst*)
{
Loop Extend_Lst.Length
{
if Type(Extend_Lst[A_Index]) !== "Array" && Type(Extend_Lst[A_Index]) !== "List"
this.Push(Extend_Lst[A_Index])
else
{
For i in Extend_Lst[A_Index]
this.Push(i)
}
}
}
GetMethod(Index)
{
Try
Index := Integer(Index)
if Type(Index) == "Integer"
Return Super[this.Init(Index)]
else if InStr(Index, ":")
{
Lst_Res := List()
Lst_Index := StrSplit(Index, ":")
if !Trim(Lst_Index[1])
Lst_Index[1] := 0
if !Trim(Lst_Index[2])
Lst_Index[2] := this.Length
For i in Range(Trim(Lst_Index[1]), Trim(Lst_Index[2]))
Lst_Res.Append(Super[this.Init(i)])
Return Lst_Res
}
}
Index(Object)
{
Flag := 0
Index := 0
For i in this
{
if !ListCmp(i, Object)
{
Flag := 1
Break
}
Index++
}
if !Flag
Index := -1
Return Index
}
Init(Index)
{
if Index >= 0
Index += 1
Return Index
}
Insert(Index, Object*)
{
this.InsertAt(this.Init(Index), Object*)
}
List(Lst*)
{
Return this.Plus(Lst*)
}
ListMap(Map)
{
Lst_Map := List()
if Type(Map) !== "Map" && Type(Map) !== "Dict"
Return "Illegal Input"
else
{
For i, Value in Map
Lst_Map.Append([i, Value])
Return Lst_Map
}
}
Max()
{
Return Max(this*)
}
Min()
{
Return Min(this*)
}
Multiple(Number)
{
Lst := this.Clone()
Loop Number - 1
{
For i in Lst
{
Try
{
this.Append(i.Clone())
Continue
}
Catch
Error := 1
this.Append(i)
}
}
}
Next()
{
if this.NextIdx <= 0
this.NextIdx := this.Length
Res := this[this.Length - this.NextIdx]
this.NextIdx--
Return Res
}
Plus(Lst*)
{
Loop Lst.Length
{
if Type(Lst[A_Index]) !== "Array" && Type(Lst[A_Index]) !== "List"
this.Append(Lst[A_Index])
else
{
For i in Lst[A_Index]
this.Append(i)
}
}
}
Pop(Index := -1)
{
if Index == -1 || Index >= this.Length
Return this.RemoveAt(-1)
else
Return this.RemoveAt(this.Init(Index))
}
Remove(Object*)
{
Loop Object.Length
{
Index := this.Index(Object[A_Index])
if Index != -1
this.Pop(Index)
}
}
Reverse()
{
Loop this.Length // 2
Swap(A_Index - 1, this.Length - A_Index, this)
}
SetMethod(Index, Value)
{
Try
Index := Integer(Index)
if Type(Index) == "Integer"
Super[this.Init(Index)] := Value
else if InStr(Index, ":")
{
Lst_Index := StrSplit(Index, ":")
if !Trim(Lst_Index[1])
Lst_Index[1] := 0
if !Trim(Lst_Index[2])
Lst_Index[2] := this.Length
For i in Range(Trim(Lst_Index[1]), Trim(Lst_Index[2]))
Super[this.Init(i)] := Value
}
}
SortMap(Map)
{
if Type(Map) !== "Map"
Return "Illegal Input"
Lst_Map := this.ListMap(Map)
For i in Range(0, Lst_Map.Length)
{
For j in Range(0, Lst_Map.Length)
{
if Lst_Map[i][1] > Lst_Map[j][1]
Swap(i, j, Lst_Map)
}
}
Return Lst_Map
}
Title()
{
Loop this.Length
if Type(this[A_Index - 1]) == "String"
this[A_Index - 1] := StrTitle(this[A_Index - 1])
}
}
Class Random
{
Static Choice(Number*)
{
Lst_Number := Array()
Loop Number.Length
{
if Type(Number[A_Index]) == "Array"
{
index := A_Index
Loop Number[index].Length
Lst_Number.Push(Number[index][A_Index])
}
else
Lst_Number.Push(Number[A_Index])
}
Return Lst_Number[this.Random(1, Lst_Number.Length)]
}
Static Random(A := 0, B := 1)
{
this.index := 624
MT := List(0)
MT.multiple(this.index)
inter(t)
{
Res := 0xFFFFFFFF & t
return Res
}
twister()
{
for i in range(0, 624)
{
y := inter((MT[i] & 0x80000000) + (MT[Mod((i + 1), 624)] & 0x7fffffff))
MT[i] := MT[Mod((i + 397), 624)] ^ y >> 1
if Mod(y, 2) != 0
MT[i] := MT[i] ^ 0x9908b0df
}
this.index := 0
}
exnum()
{
if this.index >= 624
twister()
y := MT[this.index]
y := y ^ y >> 11
y := y ^ y << 7 & 2636928640
y := y ^ y << 15 & 4022730752
y := y ^ y >> 18
this.index++
return inter(y)
}
mainset(seed)
{
MT[0] := seed
for i in range(1, 624)
MT[i] := inter(Integer(1812433253 * (MT[i - 1] ^ MT[i - 1] >> 30) + i))
return exnum()
}
if Type(A) == "Integer" && Type(B) == "Integer" && !(A == 0 && B == 1)
{
so := mainset(Time.Time()) / (2 ** 32 - 1)
Rd := A + Integer((B - A) * so)
}
else
{
so := mainset(Time.Time() + Random(0, 100)) / (2 ** 32 - 1)
Rd := A + (B - A) * so
}
Return Rd
}
}
Class Time
{
Static Time(Zone := 8)
{
Diff := Zone * 60 * 60
Return DateDiff(A_Now, 19700101000000, "Seconds") - Diff
}
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。