# Win when all enemies are removed

**URL:** <https://forum.makecode.com/t/win-when-all-enemies-are-removed/16252>\
**Category:** Help\
**Created:** [November 9, 2022, 6:09pm UTC](https://forum.makecode.com/t/win-when-all-enemies-are-removed/16252 "2022-11-09T18:09:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimRHS](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@TimRHS](https://forum.makecode.com/u/TimRHS)\
**Post date:** [November 9, 2022, 6:09pm UTC](https://forum.makecode.com/t/win-when-all-enemies-are-removed/16252/1 "2022-11-09T18:09:31Z")

</div>

Hello,

I am new to MakeCode and trying to figure out something I think should be simple. How can I end the game when all my enemies are destroyed. I tried a If/Then with Enemies = Zero, but it seems like you cannot compare that. I did see someone mention arrays, but I am not sure how to do that.

Any help would be appreciated. Just making a knock-off Pac Man for fun.

Thanks,

> **[TestPacGuy](https://arcade.makecode.com/S40668-03986-82489-08495)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![ignatio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/ignatio/32/7106_2.png) [@ignatio](https://forum.makecode.com/u/ignatio)\
**Post date:** [November 9, 2022, 10:41pm UTC](https://forum.makecode.com/t/win-when-all-enemies-are-removed/16252/2 "2022-11-09T22:41:07Z")

</div>

At game start make a variable called totalGhosts and set it to 3 (or whatever number of ghosts you have). In the block where you detect your pacman eating a ghost change totalGhosts by -1. In game update block do a logic statement If totalGhosts = 0 then Reset Game with Win condition.

> **[TestPacGuy with win condition](https://arcade.makecode.com/S02066-32479-36058-11699)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![personalnote](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/personalnote/32/31359_2.png) [@personalnote](https://forum.makecode.com/u/personalnote)\
**Post date:** [November 9, 2022, 10:43pm UTC](https://forum.makecode.com/t/win-when-all-enemies-are-removed/16252/3 "2022-11-09T22:43:55Z")

</div>

okay, so use a variable as a type of score count. If an enemy is destroyed, then the variable will +1. And so depending on the number of enemies in your game (we’ll say 10), then later you would say if the variable = 10, then you win.

---

<div class="post-metadata">

**Author:** ![TimRHS](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@TimRHS](https://forum.makecode.com/u/TimRHS)\
**Post date:** [November 10, 2022, 1:19am UTC](https://forum.makecode.com/t/win-when-all-enemies-are-removed/16252/4 "2022-11-10T01:19:36Z")

</div>

That work too! I would have thought of making my own variable instead of try to read the sprite types. Thank you, both!!

---

<div class="post-metadata">

**Author:** ![TimRHS](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@TimRHS](https://forum.makecode.com/u/TimRHS)\
**Post date:** [November 10, 2022, 1:19am UTC](https://forum.makecode.com/t/win-when-all-enemies-are-removed/16252/5 "2022-11-10T01:19:37Z")

</div>

Thank you!!! That makes complete sense!
