Mastering App Development with Unity 3D: Game Achievements Reusable Module

0 of 13 lessons complete (0%)

App Development

The “Flush” Use Case

The Clean Unity Handbook

DTOs

Add the following code to the Objectives class:

/// <summary>

/// Flush Objectives and return new ones
 /// </summary>

public struct FlushRequest

{

}

public struct FlushResponse

{


/// <summary>

/// Objectives to be done

/// </summary>

public ObjectivesModel[] objectives;


}

Controller

Add the following code to the ObjectivesController class: // MARK: Flush

public void flushObjectives()


{

var request = new Objectives.FlushRequest();


interactor.doFlush(request);
 }


Interactor

Add the following code to the ObjectivesInteractor class:

public interface IObjectivesInteractor {
void doFetch(Objectives.FetchRequest request); void doFlush(Objectives.FlushRequest request);

// MARK: Flush



public void doFlush(Objectives.FlushRequest request)


{

const int FLUSH_COST = 100;



 amount)


dans status
 +)
 LocalMoneyWorker.Instance.Buy(FLUSH_COST, delegate (int

{

var response = new Objectives.FlushResponse();
 if (amount >= 0)

{


fetchedSet, false);
 //since we are flushing, we should reset progress for (int obj = 0; obj < numberOfObjectives; obj+

{

ObjectivesWorker.Update(obj, fetchedSet, 0);


ObjectivesWorker.UpdateStatus(obj, }



 ObjectivesWorker.Flush(numberOfObjectives);


//since we flushed data we fetch objectives again
 var fetchRequest = new Objectives.FetchRequest();
 fetchRequest.numberOfObjectives = response.objectives =

numberOfObjectives;

fetchRequest.set = fetchedSet;


doFetch(fetchRequest);
 }


else //Flush failed


{

response.objectives = new

Objectives.ObjectivesModel[] { } ;
 }


this.presenter.presentFlush(response);
 } );


}


Presenter

Add the following code to the ObjectivesPresenter class:

public interface IObjectivesPresenter {

void presentFetch(Objectives.FetchRequest response); void presentFlush(Objectives.FlushResponse response); }

// MARK: Flush



public void presentFlush(Objectives.FlushResponse response)


{

if (response.objectives.Length > 0)
 {


NotifierPresenter.Instance.PerformInstantaneousRequest(“Flushed Objectives !”);


} else {

NotifierPresenter.Instance.PerformInstantaneousRequest(“You need more Money !”);


} }

en_USEnglish