Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Met Z'n Drieen source code (version 1.3)

 

Met Z'n Drieen version 1.3 source code

 

Operating system: Windows XP

IDE: C++ Builder 6.0 Enterprise Edition

Project type: GUI application

Compiler: supplied with C++ Builder 6.0 Enterprise Edition

Libraries used:

 

 

 

 

 

ProjectMetZnDrieen.cpp

 

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("UnitFormMain.cpp", FormMain);
USEFORM("UnitFormMenu.cpp", FormMenu);
USEFORM("UnitFormGewonnen.cpp", FormGewonnen);
USEFORM("UnitFormStoppen.cpp", FormStoppen);
USEFORM("UnitFormOver.cpp", FormOver);
USEFORM("UnitFormSpelregels.cpp", FormSpelregels);
USEFORM("UnitFormSprites.cpp", FormSprites);
USEFORM("UnitFormWhatsNew.cpp", FormWhatsNew);
USEFORM("UnitFormAdditionalCopyright.cpp", FormAdditionalCopyright);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->Title = "Met Z'n Drieen";
                 Application->CreateForm(__classid(TFormMenu), &FormMenu);
                 Application->CreateForm(__classid(TFormSprites), &FormSprites);
                 Application->CreateForm(__classid(TFormWhatsNew), &FormWhatsNew);
                 Application->CreateForm(__classid(TFormAdditionalCopyright), &FormAdditionalCopyright);
                 Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }
        catch (...)
        {
                 try
                 {
                         throw Exception("");
                 }
                 catch (Exception &exception)
                 {
                         Application->ShowException(&exception);
                 }
        }
        return 0;
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormAdditionalCopyright.cpp

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormAdditionalCopyright.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormAdditionalCopyright *FormAdditionalCopyright;
//---------------------------------------------------------------------------
__fastcall TFormAdditionalCopyright::TFormAdditionalCopyright(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormAdditionalCopyright.h

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormAdditionalCopyrightH
#define UnitFormAdditionalCopyrightH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormAdditionalCopyright : public TForm
{
__published: // IDE-managed Components
        TRichEdit *RichEdit;
        TImage *Image1;
private: // User declarations
public: // User declarations
        __fastcall TFormAdditionalCopyright(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormAdditionalCopyright *FormAdditionalCopyright;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormGewonnen.cpp

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include <cassert>
#include "UnitFormGewonnen.h"
#include "UnitFormSprites.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormGewonnen *FormGewonnen;
//---------------------------------------------------------------------------
__fastcall TFormGewonnen::TFormGewonnen(TComponent* Owner,
  const int winner_index,
  const bool is_human)
        : TForm(Owner)
{
  assert(FormSprites);
  Extctrls::TImage * i = 0;
  if (winner_index == 0)
  {
    i = (is_human ? FormSprites->ImagePlayer1 : FormSprites->ImageComputer1);
  }
  else if (winner_index == 1)
  {
    i = (is_human ? FormSprites->ImagePlayer2 : FormSprites->ImageComputer2);
  }
  else if (winner_index == 2)
  {
    i = (is_human ? FormSprites->ImagePlayer3 : FormSprites->ImageComputer3);
  }
  assert(i);
  Image->Picture->Graphic = i->Picture->Graphic;
}
//---------------------------------------------------------------------------

void __fastcall TFormGewonnen::OnAnyClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormGewonnen.h

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormGewonnenH
#define UnitFormGewonnenH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <jpeg.hpp>
//---------------------------------------------------------------------------
class TFormGewonnen : public TForm
{
__published: // IDE-managed Components
        TImage *Image;
        TLabel *Label1;
        TImage *ImageHeart;
        TImage *Image1;
        TImage *Image2;
        TImage *Image3;
        TImage *Image4;
        TImage *Image5;
        TImage *Image6;
        TImage *Image7;
        TImage *Image8;
        TImage *Image9;
        TImage *Image10;
        TImage *Image11;
        TImage *Image12;
        TImage *Image13;
        TImage *Image14;
        TImage *Image15;
        void __fastcall OnAnyClick(TObject *Sender);
private: // User declarations
public: // User declarations
  __fastcall TFormGewonnen(
    TComponent* Owner,
    const int winner_index,
    const bool is_human);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormGewonnen *FormGewonnen;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormMain.cpp

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormMain.h"
//---------------------------------------------------------------------------
#include "UnitFormGewonnen.h"
#include "UnitFormStoppen.h"
//---------------------------------------------------------------------------
#include <cassert>
#include <ctime>
#include <boost/scoped_ptr.hpp>
#include "UnitFormSprites.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormMain *FormMain;
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(
  TComponent* Owner,
  const bool player1_human,
  const bool player2_human,
  const bool player3_human)
  : TForm(Owner),
    m_player1_human(player1_human),
    m_player2_human(player2_human),
    m_player3_human(player3_human),
    mBlocks(16, std::vector<EnumBlock>(12,NoPlayer)),
    mPlayer(Player1),
    mMaxx(16),
    mMaxy(12)
{
  std::srand(std::clock());
  mNextRobotMove.x = -1;
  mNextRobotMove.y = -1;
  ImageBuffer->Picture->Bitmap->Width  = 800;
  ImageBuffer->Picture->Bitmap->Height = 600;
  DrawScreen();
  if (IsRobot(mPlayer)) TimerThinker->Enabled = true;
}
//---------------------------------------------------------------------------
void TFormMain::DrawScreen()
{

  //Draw blocks on buffer
  assert(FormSprites);
  for (int y=0; y!=mMaxy; ++y)
  {
    for (int x=0; x!=mMaxx; ++x)
    {
      const int xCo = x * 50;
      const int yCo = y * 50;
      Graphics::TGraphic * graphic = 0;
      switch (mBlocks[x][y])
      {
        case Player1:
          graphic = FormSprites->ImagePlayer1->Picture->Graphic;
          break;
        case Player2:
          graphic = FormSprites->ImagePlayer2->Picture->Graphic;
          break;
        case Player3:
          graphic = FormSprites->ImagePlayer3->Picture->Graphic;
          break;
        case NoPlayer:
          graphic = FormSprites->ImageEmpty->Picture->Graphic;
          break;
        default: assert(!"Should not get here");
      }
      //Draw sprite on buffer
      ImageBuffer->Canvas->Draw(xCo,yCo,graphic);
    }
  }
  //Draw buffer on canvas
  Canvas->Draw(0,0,ImageBuffer->Picture->Graphic);

  //Draw players on canvas (buffer is only used as game arena)
  if (mPlayer==Player1)
  {
    Canvas->Draw(Image1->Left,Image1->Top,FormSprites->ImagePlayer1->Picture->Graphic);
  }
  else
  {
    Canvas->Draw(Image1->Left,Image1->Top,FormSprites->ImagePlayer1Grey->Picture->Graphic);
  }
  if (mPlayer==Player2)
  {
    Canvas->Draw(Image2->Left,Image2->Top,FormSprites->ImagePlayer2->Picture->Graphic);
  }
  else
  {
    Canvas->Draw(Image2->Left,Image2->Top,FormSprites->ImagePlayer2Grey->Picture->Graphic);
  }
  if (mPlayer==Player3)
  {
    Canvas->Draw(Image3->Left,Image3->Top,FormSprites->ImagePlayer3->Picture->Graphic);
  }
  else
  {
    Canvas->Draw(Image3->Left,Image3->Top,FormSprites->ImagePlayer3Grey->Picture->Graphic);
  }
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  //When the AI is 'thinking' no clicks are allowed
  if (IsRobot(mPlayer)==true && Sender->ClassNameIs("TTimer")==false) return;

  //ImageBuffer->Visible = false;
  const int x = X / 50;
  const int y = Y / 50;
  //Is this a relevant move?
  if (mBlocks[x][y] != NoPlayer) return;
  // Yes, a relevant move
  mBlocks[x][y] = mPlayer;
  mPlayer = GetNextPlayer(mPlayer);
  //Start the AI robot!
  if (IsRobot(mPlayer)) TimerThinker->Enabled = true;

  DrawScreen();

  //Check for three on a row
  {
    for (int y=0; y!=mMaxy; ++y)
    {
      for (int x=0; x!=mMaxx; ++x)
      {
        if (mBlocks[x][y] == NoPlayer) continue;
        EnumBlock winner = NoPlayer;
        //Horizontal
        if (x + 2 < mMaxx && mBlocks[x][y] == mBlocks[x+1][y] && mBlocks[x+1][y] == mBlocks[x+2][y])
        {
          winner = mBlocks[x][y];
        }
        //Vertical
        if (y + 2 < mMaxy && mBlocks[x][y] == mBlocks[x][y+1] && mBlocks[x][y+1] == mBlocks[x][y+2])
        {
          winner = mBlocks[x][y];
        }
        if (winner!=NoPlayer)
        {
          //A winner has been found!
          TimerDoer->Enabled = false;
          TimerThinker->Enabled = false;
          boost::scoped_ptr<TFormGewonnen> formGewonnen(
            new TFormGewonnen(0,static_cast<int>(winner),!IsRobot(winner)));
          formGewonnen->Hide();
          formGewonnen->ShowModal();
          //Show FormStoppen
          boost::scoped_ptr<TFormStoppen> formStoppen(new TFormStoppen(0));
          formStoppen->Hide();
          formStoppen->ShowModal();
          if (formStoppen->ModalResult == 1)
          { //Nog een keer
            TimerDoer->Enabled = true;
            mBlocks = std::vector<std::vector<EnumBlock> >(16, std::vector<EnumBlock>(12,NoPlayer));
            mPlayer = Player1;
            if (IsRobot(mPlayer)) TimerThinker->Enabled = true;
            DrawScreen();
          }
          else
          { //Stoppen
            ModalResult = 1;
          }


        }

      }
    }
  }
}
//---------------------------------------------------------------------------



void __fastcall TFormMain::TimerThinkerTimer(TObject *Sender)
{
  //Check if moves already have been calculated
  if (mNextRobotMove.x!=-1) return;
  if (mNextRobotMove.y!=-1) return;
  if (IsRobot(mPlayer)==false)
  {
    OutputDebugString("Hey, I ain't a player!");
    return;
  }
  int xMove = -1;
  int yMove = -1;
  //Make a non-random move
  if (xMove == -1 && yMove == -1) CheckTwoHorizontalOwn(xMove,yMove);
  if (xMove == -1 && yMove == -1) CheckTwoVerticalOwn(xMove,yMove);
  if (xMove == -1 && yMove == -1) CheckTwoOther(xMove,yMove);
  if (xMove == -1 && yMove == -1) CheckTwoDiagonally(xMove,yMove);
  if (xMove == -1 && yMove == -1) CheckOneOther(xMove,yMove);
  if (xMove == -1 && yMove == -1) MakeRandomMove(xMove,yMove);
  assert(IsValidMove(xMove,yMove));
  //Do it then...
  mNextRobotMove.x = xMove;
  mNextRobotMove.y = yMove;
  //Click it on the playfield virtually
  //This will be done by TimerDoer
}
//---------------------------------------------------------------------------
void TFormMain::CheckTwoHorizontalOwn(int& xMove,int& yMove) const
{
  assert(xMove == -1 && yMove == -1);
  for (int y=0; y!=mMaxy; ++y)
  {
    for (int x=0; x!=mMaxx-1; ++x) //-1 to prevent out of range
    {
      //Two consequtive selfs
      if (mBlocks[x][y] == mPlayer && mBlocks[x+1][y] == mPlayer)
      {
        if (x >= 1)
        {
          if (mBlocks[x-1][y] == NoPlayer)
          {
            xMove = x-1; yMove = y;
            assert(IsValidMove(xMove,yMove));
            return;
          }
        }
        if (x < mMaxx-2 && mBlocks[x+2][y] == NoPlayer)
        {
          xMove = x+2; yMove = y;
          assert(IsValidMove(xMove,yMove));
          return;
        }
      }
      //Perhaps a gap?
      if (x < mMaxx-2)
      {
        if (mBlocks[x][y] == mPlayer && mBlocks[x+1][y] == NoPlayer && mBlocks[x+2][y] == mPlayer)
        {
            xMove = x+1; yMove = y;
            assert(IsValidMove(xMove,yMove));
            return;
        }
      }
    }
  }
}
//---------------------------------------------------------------------------
void TFormMain::CheckTwoVerticalOwn(int& xMove,int& yMove) const
{
  assert(xMove == -1 && yMove == -1);
  for (int y=0; y!=mMaxy-1; ++y) //-1 to prevent out of range
  {
    for (int x=0; x!=mMaxx; ++x)
    {
      //Two consequtive selfs?
      if (mBlocks[x][y] == mPlayer && mBlocks[x][y+1] == mPlayer)
      {
        if (y >= 1)
        {
          if (mBlocks[x][y-1] == NoPlayer)
          {
            xMove = x; yMove = y-1;
            assert(IsValidMove(xMove,yMove));
            return;
          }
        }
        if (y < mMaxy-2)
        {
          if (mBlocks[x][y+2] == NoPlayer)
          {
            xMove = x; yMove = y+2;
            assert(IsValidMove(xMove,yMove));
            return;
          }
        }
      }
      //Perhaps a gap?
      if (y < mMaxy-2)
      {
        if (mBlocks[x][y] == mPlayer && mBlocks[x][y+1] == NoPlayer && mBlocks[x][y+2] == mPlayer)
        {
            xMove = x; yMove = y+1;
            assert(IsValidMove(xMove,yMove));
            return;
        }
      }

    }
  }
}
//---------------------------------------------------------------------------
void TFormMain::CheckTwoOther(int& xMove,int& yMove) const
{
  assert(xMove == -1 && yMove == -1);
  const std::vector<GameMove> moves1(GetTwoHorizontalOtherMoves());
  const std::vector<GameMove> moves2(GetTwoVerticalOtherMoves());
  const std::vector<GameMove> moves(Concatenate(moves1,moves2));
  assert(moves.size() == moves1.size() + moves2.size());

  const int nMoves = moves.size();
  if (nMoves==0) return;

  { //Get moves anti-player
    std::vector<GameMove> antiPlayerMoves;
    for (int i=0; i<nMoves; ++i)
    {
      assert(IsValidMove(moves[i]));
      if (IsRobot(moves[i].anti) == false) antiPlayerMoves.push_back(moves[i]);
    }
    //If there are anti-player moves, choose one at random
    if (antiPlayerMoves.empty()==false)
    {
      const int nAntiPlayerMoves = antiPlayerMoves.size();
      const int index = std::rand() % nAntiPlayerMoves;
      xMove = antiPlayerMoves[index].x;
      yMove = antiPlayerMoves[index].y;
      assert(IsValidMove(xMove,yMove));
      return;
    }
  }
  { //Get moves anti-next-player
    std::vector<GameMove> antiNextPlayerMoves;
    for (int i=0; i<nMoves; ++i)
    {
      if (GetNextPlayer(mPlayer) == moves[i].anti) antiNextPlayerMoves.push_back(moves[i]);
    }
    //If there are anti-next-player moves, choose one at random
    if (antiNextPlayerMoves.empty()==false)
    {
      const int nAntiNextPlayerMoves = antiNextPlayerMoves.size();
      const int index = std::rand() % nAntiNextPlayerMoves;
      xMove = antiNextPlayerMoves[index].x;
      yMove = antiNextPlayerMoves[index].y;
      assert(IsValidMove(xMove,yMove));
      return;
    }
  }
  //Choose a move at random
  {
    const int index = std::rand() % nMoves;
    xMove = moves[index].x;
    yMove = moves[index].y;
    assert(IsValidMove(xMove,yMove));
  }
}
//---------------------------------------------------------------------------
const std::vector<GameMove> TFormMain::GetTwoHorizontalOtherMoves() const
{
  std::vector<GameMove> moves;
  for (int y=0; y!=mMaxy; ++y)
  {
    for (int x=0; x!=mMaxx-1; ++x) //-1 to prevent out of range
    {
      //Check consequtive
      if (mBlocks[x][y]!=NoPlayer && mBlocks[x][y] == mBlocks[x+1][y])
      {
        //Check A X B
        if (x > 0 && mBlocks[x-1][y] == NoPlayer)
        {
          //xMove = x-1; yMove = y;
          GameMove move;
          move.x = x-1;
          move.y = y;
          move.anti = mBlocks[x][y];
          assert(IsValidMove(move));
          moves.push_back(move);
        }
        //Check X B C
        if (x < mMaxx-2 && mBlocks[x+2][y] == NoPlayer)
        {
          GameMove move;
          move.x = x+2;
          move.y = y;
          move.anti = mBlocks[x][y];
          assert(IsValidMove(move));
          moves.push_back(move);
        }
      }
      //Check gap, also X B C
      if (mBlocks[x][y] != NoPlayer && x + 2 < mMaxx && mBlocks[x+1][y] == NoPlayer && mBlocks[x][y] == mBlocks[x+2][y])
      {
        GameMove move;
        move.x = x+1;
        move.y = y;
        move.anti = mBlocks[x][y];
        assert(IsValidMove(move));
        moves.push_back(move);
      }

    }
  }
  return moves;
}
//---------------------------------------------------------------------------
//A X B C (x is focus of for loop)
const std::vector<GameMove> TFormMain::GetTwoVerticalOtherMoves() const
{
  std::vector<GameMove> moves;
  for (int y=0; y!=mMaxy-1; ++y) //-1 to prevent out of range
  {
    for (int x=0; x!=mMaxx; ++x)
    {
      //Check consequtive
      if (mBlocks[x][y] != NoPlayer && mBlocks[x][y] == mBlocks[x][y+1])
      {
        //Check A X B
        if (y > 0 && mBlocks[x][y-1] == NoPlayer)
        {
          GameMove move;
          move.x = x;
          move.y = y-1;
          move.anti = mBlocks[x][y];
          assert(IsValidMove(move));
          moves.push_back(move);
        }
        //Check X B C
        if (y < mMaxy-2 && mBlocks[x][y+2] == NoPlayer)
        {
          GameMove move;
          move.x = x;
          move.y = y+2;
          move.anti = mBlocks[x][y];
          assert(IsValidMove(move));
          moves.push_back(move);
        }
      }
      //Check gap, also X B C
      if (mBlocks[x][y] != NoPlayer && y < mMaxy && mBlocks[x][y+1] == NoPlayer && mBlocks[x][y] == mBlocks[x][y+2])
      {
        GameMove move;
        move.x = x;
        move.y = y+1;
        move.anti = mBlocks[x][y];
        assert(IsValidMove(move));
        moves.push_back(move);
      }
    }
  }
  return moves;
}
//---------------------------------------------------------------------------
void TFormMain::CheckTwoDiagonally(int& xMove,int& yMove) const
{
  assert(xMove == -1 && yMove == -1);
  std::vector<GameMove> moves;

  for (int y=0; y!=mMaxy-1; ++y) //-1 To prevent out of range
  {
    for (int x=0; x!=mMaxx-1; ++x) //-1 to prevent out of range
    {
      if (mBlocks[x][y] == mPlayer && mBlocks[x+1][y+1] == mPlayer)
      {
        if (mBlocks[x+1][y] == NoPlayer)
        {
          GameMove move;
          move.x = x+1;
          move.y = y;
          assert(IsValidMove(move));
          moves.push_back(move);
        }
        if (mBlocks[x][y+1] == NoPlayer)
        {
          GameMove move;
          move.x = x;
          move.y = y+1;
          assert(IsValidMove(move));
          moves.push_back(move);
        }
      }
    }
  }
  const int nMoves = moves.size();
  if (nMoves == 0) return;
  const int index = std::rand() % nMoves;
  xMove = moves[index].x;
  yMove = moves[index].y;
  assert(IsValidMove(xMove,yMove));
}
//---------------------------------------------------------------------------
void TFormMain::CheckOneOther(int& xMove,int& yMove) const
{
  assert(xMove == -1 && yMove == -1);
  std::vector<GameMove> moves;

  for (int y=0; y!=mMaxy; ++y)
  {
    for (int x=0; x!=mMaxx; ++x)
    {
      if (mBlocks[x][y] != NoPlayer)
      {
        if (y >= 1)
        {
          if (mBlocks[x][y-1] == NoPlayer)
          {
            GameMove move;
            move.x = x;
            move.y = y-1;
            move.anti = mBlocks[x][y];
            assert(IsValidMove(move));
            moves.push_back(move);
          }
        }
        if (y < mMaxy-1)
        {
          if (mBlocks[x][y+1] == NoPlayer)
          {
            GameMove move;
            move.x = x;
            move.y = y+1;
            move.anti = mBlocks[x][y];
            assert(IsValidMove(move));
            moves.push_back(move);
          }
        }
        if (x >= 1)
        {
          if (mBlocks[x-1][y] == NoPlayer)
          {
            GameMove move;
            move.x = x-1;
            move.y = y;
            move.anti = mBlocks[x][y];
            assert(IsValidMove(move));
            moves.push_back(move);
          }
        }
        if (x < mMaxx-1)
        {
          if (mBlocks[x+1][y] == NoPlayer)
          {
            GameMove move;
            move.x = x+1;
            move.y = y;
            move.anti = mBlocks[x][y];
            assert(IsValidMove(move));
            moves.push_back(move);
          }
        }
      }
    }
  }
  const int nMoves = moves.size();
  if (nMoves == 0) return;

  { //Get moves anti-player
    std::vector<GameMove> antiPlayerMoves;
    for (int i=0; i<nMoves; ++i)
    {
      if (IsRobot(moves[i].anti) == false) antiPlayerMoves.push_back(moves[i]);
    }
    //If there are anti-player moves, choose one at random
    if (antiPlayerMoves.empty()==false)
    {
      const int nAntiPlayerMoves = antiPlayerMoves.size();
      const int index = std::rand() % nAntiPlayerMoves;
      xMove = antiPlayerMoves[index].x;
      yMove = antiPlayerMoves[index].y;
      assert(IsValidMove(antiPlayerMoves[index]));
      return;
    }
  }
  { //Get moves anti-next-player
    std::vector<GameMove> antiNextPlayerMoves;
    for (int i=0; i<nMoves; ++i)
    {
      if (GetNextPlayer(mPlayer) == moves[i].anti) antiNextPlayerMoves.push_back(moves[i]);
    }
    //If there are anti-next-player moves, choose one at random
    if (antiNextPlayerMoves.empty()==false)
    {
      const int nAntiNextPlayerMoves = antiNextPlayerMoves.size();
      const int index = std::rand() % nAntiNextPlayerMoves;
      xMove = antiNextPlayerMoves[index].x;
      yMove = antiNextPlayerMoves[index].y;
      assert(IsValidMove(antiNextPlayerMoves[index]));
      return;
    }
  }
  //Choose a move at random
  {
    const int index = std::rand() % nMoves;
    xMove = moves[index].x;
    yMove = moves[index].y;
    assert(IsValidMove(xMove,yMove));
  }

}
//---------------------------------------------------------------------------


void TFormMain::MakeRandomMove(int& xMove,int& yMove) const
{
  assert(xMove == -1 && yMove == -1);
  while(1)
  {
    xMove = std::rand() % mMaxx;
    yMove = std::rand() % mMaxy;
    if (mBlocks[xMove][yMove] == NoPlayer)
    {
      assert(IsValidMove(xMove,yMove));
      return;
    }
  }
}
//---------------------------------------------------------------------------
const bool TFormMain::IsRobot(const EnumBlock player) const
{
  assert(player!=NoPlayer);
  switch (player)
  {
    case Player1: return !m_player1_human;
    case Player2: return !m_player2_human;
    case Player3: return !m_player3_human;
    default: assert(!"Should not get here");
  }
  assert(!"Should not get here");
  return true;
}
//---------------------------------------------------------------------------
const String TFormMain::GetName(const EnumBlock player) const
{
  assert(player!=NoPlayer);
  if (IsRobot(player)==true) return "Robot";
  switch (player)
  {
    case Player1: return "Speler 1";
    case Player2: return "Speler 2";
    case Player3: return "Speler 3";
    default: assert(!"Should not get here");
  }
  assert(!"Should not get here");
  return "Richel";
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::TimerDoerTimer(TObject *Sender)
{
  if (mNextRobotMove.x!=-1 && mNextRobotMove.y!=-1)
  {
    //Move in range?
    assert(mNextRobotMove.x >= 0 && mNextRobotMove.x < mMaxx);
    assert(mNextRobotMove.y >= 0 && mNextRobotMove.y < mMaxy);
    //Move relevant?
    assert(mBlocks[mNextRobotMove.x][mNextRobotMove.y] == NoPlayer);
    TimerThinker->Enabled = false;
    FormMouseDown(TimerDoer,TMouseButton(), TShiftState(), mNextRobotMove.x*50, mNextRobotMove.y*50);
    mNextRobotMove.x=-1;
    mNextRobotMove.y=-1;
  }
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::TimerDebugTimer(TObject *Sender)
{
  String s = "Debug: ";
  s+=" TimerThinker: "; s+=(TimerThinker->Enabled ? "Y" : "N");
  s+=" TimerDoer: ";s+=(TimerDoer->Enabled ? "Y" : "N");
  s+=" Player: ";s+= GetName(mPlayer);
  s+=" IsRobot: ";s+=(IsRobot(mPlayer) ? "Y" : "N");
  OutputDebugString(s.c_str());

}
//---------------------------------------------------------------------------
const bool TFormMain::IsValidMove(const int x,const int y) const
{
  if ( x < 0)
  {
    const String s = "x < 0 : " +IntToStr(x); OutputDebugString(s.c_str());
    return false;
  }
  if (x >= mMaxx)
  {
    const String s = "x >= mMaxx : " +IntToStr(x); OutputDebugString(s.c_str());
    return false;
  }
  if (y < 0)
  {
    const String s = "y < 0 : " +IntToStr(y); OutputDebugString(s.c_str());
    return false;
  }
  if (y >= mMaxy)
  {
    String s = "y >= mMaxy : "  + IntToStr(x); OutputDebugString(s.c_str());
    return false;
  }
  if (mBlocks[x][y] != NoPlayer)
  {
    String s = "Already occupied : (" +IntToStr(x) + "," + IntToStr(y) + ")";
    OutputDebugString(s.c_str());
    return false;
  }

  return true;
}
//---------------------------------------------------------------------------
const bool TFormMain::IsValidMove(const GameMove& move) const
{
  return IsValidMove(move.x,move.y);
}
//---------------------------------------------------------------------------
const double uniform()
{
  return static_cast<double>(std::rand())/static_cast<double>(RAND_MAX);
}
//---------------------------------------------------------------------------


void __fastcall TFormMain::FormPaint(TObject *Sender)
{
  DrawScreen();
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::LabelQuitClick(TObject *Sender)
{
  ModalResult = 1;
}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormMain.h

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormMainH
#define UnitFormMainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <ImgList.hpp>
//---------------------------------------------------------------------------
#include <cassert>
#include <vector>
//---------------------------------------------------------------------------
enum EnumBlock { Player1, Player2, Player3, NoPlayer };
struct GameMove { int x; int y; EnumBlock anti; };
//---------------------------------------------------------------------------
class TFormMain : public TForm
{
__published: // IDE-managed Components
        TImage *Image1;
        TImage *Image2;
        TImage *Image3;
        TImage *ImageBuffer;
        TTimer *TimerThinker;
        TTimer *TimerDoer;
        TTimer *TimerDebug;
        TLabel *LabelQuit;
        void __fastcall FormMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
        void __fastcall TimerThinkerTimer(TObject *Sender);
        void __fastcall TimerDoerTimer(TObject *Sender);
        void __fastcall TimerDebugTimer(TObject *Sender);
        void __fastcall FormPaint(TObject *Sender);
        void __fastcall LabelQuitClick(TObject *Sender);
private: // User declarations
  GameMove mNextRobotMove;
  std::vector<std::vector<EnumBlock> > mBlocks;
  void DrawScreen();
  EnumBlock mPlayer;
  void CheckTwoHorizontalOwn(int& xMove,int& yMove) const;
  void CheckTwoVerticalOwn(int& xMove,int& yMove) const;
  const bool IsValidMove(const GameMove& move) const;
  const bool IsValidMove(const int x,const int y) const;
  void CheckTwoOther(int& xMove,int& yMove) const;

  const std::vector<GameMove> GetTwoHorizontalOtherMoves() const;
  const std::vector<GameMove> GetTwoVerticalOtherMoves() const;
  void CheckTwoDiagonally(int& xMove,int& yMove) const;
  void CheckOneOther(int& xMove,int& yMove) const;
  void MakeRandomMove(int& xMove,int& yMove) const;

public: // User declarations
  __fastcall TFormMain(TComponent* Owner,
    const bool player1_human,
    const bool player2_human,
    const bool player3_human
    );

  const bool m_player1_human;
  const bool m_player2_human;
  const bool m_player3_human;
  const int mMaxx;
  const int mMaxy;
  const bool IsRobot(const EnumBlock player) const;
  const String GetName(const EnumBlock player) const;
};
//---------------------------------------------------------------------------
extern PACKAGE TFormMain *FormMain;
//---------------------------------------------------------------------------
EnumBlock GetNextPlayer(const EnumBlock& player)
{
  assert(player!=NoPlayer);
  switch (player)
  {
    case Player1: return Player2;
    case Player2: return Player3;
    case Player3: return Player1;
  }
  assert(!"Should not get here");
  return Player1;
}
//---------------------------------------------------------------------------
/*
String EnumBlockToString(const EnumBlock& block)
{
  switch(block)
  {
    case Karen: return "Karen";
    case Kristel: return "Kristel";
    case Kathleen: return "Kathleen";
    case Heart: return Heart;
  }
  return Heart;
}
*/
//---------------------------------------------------------------------------
template <class T>
std::vector<T> Concatenate(const std::vector<T>& v1, const std::vector<T>& v2)
{
  std::vector<T> v(v1.size() + v2.size() );
  const int size1 = v1.size();
  const int size2 = v2.size();
  //Copy first vector
  for (int i=0; i<size1; ++i)
  {
    v[i] = v1[i];
  }
  //Copy second vector
  for (int i=0; i<size2; ++i)
  {
    v[size1+i] = v2[i];
  }
  return v;
}
//---------------------------------------------------------------------------
const double uniform();

#endif

 

 

 

 

 

UnitFormMenu.cpp

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormMenu.h"
#include "UnitFormMain.h"
//---------------------------------------------------------------------------
#include <cassert>
#include <boost\scoped_ptr.hpp>
#include "UnitFormOver.h"
#include "UnitFormSpelregels.h"
#include "UnitFormSprites.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormMenu *FormMenu;
//---------------------------------------------------------------------------
__fastcall TFormMenu::TFormMenu(TComponent* Owner)
  : TForm(Owner),
  m_player1_human(true),
  m_player2_human(true),
  m_player3_human(true)
{

}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::ImagePlayer1Click(TObject *Sender)
{
  m_player1_human = true;
  DrawPlayers();
}
//---------------------------------------------------------------------------

void __fastcall TFormMenu::ImageComputer1Click(TObject *Sender)
{
  m_player1_human = false;
  DrawPlayers();
}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::ImagePlayer2Click(TObject *Sender)
{
  m_player2_human = true;
  DrawPlayers();
}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::ImageComputer2Click(TObject *Sender)
{
  m_player2_human = false;
  DrawPlayers();
}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::ImagePlayer3Click(TObject *Sender)
{
  m_player3_human = true;
  DrawPlayers();
}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::ImageComputer3Click(TObject *Sender)
{
  m_player3_human = false;
  DrawPlayers();
}
//---------------------------------------------------------------------------
void TFormMenu::DrawPlayers()
{
  assert(FormSprites);
  if (m_player1_human)
  {
    ImagePlayer1->Picture   = FormSprites->ImagePlayer1->Picture;
    ImageComputer1->Picture = FormSprites->ImageComputer1Grey->Picture;
  }
  else
  {
    ImagePlayer1->Picture   = FormSprites->ImagePlayer1Grey->Picture;
    ImageComputer1->Picture = FormSprites->ImageComputer1->Picture;
  }
  if (m_player2_human)
  {
    ImagePlayer2->Picture   = FormSprites->ImagePlayer2->Picture;
    ImageComputer2->Picture = FormSprites->ImageComputer2Grey->Picture;
  }
  else
  {
    ImagePlayer2->Picture   = FormSprites->ImagePlayer2Grey->Picture;
    ImageComputer2->Picture = FormSprites->ImageComputer2->Picture;
  }
  if (m_player3_human)
  {
    ImagePlayer3->Picture   = FormSprites->ImagePlayer3->Picture;
    ImageComputer3->Picture = FormSprites->ImageComputer3Grey->Picture;
  }
  else
  {
    ImagePlayer3->Picture   = FormSprites->ImagePlayer3Grey->Picture;
    ImageComputer3->Picture = FormSprites->ImageComputer3->Picture;
  }

}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::ImageStartClick(TObject *Sender)
{
  boost::scoped_ptr<TFormMain> form(
    new TFormMain(0,
      m_player1_human,
      m_player2_human,
      m_player3_human));
  form->Hide();
  this->Hide();
  form->ShowModal();
  this->Show();
}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::ImageRulesClick(TObject *Sender)
{
  this->Hide();
  boost::scoped_ptr<TFormSpelregels> form(new TFormSpelregels(0));
  form->Hide();
  form->ShowModal();
  this->Show();

}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::ImageAboutClick(TObject *Sender)
{
  this->Hide();
  boost::scoped_ptr<TFormOver> form(new TFormOver(0));
  form->Hide();
  form->ShowModal();
  this->Show();
}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::ImageQuitClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormMenu.h

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormMenuH
#define UnitFormMenuH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <ImgList.hpp>
#include <ComCtrls.hpp>
#include <jpeg.hpp>
//---------------------------------------------------------------------------
class TFormMenu : public TForm
{
__published: // IDE-managed Components
        TImage *ImageComputer3;
        TImage *ImageComputer2;
        TImage *ImageComputer1;
        TImage *ImagePlayer3;
        TImage *ImagePlayer2;
        TImage *ImagePlayer1;
        TLabel *Label1;
        TLabel *Label2;
        TLabel *Label3;
        TLabel *Label4;
        TLabel *Label5;
        TLabel *Label6;
        TLabel *Label7;
        TLabel *Label8;
        TLabel *Label9;
        void __fastcall ImagePlayer1Click(TObject *Sender);
        void __fastcall ImageComputer1Click(TObject *Sender);
        void __fastcall ImagePlayer2Click(TObject *Sender);
        void __fastcall ImageComputer2Click(TObject *Sender);
        void __fastcall ImagePlayer3Click(TObject *Sender);
        void __fastcall ImageComputer3Click(TObject *Sender);
        void __fastcall ImageStartClick(TObject *Sender);
        void __fastcall ImageAboutClick(TObject *Sender);
        void __fastcall ImageRulesClick(TObject *Sender);
        void __fastcall ImageQuitClick(TObject *Sender);
private: // User declarations
  bool m_player1_human;
  bool m_player2_human;
  bool m_player3_human;
  void DrawPlayers();
public: // User declarations
        __fastcall TFormMenu(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormMenu *FormMenu;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormOver.cpp

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include <boost/scoped_ptr.hpp>
#include "UnitFormOver.h"
#include "UnitFormAdditionalCopyright.h"
#include "UnitFormWhatsNew.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormOver *FormOver;
//---------------------------------------------------------------------------
__fastcall TFormOver::TFormOver(TComponent* Owner)
        : TForm(Owner)
{

}
//---------------------------------------------------------------------------
void __fastcall TFormOver::ButtonWhatsNewClick(TObject *Sender)
{
  boost::scoped_ptr<TFormWhatsNew> f(new TFormWhatsNew(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TFormOver::ButtonAdditionalCopyrightClick(TObject *Sender)
{
  boost::scoped_ptr<TFormAdditionalCopyright> f(new TFormAdditionalCopyright(0));
  f->ShowModal();

}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormOver.h

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormOverH
#define UnitFormOverH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <jpeg.hpp>
#include <Graphics.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TFormOver : public TForm
{
__published: // IDE-managed Components
        TImage *ImageRichel;
        TRichEdit *RichEditLicence;
        TLabel *Label1;
        TLabel *Label2;
        TLabel *Label3;
        TLabel *Label4;
        TLabel *Label5;
        TLabel *Label6;
        TButton *ButtonWhatsNew;
        TButton *ButtonAdditionalCopyright;
        void __fastcall ButtonWhatsNewClick(TObject *Sender);
        void __fastcall ButtonAdditionalCopyrightClick(TObject *Sender);
private: // User declarations
public: // User declarations
        __fastcall TFormOver(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormOver *FormOver;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormSpelregels.cpp

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormSpelregels.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSpelregels *FormSpelregels;
//---------------------------------------------------------------------------
__fastcall TFormSpelregels::TFormSpelregels(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormSpelregels.h

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormSpelregelsH
#define UnitFormSpelregelsH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <jpeg.hpp>
//---------------------------------------------------------------------------
class TFormSpelregels : public TForm
{
__published: // IDE-managed Components
        TImage *Image1;
        TImage *Image2;
        TImage *Image3;
        TLabel *LabelQuit;
        TLabel *Label1;
        TLabel *Label2;
        TLabel *Label3;
        TLabel *Label4;
        TLabel *Label5;
        TLabel *Label6;
private: // User declarations
public: // User declarations
        __fastcall TFormSpelregels(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormSpelregels *FormSpelregels;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormSprites.cpp

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormSprites.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSprites *FormSprites;
//---------------------------------------------------------------------------
__fastcall TFormSprites::TFormSprites(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormSprites.h

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormSpritesH
#define UnitFormSpritesH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <jpeg.hpp>
//---------------------------------------------------------------------------
class TFormSprites : public TForm
{
__published: // IDE-managed Components
        TImage *ImagePlayer3;
        TImage *ImagePlayer1;
        TImage *ImagePlayer2;
        TImage *ImageEmpty;
        TImage *ImagePlayer1Grey;
        TImage *ImagePlayer2Grey;
        TImage *ImagePlayer3Grey;
        TImage *ImageComputer1;
        TImage *ImageComputer1Grey;
        TImage *ImageComputer2;
        TImage *ImageComputer3;
        TImage *ImageComputer2Grey;
        TImage *ImageComputer3Grey;
        TImage *ImagePlayerRed;
        TImage *ImageComputerRed;
        TLabel *Label1;
private: // User declarations
public: // User declarations
        __fastcall TFormSprites(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormSprites *FormSprites;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormStoppen.cpp

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormStoppen.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormStoppen *FormStoppen;
//---------------------------------------------------------------------------
__fastcall TFormStoppen::TFormStoppen(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormStoppen::OnAgainClick(TObject *Sender)
{
  this->ModalResult = 1;
}
//---------------------------------------------------------------------------

void __fastcall TFormStoppen::OnQuitClick(TObject *Sender)
{
  this->ModalResult = 2;
}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormStoppen.h

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormStoppenH
#define UnitFormStoppenH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <jpeg.hpp>
//---------------------------------------------------------------------------
class TFormStoppen : public TForm
{
__published: // IDE-managed Components
        TLabel *Label1;
        TLabel *Label2;
        TLabel *Label3;
        TImage *ImagePlayer1Grey;
        TImage *Image1;
        TImage *Image2;
        TImage *Image3;
        TImage *Image4;
        TImage *Image5;
        TLabel *Label4;
        TLabel *Label5;
        void __fastcall OnAgainClick(TObject *Sender);
        void __fastcall OnQuitClick(TObject *Sender);
private: // User declarations
public: // User declarations
        __fastcall TFormStoppen(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormStoppen *FormStoppen;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormWhatsNew.cpp

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormWhatsNew.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormWhatsNew *FormWhatsNew;
//---------------------------------------------------------------------------
__fastcall TFormWhatsNew::TFormWhatsNew(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormWhatsNew.h

 

//---------------------------------------------------------------------------
/*
    Met Z'n Drieen. A 3-player tic-tac-toe-like game.
    Copyright (C) 2010  Richel Bilderbeek

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormWhatsNewH
#define UnitFormWhatsNewH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TFormWhatsNew : public TForm
{
__published: // IDE-managed Components
        TRichEdit *RichEdit;
private: // User declarations
public: // User declarations
        __fastcall TFormWhatsNew(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormWhatsNew *FormWhatsNew;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict