Else Died

Open Source Unity Game Project, Code without Else

A Full Plattformer Styled Game without using Else, Switch and Foreach. Code Style and Structure

In the Entire Source Code of Else Died, is not a single "Else" Statement used.

The Code of Else Died is Open Source and available on Git Hub.

This project is intended to demonstrate a coding style that does not use the else statement. There is also not a single foreach and switch statement. There are only a few situations where it is really advantageous to use the else statement and require something else in the same function. The sense of the single responsibility principle in data and object-oriented programming with C# is otherwise lost.

What has the Code to Offer.

While it is easy to write some code, it is often overshadowed by the code becoming more and more bloated and noisy.  There are simple ways to prevent this from happening in the first place, such as not using an else statement.

Game Information:

Else Died is a repetitive platform shooter. Enemies spawn in waves and try to get to the end point. Prevent them from doing so by shooting at them or running through them. Keep your energy for shooting, collect money and upgrade your weapon and achieve higher scores!

Disclaimer:

Leave a Comment, Suggestions, Feedback

Game Jam Version was made during 6 Days each 10 to 14 Hours Work Time, 2634 Readable Line of Codes and 795 Executable Lines of Code.
No Else Statement, No Switch, No Foreach

I Started 4 Days after the Game Jam started, i canceled also some Mechanics which i originally planned, Placing Traps and make Direction Changer for the Enemies. Since the Time was so limited in the last 48 Hours I put a lot Gameplay together and polished the overall Game.

In the follow Up Days i will rework some Parts of the Code and then Review the Code here, Show the Changes and explain Decisions.

The Code has already Comments to Explore and Information around  the Mechanics.

Follow us un Reddit, Join our Discord  or Leave a Comment for Suggestions, Feedback and Questions.

Under Construction

The following Content is not final and might Change soon.

Using Simulation Class from 2D Platformer Microgame as Core

Change Simulation.cs

				
					    /// <summary>
    /// Tick the simulation. Returns the count of remaining events.
    /// If remaining events is zero, the simulation is finished unless events are
    /// injected from an external system via a Schedule() call.
    /// </summary>
    /// <returns></returns>
				
			

Questions about the Class

The Unitys class checks if ev.tick is greater than tick, and then just does nothing. This whole section is just death code. I would understand if we did an action in it, but since we don’t, we don’t need to. If we want to do it, we can recreate it.

I also question the try-and-catch blog. The original comment from the Unity developer says that this should never actually happen. So why are we catching something that should never happen? I’ll leave it at that, since as an excellent developer I have absolutely no idea what this even means! According to the other developer, it has no meaning!

So if we change the way we ask for the check mark, we can remove the Else statement and have the same result with less code, less noise and “a single responsibility

Change HeapQueue.cs

				
					    //if there are more than 1 items, returned item will be first in tree.
    //then, add last item to front of tree, shrink the list
    //and find correct index in tree for first item.
				
			
				
					    public T Pop() //Unity Version
    {
        T item;
        var last = items[items.Count - 1];
        items.RemoveAt(items.Count - 1);
        if (items.Count > 0)
        {
            item = items[0];
            items[0] = last;
            SiftUp();
        }
        else
        {
            item = last;
        }
        return item;
    }
				
			
				
					    public T Pop() //Stusse Games Version
    {
        var last = items[items.Count - 1];
        items.RemoveAt(items.Count - 1);

        if (items.Count > 0)
        {
            T item = items[0];
            items[0] = last;
            SiftUp();
            return item;
        }

        return last; 
    }
				
			

Not so significant but prettier.

I am not sure how to explain this change. It’s simply to remove the others and reduce the noise in this small function.

Simulation System is Awesome

Unity’s Simulation Core is an incredibly powerful tool that lets you create data-driven games quickly and easily.

Leave a Reply

Your email address will not be published.