Author Topic: Not Sure What has happened here in my use of IMP logical operator  (Read 5499 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Not Sure What has happened here in my use of IMP logical operator
« Reply #15 on: March 27, 2021, 07:21:28 pm »
@Pete  And @bplus
here the srhinked version of my demo into 17 lines

Code: QB64: [Select]
  1. Hero(1) = Int((Rnd * 79) + 1)
  2. Hero(2) = Int((Rnd * 22) + 1)
  3.     If a = 1 Then Cls ' refresh screen  / ripulisce lo schermo
  4.     If a = 1 Then If (10 < Hero(1) Imp Hero(1) >= 70) Or (2 < Hero(2) Imp Hero(2) >= 19) Then Print "Out of game" Else Print " In game"
  5.     If a < 20 And a > 1 Then If (a = 2 Or a = 19) Then Print Space$(10) + String$(60, Chr$(178)) Else Print Space$(10) + Chr$(178) + Space$(58) + Chr$(178)
  6.     If a = 24 Then Locate 24, 30
  7.     If a = 24 Then Print " cursors to  move Hero";
  8.     If a = Hero(2) Then Locate Hero(2), Hero(1)
  9.     If a = Hero(2) Then Print ""
  10.     If InKey$ = Chr$(0) + "M" Then If Hero(1) < 80 Then Hero(1) = Hero(1) + 1
  11.     If InKey$ = Chr$(0) + "H" Then If Hero(2) > 1 Then Hero(2) = Hero(2) - 1
  12.     If InKey$ = Chr$(0) + "P" Then If Hero(2) < 23 Then Hero(2) = Hero(2) + 1
  13.     If InKey$ = Chr$(0) + "K" Then If Hero(1) > 1 Then Hero(1) = Hero(1) - 1
  14.     If a = 25 Then _Limit 5
  15.     If a = 25 Then a = 1 Else a = a + 1

Please try it. I think it would be smoother with  _Keyhit
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Not Sure What has happened here in my use of IMP logical operator
« Reply #16 on: March 27, 2021, 07:31:16 pm »
@TempodiBasic

Very nice but needs one more line because hero refuses to budge specially with down keypress:
Code: QB64: [Select]
  1. Hero(1) = Int((Rnd * 79) + 1)
  2. Hero(2) = Int((Rnd * 22) + 1)
  3.     If a = 1 Then Cls ' refresh screen  / ripulisce lo schermo
  4.     If a = 1 Then If (10 < Hero(1) Imp Hero(1) >= 70) Or (2 < Hero(2) Imp Hero(2) >= 19) Then Print "Out of game" Else Print " In game"
  5.     If a < 20 And a > 1 Then If (a = 2 Or a = 19) Then Print Space$(10) + String$(60, Chr$(178)) Else Print Space$(10) + Chr$(178) + Space$(58) + Chr$(178)
  6.     If a = 24 Then Locate 24, 30
  7.     If a = 24 Then Print " cursors to  move Hero";
  8.     If a = Hero(2) Then Locate Hero(2), Hero(1)
  9.     If a = Hero(2) Then Print ""
  10.     k$ = InKey$
  11.     If k$ = Chr$(0) + "M" Then If Hero(1) < 80 Then Hero(1) = Hero(1) + 1
  12.     If k$ = Chr$(0) + "H" Then If Hero(2) > 1 Then Hero(2) = Hero(2) - 1
  13.     If k$ = Chr$(0) + "P" Then If Hero(2) < 23 Then Hero(2) = Hero(2) + 1
  14.     If k$ = Chr$(0) + "K" Then If Hero(1) > 1 Then Hero(1) = Hero(1) - 1
  15.     If a = 25 Then _Limit 25
  16.     If a = 25 Then a = 1 Else a = a + 1
  17.  
  18.  

Did Steve help you with this? ;-))


Also Hero inbound on left border but out bounds on the other borders
  [ You are not allowed to view this attachment ]  

I think you just need another = sign.

Also hero refuses to go below row 23 I think, wont run down along bottom of screen.

Still very clever!
« Last Edit: March 27, 2021, 07:41:08 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Not Sure What has happened here in my use of IMP logical operator
« Reply #17 on: March 27, 2021, 09:41:06 pm »
@TempodiBasic

I have yours down to 16 with out the message to use cursor keys, still can't go past 23 but the in/out is consistent:
Code: QB64: [Select]
  1. Hero(1) = Int((Rnd * 79) + 1) ' I fixed up
  2. Hero(2) = Int((Rnd * 22) + 1)
  3.     If a = 1 Then Cls ' refresh screen  / ripulisce lo schermo
  4.     If a = 1 Then If (11 < Hero(1) Imp Hero(1) >= 70) Or (2 < Hero(2) Imp Hero(2) >= 19) Then Print "Out of game" Else Print " In game"
  5.     If a < 20 And a > 1 Then If (a = 2 Or a = 19) Then Print Space$(10) + String$(60, Chr$(178)) Else Print Space$(10) + Chr$(178) + Space$(58) + Chr$(178)
  6.     If a = Hero(2) Then Locate Hero(2), Hero(1)
  7.     If a = Hero(2) Then Print ""
  8.     k$ = InKey$
  9.     If k$ = Chr$(0) + "M" Then If Hero(1) < 80 Then Hero(1) = Hero(1) + 1
  10.     If k$ = Chr$(0) + "H" Then If Hero(2) > 1 Then Hero(2) = Hero(2) - 1
  11.     If k$ = Chr$(0) + "P" Then If Hero(2) < 23 Then Hero(2) = Hero(2) + 1
  12.     If k$ = Chr$(0) + "K" Then If Hero(1) > 1 Then Hero(1) = Hero(1) - 1
  13.     If a = 25 Then _Limit 5
  14.     If a = 25 Then a = 1 Else a = a + 1
  15.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Not Sure What has happened here in my use of IMP logical operator
« Reply #18 on: March 27, 2021, 09:54:21 pm »
This gets full range of screen but a little noisey:
Code: QB64: [Select]
  1. hero = Int(Rnd * 25 * 80) + 1
  2. For a = 1 To 25
  3.     Locate a, 1
  4.     If a >= 2 And a <= 19 Then If a = 2 Or a = 19 Then Print Space$(9) + String$(62, 178) + Space$(9); Else Print Space$(9) + Chr$(178) + Space$(60) + Chr$(178) + Space$(9);
  5.     If a = 1 Or a > 19 Then Print Space$(80);
  6.     Locate 25, 33
  7.     If (hero \ 80 + 1) > 1 And (hero \ 80 + 1) < 20 And ((hero Mod 80) + 1 > 9) And ((hero Mod 80) + 1 < 72) Then Print "Hero is in/on bounds."; Else Print "  Hero is outside.";
  8.     Locate hero \ 80 + 1, (hero Mod 80) + 1
  9.     Print Chr$(1);
  10.     k$ = InKey$
  11.     If k$ = Chr$(0) + "M" Then hero = hero - (((hero Mod 80) + 1) <> 80)
  12.     If k$ = Chr$(0) + "K" Then hero = hero + (((hero Mod 80)) <> 0)
  13.     If k$ = Chr$(0) + "H" Then hero = hero + 80 * ((hero \ 80) > 0)
  14.     If k$ = Chr$(0) + "P" Then hero = hero - 80 * ((hero \ 80) < 24)
  15.     If a = 25 Then a = 0
  16.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Not Sure What has happened here in my use of IMP logical operator
« Reply #19 on: March 27, 2021, 11:40:37 pm »
2 more lines removed:
Code: QB64: [Select]
  1. hero = Int(Rnd * 25 * 80) + 1
  2. For a = 1 To 25
  3.     Locate a, 1
  4.     If a >= 2 And a <= 19 Then If a = 2 Or a = 19 Then Print Space$(9) + String$(62, 178) + Space$(9); Else Print Space$(9) + Chr$(178) + Space$(60) + Chr$(178) + Space$(9);
  5.     If a = 1 Or a > 19 Then Print Space$(80);
  6.     Locate 25, 33
  7.     If (hero \ 80 + 1) > 1 And (hero \ 80 + 1) < 20 And ((hero Mod 80) + 1 > 9) And ((hero Mod 80) + 1 < 72) Then Print "Hero is in/on bounds."; Else Print "  Hero is outside.";
  8.     Locate hero \ 80 + 1, (hero Mod 80) + 1
  9.     Print Chr$(1);
  10.     k$ = InKey$
  11.     If (k$ = Chr$(0) + "M") Or (k$ = Chr$(0) + "K") Then If k$ = Chr$(0) + "M" Then hero = hero - (((hero Mod 80) + 1) <> 80) Else hero = hero + (((hero Mod 80)) <> 0)
  12.     If (k$ = Chr$(0) + "H") Or (k$ = Chr$(0) + "P") Then If (k$ = Chr$(0) + "H") Then hero = hero + 80 * ((hero \ 80) > 0) Else hero = hero - 80 * ((hero \ 80) < 24)
  13.     If a = 25 Then a = 0
  14.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Not Sure What has happened here in my use of IMP logical operator
« Reply #20 on: March 28, 2021, 12:12:08 pm »
Hi Bplus
Thank you for take a look at my shrinked version of IMP demo.

Thank you for debug it.
Hero refuses to reach the bottom border of the screen to avoid meeting  help text on the 24 row.

Cool your improvements and the reducing of  number of lines.
And I see that you like my massive use of IF


Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Not Sure What has happened here in my use of IMP logical operator
« Reply #21 on: March 28, 2021, 12:54:21 pm »
Quote
Cool your improvements and the reducing of  number of lines.
And I see that you like my massive use of IF

Yes, you can make 2 statements effectively, at least 2 variable assignments, with "massive use of IF".