Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Singleton #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Singleton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class TankBase<T> where T : TankBase<T>
{
private static T instance;

// Protected constructor to prevent instantiation from other classes.
protected TankBase()
{
}
public static T GetInstance()
{
if (instance == null)
{
instance = Activator.CreateInstance(typeof(T), true) as T;
}
return instance;
}
}

public class PlayerTank : TankBase<PlayerTank>

Check notice on line 19 in Singleton.cs

View check run for this annotation

codefactor.io / CodeFactor

Singleton.cs#L19

A C# document may only contain a single class at the root level unless all of the classes are partial and are of the same type. (SA1402)
{
}

public class EnemyTank : TankBase<EnemyTank>
{

Check notice on line 24 in Singleton.cs

View check run for this annotation

codefactor.io / CodeFactor

Singleton.cs#L24

An opening curly bracket must not be followed by a blank line. (SA1505)

}

Check notice on line 26 in Singleton.cs

View check run for this annotation

codefactor.io / CodeFactor

Singleton.cs#L26

A closing curly bracket must not be preceded by a blank line. (SA1508)