Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell GUI数字猜谜游戏_Powershell_User Interface - Fatal编程技术网

Powershell GUI数字猜谜游戏

Powershell GUI数字猜谜游戏,powershell,user-interface,Powershell,User Interface,所以,基本上,我需要做一个数字猜测游戏,但有一个gui。我不知道如何使用户在文本框中编写的答案成为变量,以及如何使用该变量将其与我的其余脚本集成 以下是我迄今为止的情况: 图形用户界面: 逻辑代码: #Write your logic code here [void]$gamefrm.ShowDialog() [int]$nombre = Get-Random -Minimum 1 -Maximum 101 $essai = 0 $output = $intxt.Text $inp

所以,基本上,我需要做一个数字猜测游戏,但有一个gui。我不知道如何使用户在文本框中编写的答案成为变量,以及如何使用该变量将其与我的其余脚本集成

以下是我迄今为止的情况:

图形用户界面:

逻辑代码:


#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"

如果有人能提供帮助,请告诉我,谢谢。

您需要创建一个函数,然后将函数的开头添加到表单中的事件中。我建议您首先了解如何在powershell控制台中进行猜谜游戏,那么将其绑定到GUI中就更容易了。@ArcSet我应该使用什么样的函数?@DougMaurer我这样做了,它在控制台中工作得很好就像你在控制台中所做的那样,将其转化为一个函数,将其附加到GUI中。函数是函数,无论是基本函数还是高级函数。无论何时出于何种原因,您都可以使用这两种方法。如果您在VSCode、CRTL+Alt+J中,请查看ISE中使用CRTL+J的示例。如果您在其他系统中执行此操作,请参阅PowerShell函数的帮助文件。

#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"