Introduction

The input module takes the input from the user and determines what the user wants to do. This could be dragging a piece from one square to another or clicking a button. It passes this information to the core module.

Inputs

Input receives input from a user interface module running in VCC in the form of a mouse_click(status, x, y) message. Here status specifies the mouse button position (0 = down, 1 = up). x and y are the screen coordinates of the point where the user pressed or released the mouse button. Screen coordinates are assumed to start at (0,0) in the bottom-left corner of the screen.

Note that these mouse_click messages first pass through the lobby module. This is so that the lobby can receive input from the user when they are choosing their opponent before the start of the game. Once the game has started, the lobby module will simply forward all mouse clicks to the input module.

Outputs

The input module looks at where the user clicked on the screen and works out if they were making a move, placing a piece before the start of the game or clicking one of the buttons. It passes this information to the core module in the form of a move or button structure as described below.

Making a move

If the user clicked and released the mouse on different board squares, they were trying to move the piece on the square where the mouse was pressed to the square where the mouse was released.

move(player, x1, y1, x2, y2) will be passed to the core, where player is the player number assigned by the lobby at the start of the game. x1, y1 describe the square of the piece that was moved and x2, y2 describe the destination square.

Placing a piece

Before the game starts, players must place their pieces on the main game board. This is done by dragging a piece from the pieces panel at the bottom of the screen to a square on the main board. Hence, a user is trying to place a piece if they press the mouse button over a piece at the bottom of the screen and release it over a board square.

Again, move(player, x1, y1, x2, y2) will be passed, but this time x1, y1 represent the square that was clicked on the piece placing panel. x2, y2 describe the destination square on the main board, as before.

Clicking a button

If the user presses and releases the mouse on a button at the bottom of the screen, button(player, button_no) is output. Here button_no tells the core module which button the user clicked.

Screen Layout

This module needs to know the layout of the screen and game board. It also relies on everyone using the same pixel and board numbering conventions that I have defined. For details of the stratego screen layout and the numbering of the board squares and buttons, see the screen page.

Illegal Move Checking

This module ignores any input from the user that has coordinates that are not on the screen. Also, moves that specify the same start and destination square are ignored.

Illegal operations, such as dragging a piece from the board back to the placing panel are not passed onto the Core module. However, all moves with valid start and finish squares on the main board are output. It is then up to the core to check if there is a piece on the starting square and if the move is legal.

Test Program

I have written a test program that shows what messages would be sent to the core module given a particular input from the user. You can download this here. It runs under linux and takes the following 6 arguments:

  • Starting mouse button position (0=down, 1=up)
  • Starting x coordinate
  • Starting y coordinate
  • Finishing mouse button position
  • Finishing x coordinate
  • Finishing y coordinate

Design Decisions

The input module has been designed to be as flexible and reusable as possible so that it could be used for any other board game. The idea is that the Stratego core module could be replaced with a core module for a different board game and all the game services would still work.

This is achieved by specifying the screen layout and dimensions of the board and buttons in a header file. By editing this file, the input module will cope with a different screen size and layout, as well as different numbers of squares on the main board and placing panel. Finally the button area can contain as many buttons as necessary for the current game.

I have made use of the VCC block structure when writing this module. This makes the module easier to understand as it is broken up into logical parts. Also, the block structure clearly shows the flow of information inside the module and allows VCC to simulate the runtime on the final game machine architecture.

Bugs and Future Development

There are no known bugs in this module. However, it could be expanded further to deal with screen areas of any shape rather than just grids of squares. The input module could then be used to recognise mouse input for any program rather than just board games.

Home


Copyright © 2002 Andrew Bates
Last Updated 03/04/02