powershell - Powershell GUI 猜数字游戏
问题描述
所以基本上,我需要制作一个数字猜谜游戏,但需要一个 gui。我不知道如何使用户在文本框中编写的答案成为一个变量,以及如何将该变量与我的其余脚本集成。
这是我到目前为止所拥有的:
图形用户界面:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
#GUI
$gamefrm = New-Object system.Windows.Forms.Form
$gamefrm.ClientSize = New-Object System.Drawing.Point(573,376)
$gamefrm.text = "Deviner le nombre"
$gamefrm.TopMost = $true
$gamefrm.BackColor = [System.Drawing.ColorTranslator]::FromHtml("#bd10e0")
$ruletxt = New-Object system.Windows.Forms.TextBox
$ruletxt.multiline = $false
$ruletxt.width = 262
$ruletxt.height = 20
$ruletxt.location = New-Object System.Drawing.Point(150,39)
$ruletxt.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$ruletxt.Text = "Deviner le nombre!"
$ruletxt.AutoSize = $true
$ruletxt.ReadOnly = $true
$intxt = New-Object system.Windows.Forms.TextBox
$intxt.multiline = $false
$intxt.width = 263
$intxt.height = 20
$intxt.location = New-Object System.Drawing.Point(149,110)
$intxt.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$intxt.Text = "1"
$intxt.AutoSize = $true
$intxt.ReadOnly = $true
$outtxt = New-Object system.Windows.Forms.TextBox
$outtxt.multiline = $false
$outtxt.width = 263
$outtxt.height = 20
$outtxt.location = New-Object System.Drawing.Point(149,190)
$outtxt.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$outtxt.text = ""
$outtxt.AutoSize = $true
$gamefrm.controls.AddRange(@($ruletxt,$intxt,$outtxt,$imagepb,$Button1,))
$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "button"
$Button1.width = 60
$Button1.height = 30
$Button1.location = New-Object System.Drawing.Point(86,89)
$Button1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
逻辑代码:
#Write your logic code here
[void]$gamefrm.ShowDialog()
[int]$nombre = Get-Random -Minimum 1 -Maximum 101
$essai = 0
$output = $intxt.Text
$input = $outtxt.Text
while ($input -ne $nombre){
if ($input -gt $nombre) {$output = " trop haut "}
if ($input -lt $nombre) {$intxt.Text = " trop bas "}
if ( ( $input -gt 100 ) -or ($input -lt 0 ) ) {$intxt.Text = " entre 1 et 100! "}
$essai++
} $intxt.Text = "Correct! Nombre d'essai: $essai"
如果有人可以帮助请告诉我谢谢。
解决方案
推荐阅读
- http - 为什么 IE 使用不同的用户代理字符串重复请求,但没有会话 cookie?
- sql-server - 计算表名在存储过程中出现的次数
- flutter - Flutter:SliverPersistentHeader 在滚动时重建自身
- c# - 正则表达式在电子邮件正文中查找有效 URL,而不管换行符是否分割它,并且它需要包含“?” 特点
- node.js - 错误:forEach 未定义
- c# - 按下按钮时 Unity 再次运行非循环动画
- node.js - 将 Node.js BOT 连接到 MS Azure SQL 数据库
- android - 通过意图在活动之间传递变量会引发 NullPointerException
- ios - Swift iOS -AshleyMills Reachability 每隔几秒就会打开和关闭 wifi
- asp.net - 没有“访问控制允许来源”的请求 - Angular 4 / ASP.net