Thanks for the reply. The question was probably too general. It's less about programming books. It's about stories that I would like to implement.
For example a thriller as a point-and-click adventure.
Oh, must have jumped to conclusions, since we had a discussion about using stuff from the SFML book.
With stories things get a bit even more complicated - funny actually I've been thinking about the same scenario yesterday.
Since the "work" of a book is basically its story, with its characters and all, it will fall under the copyright, thus you're not really allowed to use its content directly. However there are some laws that allow to use of any copyrighted material through fair-use or parody. What falls into which category is something as Lethn kind of pointed out that lawyers are fighting over year in and out. You can google a bit to find some vague definitions of what falls under which law.
Personally I'd try to contact the author, even though he mostly doesn't really have a word on it, since the rights are in most cases owned by publishers, but it's worth a try and you might even get a green light.
Or if that didn't work out well, you can always use the story as basis and construct your own things on top of it, with your own characters etc. Proving the connection will be much harder and given that it will non-commercial that likely hood of the publisher hunting you down is going towards zero.
In all cases however, you need to keep in mind that you're never really safe from any lawsuit, BUT chances are unless your game gets really, really popular the publisher not the author will ever hear about it.
Finally, don't heavily rely on any advice from people on the internet that aren't lawyers and can't prove to be lawyers. We just like to think logical and with some common sense, unfortunately our world is developing more and more away from what once called "common sense".