Tic Tac Toe帮助在X中放入0! [英] Tic Tac Toe help to put 0 in the X!!

查看:100
本文介绍了Tic Tac Toe帮助在X中放入0!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何将数组中的0放入tic tac toe.
我只能在输出中创建X,但不知道如何将0和X一起插入

谢谢



Anyone can tell me how to put in the 0 in the array to make the tic tac toe.
I can only create X in the output but no idea how to insert 0 and X together

Thanks



function drawgrid {
	#########################################
	#          update display               #
	#########################################
	write-host
	$line1 = "  "+$row1[0]+" | "+$row1[1]+" | "+$row1[2]
	$line1
	$dividerline = " ----------"
	$dividerline
	$line2 = "  "+$row2[0]+" | "+$row2[1]+" | "+$row2[2]
	$line2
	$dividerline
	$line3 = "  "+$row3[0]+" | "+$row3[1]+" | "+$row3[2]
	$line3
	write-host
}
#########################################
#        setup and instructions         #
#########################################
$gameover = 'false'
$row1= @("7","8","9")
$row2 = @("4","5","6")
$row3 = @("1","2","3")
write-host
write-host "tic-tac-toe"
write-host "Enter a number (1-9) to place an X in that square"
write-host "Press Q to give up, R to restart"
drawgrid
#########################################
#               game loop               #
#########################################
while ($gameover -ne 'true') {

	#########################################
	#          get user input               #
	#########################################
	$target = Read-Host "Enter the grid number: "
	if (($target -ge 1) -and ($target -le 9)) {
	
	
##### need to add checks for R and Q inputs
		

		########################################################
		#  check that the user input points to an empty square #
		########################################################
		switch ($target) 
		{ 
        1 { if($row3[0] -eq "1") { $row3[0] = "X" } }
        2 { if($row3[1] -eq "2") { $row3[1] = "X" } }
        3 { if($row3[2] -eq "3") { $row3[2] = "X" } }
        4 { if($row2[0] -eq "4") { $row2[0] = "X" } }
        5 { if($row2[1] -eq "5") { $row2[1] = "X" } }
        6 { if($row2[2] -eq "6") { $row2[2] = "X" } }
        7 { if($row1[0] -eq "7") { $row1[0] = "X" } }
        8 { if($row1[1] -eq "8") { $row1[1] = "X" } }
        9 { if($row1[2] -eq "9") { $row1[2] = "X" } }
		}
		###########################
		#     redraw the grid     #
		###########################
		
		drawgrid
	
		
	}
	
	if ($target -eq 'Q') {
		$gameover = 'true'
	}
	
	if ($target -eq 'R') {
		$row1= @("7","8","9")
		$row2 = @("4","5","6")
		$row3 = @("1","2","3")
		drawgrid
	}
}

推荐答案

line1 = " +
line1 = " "+


row1 [ 0 ] + " |" +
row1[0]+" | "+


row1 [" +
row1[1]+" | "+


这篇关于Tic Tac Toe帮助在X中放入0!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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