Forum > Games

Leap Frogs Logic Game now with Variable Size

(1/5) > >>

Boleeman:
Here is a fixed array shape version of the Leap Frogs Game.
How could the number of frogs be made variable using a dynamic array of images of frogs, instead of shapes.
(Like the Scratch programming Version at https://scratch.mit.edu/projects/757947021/fullscreen/   )


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)    btn_reset: TButton;    success_image: TImage;    lbl_Total_moves: TLabel;    Memo1: TMemo;    shape_frog1: TShape;    shape_frog2: TShape;    shape_frog3: TShape;    shape_frog4: TShape;    shape_frog5: TShape;    shape_frog6: TShape;    shape_frog7: TShape;    shape_frog8: TShape;    shape_frog9: TShape;    procedure btn_resetClick(Sender: TObject);    procedure CloseClick(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure shapeMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);  private   public    procedure Restore();    procedure Horray();  end; var  Form1: TForm1;  Moves, Pos, Direction : integer;  Postions: Array[1..9]of Integer;  frogs: Array[1..9] of TShape;  implementation {$R *.lfm} { TForm1 } procedure TForm1.CloseClick(Sender: TObject);begin  Haltend;  procedure TForm1.FormCreate(Sender: TObject);begin  frogs[1]:=shape_frog1;  frogs[2]:=shape_frog2;  frogs[3]:=shape_frog3;  frogs[4]:=shape_frog4;  frogs[5]:=shape_frog5;  frogs[6]:=shape_frog6;  frogs[7]:=shape_frog7;  frogs[8]:=shape_frog8;  frogs[9]:=shape_frog9;  Restoreend; procedure TForm1.Restore;var i: Integer;beginfor i:=1 to 9 do  begin    Postions[i]:=i;    frogs[i].Left:=70*i;  end;Moves:=0;lbl_Total_moves.Caption:= 'Moves Made = ' + IntToStr(Moves);Memo1.Visible:=True;success_image.Visible:=False;end; procedure TForm1.Horray;beginsuccess_image.Visible:=Trueend; procedure TForm1.shapeMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var i,j: Integer;begin  for i:=1 to 9 do  if Sender=frogs[i] then     begin       if i<=5 then Direction:=1 else Direction:=-1;       for j:=1 to 2 do          begin             if (Postions[5]=Postions[i]+j*Direction) then                begin                   frogs[5].Left:=frogs[5].Left-70*j*Direction;                   frogs[i].Left:=frogs[i].Left+70*j*Direction;                   Postions[i]:=Postions[i]+j*Direction;                   Postions[5]:=Postions[5]-j*Direction;                   Moves:=Moves+1;                   lbl_Total_moves.Caption:= 'Moves Made = ' + IntToStr(Moves);                end          end;    end;    if Moves=24 then Horray; end; procedure TForm1.btn_resetClick(Sender: TObject);begin  Restoreend; end. 

KodeZwerg:

--- Quote from: Boleeman on January 20, 2024, 02:18:19 pm ---How could the number of frogs be made variable using a dynamic array of images of frogs, instead of shapes.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TFrogs = array of WhatEverYouWantItToBe; var  frogs: TFrogs;
--- End quote ---
Watching your provided images my logic would be, quick and dirty thought:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TField = array of Integer; // this holds the playable field as array of integer, while integer is a TFrog Index  TFrog = record // define all you need for 1 frog    Alliance: Integer; // 0 for the green 1 for the other    Direction: Integer; // 0 looks to the right, 1 looks to left  end;  TFrogs = array of TFrog; // make above working for all frogs, TField keeps track of where what frog is and what states it got  TImages = array of TImage; // at creation, assign a TImageList that holds all possible graphics, Like ImageIndex 0 = an empty leaf, ImageIndex 1 = green frog (alliance 0) looking to left (direction 1) plus a leaf where it sit on, ImageIndex 2 = green frog looking to right sit on a leaf .... and so onThat would be my basic needed type definitions, creating them via SetLength() like I showed in the Tower or ShapeColoring thing.

Maybe if I do program such, I would do it differently, anyway, that be my start :)

Boleeman:
Horray.

Version 2 of the Leap Frogs Games with a dynamic Array for variable sizes.

Now ... to have a choice of images:  frogs and other images.

dbannon:
Two problems -

[x] The spacing between 'frogs' messes up first time through. Press the reset button and its fine after that.

[x] It is too hard for me !

Cute game !

Davo

dseligo:

--- Quote from: dbannon on January 28, 2024, 10:56:18 am ---[x] It is too hard for me !

--- End quote ---

You just start with one color and count moves.
Red - 1 move, blue 2 moves, red 3, blue 4, red 5, and so on.
Need 195 moves for 13 frogs.

Navigation

[0] Message Index

[#] Next page

Go to full version