Implementation of game logic