That's the plot of the 80s movie The Last Starfighter
The Last Starfighter is a 1984 American space opera film directed by Nick Castle. The film tells the story of Alex Rogan (Lance Guest), a teenager who, after winning the high score in an arcade game that's secretly a simulation test, is recruited by an alien defense force to fight in an interstellar war.
I got the reference...Texas Fella pulls a gun on Cart Narcs