Lab 5 Spring 2000

The Problem

Write a program to create a tic-tac-toe game. The main window should be non-resizeable without a menu. You should have a clear button to reset the game and a system menu that allows you to quit. Moves consist of the user clicking on the place they want to move. A bitmap is placed in the location of the click and the users move is recorded in the game log (at the bottom of the page). If the user trys to click on a previously chosen location, the move is not accepted and a nasty comment about cheating appears in the game log. Finally, if the game is a draw or if someone wins, this should be recorded in the game log also.

The Interface

The following images show the game after a win and after a draw. This is the transcript in the case the user tries to enter the same square.

The log should scroll so that the current move is always visible. The following code (for the BottomRight area) shows how to handle the user click.

   String result = GameListBox->Items->Text;
   if (_game.legalMove(2,2))
      if (_game.isXMove())
         BottomRight->Picture->LoadFromFile("xMove.bmp");
      else 
         BottomRight->Picture->LoadFromFile("oMove.bmp");
   result += _game.move(2,2);
   GameListBox->Items->Text = result;
   //Find out how many in the box. If more than 5, set the top at the number of items -5   int bottom=GameListBox->Items->Count;
   if (bottom >5)
      GameListBox->TopIndex=bottom-5;

I recommend that you set the areas using panels with obvious borders. Next drop and image on top of each of the panels. In this case the image is BottomRight. Its Picture property can be set using the LoadFromFile function. You can get the three bitmaps I used by clicking here . The gray bitmap is used to erase the Os and Xs from the game board when the user selects clear.

The Schedule

  1. Monday, March 20, Scenarios are due.
  2. Wednesday, March29, Programs are due.