Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) The Tron Collection source code (version 0.9)

 

The Tron Collection version 0.9 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:

 

 

 

 

 

ProjectClassicTron.cpp

 

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

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("UnitFormClassicTronGame.cpp", FormClassicTronGame);
USEFORM("UnitFormClassicTronMenu.cpp", FormClassicTronMenu);
USEFORM("UnitFormPressKey.cpp", FormPressKey);
USEFORM("UnitFormSelectColor.cpp", FormSelectColor);
USEFORM("UnitFormChart.cpp", FormChart);
USEFORM("UnitFormClassicTronAbout.cpp", FormClassicTronAbout);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->Title = "Classic Tron";
                 Application->CreateForm(__classid(TFormClassicTronMenu), &FormClassicTronMenu);
     Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }
        catch (...)
        {
                 try
                 {
                         throw Exception("");
                 }
                 catch (Exception &exception)
                 {
                         Application->ShowException(&exception);
                 }
        }
        return 0;
}
//---------------------------------------------------------------------------

 

 

 

 

 

ProjectSuperTron.cpp

 

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

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("UnitFormSuperTronMenu.cpp", FormSuperTronMenu);
USEFORM("UnitFormPressKey.cpp", FormPressKey);
USEFORM("UnitFormSelectColor.cpp", FormSelectColor);
USEFORM("UnitFormChart.cpp", FormChart);
USEFORM("UnitFormSuperTronAbout.cpp", FormSuperTronAbout);
USEFORM("UnitFormSuperTronGame.cpp", FormSuperTronGame);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->Title = "Super Turbo";
     Application->CreateForm(__classid(TFormSuperTronMenu), &FormSuperTronMenu);
     Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }
        catch (...)
        {
                 try
                 {
                         throw Exception("");
                 }
                 catch (Exception &exception)
                 {
                         Application->ShowException(&exception);
                 }
        }
        return 0;
}
//---------------------------------------------------------------------------

 

 

 

 

 

ProjectTronCollection.cpp

 

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

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("UnitFormTronCollectionMenu.cpp", FormTronCollectionMenu);
USEFORM("UnitFormClassicTronAbout.cpp", FormClassicTronAbout);
USEFORM("UnitFormClassicTronGame.cpp", FormClassicTronGame);
USEFORM("UnitFormClassicTronMenu.cpp", FormClassicTronMenu);
USEFORM("UnitFormSuperTronAbout.cpp", FormSuperTronAbout);
USEFORM("UnitFormSuperTronGame.cpp", FormSuperTronGame);
USEFORM("UnitFormSuperTronMenu.cpp", FormSuperTronMenu);
USEFORM("UnitFormChart.cpp", FormChart);
USEFORM("UnitFormPressKey.cpp", FormPressKey);
USEFORM("UnitFormSelectColor.cpp", FormSelectColor);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->Title = "The Tron Collection";
                 Application->CreateForm(__classid(TFormTronCollectionMenu), &FormTronCollectionMenu);
     Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }
        catch (...)
        {
                 try
                 {
                         throw Exception("");
                 }
                 catch (Exception &exception)
                 {
                         Application->ShowException(&exception);
                 }
        }
        return 0;
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitClassicTronPlayer.cpp

 

//---------------------------------------------------------------------------
/*
  Classic Tron, a simple game
  Copyright (C) 2008 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
//---------------------------------------------------------------------------
#pragma hdrstop

#include "UnitClassicTronPlayer.h"

//---------------------------------------------------------------------------
ClassicTronPlayer::ClassicTronPlayer()
  : x(0),
    y(0),
    direction(0),
    nWins(0),
    nLose(0),
    color(static_cast<TColor>(0)),
    keyLeft(0),
    keyRight(0)
{

}

#pragma package(smart_init)

 

 

 

 

 

UnitClassicTronPlayer.h

 

//---------------------------------------------------------------------------
/*
  Classic Tron, a simple game
  Copyright (C) 2008 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 UnitClassicTronPlayerH
#define UnitClassicTronPlayerH
//---------------------------------------------------------------------------
#include <Graphics.hpp> //For TColor
//#include <windef.h>
typedef unsigned short WORD;
//---------------------------------------------------------------------------
struct ClassicTronPlayer
{
  ClassicTronPlayer();
  int x;
  int y;
  int direction;
  int nWins;
  int nLose;
  Graphics::TColor color;
  WORD keyLeft;
  WORD keyRight;
};

#endif

 

 

 

 

 

UnitFormChart.cpp

 

//---------------------------------------------------------------------------
/*
  The Tron Collection, three simple tron games
  Copyright (C) 2008 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 <cassert>
#include <vcl.h>
#pragma hdrstop

#include "UnitFormChart.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormChart *FormChart;
//---------------------------------------------------------------------------
__fastcall TFormChart::TFormChart(
  TComponent* Owner,
  const std::vector<int>& losses,
  const std::vector<int>& wins)
  : TForm(Owner),
    mCanClose(false)
{
  assert(losses.size() == wins.size() );
  std::vector<double> lossesDouble(losses.size());
  std::vector<double> winsDouble(wins.size());
  std::copy(losses.begin(), losses.end(), lossesDouble.begin());
  std::copy(wins.begin(), wins.end(), winsDouble.begin());
  Chart1->Series[0]->AddArray( &(lossesDouble[0]), lossesDouble.size() - 1);
  Chart1->Series[1]->AddArray( &(winsDouble[0]), winsDouble.size() - 1);
}
//---------------------------------------------------------------------------
void __fastcall TFormChart::Timer1Timer(TObject *Sender)
{
  mCanClose = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormChart::ButtonCloseClick(TObject *Sender)
{
  if (mCanClose == true) Close();
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormChart.h

 

//---------------------------------------------------------------------------
/*
  The Tron Collection, three simple tron games
  Copyright (C) 2008 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 UnitFormChartH
#define UnitFormChartH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Chart.hpp>
#include <ExtCtrls.hpp>
#include <Series.hpp>
#include <TeEngine.hpp>
#include <TeeProcs.hpp>
//---------------------------------------------------------------------------
#include <vector>
//---------------------------------------------------------------------------
class TFormChart : public TForm
{
__published: // IDE-managed Components
        TChart *Chart1;
        TBarSeries *Series1;
        TBarSeries *Series2;
        TTimer *Timer1;
        TPanel *Panel1;
        TButton *ButtonClose;
        void __fastcall Timer1Timer(TObject *Sender);
        void __fastcall ButtonCloseClick(TObject *Sender);
private: // User declarations
  bool mCanClose;
public: // User declarations
  __fastcall TFormChart(
    TComponent* Owner,
    const std::vector<int>& losses,
    const std::vector<int>& wins);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormChart *FormChart;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormClassicTronAbout.cpp

 

//---------------------------------------------------------------------------
/*
  Classic Tron, a simple game
  Copyright (C) 2008 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 "UnitFormClassicTronAbout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormClassicTronAbout *FormClassicTronAbout;
//---------------------------------------------------------------------------
__fastcall TFormClassicTronAbout::TFormClassicTronAbout(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormClassicTronAbout.h

 

//---------------------------------------------------------------------------
/*
  Classic Tron, a simple game
  Copyright (C) 2008 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 UnitFormClassicTronAboutH
#define UnitFormClassicTronAboutH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormClassicTronAbout : public TForm
{
__published: // IDE-managed Components
        TImage *Image1;
        TRichEdit *RichEdit1;
        TPanel *PanelTop;
        TPanel *PanelTopLeft;
        TLabel *Label1;
        TLabel *Label2;
        TLabel *Label3;
        TLabel *Label4;
        TLabel *Label5;
        TLabel *Label6;
        TLabel *Label7;
        TLabel *Label8;
        TLabel *Label9;
        TLabel *Label10;
        TLabel *Label11;
private: // User declarations
public: // User declarations
        __fastcall TFormClassicTronAbout(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormClassicTronAbout *FormClassicTronAbout;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormClassicTronGame.cpp

 

//---------------------------------------------------------------------------
/*
  Classic Tron, a simple game
  Copyright (C) 2008 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 <memory>
#include <cmath>
#include <cassert>
#include "UnitGraphics.h"
#include <vcl.h>
#pragma hdrstop

#include "UnitFormClassicTronGame.h"
#include "UnitFormChart.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormClassicTronGame *FormClassicTronGame;
//---------------------------------------------------------------------------
__fastcall TFormClassicTronGame::TFormClassicTronGame(
  TComponent* Owner,
  const std::vector<Player>& players,
  const int speed,
  const int maxx,
  const int maxy,
  const bool donutShapedWorld,
  const bool canWalkThroughOwnColor)
  : TForm(Owner),
    mPlayers(players),
    mMaxx(maxx),
    mMaxy(maxy),
    mDonutShapedWorld(donutShapedWorld),
    mCanWalkThroughOwnColor(canWalkThroughOwnColor)
{
  this->Constraints->MinWidth = maxx + (Width - ClientWidth);
  this->Constraints->MinHeight = maxy + (Height - ClientHeight);

  //Put the players on screen in the correct position
  {
    const int nPlayers = mPlayers.size();
    for (int i=0; i!=nPlayers; ++i)
    {
      const double fraction = static_cast<double>(i) / static_cast<double>(nPlayers);
      const double angle = (0.5 * M_PI) + ( fraction * M_PI * 2.0);
      mPlayers[i].x = (static_cast<double>(mMaxx) / 2.0)
        + ( std::sin( angle ) * 10.0 );
      mPlayers[i].y = (static_cast<double>(mMaxx) / 2.0)
        + ( -std::cos( angle ) * 10.0 );
      if (angle < 0.75 * M_PI) mPlayers[i].direction = 1;
      else if (angle < 1.25 * M_PI) mPlayers[i].direction = 2;
      else if (angle < 1.75 * M_PI) mPlayers[i].direction = 3;
      else if (angle < 2.25 * M_PI) mPlayers[i].direction = 0;
      else if (angle < 2.75 * M_PI) mPlayers[i].direction = 1;
    }
  }
  TimerGame->Interval = speed;
  ImageBuffer->Picture->Graphic->Width = mMaxx;
  ImageBuffer->Picture->Graphic->Height = mMaxy;
  PaintVcl(ImageBuffer,clBlack);
  TimerGame->OnTimer(0);
}
//---------------------------------------------------------------------------
void __fastcall TFormClassicTronGame::FormKeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
  const std::vector<Player>::iterator j = mPlayers.end();
  for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
  {
    if (i->keyLeft == Key) { i->direction = (i->direction + 3) % 4; }
    if (i->keyRight == Key) { i->direction = (i->direction + 1) % 4; }
  }
  //Caption = Key;
}
//---------------------------------------------------------------------------
void __fastcall TFormClassicTronGame::TimerGameTimer(TObject *Sender)
{
  //Check for collisions
  {
    const std::vector<Player>::iterator j = mPlayers.end();
    for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
    {
      int xTo = (*i).x;
      int yTo = (*i).y;
      switch ((*i).direction)
      {
        case 0: //Up
          yTo = (*i).y - 1;
          if (mDonutShapedWorld == true && yTo < 0) yTo+=mMaxy;
          break;
        case 1: //Right
          xTo = (*i).x + 1;
          if (mDonutShapedWorld == true && xTo >= mMaxx) xTo-=mMaxx;
          break;
        case 2: //Down
          yTo = (*i).y + 1;
          if (mDonutShapedWorld == true && yTo >= mMaxy) yTo-=mMaxy;
          break;
        case 3: //Left
          xTo = (*i).x - 1;
          if (mDonutShapedWorld == true && xTo < 0) xTo+=mMaxx;
          break;
      }
      if (mDonutShapedWorld == false
        && ( xTo < 0 || yTo < 0 || xTo >= mMaxx || yTo >= mMaxy) )
      {
        RemovePointFromLosers( (*i).color );
        RemoveColor(ImageBuffer, (*i).color );
        (*i).direction = ((*i).direction + 2) % 4;
        continue;
      }
      const TColor color = GetPixelVcl(ImageBuffer, xTo, yTo);
      if (color == clBlack || color == static_cast<TColor>(-1) ) continue; //Nothing there...
      if (color!=(*i).color)
      {
        AddPointToWinners(color);
        RemovePointFromLosers( (*i).color );
        RemoveColor(ImageBuffer, color );
      }
      if (mCanWalkThroughOwnColor == false && color==(*i).color)
      {
        RemovePointFromLosers( (*i).color );
        RemoveColor(ImageBuffer, color );
      }
    }
  }

  //Move the players
  {
    const std::vector<Player>::iterator j = mPlayers.end();
    for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
    {
      switch ((*i).direction)
      {
        case 0: //Up
          --(*i).y;
          if ((*i).y < 0) (*i).y+=mMaxy;
          break;
        case 1: //Right
          ++(*i).x;
          if ((*i).x >= mMaxx) (*i).x-=mMaxx;
          break;
        case 2: //Down
          ++(*i).y;
          if ((*i).y >= mMaxy) (*i).y-=mMaxy;
          break;
        case 3: //Left
          --(*i).x;
          if ((*i).x < 0) (*i).x+=mMaxx;
          break;
      }
    }
  }


  //Draw new player locations to buffer
  {
    const std::vector<Player>::iterator j = mPlayers.end();
    for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
    {
      SetPixel(ImageBuffer, (*i).x, (*i).y, (*i).color );
    }
  }

  //Draw buffer to screen
  Canvas->StretchDraw(this->ClientRect,ImageBuffer->Picture->Graphic);
}
//---------------------------------------------------------------------------
void TFormClassicTronGame::AddPointToWinners(const TColor color)
{
  const std::vector<Player>::iterator j = mPlayers.end();
  for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
  {
    if (i->color == color) ++(i->nWins);
  }
}
//---------------------------------------------------------------------------
void TFormClassicTronGame::RemovePointFromLosers(const TColor color)
{
  const std::vector<Player>::iterator j = mPlayers.end();
  for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
  {
    if (i->color == color) ++(i->nLose);
  }
}
//---------------------------------------------------------------------------
void __fastcall TFormClassicTronGame::FormClose(TObject *Sender,
      TCloseAction &Action)
{
  TimerGame->Enabled = false;
  const int size = mPlayers.size();
  std::vector<int> losses(size);
  std::vector<int> wins(size);
  for (int i=0; i!=size; ++i)
  {
    losses[i] = mPlayers[i].nLose;
    wins[i] = mPlayers[i].nWins;
  }

  std::auto_ptr<TFormChart> f(new TFormChart(0,losses,wins));
  f->ShowModal();
}
//---------------------------------------------------------------------------



 

 

 

 

 

UnitFormClassicTronGame.h

 

//---------------------------------------------------------------------------
/*
  Classic Tron, a simple game
  Copyright (C) 2008 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 UnitFormClassicTronGameH
#define UnitFormClassicTronGameH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
#include <vector>
#include "UnitClassicTronPlayer.h"
//---------------------------------------------------------------------------
class TFormClassicTronGame : public TForm
{
__published: // IDE-managed Components
        TImage *ImageBuffer;
        TTimer *TimerGame;
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall TimerGameTimer(TObject *Sender);
        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private: // User declarations
  typedef ClassicTronPlayer Player;
  std::vector<Player> mPlayers;
  const bool mDonutShapedWorld;
  const bool mCanWalkThroughOwnColor;
  const int mMaxx;
  const int mMaxy;
  void AddPointToWinners(const TColor color);
  void RemovePointFromLosers(const TColor color);

public: // User declarations
  __fastcall TFormClassicTronGame(TComponent* Owner,
    const std::vector<Player>& players,
    const int speed,
    const int maxx,
    const int maxy,
    const bool donutShapedWorld,
    const bool canWalkThroughOwnColor);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormClassicTronGame *FormClassicTronGame;
//---------------------------------------------------------------------------



#endif

 

 

 

 

 

UnitFormClassicTronMenu.cpp

 

//---------------------------------------------------------------------------
/*
  Classic Tron, a simple game
  Copyright (C) 2008 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 <cassert>
#include <memory>
#include <algorithm>
#include <cassert>
#include <cmath>
#include "UnitGraphics.h"
#include <vcl.h>
#pragma hdrstop

#include "UnitFormClassicTronMenu.h"
#include "UnitFormPressKey.h"
#include "UnitFormSelectColor.h"
#include "UnitFormClassicTronGame.h"
#include "UnitFormClassicTronAbout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormClassicTronMenu *FormClassicTronMenu;
//---------------------------------------------------------------------------
__fastcall TFormClassicTronMenu::TFormClassicTronMenu(TComponent* Owner)
  : TForm(Owner),
    mDonutShapedWorld(true),
    mCanWalkThroughOwnColor(false)
{
  ImageNplayersMinus->Picture->Graphic->Width = 80;
  ImageNplayersMinus->Picture->Graphic->Height = 80;
  ImageNplayersPlus->Picture->Graphic->Width = 80;
  ImageNplayersPlus->Picture->Graphic->Height = 80;
  DrawGlobeMinus(ImageNplayersMinus,255,196,196);
  DrawGlobePlus(ImageNplayersPlus,196,196,255);

  TrackBarSpeed->OnChange(0);
  TrackBarWidth->OnChange(0);
  TrackBarHeight->OnChange(0);
}
//---------------------------------------------------------------------------

void __fastcall TFormClassicTronMenu::ButtonCalibrateClick(TObject *Sender)
{
  const int nPlayers = PanelNplayers->Caption.ToIntDef(-1);
  assert(nPlayers!=-1);
  mPlayers.resize(nPlayers);
  for (int i=0; i!=nPlayers; ++i)
  {
    //Key left
    {
      const String message = "Player #" + IntToStr(i+1) + ", please press key for 'Turn left'.";
      std::auto_ptr<TFormPressKey> f(new TFormPressKey(0,message));
      f->ShowModal();
      mPlayers[i].keyLeft = f->ModalResult;
    }
    //Key right
    {
      const String message = "Player #" + IntToStr(i+1) + ", please press key for 'Turn right'.";
      std::auto_ptr<TFormPressKey> f(new TFormPressKey(0,message));
      f->ShowModal();
      mPlayers[i].keyRight = f->ModalResult;
    }
    //Color
    //Choose color
    {
      std::auto_ptr<TFormSelectColor> f(new TFormSelectColor(0));
      f->ShowModal();
      const int colorIndex = f->ModalResult - 10;
      assert(colorIndex >= 0 && colorIndex < 20);
      const double fraction = static_cast<double>(colorIndex) / 20.0;
      unsigned char r,g,b;
      Rainbow(fraction,r,g,b);
      mPlayers[i].color = RgbToColor(r,g,b);
    }
  }
  ButtonStart->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormClassicTronMenu::ButtonStartClick(TObject *Sender)
{
  const double fractionSpeed
  = static_cast<double>(TrackBarSpeed->Position)
  / static_cast<double>(TrackBarSpeed->Max);
  const double fractionWidth
  = static_cast<double>(TrackBarWidth->Position)
  / static_cast<double>(TrackBarWidth->Max);
  const double fractionHeight
  = static_cast<double>(TrackBarHeight->Position)
  / static_cast<double>(TrackBarHeight->Max);

  const int speed = 1000.0 - (fractionSpeed * 999.0);
  assert(speed > 0);
  const int maxx = 100.0 + (fractionWidth * static_cast<double>(Monitor->Width - 200));
  const int maxy = 100.0 + (fractionHeight * static_cast<double>(Monitor->Height - 200));
  std::auto_ptr<TFormClassicTronGame> f(
    new TFormClassicTronGame(
      0,
      mPlayers,
      speed,
      maxx,
      maxy,
      mDonutShapedWorld,
      mCanWalkThroughOwnColor
      ));
  f->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TFormClassicTronMenu::FormKeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
  switch(Key)
  {
    case VK_ADD:
      ImageNplayersPlus->OnClick(0);
      break;
    case VK_SUBTRACT:
      ImageNplayersMinus->OnClick(0);
      break;
    case 83: // 's'
      if (mDonutShapedWorld == true)
      {
        ImageWorldFlat->OnClick(0);
      }
      else
      {
        ImageWorldDonut->OnClick(0);
      }
      break;
    case 72: // 'h'
      if (mCanWalkThroughOwnColor == true)
      {
        ImageCannotWalkThroughOwnColor->OnClick(0);
      }
      else
      {
        ImageCanWalkThroughOwnColor->OnClick(0);
      }
      break;
  }
}
//---------------------------------------------------------------------------
void __fastcall TFormClassicTronMenu::ImageNplayersMinusClick(
      TObject *Sender)
{
  const int nPlayers = PanelNplayers->Caption.ToIntDef(-1);
  assert(nPlayers!=-1);
  if (nPlayers > 2)
  {
    PanelNplayers->Caption = IntToStr(nPlayers - 1);
    ButtonStart->Enabled = false;
  }
}
//---------------------------------------------------------------------------
void __fastcall TFormClassicTronMenu::ImageNplayersPlusClick(
      TObject *Sender)
{
  const int nPlayers = PanelNplayers->Caption.ToIntDef(-1);
  assert(nPlayers!=-1);
  if (nPlayers < 20)
  {
    PanelNplayers->Caption = IntToStr(nPlayers + 1);
    ButtonStart->Enabled = false;
  }
}
//---------------------------------------------------------------------------

void __fastcall TFormClassicTronMenu::TrackBarSpeedChange(TObject *Sender)
{
  const double fraction
  = static_cast<double>(TrackBarSpeed->Position)
  / static_cast<double>(TrackBarSpeed->Max);
  if (fraction < 0.1) PanelSpeedValue->Caption = "Slowest";
  else if (fraction < 0.40) PanelSpeedValue->Caption = "Slow";
  else if (fraction < 0.60) PanelSpeedValue->Caption = "Normal";
  else if (fraction < 0.90) PanelSpeedValue->Caption = "Fast";
  else PanelSpeedValue->Caption = "Fastest";
}
//---------------------------------------------------------------------------

void __fastcall TFormClassicTronMenu::TrackBarWidthChange(TObject *Sender)
{
  const double fraction
  = static_cast<double>(TrackBarWidth->Position)
  / static_cast<double>(TrackBarWidth->Max);
  if (fraction < 0.1) PanelWidthValue->Caption = "Smallest";
  else if (fraction < 0.40) PanelWidthValue->Caption = "Small";
  else if (fraction < 0.60) PanelWidthValue->Caption = "Medium";
  else if (fraction < 0.90) PanelWidthValue->Caption = "Large";
  else PanelWidthValue->Caption = "Largest";
}
//---------------------------------------------------------------------------

void __fastcall TFormClassicTronMenu::TrackBarHeightChange(TObject *Sender)
{
  const double fraction
  = static_cast<double>(TrackBarHeight->Position)
  / static_cast<double>(TrackBarHeight->Max);
  if (fraction < 0.1) PanelHeightValue->Caption = "Smallest";
  else if (fraction < 0.40) PanelHeightValue->Caption = "Small";
  else if (fraction < 0.60) PanelHeightValue->Caption = "Medium";
  else if (fraction < 0.90) PanelHeightValue->Caption = "Large";
  else PanelHeightValue->Caption = "Largest";
}
//---------------------------------------------------------------------------

void __fastcall TFormClassicTronMenu::ImageWorldFlatClick(TObject *Sender)
{
  ImageWorldChosen->Picture->Graphic = ImageWorldFlat->Picture->Graphic;
  mDonutShapedWorld = false;
}
//---------------------------------------------------------------------------

void __fastcall TFormClassicTronMenu::ImageWorldDonutClick(TObject *Sender)
{
  ImageWorldChosen->Picture->Graphic = ImageWorldDonut->Picture->Graphic;
  mDonutShapedWorld = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormClassicTronMenu::ImageCanWalkThroughOwnColorClick(
      TObject *Sender)
{
  ImageCanWalkThroughOwnColorChosen->Picture->Graphic
  = ImageCanWalkThroughOwnColor->Picture->Graphic;
  mCanWalkThroughOwnColor = true;
}
//---------------------------------------------------------------------------

void __fastcall TFormClassicTronMenu::ImageCannotWalkThroughOwnColorClick(
      TObject *Sender)
{
  ImageCanWalkThroughOwnColorChosen->Picture->Graphic
  = ImageCannotWalkThroughOwnColor->Picture->Graphic;
  mCanWalkThroughOwnColor = false;
}
//---------------------------------------------------------------------------
void __fastcall TFormClassicTronMenu::ButtonAboutClick(TObject *Sender)
{
  std::auto_ptr<TFormClassicTronAbout> f(new TFormClassicTronAbout(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------




 

 

 

 

 

UnitFormClassicTronMenu.h

 

//---------------------------------------------------------------------------
/*
  Classic Tron, a simple game
  Copyright (C) 2008 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 UnitFormClassicTronMenuH
#define UnitFormClassicTronMenuH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
#include <vector>
#include "UnitClassicTronPlayer.h"
//---------------------------------------------------------------------------
class TFormClassicTronMenu : public TForm
{
__published: // IDE-managed Components
        TButton *ButtonStart;
        TPanel *PanelSpeed;
        TPanel *PanelSpeedValue;
        TTrackBar *TrackBarSpeed;
        TPanel *PanelWidth;
        TPanel *PanelWidthValue;
        TTrackBar *TrackBarWidth;
        TPanel *PanelHeight;
        TPanel *PanelHeightValue;
        TTrackBar *TrackBarHeight;
        TPanel *PanelWorld;
        TPanel *PanelCanThroughOwnColor;
        TImage *ImageWorldDonut;
        TImage *ImageCannotWalkThroughOwnColor;
        TImage *ImageWorldFlat;
        TImage *ImageCanWalkThroughOwnColorChosen;
        TImage *ImageCanWalkThroughOwnColor;
        TImage *ImageWorldChosen;
        TStaticText *StaticText1;
        TStaticText *TextWalkThroughOwnColor;
        TButton *ButtonCalibrate;
        TPanel *PanelNplayers;
        TImage *ImageNplayersPlus;
        TImage *ImageNplayersMinus;
        TStaticText *TextNplayers;
        TPanel *PanelSpeedText;
        TPanel *PanelWidthText;
        TPanel *PanelHeightText;
        TButton *ButtonAbout;
        void __fastcall ButtonCalibrateClick(TObject *Sender);
        void __fastcall ImageNplayersMinusClick(TObject *Sender);
        void __fastcall ImageNplayersPlusClick(TObject *Sender);
        void __fastcall TrackBarSpeedChange(TObject *Sender);
        void __fastcall TrackBarWidthChange(TObject *Sender);
        void __fastcall TrackBarHeightChange(TObject *Sender);
        void __fastcall ImageWorldFlatClick(TObject *Sender);
        void __fastcall ImageWorldDonutClick(TObject *Sender);
        void __fastcall ButtonStartClick(TObject *Sender);
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ImageCanWalkThroughOwnColorClick(TObject *Sender);
        void __fastcall ImageCannotWalkThroughOwnColorClick(
          TObject *Sender);
        void __fastcall ButtonAboutClick(TObject *Sender);
private: // User declarations
  typedef ClassicTronPlayer Player;
  std::vector<Player> mPlayers;
  bool mDonutShapedWorld;
  bool mCanWalkThroughOwnColor;
public: // User declarations
        __fastcall TFormClassicTronMenu(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormClassicTronMenu *FormClassicTronMenu;
//---------------------------------------------------------------------------

#endif

 

 

 

 

 

UnitFormPressKey.cpp

 

//---------------------------------------------------------------------------
/*
  The Tron Collection, three simple tron games
  Copyright (C) 2008 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 "UnitFormPressKey.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormPressKey *FormPressKey;
//---------------------------------------------------------------------------
__fastcall TFormPressKey::TFormPressKey(
  TComponent* Owner, const String& text)
        : TForm(Owner)
{
  Caption = text;
  Panel1->Caption = text;
}
//---------------------------------------------------------------------------
void __fastcall TFormPressKey::FormKeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
  ModalResult = Key;
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormPressKey.h

 

//---------------------------------------------------------------------------
/*
  The Tron Collection, three simple tron games
  Copyright (C) 2008 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 UnitFormPressKeyH
#define UnitFormPressKeyH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TFormPressKey : public TForm
{
__published: // IDE-managed Components
        TPanel *Panel1;
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
private: // User declarations
public: // User declarations
  __fastcall TFormPressKey(TComponent* Owner, const String& text);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormPressKey *FormPressKey;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormSelectColor.cpp

 

//---------------------------------------------------------------------------
/*
  The Tron Collection, three simple tron games
  Copyright (C) 2008 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 <cassert>
#include <cmath>
#include <algorithm>
#include <vcl.h>
#pragma hdrstop

#include "UnitFormSelectColor.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSelectColor *FormSelectColor;
//---------------------------------------------------------------------------
__fastcall TFormSelectColor::TFormSelectColor(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormSelectColor::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  switch (Key)
  {
    case VK_F1 : ModalResult = 10; break;
    case VK_F2 : ModalResult = 11; break;
    case VK_F3 : ModalResult = 12; break;
    case VK_F4 : ModalResult = 13; break;
    case VK_F5 : ModalResult = 14; break;
    case VK_F6 : ModalResult = 15; break;
    case VK_F7 : ModalResult = 16; break;
    case VK_F8 : ModalResult = 17; break;
    case VK_F9 : ModalResult = 18; break;
    case VK_F10: ModalResult = 19; break;
    case 49: ModalResult = 20; break;
    case 50: ModalResult = 21; break;
    case 51: ModalResult = 22; break;
    case 52: ModalResult = 23; break;
    case 53: ModalResult = 24; break;
    case 54: ModalResult = 25; break;
    case 55: ModalResult = 26; break;
    case 56: ModalResult = 27; break;
    case 57: ModalResult = 28; break;
    case 48: ModalResult = 29; break;
  }
}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormSelectColor.h

 

//---------------------------------------------------------------------------
/*
  The Tron Collection, three simple tron games
  Copyright (C) 2008 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 UnitFormSelectColorH
#define UnitFormSelectColorH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormSelectColor : public TForm
{
__published: // IDE-managed Components
        TImage *ImageColors;
        TPanel *PanelColors;
        TPanel *Panel3;
        TPanel *Panel4;
        TPanel *Panel5;
        TPanel *Panel6;
        TPanel *Panel7;
        TPanel *Panel8;
        TPanel *Panel9;
        TPanel *Panel10;
        TPanel *Panel11;
        TPanel *Panel12;
        TPanel *Panel13;
        TPanel *Panel14;
        TPanel *Panel15;
        TPanel *Panel16;
        TPanel *Panel17;
        TPanel *Panel18;
        TPanel *Panel19;
        TPanel *Panel20;
        TPanel *Panel21;
        TPanel *Panel22;
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
private: // User declarations
public: // User declarations
  __fastcall TFormSelectColor(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormSelectColor *FormSelectColor;
//---------------------------------------------------------------------------



#endif

 

 

 

 

 

UnitFormSuperTronAbout.cpp

 

//---------------------------------------------------------------------------
/*
  Super Tron, a simple game
  Copyright (C) 2008 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 "UnitFormSuperTronAbout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSuperTronAbout *FormSuperTronAbout;
//---------------------------------------------------------------------------
__fastcall TFormSuperTronAbout::TFormSuperTronAbout(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormSuperTronAbout.h

 

//---------------------------------------------------------------------------
/*
  Super Tron, a simple game
  Copyright (C) 2008 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 UnitFormSuperTronAboutH
#define UnitFormSuperTronAboutH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormSuperTronAbout : public TForm
{
__published: // IDE-managed Components
  TImage *ImageAuthor;
        TRichEdit *RichEdit1;
        TPanel *PanelTop;
        TPanel *PanelTopLeft;
        TLabel *Label2;
        TLabel *Label3;
        TLabel *Label4;
        TLabel *Label6;
        TLabel *Label7;
        TLabel *Label8;
        TLabel *Label9;
        TLabel *Label11;
  TPanel *PanelBlank;
  TPanel *Panel1;
private: // User declarations
public: // User declarations
        __fastcall TFormSuperTronAbout(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormSuperTronAbout *FormSuperTronAbout;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormSuperTronGame.cpp

 

//---------------------------------------------------------------------------
/*
  Super Tron, a simple game
  Copyright (C) 2008 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 <memory>
#include <cmath>
#include <cassert>
#include "UnitGraphics.h"
#include <vcl.h>
#pragma hdrstop

#include "UnitFormSuperTronGame.h"
#include "UnitFormChart.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSuperTronGame *FormSuperTronGame;
//---------------------------------------------------------------------------
__fastcall TFormSuperTronGame::TFormSuperTronGame(
  TComponent* Owner,
  const std::vector<Player>& players,
  const int speed,
  const int maxx,
  const int maxy,
  const bool donutShapedWorld,
  const bool canWalkThroughOwnColor)
  : TForm(Owner),
    mPlayers(players),
    mMaxx(maxx),
    mMaxy(maxy),
    mDonutShapedWorld(donutShapedWorld),
    mCanWalkThroughOwnColor(canWalkThroughOwnColor)
{
  this->Constraints->MinWidth = maxx + (Width - ClientWidth);
  this->Constraints->MinHeight = maxy + (Height - ClientHeight);

  //Put the players on screen in the correct position
  {
    const int nPlayers = mPlayers.size();
    for (int i=0; i!=nPlayers; ++i)
    {
      const double fraction = static_cast<double>(i) / static_cast<double>(nPlayers);
      const double angle = (0.5 * M_PI) + ( fraction * M_PI * 2.0);
      mPlayers[i].x = (static_cast<double>(mMaxx) / 2.0)
        + ( std::sin( angle ) * 10.0 );
      mPlayers[i].y = (static_cast<double>(mMaxx) / 2.0)
        + ( -std::cos( angle ) * 10.0 );
      mPlayers[i].angle = angle;
    }
  }
  TimerGame->Interval = speed;
  ImageBuffer->Picture->Graphic->Width = mMaxx;
  ImageBuffer->Picture->Graphic->Height = mMaxy;
  PaintVcl(ImageBuffer,clBlack);
  TimerGame->OnTimer(0);
}
//---------------------------------------------------------------------------
void __fastcall TFormSuperTronGame::FormKeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
  const std::vector<Player>::iterator j = mPlayers.end();
  for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
  {
    if (i->keyLeft == Key) { i->angle -= SuperTronPlayer::deltaAngle; }
    if (i->keyRight == Key) { i->angle += SuperTronPlayer::deltaAngle; }
  }
  //Caption = Key;
}
//---------------------------------------------------------------------------
void __fastcall TFormSuperTronGame::TimerGameTimer(TObject *Sender)
{
  //Check for collisions
  {
    const std::vector<Player>::iterator j = mPlayers.end();
    for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
    {
      const int xFrom = static_cast<double>(i->x);
      const int yFrom = static_cast<double>(i->y);
      int xTo = static_cast<int>(static_cast<double>(i->x) + (std::sin(i->angle) * Player::speed));
      int yTo = static_cast<int>(static_cast<double>(i->y) - (std::cos(i->angle) * Player::speed));
      if (mDonutShapedWorld == true)
      {
        if (xTo < 0) xTo+=mMaxx;
        if (xTo >= mMaxx) xTo-=mMaxx;
        if (yTo < 0) yTo+=mMaxy;
        if (yTo >= mMaxy) yTo-=mMaxy;
      }
      else if ( xTo < 0 || yTo < 0 || xTo >= mMaxx || yTo >= mMaxy )
      {
        RemovePointFromLosers( (*i).color );
        RemoveColor(ImageBuffer, (*i).color );
        (*i).angle += M_PI; //Reverse direction
        continue;
      }

      if (xFrom == xTo && yFrom == yTo) continue; //No movement visible

      const TColor color = GetPixelVcl(ImageBuffer, xTo, yTo);
      if (color == clBlack || color == static_cast<TColor>(-1) ) continue; //Nothing there...
      if (color!=(*i).color)
      {
        AddPointToWinners(color);
        RemovePointFromLosers( (*i).color );
        RemoveColor(ImageBuffer, color );
      }
      if (mCanWalkThroughOwnColor == false && color==(*i).color)
      {
        RemovePointFromLosers( (*i).color );
        RemoveColor(ImageBuffer, color );
      }
    }
  }

  //Move the players
  {
    const double maxx = static_cast<double>(mMaxx);
    const double maxy = static_cast<double>(mMaxy);
    const std::vector<Player>::iterator j = mPlayers.end();
    for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
    {
      i->x+=(std::sin(i->angle) * Player::speed);
      i->y-=(std::cos(i->angle) * Player::speed);
      if (i->x < 0.0) i->x+=maxx;
      if (i->x >= maxx) i->x-=maxx;
      if (i->y < 0.0) i->y+=maxy;
      if (i->y >= maxy) i->y-=maxy;
    }
  }


  //Draw new player locations to buffer
  {
    const std::vector<Player>::iterator j = mPlayers.end();
    for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
    {
      SetPixel(ImageBuffer, (*i).x, (*i).y, (*i).color );
    }
  }

  //Draw buffer to screen
  Canvas->StretchDraw(this->ClientRect,ImageBuffer->Picture->Graphic);
}
//---------------------------------------------------------------------------
void TFormSuperTronGame::AddPointToWinners(const TColor color)
{
  const std::vector<Player>::iterator j = mPlayers.end();
  for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
  {
    if (i->color == color) ++(i->nWins);
  }
}
//---------------------------------------------------------------------------
void TFormSuperTronGame::RemovePointFromLosers(const TColor color)
{
  const std::vector<Player>::iterator j = mPlayers.end();
  for (std::vector<Player>::iterator i = mPlayers.begin(); i!=j; ++i)
  {
    if (i->color == color) ++(i->nLose);
  }
}
//---------------------------------------------------------------------------
void __fastcall TFormSuperTronGame::FormClose(TObject *Sender,
      TCloseAction &Action)
{
  TimerGame->Enabled = false;
  const int size = mPlayers.size();
  std::vector<int> losses(size);
  std::vector<int> wins(size);
  for (int i=0; i!=size; ++i)
  {
    losses[i] = mPlayers[i].nLose;
    wins[i] = mPlayers[i].nWins;
  }

  std::auto_ptr<TFormChart> f(new TFormChart(0,losses,wins));
  f->ShowModal();
}
//---------------------------------------------------------------------------



 

 

 

 

 

UnitFormSuperTronGame.h

 

//---------------------------------------------------------------------------
/*
  Super Tron, a simple game
  Copyright (C) 2008 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 UnitFormSuperTronGameH
#define UnitFormSuperTronGameH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
#include <vector>
#include "UnitSuperTronPlayer.h"
//---------------------------------------------------------------------------
class TFormSuperTronGame : public TForm
{
__published: // IDE-managed Components
        TImage *ImageBuffer;
        TTimer *TimerGame;
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall TimerGameTimer(TObject *Sender);
        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private: // User declarations
  typedef SuperTronPlayer Player;
  std::vector<Player> mPlayers;
  const bool mDonutShapedWorld;
  const bool mCanWalkThroughOwnColor;
  const int mMaxx;
  const int mMaxy;
  void AddPointToWinners(const TColor color);
  void RemovePointFromLosers(const TColor color);

public: // User declarations
  __fastcall TFormSuperTronGame(TComponent* Owner,
    const std::vector<Player>& players,
    const int speed,
    const int maxx,
    const int maxy,
    const bool donutShapedWorld,
    const bool canWalkThroughOwnColor);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormSuperTronGame *FormSuperTronGame;
//---------------------------------------------------------------------------



#endif

 

 

 

 

 

UnitFormSuperTronMenu.cpp

 

//---------------------------------------------------------------------------
/*
  Super Tron, a simple game
  Copyright (C) 2008 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 <boost/scoped_ptr.hpp>
#include <algorithm>
#include <cassert>
#include <cmath>
#include "UnitGraphics.h"
#include "UnitFormSuperTronMenu.h"
#include "UnitFormPressKey.h"
#include "UnitFormSelectColor.h"
#include "UnitFormSuperTronGame.h"
#include "UnitFormSuperTronAbout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSuperTronMenu *FormSuperTronMenu;
//---------------------------------------------------------------------------
__fastcall TFormSuperTronMenu::TFormSuperTronMenu(TComponent* Owner)
  : TForm(Owner),
    mDonutShapedWorld(true),
    mCanWalkThroughOwnColor(false)
{
  ImageNplayersMinus->Picture->Graphic->Width = 80;
  ImageNplayersMinus->Picture->Graphic->Height = 80;
  ImageNplayersPlus->Picture->Graphic->Width = 80;
  ImageNplayersPlus->Picture->Graphic->Height = 80;
  DrawGlobeMinus(ImageNplayersMinus,255,196,196);
  DrawGlobePlus(ImageNplayersPlus,196,196,255);

  TrackBarSpeed->OnChange(0);
  TrackBarWidth->OnChange(0);
  TrackBarHeight->OnChange(0);
  TrackBarNangles->OnChange(0);
}
//---------------------------------------------------------------------------

void __fastcall TFormSuperTronMenu::ButtonCalibrateClick(TObject *Sender)
{
  const int nPlayers = PanelNplayers->Caption.ToIntDef(-1);
  assert(nPlayers!=-1);
  mPlayers.resize(nPlayers);
  for (int i=0; i!=nPlayers; ++i)
  {
    //Key left
    {
      const String message = "Player #" + IntToStr(i+1) + ", please press key for 'Turn left'.";
      std::auto_ptr<TFormPressKey> f(new TFormPressKey(0,message));
      f->ShowModal();
      mPlayers[i].keyLeft = f->ModalResult;
    }
    //Key right
    {
      const String message = "Player #" + IntToStr(i+1) + ", please press key for 'Turn right'.";
      std::auto_ptr<TFormPressKey> f(new TFormPressKey(0,message));
      f->ShowModal();
      mPlayers[i].keyRight = f->ModalResult;
    }
    //Color
    //Choose color
    {
      std::auto_ptr<TFormSelectColor> f(new TFormSelectColor(0));
      f->ShowModal();
      const int colorIndex = f->ModalResult - 10;
      assert(colorIndex >= 0 && colorIndex < 20);
      const double fraction = static_cast<double>(colorIndex) / 20.0;
      unsigned char r,g,b;
      Rainbow(fraction,r,g,b);
      mPlayers[i].color = RgbToColor(r,g,b);
    }
  }
  ButtonStart->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormSuperTronMenu::ButtonStartClick(TObject *Sender)
{
  const double fractionSpeed
  = static_cast<double>(TrackBarSpeed->Position)
  / static_cast<double>(TrackBarSpeed->Max);
  const double fractionWidth
  = static_cast<double>(TrackBarWidth->Position)
  / static_cast<double>(TrackBarWidth->Max);
  const double fractionHeight
  = static_cast<double>(TrackBarHeight->Position)
  / static_cast<double>(TrackBarHeight->Max);

  const int speed = 1000.0 - (fractionSpeed * 999.0);
  assert(speed > 0);
  const int maxx = 100.0 + (fractionWidth * static_cast<double>(Monitor->Width - 200));
  const int maxy = 100.0 + (fractionHeight * static_cast<double>(Monitor->Height - 200));
  boost::scoped_ptr<TFormSuperTronGame> f(
    new TFormSuperTronGame(
      0,
      mPlayers,
      speed,
      maxx,
      maxy,
      mDonutShapedWorld,
      mCanWalkThroughOwnColor
      ));
  f->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TFormSuperTronMenu::FormKeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
  switch(Key)
  {
    case VK_ADD:
      ImageNplayersPlus->OnClick(0);
      break;
    case VK_SUBTRACT:
      ImageNplayersMinus->OnClick(0);
      break;
    case 83: // 's'
      if (mDonutShapedWorld == true)
      {
        ImageWorldFlat->OnClick(0);
      }
      else
      {
        ImageWorldDonut->OnClick(0);
      }
      break;
    case 72: // 'h'
      if (mCanWalkThroughOwnColor == true)
      {
        ImageCannotWalkThroughOwnColor->OnClick(0);
      }
      else
      {
        ImageCanWalkThroughOwnColor->OnClick(0);
      }
      break;
  }
}
//---------------------------------------------------------------------------
void __fastcall TFormSuperTronMenu::ImageNplayersMinusClick(
      TObject *Sender)
{
  const int nPlayers = PanelNplayers->Caption.ToIntDef(-1);
  assert(nPlayers!=-1);
  if (nPlayers > 2)
  {
    PanelNplayers->Caption = IntToStr(nPlayers - 1);
    ButtonStart->Enabled = false;
  }
}
//---------------------------------------------------------------------------
void __fastcall TFormSuperTronMenu::ImageNplayersPlusClick(
      TObject *Sender)
{
  const int nPlayers = PanelNplayers->Caption.ToIntDef(-1);
  assert(nPlayers!=-1);
  if (nPlayers < 20)
  {
    PanelNplayers->Caption = IntToStr(nPlayers + 1);
    ButtonStart->Enabled = false;
  }
}
//---------------------------------------------------------------------------

void __fastcall TFormSuperTronMenu::TrackBarSpeedChange(TObject *Sender)
{
  const double fraction
  = static_cast<double>(TrackBarSpeed->Position)
  / static_cast<double>(TrackBarSpeed->Max);
  if (fraction < 0.1) PanelSpeedValue->Caption = "Slowest";
  else if (fraction < 0.40) PanelSpeedValue->Caption = "Slow";
  else if (fraction < 0.60) PanelSpeedValue->Caption = "Normal";
  else if (fraction < 0.90) PanelSpeedValue->Caption = "Fast";
  else PanelSpeedValue->Caption = "Fastest";
}
//---------------------------------------------------------------------------

void __fastcall TFormSuperTronMenu::TrackBarWidthChange(TObject *Sender)
{
  const double fraction
  = static_cast<double>(TrackBarWidth->Position)
  / static_cast<double>(TrackBarWidth->Max);
  if (fraction < 0.1) PanelWidthValue->Caption = "Smallest";
  else if (fraction < 0.40) PanelWidthValue->Caption = "Small";
  else if (fraction < 0.60) PanelWidthValue->Caption = "Medium";
  else if (fraction < 0.90) PanelWidthValue->Caption = "Large";
  else PanelWidthValue->Caption = "Largest";
}
//---------------------------------------------------------------------------

void __fastcall TFormSuperTronMenu::TrackBarHeightChange(TObject *Sender)
{
  const double fraction
  = static_cast<double>(TrackBarHeight->Position)
  / static_cast<double>(TrackBarHeight->Max);
  if (fraction < 0.1) PanelHeightValue->Caption = "Smallest";
  else if (fraction < 0.40) PanelHeightValue->Caption = "Small";
  else if (fraction < 0.60) PanelHeightValue->Caption = "Medium";
  else if (fraction < 0.90) PanelHeightValue->Caption = "Large";
  else PanelHeightValue->Caption = "Largest";
}
//---------------------------------------------------------------------------

void __fastcall TFormSuperTronMenu::ImageWorldFlatClick(TObject *Sender)
{
  ImageWorldChosen->Picture->Graphic = ImageWorldFlat->Picture->Graphic;
  mDonutShapedWorld = false;
}
//---------------------------------------------------------------------------

void __fastcall TFormSuperTronMenu::ImageWorldDonutClick(TObject *Sender)
{
  ImageWorldChosen->Picture->Graphic = ImageWorldDonut->Picture->Graphic;
  mDonutShapedWorld = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormSuperTronMenu::ImageCanWalkThroughOwnColorClick(
      TObject *Sender)
{
  ImageCanWalkThroughOwnColorChosen->Picture->Graphic
  = ImageCanWalkThroughOwnColor->Picture->Graphic;
  mCanWalkThroughOwnColor = true;
}
//---------------------------------------------------------------------------

void __fastcall TFormSuperTronMenu::ImageCannotWalkThroughOwnColorClick(
      TObject *Sender)
{
  ImageCanWalkThroughOwnColorChosen->Picture->Graphic
  = ImageCannotWalkThroughOwnColor->Picture->Graphic;
  mCanWalkThroughOwnColor = false;
}
//---------------------------------------------------------------------------
void __fastcall TFormSuperTronMenu::ButtonAboutClick(TObject *Sender)
{
  std::auto_ptr<TFormSuperTronAbout> f(new TFormSuperTronAbout(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TFormSuperTronMenu::TrackBarNanglesChange(TObject *Sender)
{
  const int nAngles = TrackBarNangles->Position;
  PanelNanglesValue->Caption = nAngles;
  SuperTronPlayer::deltaAngle = (2.0 * M_PI) / static_cast<double>(nAngles);
}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormSuperTronMenu.h

 

//---------------------------------------------------------------------------
/*
  Super Tron, a simple game
  Copyright (C) 2008 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 UnitFormSuperTronMenuH
#define UnitFormSuperTronMenuH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
#include <vector>
#include "UnitSuperTronPlayer.h"
//---------------------------------------------------------------------------
class TFormSuperTronMenu : public TForm
{
__published: // IDE-managed Components
        TButton *ButtonStart;
        TPanel *PanelSpeed;
        TPanel *PanelSpeedValue;
        TTrackBar *TrackBarSpeed;
        TPanel *PanelWidth;
        TPanel *PanelWidthValue;
        TTrackBar *TrackBarWidth;
        TPanel *PanelHeight;
        TPanel *PanelHeightValue;
        TTrackBar *TrackBarHeight;
        TPanel *PanelWorld;
        TPanel *PanelCanThroughOwnColor;
        TImage *ImageWorldDonut;
        TImage *ImageCannotWalkThroughOwnColor;
        TImage *ImageWorldFlat;
        TImage *ImageCanWalkThroughOwnColorChosen;
        TImage *ImageCanWalkThroughOwnColor;
        TImage *ImageWorldChosen;
        TStaticText *StaticText1;
        TStaticText *TextWalkThroughOwnColor;
        TButton *ButtonCalibrate;
        TPanel *PanelNplayers;
        TImage *ImageNplayersPlus;
        TImage *ImageNplayersMinus;
        TStaticText *TextNplayers;
        TPanel *PanelSpeedText;
        TPanel *PanelWidthText;
        TPanel *PanelHeightText;
        TButton *ButtonAbout;
  TPanel *PanelNangles;
  TPanel *PanelNanglesValue;
  TTrackBar *TrackBarNangles;
  TPanel *PanelNanglesLeft;
        void __fastcall ButtonCalibrateClick(TObject *Sender);
        void __fastcall ImageNplayersMinusClick(TObject *Sender);
        void __fastcall ImageNplayersPlusClick(TObject *Sender);
        void __fastcall TrackBarSpeedChange(TObject *Sender);
        void __fastcall TrackBarWidthChange(TObject *Sender);
        void __fastcall TrackBarHeightChange(TObject *Sender);
        void __fastcall ImageWorldFlatClick(TObject *Sender);
        void __fastcall ImageWorldDonutClick(TObject *Sender);
        void __fastcall ButtonStartClick(TObject *Sender);
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ImageCanWalkThroughOwnColorClick(TObject *Sender);
        void __fastcall ImageCannotWalkThroughOwnColorClick(
          TObject *Sender);
        void __fastcall ButtonAboutClick(TObject *Sender);
  void __fastcall TrackBarNanglesChange(TObject *Sender);
private: // User declarations
  typedef SuperTronPlayer Player;
  std::vector<Player> mPlayers;
  bool mDonutShapedWorld;
  bool mCanWalkThroughOwnColor;
public: // User declarations
        __fastcall TFormSuperTronMenu(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormSuperTronMenu *FormSuperTronMenu;
//---------------------------------------------------------------------------

#endif

 

 

 

 

 

UnitFormTronCollectionMenu.cpp

 

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

#include <vcl.h>
#pragma hdrstop

#include <boost/scoped_ptr.hpp>
#include "UnitFormTronCollectionMenu.h"
#include "UnitFormSuperTronMenu.h"
#include "UnitFormClassicTronMenu.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormTronCollectionMenu *FormTronCollectionMenu;
//---------------------------------------------------------------------------
__fastcall TFormTronCollectionMenu::TFormTronCollectionMenu(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TFormTronCollectionMenu::ImageClassicTronMouseDown(
      TObject *Sender, TMouseButton Button, TShiftState Shift, int X,
      int Y)
{
  boost::scoped_ptr<TFormClassicTronMenu> f(new TFormClassicTronMenu(0));
  f->ShowModal();

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

void __fastcall TFormTronCollectionMenu::ImageSuperTronMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  boost::scoped_ptr<TFormSuperTronMenu> f(new TFormSuperTronMenu(0));
  f->ShowModal();

}
//---------------------------------------------------------------------------
void __fastcall TFormTronCollectionMenu::ImageUltimateTronMouseDown(
      TObject *Sender, TMouseButton Button, TShiftState Shift, int X,
      int Y)
{
  //boost::scoped_ptr<TFormUltimateTronMenu> f(new TFormUltimateTronMenu(0));
  //f->ShowModal();
}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormTronCollectionMenu.h

 

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

#ifndef UnitFormTronCollectionMenuH
#define UnitFormTronCollectionMenuH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormTronCollectionMenu : public TForm
{
__published: // IDE-managed Components
  TPanel *PanelTitle;
  TImage *ImageClassicTron;
  TImage *ImageSuperTron;
  TImage *ImageUltimateTron;
  void __fastcall ImageClassicTronMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
  void __fastcall ImageSuperTronMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
  void __fastcall ImageUltimateTronMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
private: // User declarations
public: // User declarations
        __fastcall TFormTronCollectionMenu(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormTronCollectionMenu *FormTronCollectionMenu;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitGraphics.cpp

 

//---------------------------------------------------------------------------
/*
  The Tron Collection, three simple tron games
  Copyright (C) 2008 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 <algorithm>
#include <cassert>
#include <cmath>
#include <ExtCtrls.hpp>
#pragma hdrstop

#include "UnitGraphics.h"
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppRainbow.htm
void Rainbow(
  const double x,
  unsigned char& r,
  unsigned char& g,
  unsigned char& b)
{
  const int r0 = GetRed(x);
  const int g0 = GetGreen(x);
  const int b0 = GetBlue(x);
  const int max = std::max(r0, std::max(g0,b0));
  assert(max!=0);

  r = 255.0 * static_cast<double>(r0) / static_cast<double>(max);
  g = 255.0 * static_cast<double>(g0) / static_cast<double>(max);
  b = 255.0 * static_cast<double>(b0) / static_cast<double>(max);
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppRainbow.htm
const unsigned char GetRed(const double x)
{
  assert( x >= 0.0 && x < 1.0);
  const double f = std::max(0.0,
    (x < 0.5
    ? std::cos(x * 1.5 * M_PI)
    : -std::sin(x * 1.5 * M_PI)
    ) );
  assert( f >= 0.0);
  assert( f <= 1.0);
  const double y = 255.0 * f;
  assert( static_cast<int>(y) < 256 );
  return static_cast<unsigned char>(y);
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppRainbow.htm
const unsigned char GetGreen(const double x)
{
  assert( x >= 0.0 && x < 1.0);

  const double f = std::max(0.0, std::sin( x * 1.5 * M_PI ) );
  assert( f >= 0.0);
  assert( f <= 1.0);
  const double y = 255.0 * f;
  assert( static_cast<int>(y) < 256 );
  return static_cast<unsigned char>(y);
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppRainbow.htm
const unsigned char GetBlue(const double x)
{
  assert( x >= 0.0 && x < 1.0);

  const double f = std::max(0.0, -std::cos( x * 1.5 * M_PI ) );

  assert( f >= 0.0);
  assert( f <= 1.0);
  const double y = 255.0 * f;
  assert( static_cast<int>(y) < 256 );
  return static_cast<unsigned char>(y);
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppGetPixel.htm
void GetPixel(
  const TImage * const image,
  const int x,
  const int y,
  unsigned char& red,
  unsigned char& green,
  unsigned char& blue)
{
  assert(image!=0 && "Image is NULL");
  assert(image->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(image->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");
  assert( x >= 0 && "x coordinat is below zero");
  assert( y >= 0 && "y coordinat is below zero");
  assert( x < image->Picture->Bitmap->Width && "x coordinat is beyond image width");
  assert( y < image->Picture->Bitmap->Height && "y coordinat is beyond image height");

  const unsigned char * const line
    = static_cast<unsigned char *>(image->Picture->Bitmap->ScanLine[y]);

  red = line[x*3+2];
  green = line[x*3+1];
  blue = line[x*3+0];
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppGetPixel.htm
const TColor GetPixelVcl(
  const TImage * const image,
  const int x,
  const int y)
{
  assert(image!=0 && "Image is NULL");
  assert(image->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(image->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");
  assert( x >= 0 && "x coordinat is below zero");
  assert( y >= 0 && "y coordinat is below zero");
  assert( x < image->Picture->Bitmap->Width && "x coordinat is beyond image width");
  assert( y < image->Picture->Bitmap->Height && "y coordinat is beyond image height");

  const unsigned char * const line
    = static_cast<unsigned char *>(image->Picture->Bitmap->ScanLine[y]);

  return static_cast<TColor>(RGB(
    line[x*3+2], //Red
    line[x*3+1], //Green
    line[x*3+0] //Blue
    ));
}
//---------------------------------------------------------------------------
void SetPixel(
  TImage * const image,
  const int x,
  const int y,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue)
{
  assert(image!=0 && "Image is NULL");
  assert(image->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(image->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");
  assert( x >= 0 && "x coordinat is below zero");
  assert( y >= 0 && "y coordinat is below zero");
  assert( x < image->Picture->Bitmap->Width && "x coordinat is beyond image width");
  assert( y < image->Picture->Bitmap->Height && "y coordinat is beyond image height");

  unsigned char * const line
    = static_cast<unsigned char *>(image->Picture->Bitmap->ScanLine[y]);

  line[x*3+2] = red;
  line[x*3+1] = green;
  line[x*3+0] = blue;
}
//---------------------------------------------------------------------------
void SetPixel(
  TImage * const image,
  const int x,
  const int y,
  const TColor color)
{
  assert(image!=0 && "Image is NULL");
  assert(image->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(image->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");
  assert( x >= 0 && "x coordinat is below zero");
  assert( y >= 0 && "y coordinat is below zero");
  assert( x < image->Picture->Bitmap->Width && "x coordinat is beyond image width");
  assert( y < image->Picture->Bitmap->Height && "y coordinat is beyond image height");

  unsigned char * const line
    = static_cast<unsigned char *>(image->Picture->Bitmap->ScanLine[y]);

  line[x*3+2] = GetRValue(color);
  line[x*3+1] = GetGValue(color);
  line[x*3+0] = GetBValue(color);
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppPaint.htm
void PaintVcl(TImage * const image,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue )
{
  assert(image!=0);
  assert(image->Picture->Bitmap != 0);
  assert(image->Picture->Bitmap->PixelFormat == pf24bit);

  const int maxx = image->Picture->Bitmap->Width;
  const int maxy = image->Picture->Bitmap->Height;
  for (int y = 0; y != maxy; ++y)
  {
    unsigned char * const myLine
      = static_cast<unsigned char*>(image->Picture->Bitmap->ScanLine[y]);
    for (int x = 0; x != maxx; ++x)
    {
      myLine[x*3+2] = red ; //Red
      myLine[x*3+1] = green; //Green
      myLine[x*3+0] = blue ; //Blue
    }
  }
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl
void PaintVcl(TImage * const image, const TColor color)
{
  assert(image!=0);
  assert(image->Picture->Bitmap != 0);
  assert(image->Picture->Bitmap->PixelFormat == pf24bit);

  const int maxx = image->Picture->Bitmap->Width;
  const int maxy = image->Picture->Bitmap->Height;
  const unsigned char red = GetRValue(color);
  const unsigned char green = GetGValue(color);
  const unsigned char blue = GetBValue(color);

  for (int y = 0; y != maxy; ++y)
  {
    unsigned char * const myLine
      = static_cast<unsigned char*>(image->Picture->Bitmap->ScanLine[y]);
    for (int x = 0; x != maxx; ++x)
    {
      myLine[x*3+2] = red ; //Red
      myLine[x*3+1] = green; //Green
      myLine[x*3+0] = blue ; //Blue
    }
  }
}
//---------------------------------------------------------------------------

//From http://www.richelbilderbeek.nl
void RemoveColor(TImage * const image, const TColor color)
{
  assert(image!=0);
  assert(image->Picture->Bitmap != 0);
  assert(image->Picture->Bitmap->PixelFormat == pf24bit);

  const int maxx = image->Picture->Bitmap->Width;
  const int maxy = image->Picture->Bitmap->Height;
  const unsigned char red = GetRValue(color);
  const unsigned char green = GetGValue(color);
  const unsigned char blue = GetBValue(color);

  const unsigned char redBlack = GetRValue(clBlack);
  const unsigned char greenBlack = GetGValue(clBlack);
  const unsigned char blueBlack = GetBValue(clBlack);
  for (int y = 0; y != maxy; ++y)
  {
    unsigned char * const myLine
      = static_cast<unsigned char*>(image->Picture->Bitmap->ScanLine[y]);
    for (int x = 0; x != maxx; ++x)
    {
      if ( myLine[x*3+2] == red //Red
        && myLine[x*3+1] == green //Green
        && myLine[x*3+0] == blue ) //Blue
      {
        myLine[x*3+2] = redBlack ; //Red
        myLine[x*3+1] = greenBlack ; //Green
        myLine[x*3+0] = blueBlack ; //Blue
      }
    }
  }
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl
void RemoveColor(TImage * const image,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue )
{
  assert(image!=0);
  assert(image->Picture->Bitmap != 0);
  assert(image->Picture->Bitmap->PixelFormat == pf24bit);

  const int maxx = image->Picture->Bitmap->Width;
  const int maxy = image->Picture->Bitmap->Height;
  for (int y = 0; y != maxy; ++y)
  {
    unsigned char * const myLine
      = static_cast<unsigned char*>(image->Picture->Bitmap->ScanLine[y]);
    for (int x = 0; x != maxx; ++x)
    {
      if ( myLine[x*3+2] == red //Red
        && myLine[x*3+1] == green //Green
        && myLine[x*3+0] == blue ) //Blue
      {
        myLine[x*3+2] = 0 ; //Red
        myLine[x*3+1] = 0 ; //Green
        myLine[x*3+0] = 0 ; //Blue
      }
    }
  }
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl
const TColor RgbToColor(
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue )
{
  return static_cast<TColor>(RGB(red,green,blue));
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl
void ColorToRgb(
  const TColor color,
  unsigned char& red,
  unsigned char& green,
  unsigned char& blue )
{
  red = GetRValue(color);
  green = GetGValue(color);
  blue = GetBValue(color);
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppDrawGlobe.htm
void DrawGlobe(
  TImage * const image,
  const unsigned char rMax,
  const unsigned char gMax,
  const unsigned char bMax)
{
  assert(image!=0);
  const int width = image->Picture->Bitmap->Width;
  const int height = image->Picture->Bitmap->Height;
  const double midX = static_cast<double>(width ) / 2.0;
  const double midY = static_cast<double>(height) / 2.0;
  const double maxDist = std::min(midX,midY);
  for (int y=0; y!=height; ++y)
  {
    unsigned char * const line
      = static_cast<unsigned char *>(image->Picture->Bitmap->ScanLine[y]);
    const double yD = static_cast<double>(y);
    for (int x=0; x!=width; ++x)
    {
      const double xD = static_cast<double>(x);
      const double dist = std::sqrt( ((xD - midX) * (xD - midX)) + ((yD - midY) * (yD - midY)) );
      if (dist <= maxDist)
      {
        const double relDist = dist / maxDist;
        const int r = relDist * static_cast<double>(rMax);
        const int g = relDist * static_cast<double>(gMax);
        const int b = relDist * static_cast<double>(bMax);
        assert( r >= 0);
        assert( r < 256);
        assert( g >= 0);
        assert( g < 256);
        assert( b >= 0);
        assert( b < 256);
        line[x*3+2] = (r == 0 ? 1 : r); //Never use a zero for red
        line[x*3+1] = (g == 0 ? 1 : g); //Never use a zero for green
        line[x*3+0] = (b == 0 ? 1 : b); //Never use a zero for blue
      }
      else
      {
        line[x*3+2] = 0;
        line[x*3+1] = 0;
        line[x*3+0] = 0;
      }
    }
  }
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppDrawGlobeMinus.htm
void DrawGlobeMinus(TImage * const image,

  const unsigned char red,
  const unsigned char green,
  const unsigned char blue)
{
  DrawGlobe(image,red,green,blue);
  const int height = image->Picture->Bitmap->Height;
  const int width = image->Picture->Bitmap->Width;
  image->Canvas->Pen->Width = height / 10;
  image->Canvas->Pen->Color = static_cast<TColor>(RGB(red,green,blue));
  image->Canvas->MoveTo(1 * width / 4,height / 2);
  image->Canvas->LineTo(3 * width / 4,height / 2);
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppDrawGlobePlus.htm
void DrawGlobePlus(TImage * const image,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue)
{
  DrawGlobe(image,red,green,blue);
  const int height = image->Picture->Bitmap->Height;
  const int width = image->Picture->Bitmap->Width;
  image->Canvas->Pen->Width = height / 10;
  image->Canvas->Pen->Color = static_cast<TColor>(RGB(red,green,blue));
  image->Canvas->MoveTo(1 * width / 4,height / 2);
  image->Canvas->LineTo(3 * width / 4,height / 2);
  image->Canvas->MoveTo(width / 2,1 * height / 4);
  image->Canvas->LineTo(width / 2,3 * height / 4);
}
//---------------------------------------------------------------------------

#pragma package(smart_init)

 

 

 

 

 

UnitGraphics.h

 

//---------------------------------------------------------------------------
/*
  The Tron Collection, three simple tron games
  Copyright (C) 2008 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 UnitGraphicsH
#define UnitGraphicsH
//---------------------------------------------------------------------------
namespace Extctrls { class TImage; }
#include <Graphics.hpp>
//---------------------------------------------------------------------------


void DrawGlobePlus(Extctrls::TImage * const image,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue);
void DrawGlobeMinus(Extctrls::TImage * const image,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue);
void DrawGlobe(
  Extctrls::TImage * const image,
  const unsigned char rMax,
  const unsigned char gMax,
  const unsigned char bMax);
void Rainbow(
  const double x,
  unsigned char& r,
  unsigned char& g,
  unsigned char& b);
const TColor RgbToColor(
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue );

const unsigned char GetRed(const double x);
const unsigned char GetGreen(const double x);
const unsigned char GetBlue(const double x);


void GetPixel(
  const Extctrls::TImage * const image,
  const int x,
  const int y,
  unsigned char& red,
  unsigned char& green,
  unsigned char& blue);
const TColor GetPixelVcl(
  const Extctrls::TImage * const image,
  const int x,
  const int y);
void SetPixel(
  Extctrls::TImage * const image,
  const int x,
  const int y,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue);
void SetPixel(
  Extctrls::TImage * const image,
  const int x,
  const int y,
  const TColor color);
void PaintVcl(Extctrls::TImage * const image,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue );
void PaintVcl(Extctrls::TImage * const image, const TColor color);
void RemoveColor(Extctrls::TImage * const image,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue );
void RemoveColor(Extctrls::TImage * const image, const TColor color);
const TColor RgbToColor(
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue );



#endif

 

 

 

 

 

UnitSuperTronPlayer.cpp

 

//---------------------------------------------------------------------------
/*
  Super Tron, a simple game
  Copyright (C) 2008 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
//---------------------------------------------------------------------------
#pragma hdrstop

#include <cmath>
#include "UnitSuperTronPlayer.h"

//---------------------------------------------------------------------------
double SuperTronPlayer::deltaAngle = 0.1 * M_PI;
const double SuperTronPlayer::speed = 1.0;
//---------------------------------------------------------------------------
SuperTronPlayer::SuperTronPlayer()
  : x(0.0),
    y(0.0),
    angle(0.0),
    nWins(0),
    nLose(0),
    color(static_cast<TColor>(0)),
    keyLeft(0),
    keyRight(0)
{

}

#pragma package(smart_init)

 

 

 

 

 

UnitSuperTronPlayer.h

 

//---------------------------------------------------------------------------
/*
  Super Tron, a simple game
  Copyright (C) 2008 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 UnitSuperTronPlayerH
#define UnitSuperTronPlayerH
//---------------------------------------------------------------------------
#include <Graphics.hpp> //For TColor
//#include <windef.h>
typedef unsigned short WORD;
//---------------------------------------------------------------------------
struct SuperTronPlayer
{
  SuperTronPlayer();
  double x;
  double y;
  double angle;
  int nWins;
  int nLose;
  Graphics::TColor color;
  WORD keyLeft;
  WORD keyRight;
  static double deltaAngle;
  static const double speed;
};

#endif

 

 

 

 

 

UnitTronTurboPlayer.cpp

 

//---------------------------------------------------------------------------
/*
  Tron Turbo, a simple game
  Copyright (C) 2008 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
//---------------------------------------------------------------------------
#pragma hdrstop

#include <cmath>
#include "UnitTronTurboPlayer.h"

//---------------------------------------------------------------------------
double TronTurboPlayer::deltaAngle = 0.1 * M_PI;
const double TronTurboPlayer::speed = 1.0;
//---------------------------------------------------------------------------
TronTurboPlayer::TronTurboPlayer()
  : x(0.0),
    y(0.0),
    angle(0.0),
    nWins(0),
    nLose(0),
    color(static_cast<TColor>(0)),
    keyLeft(0),
    keyRight(0)
{

}

#pragma package(smart_init)

 

 

 

 

 

UnitTronTurboPlayer.h

 

//---------------------------------------------------------------------------
/*
  Tron Turbo, a simple game
  Copyright (C) 2008 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 UnitTronTurboPlayerH
#define UnitTronTurboPlayerH
//---------------------------------------------------------------------------
#include <Graphics.hpp> //For TColor
//#include <windef.h>
typedef unsigned short WORD;
//---------------------------------------------------------------------------
struct TronTurboPlayer
{
  TronTurboPlayer();
  double x;
  double y;
  double angle;
  int nWins;
  int nLose;
  Graphics::TColor color;
  WORD keyLeft;
  WORD keyRight;
  static double deltaAngle;
  static const double speed;
};

#endif

 

 

 

 

 

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict