I read this book a long time ago, but I believe I have a decent answer. Ender's teachers used a computer program called 'the mind game' which generated environments and scenarios based on Ender's thoughts which Ender spends his free time interacting with. His teachers also manipulate him in the later stages of his time at Battle School by telling him that he is moving on to a new practice battle system with his peers, when in fact they are actually commanding real fleets against the buggers.
Eventually the computer game from Battle school becomes self-aware and obtains an aiua of its own and becomes the entity called Jane which exists in the ansible networks and becomes a companion of Ender. Also Ender finds out how the teachers manipulated him and is profoundly shaken by his knowledge that he comitted xenocide (or though he did) which leads him to write his books and become a speaker for the dead.