Gamelogic
  • Home
  • Blog
  • Tools
    • Grids 2 (for Unity)
      • Features
      • Documentation
    • Grids 1 (Legacy, for Unity)
      • 30 games in 30 days
      • Features
      • Tutorials, Documentation, and FAQ
      • Games made with Grids for Unity
      • Examples
      • What is new?
      • Grid Prototypes and Previews
      • Buy
    • Extensions
    • Colors
      • Features
      • Documentation and tutorials
      • Buy
    • Words
      • Features
      • Documentation
      • Buy
    • Abstract Strategy
      • Features
      • Documentation and tutorials
      • Examples
      • Buy
    • Match
      • Features
    • Grids (for GameMaker)
      • 30 games in 30 days
      • Features
      • Documentation
      • Buy
  • Buy
  • Articles
  • Support
    • Knowledge Base
    • Email Support
  • About
    • Meet our team

Moving a piece and changing turns

Moving_Piece

Setup a game board with pieces as explained in this tutorial.

Now make a new script that will handle the logic for moving pieces and swapping turns. In this case:

  • Each player will have one move.
  • A player can move his or her piece to any open space on the board. (This is configured on the logical piece prefab).
  • In each turn, the player selects the piece to move, and then select the square to move the piece to.

The script has to get a reference to the Grid Game Manager, and register the players. It also has to handle mouse input. The setup used for this example is typical of these types of games. We keep track of the currently selected piece. When the grid is clicked:

  • If the currently selected piece is null, and the click is over a piece of the player whose turn it is, we make that piece the selected piece.
  • If it is not null, and we click on an empty square, the piece is moved there (and the turn ends automatically)
  • If it is not null, and we click on a piece of the player whose turn it is, that piece becomes the new currently selected piece.

To check out this example:

  1. Import Abstract Strategy in a new project.
  2. Import the package below into the same project.
  3. Open the MovePieceAndSwapTurns scene.

MovePieceAndSwapTurns.unitypackage

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

  1. Animating a piece in the board  To have pieces animate when they move, follow these steps...
  2. Triangle Puzzle Game  This example shows the basic principles of implementing certain mechanics:...
  3. Setting up a grid and board  (To Learn more about Grids, see the documentation page for...
  4. Overview of Architecture  Game Manager The game manager is largely responsible for being...

  • Home
  • Features
  • Blog
  • About
  • 14 Eglin Road, Sunninghill, Johannesburg, South Africa
  • support@gamelogic.co.za
Stay Connected
  • Facebook
  • Google
  • Linkedin
  • Rss
  • Twitter
  • Gamelogic © 2013