質問編集履歴
1
ソースコードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,1 +1,38 @@
|
|
1
|
-
swift playgroundsで学んているものです。次のようなプログラムを書いてみたのですが、キャラクターが前に歩きません。どうすればいいか教えてください
|
1
|
+
swift playgroundsで学んているものです。次のようなプログラムを書いてみたのですが、キャラクターが前に歩きません。どうすればいいか教えてください
|
2
|
+
|
3
|
+
画像だと見切れていたのでソースコードです
|
4
|
+
|
5
|
+
let totalGems = 5
|
6
|
+
|
7
|
+
var getGems = 0
|
8
|
+
|
9
|
+
world.place(Gem(), atColumn: 3, row: 1)
|
10
|
+
world.place(Gem(), atColumn: 5, row: 1)
|
11
|
+
world.place(Gem(), atColumn: 5, row: 3)
|
12
|
+
world.place(Gem(), atColumn: 3, row: 3)
|
13
|
+
|
14
|
+
world.place(Gem(), atColumn: 6, row: 6)
|
15
|
+
|
16
|
+
world.place(Portal(color:#colorLiteral(red: 0.4653213024, green: 0.7332682014, blue: 0.2536376119, alpha: 1.0)), atStartColumn: 1, startRow: 3, atEndColumn: 7, endRow: 6)
|
17
|
+
|
18
|
+
let character = Character()
|
19
|
+
world.place(Character(), facing:east, atColumn: 2, row: 1)
|
20
|
+
|
21
|
+
while getGems<totalGems{
|
22
|
+
|
23
|
+
while character.isBlocked && character.isBlockedRight{
|
24
|
+
character.turnLeft()
|
25
|
+
}
|
26
|
+
while character.isBlocked && character.isBlockedLeft{
|
27
|
+
character.isBlockedRight
|
28
|
+
}
|
29
|
+
while character.isOnGem{
|
30
|
+
character.collectGem()
|
31
|
+
getGems += 1
|
32
|
+
}
|
33
|
+
while character.isOnClosedSwitch{
|
34
|
+
character.toggleSwitch()
|
35
|
+
}
|
36
|
+
|
37
|
+
character.moveForward()
|
38
|
+
}
|