Showing
11 changed files
with
132 additions
and
56 deletions
.idea/.idea.Bird-TDD/.idea/contentModel.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project version="4"> | ||
| 3 | + <component name="ContentModelStore"> | ||
| 4 | + <e p="$PROJECT_DIR$" t="IncludeRecursive"> | ||
| 5 | + <e p="Assembly-CSharp-Editor-firstpass.csproj" t="IncludeRecursive" /> | ||
| 6 | + <e p="Assembly-CSharp.csproj" t="IncludeRecursive" /> | ||
| 7 | + <e p="Assets" t="Include"> | ||
| 8 | + <e p="Plugins" t="Include"> | ||
| 9 | + <e p="Editor" t="Include"> | ||
| 10 | + <e p="JetBrains" t="Include"> | ||
| 11 | + <e p="Unity3DRider.cs" t="Include" /> | ||
| 12 | + </e> | ||
| 13 | + </e> | ||
| 14 | + </e> | ||
| 15 | + <e p="Scripts" t="Include"> | ||
| 16 | + <e p="Bird.cs" t="Include" /> | ||
| 17 | + <e p="Column.cs" t="Include" /> | ||
| 18 | + <e p="ColumnPool.cs" t="Include" /> | ||
| 19 | + <e p="GameControl.cs" t="Include" /> | ||
| 20 | + <e p="IUnityInput.cs" t="Include" /> | ||
| 21 | + <e p="RepeatingBackground.cs" t="Include" /> | ||
| 22 | + <e p="ScrollingObject.cs" t="Include" /> | ||
| 23 | + </e> | ||
| 24 | + <e p="Test Scripts" t="Include"> | ||
| 25 | + <e p="BirdTest.cs" t="Include" /> | ||
| 26 | + </e> | ||
| 27 | + </e> | ||
| 28 | + <e p="Bird-TDD.sln" t="IncludeFlat" /> | ||
| 29 | + <e p="Library" t="ExcludeRecursive" /> | ||
| 30 | + <e p="obj" t="ExcludeRecursive" /> | ||
| 31 | + <e p="packages" t="ExcludeRecursive" /> | ||
| 32 | + <e p="Temp" t="ExcludeRecursive"> | ||
| 33 | + <e p="bin" t="ExcludeRecursive" /> | ||
| 34 | + </e> | ||
| 35 | + </e> | ||
| 36 | + <e p="$USER_HOME$/Library/Caches/Rider2017.3/resharper-host/local/Transient/ReSharperHost/v11/SolutionCaches/_Bird-TDD.-1979534893.00" t="ExcludeRecursive" /> | ||
| 37 | + </component> | ||
| 38 | +</project> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
.idea/.idea.Bird-TDD/.idea/indexLayout.xml
0 → 100644
.idea/.idea.Bird-TDD/.idea/modules.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project version="4"> | ||
| 3 | + <component name="ProjectModuleManager"> | ||
| 4 | + <modules> | ||
| 5 | + <module fileurl="file://$PROJECT_DIR$/.idea/.idea.Bird-TDD/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.Bird-TDD/riderModule.iml" /> | ||
| 6 | + </modules> | ||
| 7 | + </component> | ||
| 8 | +</project> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
.idea/.idea.Bird-TDD/.idea/vcs.xml
0 → 100644
.idea/.idea.Bird-TDD/.idea/workspace.xml
0 → 100644
This diff is collapsed. Click to expand it.
.idea/.idea.Bird-TDD/riderModule.iml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<module type="RIDER_MODULE" version="4"> | ||
| 3 | + <component name="NewModuleRootManager"> | ||
| 4 | + <content url="file://$MODULE_DIR$/../.." /> | ||
| 5 | + <orderEntry type="sourceFolder" forTests="false" /> | ||
| 6 | + </component> | ||
| 7 | +</module> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -56,19 +56,19 @@ public class Bird : MonoBehaviour | ... | @@ -56,19 +56,19 @@ public class Bird : MonoBehaviour |
| 56 | anim.SetTrigger("Die"); | 56 | anim.SetTrigger("Die"); |
| 57 | //...and tell the game control about it. | 57 | //...and tell the game control about it. |
| 58 | 58 | ||
| 59 | - if (GameControl.instance != null) | 59 | + |
| 60 | - { | 60 | + GameControl.Instance.BirdDied(); |
| 61 | - GameControl.instance.BirdDied(); | 61 | + |
| 62 | - } | ||
| 63 | } | 62 | } |
| 64 | 63 | ||
| 65 | void OnTriggerEnter2D(Collider2D other) | 64 | void OnTriggerEnter2D(Collider2D other) |
| 66 | { | 65 | { |
| 67 | - | 66 | + if (other.CompareTag("Column")) |
| 67 | + { | ||
| 68 | //If the bird hits the trigger collider in between the columns then | 68 | //If the bird hits the trigger collider in between the columns then |
| 69 | //tell the game control that the bird scored. | 69 | //tell the game control that the bird scored. |
| 70 | - GameControl.instance.BirdScored(); | 70 | + GameControl.Instance.BirdScored(); |
| 71 | - | 71 | + } |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | public void Jump() | 74 | public void Jump() | ... | ... |
| ... | @@ -38,7 +38,7 @@ public class ColumnPool : MonoBehaviour | ... | @@ -38,7 +38,7 @@ public class ColumnPool : MonoBehaviour |
| 38 | { | 38 | { |
| 39 | timeSinceLastSpawned += Time.deltaTime; | 39 | timeSinceLastSpawned += Time.deltaTime; |
| 40 | 40 | ||
| 41 | - if (GameControl.instance.gameOver == false && timeSinceLastSpawned >= spawnRate) | 41 | + if (GameControl.Instance.gameOver == false && timeSinceLastSpawned >= spawnRate) |
| 42 | { | 42 | { |
| 43 | timeSinceLastSpawned = 0f; | 43 | timeSinceLastSpawned = 0f; |
| 44 | 44 | ... | ... |
| ... | @@ -6,7 +6,7 @@ using UnityEngine.SceneManagement; | ... | @@ -6,7 +6,7 @@ using UnityEngine.SceneManagement; |
| 6 | 6 | ||
| 7 | public class GameControl : MonoBehaviour | 7 | public class GameControl : MonoBehaviour |
| 8 | { | 8 | { |
| 9 | - public static GameControl instance; //A reference to our game control script so we can access it statically. | 9 | + private static GameControl instance; //A reference to our game control script so we can access it statically. |
| 10 | public Text scoreText; //A reference to the UI text component that displays the player's score. | 10 | public Text scoreText; //A reference to the UI text component that displays the player's score. |
| 11 | public GameObject gameOvertext; //A reference to the object that displays the text which appears when the player dies. | 11 | public GameObject gameOvertext; //A reference to the object that displays the text which appears when the player dies. |
| 12 | 12 | ||
| ... | @@ -15,16 +15,26 @@ public class GameControl : MonoBehaviour | ... | @@ -15,16 +15,26 @@ public class GameControl : MonoBehaviour |
| 15 | public float scrollSpeed = -1.5f; | 15 | public float scrollSpeed = -1.5f; |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | - void Awake() | 18 | + public static GameControl Instance |
| 19 | { | 19 | { |
| 20 | - //If we don't currently have a game control... | 20 | + get |
| 21 | + { | ||
| 22 | + if (instance != null) | ||
| 23 | + { | ||
| 24 | + return instance; | ||
| 25 | + } | ||
| 26 | + else | ||
| 27 | + { | ||
| 28 | + instance = FindObjectOfType<GameControl>(); | ||
| 29 | + | ||
| 21 | if (instance == null) | 30 | if (instance == null) |
| 22 | - //...set this one to be it... | 31 | + { |
| 23 | - instance = this; | 32 | + instance = new GameObject().AddComponent<GameControl>(); |
| 24 | - //...otherwise... | 33 | + } |
| 25 | - else if(instance != this) | 34 | + } |
| 26 | - //...destroy this one because it is a duplicate. | 35 | + |
| 27 | - Destroy (gameObject); | 36 | + return instance; |
| 37 | + } | ||
| 28 | } | 38 | } |
| 29 | 39 | ||
| 30 | void Update() | 40 | void Update() |
| ... | @@ -54,9 +64,20 @@ public class GameControl : MonoBehaviour | ... | @@ -54,9 +64,20 @@ public class GameControl : MonoBehaviour |
| 54 | 64 | ||
| 55 | public void BirdDied() | 65 | public void BirdDied() |
| 56 | { | 66 | { |
| 67 | + if (gameOvertext != null) | ||
| 68 | + { | ||
| 57 | //Activate the game over text. | 69 | //Activate the game over text. |
| 58 | - gameOvertext.SetActive (true); | 70 | + gameOvertext.SetActive(true); |
| 71 | + } | ||
| 72 | + | ||
| 59 | //Set the game to be over. | 73 | //Set the game to be over. |
| 60 | gameOver = true; | 74 | gameOver = true; |
| 61 | } | 75 | } |
| 76 | + | ||
| 77 | + public void Reset() | ||
| 78 | + { | ||
| 79 | + gameOver = false; | ||
| 80 | + score = 0; | ||
| 81 | + } | ||
| 82 | + | ||
| 62 | } | 83 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -17,7 +17,7 @@ public class ScrollingObject : MonoBehaviour | ... | @@ -17,7 +17,7 @@ public class ScrollingObject : MonoBehaviour |
| 17 | 17 | ||
| 18 | rb2d.bodyType = RigidbodyType2D.Kinematic; | 18 | rb2d.bodyType = RigidbodyType2D.Kinematic; |
| 19 | //Start the object moving. | 19 | //Start the object moving. |
| 20 | - rb2d.velocity = new Vector2 (GameControl.instance.scrollSpeed, 0); | 20 | + rb2d.velocity = new Vector2 (GameControl.Instance.scrollSpeed, 0); |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | } | 23 | } |
| ... | @@ -25,13 +25,13 @@ public class ScrollingObject : MonoBehaviour | ... | @@ -25,13 +25,13 @@ public class ScrollingObject : MonoBehaviour |
| 25 | void Update() | 25 | void Update() |
| 26 | { | 26 | { |
| 27 | // If the game is over, stop scrolling. | 27 | // If the game is over, stop scrolling. |
| 28 | - if(GameControl.instance.gameOver == true) | 28 | + if(GameControl.Instance.gameOver == true) |
| 29 | { | 29 | { |
| 30 | rb2d.velocity = Vector2.zero; | 30 | rb2d.velocity = Vector2.zero; |
| 31 | } | 31 | } |
| 32 | else | 32 | else |
| 33 | { | 33 | { |
| 34 | - rb2d.velocity = new Vector2 (GameControl.instance.scrollSpeed, 0); | 34 | + rb2d.velocity = new Vector2 (GameControl.Instance.scrollSpeed, 0); |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -29,6 +29,8 @@ namespace FlappyBird.PlayModeTest | ... | @@ -29,6 +29,8 @@ namespace FlappyBird.PlayModeTest |
| 29 | bird = instance.AddComponent<Bird>(); | 29 | bird = instance.AddComponent<Bird>(); |
| 30 | 30 | ||
| 31 | bird.upForce = 500f; | 31 | bird.upForce = 500f; |
| 32 | + | ||
| 33 | + GameControl.Instance.Reset(); | ||
| 32 | } | 34 | } |
| 33 | 35 | ||
| 34 | [UnityTest] | 36 | [UnityTest] |
| ... | @@ -58,6 +60,7 @@ namespace FlappyBird.PlayModeTest | ... | @@ -58,6 +60,7 @@ namespace FlappyBird.PlayModeTest |
| 58 | 60 | ||
| 59 | } | 61 | } |
| 60 | 62 | ||
| 63 | + | ||
| 61 | [UnityTest] | 64 | [UnityTest] |
| 62 | public IEnumerator _Down_Fire1_Button_to_Bird_Jump_Up() | 65 | public IEnumerator _Down_Fire1_Button_to_Bird_Jump_Up() |
| 63 | { | 66 | { |
| ... | @@ -77,12 +80,9 @@ namespace FlappyBird.PlayModeTest | ... | @@ -77,12 +80,9 @@ namespace FlappyBird.PlayModeTest |
| 77 | 80 | ||
| 78 | 81 | ||
| 79 | [UnityTest] | 82 | [UnityTest] |
| 80 | - public IEnumerator _Down_Fire1_Button_to_Bird_Speed_Not_Negative() | 83 | + public IEnumerator _Bird_Jump_to_Bird_Speed_Not_Negative() |
| 81 | { | 84 | { |
| 82 | - var unityInput = Substitute.For<IUnityInputService>(); | 85 | + bird.Jump(); |
| 83 | - unityInput.GetButtonDown("Fire1").Returns(true); | ||
| 84 | - | ||
| 85 | - bird.UnityInput = unityInput; | ||
| 86 | 86 | ||
| 87 | yield return null; | 87 | yield return null; |
| 88 | 88 | ||
| ... | @@ -93,14 +93,13 @@ namespace FlappyBird.PlayModeTest | ... | @@ -93,14 +93,13 @@ namespace FlappyBird.PlayModeTest |
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | [UnityTest] | 95 | [UnityTest] |
| 96 | - public IEnumerator _Down_Fire1_After_2sec_to_Bird_Y_Speed_Not_Negative() | 96 | + public IEnumerator _Jump_After_2sec_to_Bird_Y_Speed_Not_Negative() |
| 97 | { | 97 | { |
| 98 | 98 | ||
| 99 | 99 | ||
| 100 | yield return new WaitForSeconds(2.0f); | 100 | yield return new WaitForSeconds(2.0f); |
| 101 | - var unityInput = Substitute.For<IUnityInputService>(); | 101 | + |
| 102 | - unityInput.GetButtonDown("Fire1").Returns(true); | 102 | + bird.Jump(); |
| 103 | - bird.UnityInput = unityInput; | ||
| 104 | 103 | ||
| 105 | yield return null; | 104 | yield return null; |
| 106 | 105 | ||
| ... | @@ -113,11 +112,8 @@ namespace FlappyBird.PlayModeTest | ... | @@ -113,11 +112,8 @@ namespace FlappyBird.PlayModeTest |
| 113 | [UnityTest] | 112 | [UnityTest] |
| 114 | public IEnumerator _Bird_Trigger_Collide_With_Column_Tag_to_Add_Score() | 113 | public IEnumerator _Bird_Trigger_Collide_With_Column_Tag_to_Add_Score() |
| 115 | { | 114 | { |
| 116 | - var gameContorl = new GameObject().AddComponent<GameControl>(); | ||
| 117 | - | ||
| 118 | - yield return null; | ||
| 119 | 115 | ||
| 120 | - var score = gameContorl.score; | 116 | + var score = GameControl.Instance.score; |
| 121 | 117 | ||
| 122 | var collider = new GameObject().AddComponent<BoxCollider2D>(); | 118 | var collider = new GameObject().AddComponent<BoxCollider2D>(); |
| 123 | collider.tag = "Column"; | 119 | collider.tag = "Column"; |
| ... | @@ -126,52 +122,47 @@ namespace FlappyBird.PlayModeTest | ... | @@ -126,52 +122,47 @@ namespace FlappyBird.PlayModeTest |
| 126 | 122 | ||
| 127 | yield return null; | 123 | yield return null; |
| 128 | 124 | ||
| 129 | - Assert.Greater(gameContorl.score,score); | 125 | + Assert.AreEqual(score + 1,GameControl.Instance.score); |
| 130 | } | 126 | } |
| 131 | 127 | ||
| 132 | [UnityTest] | 128 | [UnityTest] |
| 133 | public IEnumerator _Bird_Trigger_Collide_With_Not_Column_Tag_to_Not_Change_Score() | 129 | public IEnumerator _Bird_Trigger_Collide_With_Not_Column_Tag_to_Not_Change_Score() |
| 134 | { | 130 | { |
| 135 | - var gameContorl = new GameObject().AddComponent<GameControl>(); | 131 | + var score = GameControl.Instance.score; |
| 136 | 132 | ||
| 137 | - yield return null; | 133 | + var collider = new GameObject().AddComponent<BoxCollider2D>(); |
| 138 | 134 | ||
| 139 | - var score = gameContorl.score; | 135 | + yield return null; |
| 140 | 136 | ||
| 141 | - bird.SendMessage("OnTriggerEnter2D",new Collider2D()); | 137 | + bird.SendMessage("OnTriggerEnter2D",collider); |
| 142 | 138 | ||
| 143 | yield return null; | 139 | yield return null; |
| 144 | 140 | ||
| 145 | - Assert.AreEqual(gameContorl.score,score); | 141 | + Assert.AreEqual(GameControl.Instance.score,score); |
| 146 | } | 142 | } |
| 147 | 143 | ||
| 148 | } | 144 | } |
| 149 | 145 | ||
| 150 | public class GameControlTest | 146 | public class GameControlTest |
| 151 | { | 147 | { |
| 152 | - private GameControl gameControl; | ||
| 153 | 148 | ||
| 154 | [SetUp] | 149 | [SetUp] |
| 155 | public void BeforeEveryTest() | 150 | public void BeforeEveryTest() |
| 156 | { | 151 | { |
| 157 | - if (GameControl.instance != null) | 152 | + GameControl.Instance.scoreText = new GameObject("Score Text").AddComponent<Text>(); |
| 158 | - { | 153 | + GameControl.Instance.gameOvertext = new GameObject("Game Over Text"); |
| 159 | - GameObject.Destroy(GameControl.instance.gameObject); | 154 | + GameControl.Instance.Reset(); |
| 160 | - } | ||
| 161 | - | ||
| 162 | - gameControl = new GameObject("GameControl").AddComponent<GameControl>(); | ||
| 163 | - | ||
| 164 | - gameControl.scoreText = new GameObject().AddComponent<Text>(); | ||
| 165 | - gameControl.gameOvertext = new GameObject(); | ||
| 166 | 155 | ||
| 167 | } | 156 | } |
| 168 | 157 | ||
| 158 | + | ||
| 169 | [Test] | 159 | [Test] |
| 170 | public void _Bird_Scored_then_Displayd_Text_Contain_Updated_Score() | 160 | public void _Bird_Scored_then_Displayd_Text_Contain_Updated_Score() |
| 171 | { | 161 | { |
| 172 | - gameControl.BirdScored(); | ||
| 173 | 162 | ||
| 174 | - Assert.IsTrue(gameControl.scoreText.text.Contains(gameControl.score.ToString())); | 163 | + GameControl.Instance.BirdScored(); |
| 164 | + | ||
| 165 | + Assert.IsTrue(GameControl.Instance.scoreText.text.Contains(GameControl.Instance.score.ToString())); | ||
| 175 | } | 166 | } |
| 176 | 167 | ||
| 177 | [UnityTest] | 168 | [UnityTest] |
| ... | @@ -179,7 +170,7 @@ namespace FlappyBird.PlayModeTest | ... | @@ -179,7 +170,7 @@ namespace FlappyBird.PlayModeTest |
| 179 | { | 170 | { |
| 180 | var scrollingObject = new GameObject().AddComponent<ScrollingObject>(); | 171 | var scrollingObject = new GameObject().AddComponent<ScrollingObject>(); |
| 181 | 172 | ||
| 182 | - gameControl.scrollSpeed = 0f; | 173 | + GameControl.Instance.scrollSpeed = 0f; |
| 183 | 174 | ||
| 184 | yield return null; | 175 | yield return null; |
| 185 | yield return new WaitForFixedUpdate(); | 176 | yield return new WaitForFixedUpdate(); |
| ... | @@ -192,15 +183,13 @@ namespace FlappyBird.PlayModeTest | ... | @@ -192,15 +183,13 @@ namespace FlappyBird.PlayModeTest |
| 192 | { | 183 | { |
| 193 | var scrollingObject = new GameObject().AddComponent<ScrollingObject>(); | 184 | var scrollingObject = new GameObject().AddComponent<ScrollingObject>(); |
| 194 | 185 | ||
| 195 | - gameControl.gameOver = true; | 186 | + GameControl.Instance.gameOver = true; |
| 196 | 187 | ||
| 197 | yield return null; | 188 | yield return null; |
| 198 | yield return new WaitForFixedUpdate(); | 189 | yield return new WaitForFixedUpdate(); |
| 199 | 190 | ||
| 200 | Assert.AreEqual(Vector2.zero, scrollingObject.GetComponent<Rigidbody2D>().velocity); | 191 | Assert.AreEqual(Vector2.zero, scrollingObject.GetComponent<Rigidbody2D>().velocity); |
| 201 | } | 192 | } |
| 202 | - | ||
| 203 | - | ||
| 204 | } | 193 | } |
| 205 | 194 | ||
| 206 | 195 | ... | ... |
-
Please register or login to post a comment