Math, asked by majajajoo2985, 1 year ago

2. Represent a football match in an object oriented way.

Answers

Answered by chinna66
0
When faced with the same problem, I just started the game in a procedural style - then refactored to objects and classes where they became obvious. I can’t say the outcome was good - when you don’t have a plan, it rarely is. But it sure beats sitting around and dreaming about UML diagrams :D

Of course, the answer is obvious in hindsight - you just need classes and objects for every class of object and object in a football game; players, teams, stadiums, the ball, the scoreboard, maybe spectators or something, as well as game-world internal objects like sprites or meshes, world physics, AI player, network player and a controller for all of them (it’s fun to make the AI use the same “interface” into the game that humans do - player objects can be made to not care in what way they are being controlled (local controller, network or AI)).

Most of your game objects will want to have update and render methods, where the first allows them to inspect what is happening and change their state, and the second lets them draw themselves to the screen. For example in its update method a Ball object will check for collisions, and if there are any calculate forces to apply to itself (which result in acceleration, which results in change of velocity, which ultimately results in change of position - so when the render call comes along, you will draw yourself with a bit of an offset, and the players will see the ball starting to move).

Similar questions