While that answer is a good synopsis of the novel's plot, the question has to do with "the "main idea" of the book, a much more abstract and analytical inquiry. The author is novelizing several important questions: To what degree is rebellion against authority an integral part of growing up? Has humanity been fighting the wrong enemy? Are we as a race not so superior as we think? Has our belligerent, protective, military mindset cost us dearly? Etc. It is a Bildungsroman about civilization itself. When read in this light, as opposed to a preteenager's fantasy, it can take its place alongside Catcher in the Rye and Lord of the Flies, although only time will tell.
The book "Ender's Game," by Orson Scott Card, is set far into the future. Earth has been at war with an alien civilization with which it cannot effectively communicate.
As a result of their near destruction, leaders on Earth have set about trying to identify and develop superior military leaders and strategists to help them win their next fight with the aliens. Ender, after a series of experiences, begins to emerge as a brilliant military mind.
The book's climax is effectively rendered as the young Ender, told that he is taking part in a test of military leadership, actually fights a decisive battle with the alien race. Without realizing it at the time, he wins the battle no one else could win in the past and saves Earth.
However, the victory comes at a high price, as Ender causes the death of many soldiers and almost every one of the enemy. The story changes its tone as Ender sees the results of war. The book ends with Ender agreeing to help the alien race re-establish themselves on another world.