Recent

Author Topic: Helppp!!!!!!  (Read 9335 times)

lazarusins

  • New Member
  • *
  • Posts: 17
Helppp!!!!!!
« on: May 20, 2017, 06:42:24 pm »
Hello!Please help me. I have to crate program on lazarus for school , i am beginner.I have to make simple programm where is :
 if .. then .. else ..
 case .. of ..
for .. to .. do .. ;
while .. do .. ;
repeat .. until .. ;
int, round..
char, string.
random.
2 funkcions an procedures.

What can i make?


Eugene Loza

  • Hero Member
  • *****
  • Posts: 673
    • My games in Pascal
Re: Helppp!!!!!!
« Reply #1 on: May 20, 2017, 06:53:15 pm »
Basically you can make anything you like. But personally I prefer making computer games - it's both fun and educational :)

In your case you can make a simple guess game.
Let computer think of a number 0..1000 (based on randomize -> random)
And let player input some number.
Computer will say something like "No, too cold", "well, that's close!", "More... much more", etc. based on how far the player's guess was. (You can organize it by  case (player's guess / computer's number))
The game will go on until player guesses the number or says "I give up!".

You can easily demonstrate usage of most of those functions here. When you have something working, post it here, and people will help you to include others you're missing if you're strictly demanded to use all of those.
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

lazarusins

  • New Member
  • *
  • Posts: 17
Re: Helppp!!!!!!
« Reply #2 on: May 20, 2017, 07:04:24 pm »
Yes that is cool idea, but how can i make it?:)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 673
    • My games in Pascal
Re: Helppp!!!!!!
« Reply #3 on: May 20, 2017, 07:11:07 pm »
The usual approach is "start simple" and then extend your program.
E.g. first just make a program that will write a string on a screen and wait for player input.
Then make repeat...until, until player input equals to a specific string (e.g. "exit")
Then make computer react to player's input differently depending on player's input.
Now you're almost ready to make the game itself. Just make computer generate a random number and make him react depending on whether player's input is greater/smaller or equal to that number.
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

lazarusins

  • New Member
  • *
  • Posts: 17
Re: Helppp!!!!!!
« Reply #4 on: May 20, 2017, 07:16:21 pm »
Ohhh that sounds soo difficult....

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Helppp!!!!!!
« Reply #5 on: May 20, 2017, 07:24:54 pm »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$ifdef fpc}{$mode objfpc}{$apptype console}{$endif}
  3. uses sysutils;
  4. procedure proc1;
  5. begin
  6.   Beep;
  7. end;
  8.  
  9. procedure proc2;
  10. begin
  11.   Proc1;
  12. end;
  13.  
  14. function func1:boolean;
  15. begin
  16.    result := Boolean(random(1));
  17. end;
  18.  
  19. function func2:boolean;
  20. begin
  21.   result := true;
  22. end;
  23.  
  24. var
  25.    a,b:Boolean;
  26.    c:integer = 100;
  27.    d:single = 100.1;
  28.    e:string = 'Finished homework';
  29. begin
  30.    if round(d)= c then
  31.    begin
  32.      b:=func1;
  33.      if b = func1 then
  34.      case b of
  35.        true:proc1;
  36.        false:proc2;
  37.      else
  38.        for b := false to true do
  39.        while  b = func2 do
  40.          repeat
  41.            a :=func1;
  42.          until a = b;
  43.      end;
  44.    writeln(e);
  45.    end;
  46. end.

Explanation of all this is probably in your school books.
But otherwise feel free to read the documentation  8-)

BTW: It IS a game... Sometimes it beeps, sometimes not. So gamble on it.
       
« Last Edit: May 20, 2017, 07:41:42 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

lazarusins

  • New Member
  • *
  • Posts: 17
Re: Helppp!!!!!!
« Reply #6 on: May 20, 2017, 07:46:16 pm »

Unfortunately that program is not working on my computer :-X

sky_khan

  • Guest
Re: Helppp!!!!!!
« Reply #7 on: May 20, 2017, 07:49:18 pm »
You are kidding right ? Tell me you are kidding. Because this must be a joke.

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Helppp!!!!!!
« Reply #8 on: May 20, 2017, 07:49:48 pm »
It works. And fits all requirements.
« Last Edit: May 20, 2017, 07:51:53 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

lazarusins

  • New Member
  • *
  • Posts: 17
Re: Helppp!!!!!!
« Reply #9 on: May 20, 2017, 07:55:52 pm »
When i started programm, that at once stoped and lazarus sad "Exocution stopped":(

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Helppp!!!!!!
« Reply #10 on: May 20, 2017, 08:03:41 pm »
That's ok. Means that the program works...

Now I have this very difficult task for you.
Go to the end of the program where it reads end. (with a dot.)
Now just before that write: readln;

Try again. You will see that Lazarus now waits until you press Enter and then says "execution stopped".
But if you run the program from a command line it already works..

The readln; is just an extra.

BTW: Change the program a lot: your teacher will immediately know this is written by a village idiot that knows a heck of a lot about Pascal.... O:-)
« Last Edit: May 20, 2017, 08:06:01 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Handoko

  • Hero Member
  • *****
  • Posts: 5150
  • My goal: build my own game engine using Lazarus
Re: Helppp!!!!!!
« Reply #11 on: May 20, 2017, 08:16:16 pm »
Readln function maybe have not been taught in his class. His teacher will be surprised how clever the student is.  :D

Alternatively, use several (or a lot of) for..do loops.

lazarusins

  • New Member
  • *
  • Posts: 17
Re: Helppp!!!!!!
« Reply #12 on: May 20, 2017, 08:19:50 pm »
Yes i know readln funkcion. But i dont understand the mean of this program.This program only write "Finished homework" an that is all...

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Helppp!!!!!!
« Reply #13 on: May 20, 2017, 08:33:11 pm »
Yes i know readln funkcion. But i dont understand the mean of this program.This program only write "Finished homework" an that is all...
Does it have to do anything 'useful' ? (note that i wrote that between quotes. What is useful for one might not be so useful for someone else).

It is an attempt to incorporated all constructs that you asked for. On a quick glance only the char and int/round parts are missing. Perhaps you are able to add those yourself ?

bytebites

  • Hero Member
  • *****
  • Posts: 639
Re: Helppp!!!!!!
« Reply #14 on: May 20, 2017, 08:38:03 pm »
It is little boring since case-statement never gets to else-branch.

 

TinyPortal © 2005-2018