Console keyboard input OOP
Posted
by
Alexandre P. Levasseur
on Programmers
See other posts from Programmers
or by Alexandre P. Levasseur
Published on 2013-11-05T02:40:43Z
Indexed on
2013/11/05
4:12 UTC
Read the original article
Hit count: 765
design-patterns
|game-development
I am trying to build a very simple console-based game with a focus on using OOP instead of procedural programming because I intend to build up on that code for more complex projects.
I am wondering if there is a design pattern that nicely handles this use case:
- There is a
Player
class with aMakeMove()
method interacting with the board game.
The MakeMove()
method has to somehow get the user input yet I do not want to code it into the Player
class as this would reduce cohesion and augment coupling.
I was thinking of maybe having some controller class handle the sequence of events and thus the calls to keyboard input. However, that controller class would need to be able to handle differently the subclasses of Player
(e.g. the AI
class does not require keyboard input).
Thoughts ?
© Programmers or respective owner