I remember reading a book long, long ago, maybe in 6th grade. In it, someone had invented a game simulator, sort of like a virtual reality thing where it would induce daydreams in the user who controlled it like a daydream. Only it had a malfunction, and it would shock the user who would lose consciousness and not know it wasn't reality. There was supposed to be some sort of tournament or something.
In the game, there were certain devices which had to be protected, some sort of cube. The bad guys would use them to do something bad, but you needed them to do something good. Can't remember what they were, or what they were for.
The bad guys had "wraiths" which were energy-based creatures, sort of the basic foot soldier of the bad guys. There were also these wheelbarrow-like robots, which would sneak up behind you and bump your knees to knock you down into the "bucket" which would snap shut and trap you, to be delivered to a dungeon or something.
The only big advantage the good guy had was a "puzzle gun." It was the shape of a small rifle but had three holes in it, where you could insert up to three of several battery-shaped devices (I'll just call them batteries) each of which had a specific function. You could combine batteries to get a very specific outcome. For instance, one battery might be "amplify" and one might be "heat" and one might be "disperse." You could only use each battery so much before it became depleted. I think in the end, the protagonist stuck the "disperse" battery in the gun backwards and had to duct tape it in place - this would drain the power of the wraiths and charge the batteries in the gun, or something like that.
I just can't remember the name of the book! I'm building up a library of both fiction and nonfiction for my (future) children, whom we plan to home-school. I saw a thread which mentioned Tom Swift and that reminded me of this book, but I'm pretty sure this isn't a Tom Swift book.
Any ideas? Anybody else read it? How badly did I mangle the book with my memories?