Jump to content
  • Advertisement
Sign in to follow this  
KitKat20152016

Unity Programming patterns my reward system

This topic is 711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this reward logic in my reward ,  my goal is to build a library which I can keep reuse later , however by this following method I can't 

class RewardSystem
{

float m_timer;
void Update()
{
  m_timer -= time.deltaTime;
}

void btn_Reward()
{
   if(m_timer > 0)
   {
       UnityAds.ShowAd();
       if(UnityAds.FinishAd())
       {
          CoinSystem.m_coins += 100;
       }  
   }
   else 
   {
      CoinSystem.m_coins += 100;
   }
}
}

The problem I'm having here is if the user does not have want to have ads system instead doing something else to collect coins or they decided to collect the coins with just pressing a button without looking the ads, people would need to rewrite it, and also it breaks the SOILD principle. So I'm wondering is there any programming patterns can help me to solve this problrem ,thanks 

Share this post


Link to post
Share on other sites
Advertisement

If you need to seperate this logic then create another class- and think of abstractions.

"I have an abstracted logic for doing an activity, in the end it returns the state of the activity and rewards the player."

 

So:

 

interface IActivity { 

bool Run(); 

}

 

class A {

 IActivty MyActivity;

   void Reward() {

      var result = mMyActivity.Run();

      if(result) { coins +=100;} 

   }

}

Edited by WoopsASword

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!