Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RPG Party System
#1
I don't know where to put this, since it's QBASIC code rewritten in FreeBASIC, and I plan to start writing my RPG in FreeBASIC because of the music and millisecond sleep timers.

Anyway, it's good to see the fourm back to the way it was. I hope I didn't miss much while I was gone.

Now then: I've been working on a Party System skeleton for my RPG a couple months ago, and I just recently pulled it up and rewrote it a bit with a new TYPE statement and sleep counts. But there are still two problem I detected: The function that allows you to throw a party member out of your party doesn't work right. It seems to only kick people out when the input is all lowercase or uppercase, and even then it claims to kick people out of your party that aren't even in there (or were there) in the first place. I can't quite explain it, you'll have to see for yourself.

I also added a debug mode to quickly test the party and monster fuctions. Sometimes, though, when I use debug mode to fill my roster, I get two of the same people in my party. How would I prevent that?

Two other requests: Is there a way I can make this code look less messy, and do you notice anything else wrong?

Thanks.

Code:
'PARTY SYSTEM TEST

OPTION BASE 1

DECLARE SUB PartyAsk ()
DECLARE SUB PartyCount ()
DECLARE SUB Attacked ()
DECLARE SUB DebugFullRoster ()

RANDOMIZE TIMER

DIM places$(6) 'declare locations
places$(1) = "a dark forest."
places$(2) = "a rocky cave."
places$(3) = "a sandy beach."
places$(4) = "a stinky bog."
places$(5) = "a supermarket."
places$(6) = "a small village."

TYPE partymem 'set party member type
    charname AS STRING
    charhp AS INTEGER
    charhitpercent AS INTEGER
END TYPE

DIM SHARED currparty(5) AS partymem

'set other stuff
DIM SHARED hp AS INTEGER

hp% = 50
order% = 2
party% = INT(RND * 10) + 1
monster% = INT(RND * 8) + 1

IF party% = 5 THEN party% = INT(RND * 10) + 1
IF monster% = 4 THEN monster% = INT(RND * 8) + 1

1
rndplaces% = INT(RND * 6) + 1

'begin
CLS
PRINT "PARTY SYSTEM EXAMPLE"
PRINT
PRINT "Walking along, you find yourself in " + places$(rndplaces%)
IF (party% = 5) THEN CALL PartyAsk: GOTO 1
IF (monster% = 4) THEN CALL Attacked: GOTO 1

IF (party% <> 5) AND (monster% <> 4) THEN
  PRINT
  PRINT "What do you wish to do?"
  PRINT "[1.] Go On"
  
   IF currparty(1).charname <> "" THEN PRINT "[2.] Check On Party Members": order% = 3

  PRINT "["; LTRIM$(RTRIM$(STR$(order%))); ".] Quit"
  PRINT
  PRINT "[A.] Initiate DEBUG MODE"
  PRINT
  INPUT ">>", choice$
END IF

SELECT CASE UCASE$(choice$)
CASE "1"
  party% = INT(RND * 10) + 1
  monster% = INT(RND * 8) + 1
  GOTO 1
CASE "2"
  IF order% = 3 THEN CALL PartyCount: GOTO 1
  END
CASE "3"
  IF order% = 3 THEN END
  PRINT "Choice 3 doesn't exist."
  GOTO 1
CASE "A"

  debug:
  CLS
  PRINT "[ DEBUG MODE ]"
  PRINT
  PRINT "[1.] Initiate Party Inquery"
  PRINT " [X.] Fill Party Roster (5x)"
  PRINT "[2.] Initiate Monster Attack"
  PRINT "[3.] Return to Main Menu"
  PRINT
  INPUT ">>", debug$
   IF debug$ = "1" THEN CALL PartyAsk: GOTO 1
   IF debug$ = "2" THEN CALL Attacked: GOTO 1
   IF debug$ = "3" THEN GOTO 1
   IF UCASE$(debug$) = "X" THEN CALL DebugFullRoster: GOTO 1
   IF debug$ <> "1" AND debug$ <> "2" AND debug$ <> "3" AND UCASE$(debug$) <> "X" THEN GOTO debug

CASE ELSE
  GOTO 1
  
END SELECT
END


SUB PartyAsk
RANDOMIZE TIMER

DIM npcs$(10)
npcs$(1) = "Mary"
npcs$(2) = "Joe"
npcs$(3) = "Mark"
npcs$(4) = "Frank"
npcs$(5) = "Earl"
npcs$(6) = "Sammy"
npcs$(7) = "Alex"
npcs$(8) = "Caroline"
npcs$(9) = "Bob"
npcs$(10) = "Harry"

npc% = INT(RND * 10) + 1

CLS

FOR count% = 1 TO 5
        IF npcs$(npc%) = currparty(count%).charname THEN npc% = INT(RND * 10) + 1: EXIT FOR
NEXT count%

PRINT npcs$(npc%) + " wants to join your party! Do you accept?"
PRINT "[1.] Yes"
PRINT "[2.] No"
PRINT
INPUT ">>", accept%


IF accept% = 1 THEN
FOR num = 1 TO 5
   IF currparty(num).charname = "" THEN currparty(num).charname = npcs$(npc%): currparty(num).charhp = 50: EXIT FOR
   IF currparty(num).charname <> "" THEN no% = no% + 1
NEXT num

  IF no% <> 5 THEN
    CLS
    PRINT
    PRINT npcs$(npc%); " has joined your party!"
    PRINT
    PRINT "PRESS ANY KEY TO CONTINUE"
  ELSE
    CLS
    PRINT
    PRINT "You cannot sustain more than five party members."
  END IF
  
   DO
    LOOP UNTIL INKEY$ <> ""
END IF

IF accept% = 2 THEN
  CLS
  PRINT
  PRINT npcs$(npc%) + " was turned down."
  PRINT
  PRINT "PRESS ANY KEY TO CONTINUE"
DO
  LOOP UNTIL INKEY$ <> ""
END IF

party% = INT(RND * 10) + 1
END SUB


SUB PartyCount
7
  CLS

  PRINT "People in your party:"
   FOR num = 1 TO 5
    IF currparty(num).charname <> "" THEN PRINT currparty(num).charname + ",";
    IF currparty(num).charhp <> 0 THEN PRINT currparty(num).charhp
   NEXT num

PRINT
PRINT "[1.] Heal"
PRINT "[2.] Throw out"
PRINT "[3.] Return to Main Menu"
PRINT
INPUT ">>", choice%

SELECT CASE choice%
  CASE 1
   CLS
    PRINT "People in your party:"
    FOR num = 1 TO 5
    IF currparty(num).charname <> "" THEN PRINT currparty(num).charname + ",";
    IF currparty(num).charhp <> 0 THEN PRINT currparty(num).charhp
   NEXT num
  
   PRINT
   INPUT "Who would you like to heal"; heal$
    FOR num = 1 TO 5
     IF UCASE$(heal$) = UCASE$(currparty(num).charname) THEN
       IF currparty(num).charhp = 50 THEN PRINT UCASE$(heal$) + " is already at full health.": DO WHILE INKEY$="": LOOP: GOTO 7
      personnum% = num
      healperson$ = UCASE$(currparty(num).charname)
      EXIT FOR
     END IF
    NEXT num

  PRINT
  PRINT healperson$ + " gained 5 HP!"
  IF currparty(personnum%).charhp >= 50 THEN
   currparty(personnum%).charhp = 50
  ELSE
   currparty(personnum%).charhp = currparty(personnum%).charhp + 5
  END IF
  
  DO WHILE INKEY$ = "": LOOP: GOTO 7

CASE 2
  CLS
    PRINT "People in your party:"
     FOR num = 1 TO 5
      IF currparty(num).charname <> "" THEN PRINT currparty(num).charname + ",";
      IF currparty(num).charhp <> 0 THEN PRINT currparty(num).charhp
     NEXT num
  PRINT
  INPUT "Who do you wish to relieve of duty"; throwout$
   FOR num = 1 TO 5
    IF UCASE$(throwout$) <> UCASE$(currparty(num).charname) THEN no% = no% + 1
    IF UCASE$(throwout$) = UCASE$(currparty(num).charname) THEN
     personnum% = num
     throwperson$ = UCASE$(currparty(num).charname)
     EXIT FOR
    END IF
   NEXT num
  
   IF no% = 5 THEN PRINT UCASE$(throwout$) + " is not in your party.": DO WHILE INKEY$ = "": LOOP: GOTO 7
  
   PRINT
   PRINT throwperson$ + " has been kicked out of your party!"
   currparty(personnum%).charname = ""
   currparty(personnum%).charhp = 0
   currparty(personnum%).charhitpercent = 0

   DO WHILE INKEY$ = "": LOOP: GOTO 7

CASE 3
  GOTO finito
END SELECT

finito:
END SUB


SUB Attacked
monsterhp% = 100
hit% = INT(RND * 5) + 1

RANDOMIZE TIMER
CLS
  PRINT "A monster attacks!"
  PRINT
  PRINT "You get ready to battle!"
  PRINT
  PRINT "PRESS ANY KEY TO CONTINUE"

  DO WHILE INKEY$ = ""
  LOOP

4

  IF monsterhp% <= 0 THEN CLS : PRINT "The monster is dead! Congrats!": DO WHILE INKEY$ = "": LOOP: GOTO fin
  IF hp% <= 0 THEN CLS : PRINT "You have died. Game over.": END

'prepare hit probability for party members
IF currparty(1).charname <> "" THEN
FOR npchitcount% = 1 TO 5
   npchitnum% = INT(RND * 5) + 1
   IF currparty(npchitcount%).charname <> "" THEN currparty(npchitcount%).charhitpercent = npchitnum%
NEXT npchitcount%
END IF

CLS
'display main screen, list HPs
  PRINT "MONSTER'S HP:"; monsterhp%
  PRINT "YOUR HP:"; hp%
   IF currparty(1).charname <> "" THEN
    FOR listhp = 1 TO 5
      IF currparty(listhp).charname <> "" AND currparty(listhp).charhp > 0 THEN PRINT UCASE$(currparty(listhp).charname) + "'S HP:"; currparty(listhp).charhp
    IF currparty(listhp).charhp <= 0 AND currparty(listhp).charname <> "" THEN
     PRINT currparty(listhp).charname + " has died!"
     currparty(listhp).charname = ""
     currparty(listhp).charhp = 0
     currparty(listhp).charhitpercent = 0
    END IF
  
    NEXT listhp
   END IF

PRINT
PRINT "What would you like to do?"
PRINT "[1.] Attack"
PRINT "[2.] Flee"
PRINT
INPUT ">>", choice%

SELECT CASE choice%
CASE 1
SLEEP 1
        hpdeplete% = INT(RND * 10) + 1
       IF hit% = 3 OR hit% = 4 THEN
        PRINT "You hit the monster for"; hpdeplete%; " of damage!"
        monsterhp% = monsterhp% - hpdeplete%
        hit% = INT(RND * 10) + 1
        SLEEP 800
       ELSE
        PRINT "You miss!"
        hit% = INT(RND * 10) + 1
        SLEEP 800
       END IF

SLEEP 1
  
IF currparty(1).charname <> "" THEN
    FOR attacknum = 1 TO 5
      npcdeplete% = INT(RND * 10) + 1
      
       IF currparty(attacknum).charname <> "" AND currparty(attacknum).charhp <> 0 THEN
        IF currparty(attacknum).charhitpercent = 3 OR currparty(attacknum).charhitpercent = 4 THEN
         PRINT currparty(attacknum).charname + " hits the monster for"; npcdeplete%; " points of damage!"
         monsterhp% = monsterhp% - npcdeplete%
        ELSE
         PRINT currparty(attacknum).charname + " missed!"
        END IF
       END IF
  IF (currparty(attacknum).charname <> "") THEN SLEEP 800

   NEXT attacknum
END IF

SLEEP 800

PRINT
monsterdeplete% = INT(RND * 20) + 1
monsterhit% = INT(RND * 5) + 1
IF monsterhit% = 3 OR monsterhit% = 4 THEN
  PRINT "The monster attacks you for"; monsterdeplete%; " points of damage!"
  hp% = hp% - monsterdeplete%
  SLEEP 800
ELSE
  PRINT "You dodge the monster's attack!"
  SLEEP 800
END IF

IF currparty(1).charname <> "" THEN

npccount% = 0

FOR partymems = 1 TO 5
  IF currparty(partymems).charname <> "" THEN npccount% = npccount% + 1
NEXT partymems

  FOR monsterattack% = 1 TO npccount%
    monsterdeplete% = INT(RND * 20) + 1
    monsterhit% = INT(RND * 5) + 1

   IF currparty(monsterattack%).charname <> "" THEN
    IF monsterhit% = 3 OR monsterhit% = 4 THEN
      PRINT "The monster attacks " + currparty(monsterattack%).charname + " for"; monsterdeplete%; " points of damage!"
      currparty(monsterattack%).charhp = currparty(monsterattack%).charhp - monsterdeplete%
    ELSE
      PRINT currparty(monsterattack%).charname + " dodges the monster's attack!"
    END IF
   END IF
  SLEEP 800

NEXT monsterattack%
END IF


GOTO 4

CASE 2
  CLS
  PRINT "You flee like a little girl!"
  PRINT
  PRINT "PRESS ANY KEY TO CONTINUE"
   DO WHILE INKEY$ = ""
    LOOP
  GOTO fin

CASE ELSE
  GOTO 4
END SELECT

fin:
monster% = INT(RND * 8) + 1
END SUB


SUB DebugFullRoster

RANDOMIZE TIMER

DIM npcs$(10)
npcs$(1) = "Mary"
npcs$(2) = "Joe"
npcs$(3) = "Mark"
npcs$(4) = "Frank"
npcs$(5) = "Earl"
npcs$(6) = "Sammy"
npcs$(7) = "Alex"
npcs$(8) = "Caroline"
npcs$(9) = "Bob"
npcs$(10) = "Harry"

FOR fullroster = 1 TO 6
npc% = INT(RND * 10) + 1

FOR num = 1 TO 5
   IF currparty(num).charname = npcs$(npc%) THEN npc% = INT(RND * 10) + 1
   IF currparty(num).charname = "" THEN currparty(num).charname = npcs$(npc%): currparty(num).charhp = 50: EXIT FOR
   IF currparty(num).charname <> "" THEN no% = no% + 1: IF no% = 5 THEN EXIT FOR
NEXT num
NEXT fullroster

  IF no% = 5 THEN
    CLS
    PRINT
    PRINT "You cannot sustain more than five party members."
  END IF
  
party% = INT(RND * 10) + 1
END SUB
url=http://www.freewebs.com/boxtopstuff/]Planet Boxtop[/url] (Look out for the redesign!)
The only member of QBNF with severe "tomorrow syndrome."
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)