Trouver un fichier de code source :
   

Version Française - English Version
Accueil > 

Delphi

 > 

JEUX D' OTHELLO

 > 

Othello/Othello Test/Unit1.pas


JEUX D' OTHELLO

Othello/Othello Test/Unit1.pas


Informations sur ce code source

Cliquez pour voir la capture en taille normale
Code Source JEUX D' OTHELLO
Auteur fredbluefish
Fichier Othello/Othello Test/Unit1.pas en Delphi
Publié le 25/09/2012

Voici mon premier code source ! C' est un jeux d' othello (reversi) écrit en Delphi. Ce n' est pas un composant graphique mais un composant qui joue via des événements Perso facilement configurable depuis l' IDE Les événements sont déclenchés pour
 

Fichier : Othello/Othello Test/Unit1.pas

Nombre de lignes : 280 lignes


Afficher ce fichier en plein écran
  • unit Unit1;
  • //////////////////////////////////////////////////////////////
  • /// ///
  • /// Content : Example Programm for the TOthello Unit ///
  • /// Date : 25/09/2012 ///
  • /// Author : Klieber Frederic ///
  • /// See corresponding Unit for the Help of the setup !! ///
  • /// ///
  • //////////////////////////////////////////////////////////////
  • interface
  • uses
  • Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, StrUtils,
  • Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Othello_Unit, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ImgList;
  • type
  • ImgArr = array[0..63] of TImage ;
  • TForm1 = class(TForm)
  • NewGame: TButton;
  • Labelnewgame: TLabel;
  • GroupBox1: TGroupBox;
  • bl: TLabel;
  • GroupBox2: TGroupBox;
  • wl: TLabel;
  • LabelPlayer: TLabel;
  • Othello: TOthello;
  • GroupBox4: TGroupBox;
  • CHeckHint: TCheckBox;
  • CheckPlayable: TCheckBox;
  • procedure ImageSquareClick(Sender: TObject);
  • procedure FormCreate(Sender: TObject);
  • procedure NewGameClick(Sender: TObject);
  • procedure OthelloFlip(pt: TPoint; color: TDiscColor);
  • procedure ImageSquareMouseLeave(Sender: TObject);
  • procedure ImageSquareMouseEnter(Sender: TObject);
  • procedure CHeckHintClick(Sender: TObject);
  • procedure CheckPlayableClick(Sender: TObject);
  • procedure OthelloGameNew(Sender: TObject);
  • procedure OthelloGameEnd(Sender: TObject);
  • procedure OthelloPlaceBegin(pt: TPoint; color: TDiscColor);
  • procedure OthelloPlaceError(pt: TPoint; color: TDiscColor);
  • procedure OthelloShowPlayableBegin(pt: TPoint; color: TDiscColor);
  • procedure OthelloShowPlayableEnd(pt: TPoint; color: TDiscColor);
  • procedure OthelloShowHintBegin(pt: TPoint; color: TDiscColor);
  • procedure OthelloShowHintEnd(pt: TPoint; color: TDiscColor);
  • procedure OthelloPlaceEnd(pt: TPoint; color: TDiscColor);
  • private
  • Bitmap0,Bitmap1,Bitmap2,Bitmap3 : TBitmap;
  • FImgArr :ImgArr ;
  • public
  • { Déclarations publiques }
  • end;
  • var
  • Form1: TForm1;
  • implementation
  • {$R *.dfm}
  • // Draw the Board and setup the events handler too th Square
  • procedure TForm1.FormCreate(Sender: TObject);
  • var
  • i : integer ;
  • img1 :TImage ;
  • begin
  • Bitmap0 := TBitmap.Create;
  • Bitmap1 := TBitmap.Create;
  • Bitmap2 := TBitmap.Create;
  • Bitmap3 := TBitmap.Create;
  • Bitmap0.Handle := LoadBitmap(hInstance, 'Bitmap_0');
  • Bitmap1.Handle := LoadBitmap(hInstance, 'Bitmap_1');
  • Bitmap2.Handle := LoadBitmap(hInstance, 'Bitmap_2');
  • Bitmap3.Handle := LoadBitmap(hInstance, 'Bitmap_3');
  • for i := 0 to 63 do
  • begin
  • img1 := Timage.Create(Form1);
  • img1.Width := 45 ;
  • img1.Height := 45 ;
  • img1.Top := 15 + self.Othello.SqareNumberToPoint(i).X * 45 ;
  • img1.Left := 15 + self.Othello.SqareNumberToPoint(i).Y * 45 ;
  • img1.Stretch := true;
  • img1.Parent := Form1;
  • img1.Name := 'Img_'+IntToStr(i);
  • Img1.Canvas.Draw(0,0,Bitmap0);
  • FImgArr[i]:= img1;
  • // Will launch the Play of a disc
  • img1.OnClick := ImageSquareClick ;
  • // Will Launch the ShowPlayable proc. and the events
  • img1.OnMouseEnter := ImageSquareMouseEnter;
  • // Will launch the Realease proc.and the Events
  • img1.OnMouseLeave := ImageSquareMouseLeave;
  • end;
  • end;
  • // Make a New Game
  • procedure TForm1.NewGameClick(Sender: TObject);
  • var
  • i : integer ;
  • begin
  • // Setting the Image array images to the empty square picture
  • for i := 0 to 63 do
  • begin
  • FImgArr[i].Canvas.Draw(0,0,Bitmap0);
  • end;
  • // MUST BE CALLED BEFORE EVERYTHING ELSE
  • self.Othello.NewGame;
  • self.LabelPlayer.Caption := 'Black to play' ;
  • self.wl.Caption := '2';
  • self.bl.Caption := '2';
  • // Show Hints creates Messages OnShowHint as many as required
  • self.Othello.Show_Hint := self.CheckHint.Checked ;
  • // Show Playable creates Messages OnShowHint as many as required
  • self.Othello.Show_Playable := self.CheckPlayable.Checked ;
  • end;
  • // Set the ShowHint property
  • procedure TForm1.CHeckHintClick(Sender: TObject);
  • begin
  • self.Othello.Show_Hint := self.CheckHint.Checked ;
  • end;
  • // Set the ShowPlayable property
  • procedure TForm1.CheckPlayableClick(Sender: TObject);
  • begin
  • self.Othello.Show_Playable := self.CheckPlayable.Checked ;
  • end;
  • // Click to play !!
  • procedure TForm1.ImageSquareClick(Sender: TObject);
  • var
  • name : string ;
  • number: integer ;
  • begin
  • //Get the Number of the Square
  • name := (Sender as Timage).Name ;
  • number:= StrToInt(StrUtils.SplitString(name,'_')[1]) ;
  • self.Othello.PlaceDiscsProc(number,self.Othello.TurnToPlay);
  • end;
  • // Process ShowHint if the corresponding property is TRUE , message will be sent to ShowHintBegin
  • procedure TForm1.ImageSquareMouseEnter(Sender: TObject);
  • var
  • name : string ;
  • number: integer ;
  • begin
  • name := (Sender as Timage).Name ;
  • number:= StrToInt(StrUtils.SplitString(name,'_')[1]) ;
  • // This Must be called, will be executed ONLY if
  • // self.Othello.ShowHint is TRUE
  • // will send some events for all the squares
  • //who *could* be turned
  • self.Othello.ShowHintProc(number,self.Othello.TurnToPlay);
  • end;
  • // End Process ShowHint if the corresponding property is TRUE , message will be sent to ShowHintEnd
  • procedure TForm1.ImageSquareMouseLeave(Sender: TObject);
  • var
  • name : string ;
  • number: integer ;
  • begin
  • // Will send messages for all the squares who could be turned
  • // Back
  • self.Othello.ReleaseHintProc(self.Othello.TurnToPlay);
  • end;
  • // Occurs for every Disc who will be turned while playing, message will be sent to Flip
  • procedure TForm1.OthelloFlip(pt: TPoint; color: TDiscColor);
  • var
  • i : integer;
  • begin
  • // Change the imafe of the flipped Square
  • i := self.Othello.PointToSqareNumber(pt) ;
  • if color = White then
  • FImgArr[i].Canvas.Draw(0,0,Bitmap2);
  • if color = Black then
  • FImgArr[i].Canvas.Draw(0,0,Bitmap1);
  • FImgArr[i].Refresh;
  • end;
  • // Must be called BEFORE everything else ...
  • procedure TForm1.OthelloGameNew(Sender: TObject);
  • begin
  • self.Labelnewgame.caption := 'New Game Started';
  • end;
  • // Called at the end of the game
  • procedure TForm1.OthelloGameEnd(Sender: TObject);
  • begin
  • self.wl.Caption := IntToStr(self.Othello.WhiteCount) ;
  • self.bl.Caption := IntToStr(self.Othello.BlackCount) ;
  • self.LabelPlayer.Caption := 'No move possible';
  • self.Labelnewgame.Caption :='End of the Game';
  • ShowMessage('End of Game ..');
  • end;
  • // Occurs when the users adds a disc while playing
  • procedure TForm1.OthelloPlaceBegin(pt: TPoint; color: TDiscColor);
  • var
  • i : integer ;
  • begin
  • i := self.Othello.PointToSqareNumber(pt) ;
  • if color = Black then
  • FImgArr[i].Canvas.Draw(0,0,Bitmap1);
  • if color = White then
  • FImgArr[i].Canvas.Draw(0,0,Bitmap2);
  • FImgArr[i].Refresh;
  • end;
  • // Occurs et the end of the place of a disc
  • procedure TForm1.OthelloPlaceEnd(pt: TPoint; color: TDiscColor);
  • begin
  • if self.Othello.TurnToPlay = Black then self.LabelPlayer.Caption := 'Black to play' ;
  • if self.Othello.TurnToPlay = White then self.LabelPlayer.Caption := 'White to play' ;
  • self.wl.Caption := IntToStr(self.Othello.WhiteCount) ;
  • self.bl.Caption := IntToStr(self.Othello.BlackCount) ;
  • end;
  • // Occurs if the disc placement is NOT correct
  • procedure TForm1.OthelloPlaceError(pt: TPoint; color: TDiscColor);
  • begin
  • // Fired when the Square is not valid when played ..thru "PlaceDiscsInGame" proc.
  • ShowMessage('Can not Play his !');
  • end;
  • // Draws the highlight square image for every possible move
  • procedure TForm1.OthelloShowHintBegin(pt: TPoint; color: TDiscColor);
  • var
  • i : integer ;
  • begin
  • i := self.Othello.PointToSqareNumber(pt) ;
  • if color = Black then
  • FImgArr[i].Canvas.Draw(0,0,Bitmap1);
  • if color = White then
  • FImgArr[i].Canvas.Draw(0,0,Bitmap2);
  • FImgArr[i].Refresh;
  • end;
  • // Changes back the Bitmap for every possible square
  • procedure TForm1.OthelloShowHintEnd(pt: TPoint; color: TDiscColor);
  • var
  • i : integer ;
  • begin
  • i := self.Othello.PointToSqareNumber(pt) ;
  • if color = Black then
  • FImgArr[i].Canvas.Draw(0,0,Bitmap2);
  • if color = White then
  • FImgArr[i].Canvas.Draw(0,0,Bitmap1);
  • FImgArr[i].Refresh;
  • end;
  • // Draws the Highlight bitmap for the possible squares
  • procedure TForm1.OthelloShowPlayableBegin(pt: TPoint; color: TDiscColor);
  • var
  • i : integer ;
  • begin
  • i := self.Othello.PointToSqareNumber(pt) ;
  • FImgArr[i].Canvas.Draw(0,0,Bitmap3);
  • FImgArr[i].Refresh;
  • end;
  • // Draws back the normal empty image
  • procedure TForm1.OthelloShowPlayableEnd(pt: TPoint; color: TDiscColor);
  • var
  • i : integer ;
  • begin
  • i := self.Othello.PointToSqareNumber(pt) ;
  • FImgArr[i].Canvas.Draw(0,0,Bitmap0);
  • FImgArr[i].Refresh;
  • end;
  • end.


Liste des fichiers du ZIP

FichierTaille
Othello/Capture.JPG39,95 Ko
Othello/Othello Test/__history/Test_Othello.dpr.~1~238 o
Othello/Othello Test/__history/Test_Othello.dpr.~2~238 o
Othello/Othello Test/__history/Test_Othello.dpr.~3~253 o
Othello/Othello Test/__history/Test_Othello.dpr.~4~345 o
Othello/Othello Test/__history/Test_Othello.dpr.~5~345 o
Othello/Othello Test/__history/Unit1.dfm.~1~2,8 Ko
Othello/Othello Test/__history/Unit1.dfm.~2~2,82 Ko
Othello/Othello Test/__history/Unit1.dfm.~3~2,82 Ko
Othello/Othello Test/__history/Unit1.pas.~10~8,13 Ko
Othello/Othello Test/__history/Unit1.pas.~11~8,13 Ko
Othello/Othello Test/__history/Unit1.pas.~12~8,11 Ko
Othello/Othello Test/__history/Unit1.pas.~13~8,11 Ko
Othello/Othello Test/__history/Unit1.pas.~14~8,48 Ko
Othello/Othello Test/__history/Unit1.pas.~15~8,48 Ko
Othello/Othello Test/__history/Unit1.pas.~6~7,64 Ko
Othello/Othello Test/__history/Unit1.pas.~7~7,64 Ko
Othello/Othello Test/__history/Unit1.pas.~8~7,74 Ko
Othello/Othello Test/__history/Unit1.pas.~9~7,74 Ko
Othello/Othello Test/__history/Unit2.dfm.~34~2,64 Ko
Othello/Othello Test/__history/Unit2.dfm.~35~2,64 Ko
Othello/Othello Test/__history/Unit2.dfm.~36~2,44 Ko
Othello/Othello Test/__history/Unit2.dfm.~37~2,78 Ko
Othello/Othello Test/__history/Unit2.dfm.~38~2,81 Ko
Othello/Othello Test/__history/Unit2.dfm.~39~2,81 Ko
Othello/Othello Test/__history/Unit2.dfm.~40~2,81 Ko
Othello/Othello Test/__history/Unit2.dfm.~41~2,48 Ko
Othello/Othello Test/__history/Unit2.dfm.~42~2,37 Ko
Othello/Othello Test/__history/Unit2.dfm.~43~2,8 Ko
Othello/Othello Test/__history/Unit2.pas.~39~7,59 Ko
Othello/Othello Test/__history/Unit2.pas.~40~7,57 Ko
Othello/Othello Test/__history/Unit2.pas.~41~7,6 Ko
Othello/Othello Test/__history/Unit2.pas.~42~7,64 Ko
Othello/Othello Test/__history/Unit2.pas.~43~7,64 Ko
Othello/Othello Test/__history/Unit2.pas.~44~7,63 Ko
Othello/Othello Test/__history/Unit2.pas.~45~7,63 Ko
Othello/Othello Test/__history/Unit2.pas.~46~7,62 Ko
Othello/Othello Test/__history/Unit2.pas.~47~7,62 Ko
Othello/Othello Test/__history/Unit2.pas.~48~7,62 Ko
Othello/Othello Test/Images/Blanc.bmp6,03 Ko
Othello/Othello Test/Images/Noir.bmp6,03 Ko
Othello/Othello Test/Images/Possible.bmp6,03 Ko
Othello/Othello Test/Images/Vide.bmp6,03 Ko
Othello/Othello Test/Test_Othello.dpr345 o
Othello/Othello Test/Test_Othello.dproj8,39 Ko
Othello/Othello Test/Test_Othello.dproj.local1,92 Ko
Othello/Othello Test/Test_Othello.dres24,28 Ko
Othello/Othello Test/Test_Othello.identcache149 o
Othello/Othello Test/Test_Othello.mes6,83 Ko
Othello/Othello Test/Test_Othello.res291,6 Ko
Othello/Othello Test/Test_OthelloResource.rc149 o
Othello/Othello Test/Unit1.dfm3,03 Ko
Othello/Othello Test/Unit1.pas8,48 Ko
Othello/Othello Test/Unit2.dfm2,8 Ko
Othello/Othello_Unit.pas26,47 Ko

Pour télécharger le zip au complet, veuillez vous rendre sur cette page :
Télécharger JEUX D' OTHELLO


Sources du même langage comportant un zip


Voir la suite...





Softwares to download (FR)...

  • Nego Facturation (1.84) [Gratuit / Freeware]
    Nego Facturation (1.84) [Gratuit / Freeware]
    Nego Facturation est un logiciel complet qui permet de gérer vos factures et devis très simplement. Ce programme est doté d'une ergonomie incomparable déstinée à satisfaire les utilisateurs les plu...
  • Revealer Keylogger Free (2.07) [Gratuit / Freeware]
    Revealer Keylogger Free (2.07) [Gratuit / Freeware]
    Keylogger invisible et gratuit pour Windows 8, 7, Vista ou XP. Revealer Keylogger Free vous permet de surveiller l'activité des utilisateurs de votre ordinateur et d'enregistrer toutes les touches du ...
  • Devis-Factures PHMSD (2.1.0.1)
    Devis-Factures PHMSD (2.1.0.1)
    Configuration minimale Nécessite Windows™ 2000, XP, Windows 7, 8, Vista (Service Pack à jour) - Processeur 500 Mhz (700 Mhz conseillé) - 256 Mo de Ram - 100 Mo d'espace disque disponible po...

Sondage...

Le top des photos

Photo ??Photo ???????????????
Photo ????????Photo ????????
 

Développement réalisé par Nicolas SOREL (Nix) et Emmanuel (EBArtSoft) avec l'aide de Cyril DURAND, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,53 sec