質問編集履歴
1
ソースコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1 +1,75 @@
|
|
1
1
|
swift playgroundsで学んているものです。次のようなプログラムを書いてみたのですが、キャラクターが前に歩きません。どうすればいいか教えてください
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
画像だと見切れていたのでソースコードです
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
let totalGems = 5
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
var getGems = 0
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
world.place(Gem(), atColumn: 3, row: 1)
|
18
|
+
|
19
|
+
world.place(Gem(), atColumn: 5, row: 1)
|
20
|
+
|
21
|
+
world.place(Gem(), atColumn: 5, row: 3)
|
22
|
+
|
23
|
+
world.place(Gem(), atColumn: 3, row: 3)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
world.place(Gem(), atColumn: 6, row: 6)
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
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)
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
let character = Character()
|
36
|
+
|
37
|
+
world.place(Character(), facing:east, atColumn: 2, row: 1)
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
while getGems<totalGems{
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
while character.isBlocked && character.isBlockedRight{
|
46
|
+
|
47
|
+
character.turnLeft()
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
while character.isBlocked && character.isBlockedLeft{
|
52
|
+
|
53
|
+
character.isBlockedRight
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
while character.isOnGem{
|
58
|
+
|
59
|
+
character.collectGem()
|
60
|
+
|
61
|
+
getGems += 1
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
while character.isOnClosedSwitch{
|
66
|
+
|
67
|
+
character.toggleSwitch()
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
character.moveForward()
|
74
|
+
|
75
|
+
}
|