BigMacintosh / Parking

Year 3 Games Project
MIT License
6 stars 0 forks source link

Players are created outside of the World class #255

Closed ChrisGora closed 4 years ago

ChrisGora commented 4 years ago

This allows the Players to be mocked

ChrisGora commented 4 years ago

I don't see any other way to be able to mock the Player class when I write tests

ChrisGora commented 4 years ago

The World class is a very neat, pure C# class so there is no need to Mock it. But the Player class does all Unity stuff so it needs to be mocked

RileyEv commented 4 years ago

You're going to have to convince me tomorrow because personally do no agree with the way you've changed it.

Player is a class for storing internal state inside the world. I don't think anything outside of the world classes should be creating players.

ChrisGora commented 4 years ago

Okay, I can see 2 solutions then:

1) The World has two methods CreatePlayer and AddPlayer. CreatePlayer uses AddPlayer. We say in comments that AddPlayer is not meant to be used outside of the class (but has to stay public for testing).

2) The Player class methods become all package-private. This prevents anyone from doing anything with the Player other than instantiating it.

Neither are ideal but I need a way of mocking Players

ChrisGora commented 4 years ago
  1. Maybe the best tbh. I could add a TEST_ONLY_AddPlayer then it's painfully obvious that it's for testing only
liamdalg commented 4 years ago

Ngl I think I agree with this. Pretty sure this is called Inversion of Control. Might be necessary anyway for adding other player types (if non-human players ever came up), since the world no longer cares about how to create a player, only that one exists.

adeeg commented 4 years ago

This allows the Players to be mocked

kinda mean. we want to encourage plays to play the game regardless of their ability. this is the negativeness in the team i was talking about