我现在面临着一个问题......我正在尝试制作一个淘气球并且穿越游戏,我正在努力决定用户是否已经猜到了网格之外...这是我的代码到目前为止,结果是代码崩溃,请你帮忙吗?
以下代码是我目前正在运行以获得此结果的代码。
<title>Drawing tools</title>
<style>
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: -34.397,
lng: 150.644
},
zoom: 8
});
var lineSymbol = {
path: 'M 0,-1 0,1',
strokeOpacity: 1,
scale: 2
};
var symbolMark = new google.maps.Marker({
// map: map,
position: {
lat: -34.35,
lng: 150.644
},
icon: lineSymbol
});
var polyline = new google.maps.Polyline({
map: map,
path: [{
lat: -34.397,
lng: 149
}, {
lat: -34.397,
lng: 150.644
}, {
lat: -34.8,
lng: 150.0
}, {
lat: -35.2,
lng: 151
}],
icons: [{
icon: lineSymbol,
offset: '0',
repeat: '10px'
}],
strokeOpacity: 0,
stokeWeight: 0
});
for (var i = 0; i < polyline.getPath().getLength(); i++) {
var marker = new google.maps.Marker({
map: map,
position: polyline.getPath().getAt(i),
icon: {
url: "https://maps.gstatic.com/intl/en_us/mapfiles/markers2/measle.png",
size: new google.maps.Size(7, 7),
anchor: new google.maps.Point(3.5, 3.5)
}
})
}
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.POLYLINE,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
google.maps.drawing.OverlayType.MARKER,
google.maps.drawing.OverlayType.CIRCLE,
google.maps.drawing.OverlayType.POLYGON,
google.maps.drawing.OverlayType.POLYLINE,
google.maps.drawing.OverlayType.RECTANGLE
]
},
markerOptions: {
icon: 'images/beachflag.png'
},
polylineOptions: {
strokeOpacity: 0,
strokeWeight: 3,
icons: [{
icon: lineSymbol,
offset: '0',
repeat: '10px'
}],
}
});
drawingManager.setMap(map);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?libraries=drawing&callback=initMap" async defer></script>
答案 0 :(得分:0)
如果数据输入正常,请尝试合并while
语句和break
即
while True:
Down_position = (int(input("How many places would you like to move down")))
step = Down_position
if (step + x <= grid_size) and (step + x >= 0):
x += step
break
else:
print ("Sorry, that isn't on the grid")
print_board(board)
以下是一些工作代码(仅使用Down)作为示例。
def print_grid():
print (0,top)
print ("-----------------------------------")
for i in range(len(grid)):
print (i,grid[i])
print ("-----------------------------------")
x = 0
y = 0
top =[0,1,2,3,4,5,6,7,8,9]
grid=[]
for i in range(10):
grid.append([0]*10)
grid_size = len(grid)-1
while True:
while True:
Down_position = (int(input("How many places would you like to move down ")))
step = Down_position
if (step + x <= grid_size) and (step + x >= 0):
grid[x][y] = 0
x += step
grid[x][y] = 1
print_grid()
break
else:
print("******************************")
print ("Sorry, that isn't on the grid")
print("******************************")
print_grid()