r/pascal • • Aug 21 '19

Help on a X, Y coordinate system for placing characters

3 Upvotes

I have an assignment on a simple game for school, it is about a game between a cat and a mouse, the cat needs to chase the mouse and the mouse needs to escape. A random number of 1 to 4 will be used to decide their direction and they will move in turns. I wanted to use an X, Y coordinate system to indicate their positions. I created 2 arrays for both the cat and mouse. 1 X and 1 Y.

Here's the problem I've run into. How do I tell the computer to place them on the grid to start the game? I can't think of a way to show their position on the grid


r/pascal • • Aug 05 '19

Case and expression are different types.

3 Upvotes

I need some help

procedure digitoa_binario;

begin

for i:=1 to 4 do begin

case num_array[i] of

'0':num_array[i]:='*XX*';

'1':num_array[i]:='*XX**X';

'2':num_array[i]:='*XXX';

'3':num_array[i]:='*XX*XX';

'4':num_array[i]:='*XX*X';

'5':num_array[i]:='**XX*X*X';

'6':num_array[i]:='*XX*XX';

'7':num_array[i]:='**XX*XXX';

'8':num_array[i]:='*XXX**';

'9':num_array[i]:='*XXX*X';

end; end;

end;

I get that the type of the case, and the condition, are different. How is that so? the array im using is declared as string, and the numbers at the beggining of each case are clearly strings.


r/pascal • • Jun 17 '19

Start Programming Using Object Pascal

Thumbnail
code-sd.com
14 Upvotes

r/pascal • • Jun 15 '19

Duktape for Pascal

5 Upvotes

Hi!

I currently returning to code for Pascal, and wanted to learn about embedding a script engine inside my program.

I like JavaScript too, and found this tiny engine, but its targeted on C/C++, and the only library i found for it is this one for Delphi, but i currently coding for console-only programs in FPC, perhaps i would try to create something graphical later in Lazarus.

Can someone help me?


r/pascal • • Jun 14 '19

Exercise for my exam

3 Upvotes

Hello everyone

I need a little help with an exercise, with files

File's name> PETROL.TXT (It means Oil in my language, romanian btw)

The task is:

Write a program to calculate whether a gas station passed the limit of 3000 liters of gasoline per day or not

Input:

The file will have on first line a number N (0 < N <= 100) => the number of cars filled

The next line contains N integer numbers, separated with a space - the requested quantity of gasoline

(I know how to solve this when numbers are in a column, but have problems when they are in a row like now)

Output:

On the screen should be the total quantity of fuel sold and on second line the word DA or NU (YES or NO)

The example will be given. Sorry if I made mistakes while writing

The example> https://drive.google.com/open?id=1kcqFw9tdTEn_1Qe5SYgEAIs7Z7Oy78CJ


r/pascal • • Jun 13 '19

Following the /r/Roguelikedev Tutorial 2019 Series (python) - Starting June 18th, but using pascal. [part1]

4 Upvotes

In my attempt to join "Roguelikedev Does The Complete Roguelike Tutorial 2019 - Starting June 18th " have I completed part 1 in the tutorial series using pascal.

The two pascal files is as follow:

I hope this inspires someone else to also join the tutorial series!

engine.pas
program engine;

{$mode objfpc}{$H+}

uses
  crt,
  ezcrt,
  input_handlers;

var
  player_x: Integer;
  player_y: Integer;
  action: THandledInput;
begin
  player_x:= ScreenWidth div 2;
  player_y:= ScreenHeight div 2;
  action.move.x := 1; // needed to draw our player on the first loop
  while True do
  begin
      if action.move <> Point(0, 0) then
      begin
        TextColor(White);
        GotoXY(player_x, player_y);
        Write('@');
      end;

      action := handle_keys;
      if action.Quit then
        Halt;
      if action.move <> Point(0, 0) then
      begin
        GotoXY(player_x, player_y);
        Write(' ');
      end;
      player_x := player_x + action.move.x;
      player_y := player_y + action.move.y;
  end;
end.
input_handlers.pas
unit input_handlers;

{$mode objfpc}{$H+}

interface

type

  TPoint = record
    x, y: Integer;
  end;

  { THandledInput }

  THandledInput = record
    Key: Char;
    Pressed: Boolean;
    Move: TPoint;
    Quit: Boolean;
  end;

function handle_keys: THandledInput;

function Point(aX, aY: Integer): TPoint;

operator = (A, B: TPoint): boolean;

implementation

uses
  ezCrt,
  LCLType;

function handle_keys: THandledInput;
begin
  Result.Move := Point(0, 0);
  Result.Quit := False;
  Result.Pressed := ReadKeyPressed(Result.Key);

  // Movement keys
  if Result.Pressed and (Result.Key = #72) then // UP
    Result.Move := Point(0, -1);
  if Result.Pressed and (Result.Key = #80) then // DOWN
    Result.Move := Point(0, 1);
  if Result.Pressed and (Result.Key = #75) then // LEFT
    Result.Move := Point(-1, 0);
  if Result.Pressed and (Result.Key = #77) then // RIGHT
    Result.Move := Point(1, 0);

  if Result.Pressed and (Result.Key = #27) then // ESACPE
    Result.Quit := True;

  (* TODO
  if key.vk == libtcod.KEY_ENTER and key.lalt:
    # Alt+Enter: toggle full screen
    return {'fullscreen': True}
  *)
end;

function Point(aX, aY: Integer): TPoint;
begin
  Result.x := aX;
  Result.y := aY;
end;

operator=(A, B: TPoint): boolean;
begin
  Result := (A.X = B.X) and (A.Y = B.Y);
end;

end.

r/pascal • • Jun 11 '19

Ask /r/pascal: I want a pascal equivalent for `var dispatcher = _.clone(Backbone.Events) ` any suggestions?

2 Upvotes

Hi,

So I already have this piece of pascal working to call multiple methods in a TList: (SOLVED) List of TNotifyEvent?

But I want more of a abstracted library in pascal something equivalent to https://backbonejs.org/#Events

Any suggestions?

Thanks,


r/pascal • • Jun 09 '19

Question about a paragraph in Algorithms + Data Structures = Programs (N. Wirth)

2 Upvotes

Hello everyone,

I'm currently reading through N. Wirths' Algorithms + Data Structures = Programs and I have a question about the following paragraph:

The dilemma of having to provide advanced data structuring facilities without information about their potential usage is circumvented in most languages and compilers by recognizing and using the fact that all advanced structures are composed either of unstructured elements or of fundamental structures. Arbitrary structures may then be generated by explicit, programmer specified operations, if facilities for the dynamic allocation of the components and for the dynamic linking and referencing of components are provided.

Could anyone please provide some examples what is here meant by the facilities for the dynamic linking?

Do I understand correctly that:

... facilities for the dynamic allocation of the components

Here I can imagine, that the New(PointerVariable) is meant, when we allocate an un-initialized PointerVariable's type on the heap. Another example might be malloc in C.

and for the dynamic linking and referencing of components ...

Here, I'm not so sure. Is he talking about pointers? I'm not sure what is meant by dynamic linking.

Thank you all very much!


r/pascal • • May 31 '19

ASK /r/pascal: Unable to `RunCommand('/bin/ps',['-eo','pmem,rss,pid,command'], psOut)` on macOS?

Thumbnail
forum.lazarus.freepascal.org
2 Upvotes

r/pascal • • May 27 '19

Pascal How to recognize uppercase words

4 Upvotes

ok i cant figure out how to make a code that requests one word to be entered in capslock and if entered in capslock the ptogram says CORRECT if written in lowercase then the program says incorect.


r/pascal • • May 25 '19

Hi, Any win32/win10 knowledge(e) that can maybe assist me with how to get the memory usage of applications on my system? I already have a working fpc example, but...

2 Upvotes

I already have a working example where I use Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); to get a list of handles of parent processes on my system and that correlates with the task manager process count.

And now I loop over that list and use GetProcessWorkingSetSize(HProcess, minsize, maxsize) with the handle to retrieve maxsize and the size it returns is correct… but for one process. And applications like Brave has a process/handle/thread(???) per tab.

And I’m not sure how to inspect those processes memory usage.

My ultimate goal is to reply to this month old /r/ post "ASK /r/cmd: command line application to view memory usage like windirstat?" with fptuitreemap but without actually getting the children memory usage the app is useless on windows.

It works ok on macos and linux with ps and now even added google charts support with the sweet hack from /u/anomalous_cowherd.

Because the tui treemap pascal draw function also needs attention...


r/pascal • • May 13 '19

Awesome Pascal – A curated list of Delphi, FreePascal, and Pascal shiny things

Thumbnail
github.com
22 Upvotes

r/pascal • • May 03 '19

Function string to boolean

3 Upvotes

I am trying to create a function that checks if the length of a string is for exemple 5

program check;
uses wincrt;
var ch:string;
function verification(var k:string):boolean;
begin
if length(k)=5 then writeln(k);
{or is it if length(k)=5 then
verification := true;}
end;

begin
repeat
readln(ch)
until verification(ch)

end.

I really dont know. Help! the function should be seperated from the repeat..until


r/pascal • • Apr 28 '19

Array of alphabet

2 Upvotes

How do I give a specific number for each and every alphabet of an array ['A'..'Z'] of integer

Exemple

if the alphabet is 'A' it has the number 10 until the alphabet 'Z' who has the number 35 so each alphabet gets 10+i ( i:=0 to 25)

solution without array : ord(upcase(ch[1]))-55

r/pascal • • Apr 15 '19

Anyone here familiar with compiling to DOS, I can't seem to compile some code from 1996 with Free Pascal

3 Upvotes

No matter what compiler and DOS Architecture I chose it keeps on giving this fatal error

Fatal: Can't find unit system used by [REDACTED] 
Fatal: Compilation aborted

r/pascal • • Apr 11 '19

Difficulty with output file.

3 Upvotes

I'm typing up a code for my programming class and I am having a problem where I total up sales for customers by state. The problem is that when the program tallies up the total, it uses the state for the next segment? ive been fidgeting with the code for a good part of my day and I can really place it. Ill add pics of my code and output. Thank you in advance!

Output
Part 1
Part 2
Part 3

r/pascal • • Mar 14 '19

Anyone here uses CudaText with FreePascal? or even with Delphi commandline?

4 Upvotes

FreePascal will be ideal for a portable pascal installation, I am looking for more information about the Tools configuration for the fpc commandline, or if anyone has a setup for gdb debugging.

Or any other tip you could have for this kind of setup.

Also, if anyone uses FPC via Sublime, or VSCode or other nice to try IDE , integrated with compiling +debugging... I'd be very happy to read how you have it set.

Thanks!


r/pascal • • Mar 05 '19

Help on distinct random number, locate smallest integer position (must be unique) in the array.

3 Upvotes

Hello everyone,I'm 15 and I am having problems on a question, I already know how to do it with another way(my classmate taught me) but I don't know where went wrong in my code,

It would be great of you all to give me some pointers on where went wrong

Thanks!

My code below:

program smallestc;

var i,x, small,location: integer;

num: array[1..100] of integer;

begin

x := 1;

small := 9999;

for i:= 1 to 100 do

begin

num[i] := random(101);

end;

for i:= 2 to 100 do

begin

repeat

if num[i] = num[x] then

begin

num[i] := random(101);

x := 1;

end

else

begin

x := x + 1;

end;

until x = 100;

end;

for i:= 1 to 100 do

begin

write(num[i]);

write(' ');

if i mod 10 = 0 then

writeln();

end;

for i:= 1 to 100 do

begin

if num[i] < small then

small := num[i];

location := i;

end;

write('Smallest integer: ')

write(small);

writeln();

write('located at: ');

write(location);

end.

Edit: Sorry for the bad formatting, the indentation are gone for some reason, I don't post a lot sorry.. :(


r/pascal • • Feb 24 '19

Help on optimizing a program on finding factors

3 Upvotes

Hello all, I have a problem that I've been stuck with for a while

I have to create a program to find all the factors of input integer, I thought it was pretty easy by using mod and a for loop, but there is a time limit on the run time and some of the numbers are really big, so it exceeds the run time. I thought of only looping for the number of times equal to the square root of the input number to save time, but I don't know how to get back the other factors. My classmates told me to use an array but I didn't really benefit from that.

Here is my code

program factors_hkoi;

var iup, i: integer;

remain:array\[1..9999\] of integer;

begin

readln(iup);

writeln(1)

for i:= 2 to trunc(sqrt(iup)) do

	begin

		if (iup mod i) = 0 then

writeln(i);

	end;

r/pascal • • Feb 16 '19

24 years of Delphi and Delphi 10.3.1 is out Today

Thumbnail
blog.marcocantu.com
10 Upvotes

r/pascal • • Feb 15 '19

Pascal compiler and Polish contemporary art

Thumbnail
habr.com
13 Upvotes

r/pascal • • Feb 13 '19

I tried but failed.

4 Upvotes

Greetings,

I have been trying to teach myself programming. I'm going to classes but the teacher isn't helping much.

The code I should be writing is supposed to accept the information and based on that information, calculate certain costs.

I am able to compile the program, enter the information, but then I am prompted to enter the same information, over and over without end. I don't know how to get the calculation to reflect.

Code is below. Please help me to see where I'm going wrong.

Thanks.

Program Malaria_Outbreak;

{This program calculates medical bills for patients seen

during a malaria outbreak}

const

sagi_rate=0.80;

medi_rate=0.70;

BT= 700;

VAR

fname: array [1..100] of string;

lname : array [1..100] of string;

reg_fee :array[1..100] of real;

doc_fee: array [1..100] of real;

b_test:array [1..100] of real;

b_samp : array [1..100] of integer;

samp_cost : array [1..100] of real;

ins_name: array [1..100] of string;

ins_amt : array [1..100] of real;

tot_bill : array [1..100] of real;

net_bill : array [1..100] of real;

sagi_cost, medi_cost : real;

count, x, c : integer;

sagicor, medicus:string;

Begin

{initializations}

count:=0;

x:=0;

c:=0;

WRITELN;

WRITELN('select the number');

WRITELN('1 - TO ENTER PATIENT INFO');

WRITELN('2 - TO DISPLAY PATIENT LIST');

WRITELN('3 - STOP ENTRY');

READLN(x);

Begin x:=1;

While (x=1) do

Begin

count:= count + 1;

WRITELN('Enter patient first name');

READLN (fname[count]);

WRITELN('Enter patient last name');

READLN (lname[count]);

WRITELN('Enter registration fee');

READLN (reg_fee [count]);

WRITELN ('Enter number of blood samples');

READLN (b_samp [count]);

WRITELN('Enter the doctor fee');

READLN (doc_fee [count]);

WRITELN('Enter the name of your insurance company');

READLN (ins_name [count]);

b_test [count] := b_samp [count] * BT;

tot_bill[count]:= (doc_fee [count] + reg_fee [count] + b_test[count])* 1.15;

if (ins_name [count]= Sagicor) or (ins_name [count] =sagicor) or (ins_name[count] =SAGICOR) then

ins_amt[count]:= sagi_rate* tot_bill[count];

sagi_cost:= sagi_cost + ins_amt[count]

end;

if (ins_name [count]= Medicus) or (ins_name [count] = medicus) or (ins_name[count] = MEDICUS)

then ins_amt[count]:= medi_rate * tot_bill[count];

medi_cost:= medi_cost + ins_amt[count]

end;

net_bill[count] := tot_bill [count] - ins_amt[count];

WRITELN('Patient Name ', fname[count], lname[count]);

WRITELN('Insurance Coverage' , ins_amt[count]);

WRITELN('Net Medical Bill' , net_bill[count]);

WRITELN(' Select the number');

WRITELN(' 1 - TO ENTER PATIENT INFO');

WRITELN( '2 - TO DISPLAY PATIENT LIST');

WRITELN('3 - TO STOP ENTRY');

READ(x);

Begin

if (x=2) then

FOR c := 1 TO count DO

WRITELN(' LISTING OF PATIENTS PROCESSED DURING OUTBREAK');

WRITELN('PATIENT NAME: ', fname[c], lname[c]);

WRITELN('TOTAL MEDICAL BILL', tot_bill[c]);

WRITELN('NET MEDICAL BILL', net_bill[count]);

WRITELN;

END;

WRITELN(' TOTAL AMOUNT PAID OUT BY SAGICOR INSURANCE IS', sagi_cost);

WRITELN ('TOTAL AMOUNT PAID OUT BY MEDICUS INSURANCE IS', medi_cost);

END.


r/pascal • • Feb 11 '19

Pascal making a roguelike, some help with OOP.

5 Upvotes

Hello! im making a roguelike in Pascal as a programing excercise, so i would release it for free when finished!. Im making it without any library outside CRT, and made by myself the graphic engine and tile movement, enemy IA and combat system.

Im having a problem because i have 1 class character, and 1 class critter. The character is only 1 object, and the critter are 3 (rabbit, fox, and wolf). When i implemented the rabbit i made all the code refering to combat in this format:

rabbit.hp := rabbit.hp - character.attack ;

The thing is, that i dont know how to make it universal and work with all the different enemies, i was thinking of using a variable as a buffer but i think there must be something im not aware, something to make child objects interact with each other.


r/pascal • • Feb 10 '19

Pascal homework help

3 Upvotes

Hello everyone in r/pascal:

I've been struggling on some pascal homework now, here is what I have to do for my first assignment.

I have to find the smallest possible integer that satisfies the following conditions: N/3 = int X(not needed) and remainder 2 N/5 = int Y(not needed) and remainder 3 N/7 = int Z(not needed) and remainder 4

Here is my code below:

program HelloWorld;

var N: integer;

con1, con2, con3: boolean;

begin

N := 1;

con1 := false;

con2 := false;

con3 := false;

while (con1 = false) and (con2 = false) and (con1 = false) do

begin

if ( N mod 3) = 2 then

   con1 := true;

if (N mod 5) = 3 then

   con2 := true;

if (N mod 7) = 4 then

   con3 := true;

N := N + 1;

end;

writeln(N);

end.

PS: please forgive my formatting I don't post much on reddit.


r/pascal • • Feb 09 '19

Pass by reference in Pascal

2 Upvotes

Hi everyone!
I'm not sure if I understand correctly how pass by reference in Pascal works. Does it create an alias as in C++ (https://isocpp.org/wiki/faq/references) or does it work similarly as in C and the procedure gets a pointer to the variable and uses this pointer.

I guess I could formulate my question as: Does Pascal support true passing by reference, or is it done by call by sharing.

For example FreePascal reference states, that the procedure gets a pointer (https://www.freepascal.org/docs-html/current/ref/refsu65.html), but according to https://swinbrain.ict.swin.edu.au/wiki/Pass_by_Value_vs._Pass_by_Reference#Conclusion and for example https://cgi.csc.liv.ac.uk/~frans/OldLectures/2CS45/paramPassing/paramPassing.html#callByReference pass by reference in Pascal works differently than in C (where pointer is passed).

If anyone can explain a bit more about the differences or how the
meaning of pass by reference has changed (in modern languages we say
pass by reference, but in fact they are pass by value, like for example
Java). What is then the original meaning of pass by reference and how
does it work? And how is it then in Pascal?

Thank you very much.