UnderwareDESIGN

PlayBASIC => Game Design => Topic started by: Pagan Slim on June 14, 2010, 05:37:44 AM

Title: Fight simulation perfected - for now.
Post by: Pagan Slim on June 14, 2010, 05:37:44 AM
I think I have this thing perfected.  It needs polished but at least it works like I wanted.  :P  


[pbcode]

; PROJECT : PERFECT FIGHT ROUTINE
; AUTHOR  : Pagan Slim
; CREATED : 6/13/2010
; EDITED  : 6/13/2010
; ---------------------------------------------------------------------

;combat routine
CLS
;Initialize AND Randomize
;create stats


NPC_HITPOINTS = RNDRANGE (2,12)

HITPOINTS = RNDRANGE (3,12);WEIGHTED IN MY FAVOR.

PRINT "HIT POINTS " + Str$(HITPOINTS)

PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)

PRINT " "
sync
WAIT 3000

   ;Game Loop
   DO
;Initiative:
;who's first
COINTOSS=RND (120)

PRINT "* INITIATIVE * " + Str$(COINTOSS)
   PRINT " "
   SYNC
IF COINTOSS>60
   GOSUB MEFIRST:
ELSE
   GOSUB NPCFIRST   
ENDIF
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_dead
IF HITPOINTS<1
   PRINT "You're DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF
IF HITPOINTS<1
   GOSUB THE_END
   ENDIF
RETURN


;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead
IF NPC_HITPOINTS<1
   PRINT "NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF
IF NPC_HITPOINTS<1
   GOSUB THE_END
   ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "It is over for now. The End."
PRINT " "
SYNC
WAIT 2000
END
RETURN

[/pbcode]





Title: Re: Fight simulation perfected - for now.
Post by: kevin on June 14, 2010, 08:11:16 AM
 i'm glad you're showing progress, but please don't start a new thread for each related post.  
Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 14, 2010, 08:53:20 AM
I knew I'd screw something up.  Sorry.
Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 14, 2010, 08:57:24 AM
This is several guys fighting.  It works.  I used a loop to create 1 to 5 npc's.


[pbcode]

; PROJECT : SEVERAL GUYS FIGHT
; AUTHOR  : Pagan Slim
; CREATED : 6/13/2010
; EDITED  : 6/13/2010
; ---------------------------------------------------------------------

;combat routine
CLS
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = RND (5)

NPC_HITPOINTS = RNDRANGE (2,10)

HITPOINTS = RNDRANGE (2,10)

PRINT "HIT POINTS " + Str$(HITPOINTS)
PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
sync
WAIT 3000

   ;Game Loop
   DO
;Initiative:
;who's first
COINTOSS=RND (120)

PRINT "* INITIATIVE * " + Str$(COINTOSS)
   PRINT " "
   SYNC
IF COINTOSS>60
   GOSUB MEFIRST:
ELSE
   GOSUB NPCFIRST   
ENDIF
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
FOR N = 1 TO NUM_GUYS
ATTACK=RNDRANGE (1,8)
PRINT "Guy Number " + Str$(N)
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000

NEXT

;if_dead
IF HITPOINTS<1
   PRINT "You're DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF
IF HITPOINTS<1
   GOSUB THE_END
   ENDIF
RETURN


;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead
IF NPC_HITPOINTS<1
   PRINT "NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF
IF NPC_HITPOINTS<1
   GOSUB THE_END
   ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "DEATH IS ALWAYS THE ONLY VICTOR."
PRINT " "
SYNC
WAITKEY
END
RETURN

[/pbcode]


  EDIT: use CODE in square brackets when showing code



Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 15, 2010, 10:34:43 PM
Super Improved.  Now dead NPC's are properly disposed of.  I need to figure out how to make the text either scroll when the screen is filled or something.  A long fight going to the bottom of the screen stops and does not allow me to see the conclusion.  This is how I learn - by finding new obstacles to overcome.

[pbcode]

; PROJECT : 3 GUYS FIGHT 2
; AUTHOR  : Pagan Slim
; CREATED : 6/13/2010
; EDITED  : 6/15/2010
; ---------------------------------------------------------------------

;combat routine
CLS
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = RND (5)+ 1


NPC_HITPOINTS = RNDRANGE (2,10)

HITPOINTS = RNDRANGE (7,18);ADJUSTED TO EQUAL THE ODDS.

PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
sync
WAIT 3000

   ;Game Loop
   DO
;Initiative:
;who's first
COINTOSS=RND (120)

PRINT "* INITIATIVE * " + Str$(COINTOSS)
   PRINT " "
   SYNC
   
   PRINT "Number of NPCs " + Str$(NUM_GUYS)
print " "
SYNC

IF COINTOSS>60
   PRINT "The initiative is yours."
ELSE
   PRINT "NPC(S) has initiative."
ENDIF
      

   
IF COINTOSS>60
   GOSUB MEFIRST:
ELSE
   GOSUB NPCFIRST   
ENDIF
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
   FOR N = 1 TO NUM_GUYS
ATTACK=RNDRANGE (1,8)
PRINT "NPC Number " + Str$(N)
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000

;if_dead
IF HITPOINTS<1
   PRINT "You're DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF
IF HITPOINTS<1
   GOSUB THE_END
   ENDIF
RETURN

   NEXT




;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1 THEN NUM_GUYS = NUM_GUYS - 1
IF NPC_HITPOINTS < 1
   PRINT "ONE NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF

;When last npc is dead game over...
IF NUM_GUYS < 1
   PRINT "You win."
ENDIF

IF NUM_GUYS < 1
   GOSUB THE_END
   ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "DEATH IS ALWAYS THE ONLY VICTOR."
PRINT " "
SYNC
WAITKEY
END
RETURN

[/pbcode]




Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 15, 2010, 11:10:29 PM
This is the last post on this thread until I get the screen thing and arrays worked out.  I know I can make this awesome someday and apply it to a real game.  This one is this best up to this point.

[pbcode]

; PROJECT : Gangbang FIGHT 01
; AUTHOR  : Pagan Slim
; CREATED : 6/13/2010
; EDITED  : 6/15/2010
; ---------------------------------------------------------------------

;combat routine
CLS
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = RND (5)+ 1


NPC_HITPOINTS = RNDRANGE (2,10)

HITPOINTS = RNDRANGE (7,18);ADJUSTED TO EQUAL THE ODDS.

PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
sync
WAIT 3000

   ;Game Loop
   DO
;Initiative:
;who's first
COINTOSS=RND (120)

;PRINT "* INITIATIVE * " + Str$(COINTOSS)
   ;PRINT " "
   ;SYNC
   
   PRINT "Number of NPCs " + Str$(NUM_GUYS)
print " "
SYNC

IF COINTOSS>60
   PRINT "The initiative is yours."
   PRINT " "
ELSE
   PRINT "NPC(s) has initiative."
   PRINT " "
ENDIF
      

   
IF COINTOSS>60
   GOSUB MEFIRST:
ELSE
   GOSUB NPCFIRST   
ENDIF
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
   FOR N = 1 TO NUM_GUYS
ATTACK = RNDRANGE (1,6)+1
Print "NPC Number " + Str$(N)+" attacks you!"
PRINT " "
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000

;if_dead
IF HITPOINTS<1
   PRINT "You're DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF
IF HITPOINTS<1
   GOSUB THE_END
ENDIF
NEXT
   
RETURN

   




;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1 THEN NUM_GUYS = NUM_GUYS - 1
IF NPC_HITPOINTS < 1
   PRINT "ONE NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF

;When last npc is dead game over...
IF NUM_GUYS < 1
   PRINT "You win."
ENDIF

IF NUM_GUYS < 1
   GOSUB THE_END
   ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "It's over boys."
PRINT " "
SYNC
WAITKEY
END
RETURN
[/pbcode]





Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 16, 2010, 05:53:07 AM
I repaired the screen problem and improved the combat.  So I lied about the last post on this topic.


[pbcode]

; PROJECT : GangFIGHT 01
; AUTHOR  : Pagan Slim
; CREATED : 6/13/2010
; EDITED  : 6/15/2010
; ---------------------------------------------------------------------

;combat routine
CLS
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = RND (5)+ 1


NPC_HITPOINTS = RNDRANGE (2,10)

HITPOINTS = RNDRANGE (7,18);ADJUSTED TO EQUAL THE ODDS.

PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
sync
WAIT 3000

   ;Game Loop
   DO
;Initiative:
;who's first
COINTOSS=RND (120)

;PRINT "* INITIATIVE * " + Str$(COINTOSS)
   ;PRINT " "
   ;SYNC
   
   PRINT "Number of NPCs " + Str$(NUM_GUYS)
print " "
SYNC

IF COINTOSS>60
   PRINT "The initiative is yours."
   PRINT " "
ELSE
   PRINT "NPC(s) has initiative."
   PRINT " "
ENDIF
      

   
IF COINTOSS>60
   GOSUB MEFIRST:
ELSE
   GOSUB NPCFIRST   
ENDIF

PRINT "Press a key to go on."
PRINT " "
SYNC
WAITKEY
CLS
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
   FOR N = 1 TO NUM_GUYS
ATTACK = RNDRANGE (1,6)+1
Print "NPC Number " + Str$(N)+" attacks you!"
PRINT " "
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000

;if_dead
IF HITPOINTS<1
   PRINT "You're DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF
IF HITPOINTS<1
   GOSUB THE_END
ENDIF
NEXT
   
RETURN

   




;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1 THEN NUM_GUYS = NUM_GUYS - 1
IF NPC_HITPOINTS < 1
   PRINT "ONE NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF

;When last npc is dead game over...
IF NUM_GUYS < 1
   PRINT "You win."
ENDIF

IF NUM_GUYS < 1
   GOSUB THE_END
   ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "It's over boys."
PRINT " "
SYNC
WAITKEY
END
RETURN

[/pbcode]




Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 16, 2010, 11:03:06 AM
A fight simulation with a gang and the attackers have names.  This is the best thing I've done for a fight simulation yet.  I can see that old game shaping up right now.

[pbcode]

; PROJECT : Personalized Gang Fight 01
; AUTHOR  : Pagan Slim
; CREATED : 6/13/2010
; EDITED  : 6/16/2010
; ---------------------------------------------------------------------
LoadFont "Arial",1,18,0

   Setfps 30

   
;combat routine
CLS
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = RND (5)+ 1


NPC_HITPOINTS = RNDRANGE (2,10)

HITPOINTS = RNDRANGE (7,18);ADJUSTED TO EQUAL THE ODDS.

PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
sync
WAIT 3000

   ;Game Loop
   DO
;Initiative:
;who's first
COINTOSS=RND (120)

;PRINT "* INITIATIVE * " + Str$(COINTOSS)
   ;PRINT " "
   ;SYNC
   
   PRINT "Number of NPCs " + Str$(NUM_GUYS)
print " "
SYNC

IF COINTOSS>60
   PRINT "The initiative is yours."
   PRINT " "
ELSE
   PRINT "NPC(s) has initiative."
   PRINT " "
ENDIF
      

   
IF COINTOSS>60
   GOSUB MEFIRST:
ELSE
   GOSUB NPCFIRST   
ENDIF

PRINT "Press a key to go on."
PRINT " "
SYNC
WAITKEY
CLS ;clear screen for next round of combat.
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
   FOR N = 1 TO NUM_GUYS
      IF N = 1
         PRINT "Bucktooth Sam Attacks."
            ENDIF
      IF N = 2
      PRINT "Bad Bob Attacks You."
      sync
         ENDIF
      IF N = 3
      PRINT "Wicked Wanda Attacks You."
         ENDIF
      IF N = 4
      PRINT "Evil Earl Attacks You."
      
         ENDIF
      IF N = 5
      PRINT "Hatchet Molly Attacks You."
      
         ENDIF
      IF N = 6
      PRINT"Deadly Dilford Attacks You."
      ENDIF
   IF N < 1
      PRINT "The Mysterious Glitch attacks You."   
      PRINT " "
      sync
         ENDIF
ATTACK = RNDRANGE (1,6)+1
;Print "NPC Number " + Str$(N)+" attacks you!"
PRINT " "
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000

;if_dead
IF HITPOINTS<1
   PRINT "You're DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF
IF HITPOINTS<1
   GOSUB THE_END
ENDIF
NEXT
   
RETURN

;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1 THEN NUM_GUYS = NUM_GUYS - 1
IF NPC_HITPOINTS < 1
   PRINT "ONE NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF

;When last npc is dead game over...
IF NUM_GUYS < 1
   PRINT "You win."
ENDIF

IF NUM_GUYS < 1
   GOSUB THE_END
   ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "It's over boys."
PRINT " "
SYNC
WAITKEY
END
RETURN

[/pbcode]




Title: Re: Fight simulation perfected - for now.
Post by: Big C. on June 16, 2010, 03:00:19 PM
hey slim,

here are some tips from me...

first:
QuoteIF COINTOSS>60
   PRINT "The initiative is yours."
   PRINT " "
ELSE
   PRINT "NPC(s) has initiative."
   PRINT " "
ENDIF
     
IF COINTOSS>60
   GOSUB MEFIRST:
ELSE
   GOSUB NPCFIRST   
ENDIF

This two if-statements can you merge in one because the condition in both if statements is the same.
If COINTOSS>60
   Print "The initiative is yours."
   Print " "
   Gosub MEFIRST:
Else
   Print "NPC(s) has initiative."
   Print " "
   Gosub NPCFIRST:
EndIf


Second:
QuoteIF N = 1
         PRINT "Bucktooth Sam Attacks."
            ENDIF
      IF N = 2
      PRINT "Bad Bob Attacks You."
      sync
         ENDIF
      IF N = 3
      PRINT "Wicked Wanda Attacks You."
         ENDIF
      IF N = 4
      PRINT "Evil Earl Attacks You."
     
         ENDIF
      IF N = 5
      PRINT "Hatchet Molly Attacks You."
     
         ENDIF
      IF N = 6
      PRINT"Deadly Dilford Attacks You."
      ENDIF
   IF N < 1
      PRINT "The Mysterious Glitch attacks You."   
      PRINT " "
      sync
         ENDIF

Here you can summarize the particulars if-Statements if you use an array. Here another way:

;at the beginning of the code maybe for 'CLS' write this

Dim Guys$(6) ; Array Indexes are zero inclusive. That means 0,1,2, etc .. up to the Number of Elements are valid Indexes

For Guys_Name = 0 to 6 ; 0 will be the 'The Mysterious Glitch'
     Guys$(Guys_Name) = ReadData$()
Next Guys_Name

;this is the optimized piece of code which print the guy who attacks the player

  PRINT Guys$(N)
  Print " "

;write this at the end of your Program
Data "The Mysterious Glitch attacks You.", "Bucktooth Sam Attacks.", "Bad Bob Attacks You.", "Wicked Wanda Attacks You."
Data "Evil Earl Attacks You.", "Hatchet Molly Attacks You.", "The Mysterious Glitch attacks You."


third (the same under first)
Quote;if_dead
IF HITPOINTS<1
   PRINT "You're DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF
IF HITPOINTS<1
   GOSUB THE_END
ENDIF

can change to


IF HITPOINTS<1
   PRINT "You're DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
   Gosub THE_END
ENDIF


Fourth (the same as first)
Quote;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1 THEN NUM_GUYS = NUM_GUYS - 1
IF NPC_HITPOINTS < 1
   PRINT "ONE NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF

can change to
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1
   NUM_GUYS = NUM_GUYS - 1
   PRINT "ONE NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF


fifth (also the same as first)
Quote
;When last npc is dead game over...
IF NUM_GUYS < 1
   PRINT "You win."
ENDIF

IF NUM_GUYS < 1
   GOSUB THE_END
ENDIF

can change to

;When last npc is dead game over...
IF NUM_GUYS < 1
   PRINT "You win."
   Gosub THE_END
ENDIF


Not a tip but a hint
Quote
IF N < 1
      PRINT "The Mysterious Glitch attacks You."   
      PRINT " "
      sync
ENDIF

The Condition N<1 will never reach because your For/Next Loop starts with the following line...

FOR N = 1 TO NUM_GUYS

If you follow the tips then you will get this..


; PROJECT : Personalized Gang Fight 01
; AUTHOR  : Pagan Slim
; CREATED : 6/13/2010
; EDITED  : 6/16/2010
; ---------------------------------------------------------------------
LoadFont "Arial",1,18,0

SetFPS 30

Dim Guys$(6) ; Array Indexes are zero inclusive. That means 0,1,2, etc .. up to the Number of Elements are valid Indexes

For Guys_Name = 0 to 6 ; 0 will be the 'The Mysterious Glitch'
     Guys$(Guys_Name) = ReadData$()
Next Guys_Name
   
;combat routine
Cls
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = Rnd (5)+ 1


NPC_HITPOINTS = RndRange (2,10)

HITPOINTS = RndRange (7,18);ADJUSTED TO EQUAL THE ODDS.

Print "YOUR HIT POINTS " + Str$(HITPOINTS)
Print " "
Print "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
Print " "
Sync
Wait 3000

   ;Game Loop
   Do
;Initiative:
;who's first
COINTOSS=Rnd (120)

;PRINT "* INITIATIVE * " + Str$(COINTOSS)
   ;PRINT " "
   ;SYNC
   
   Print "Number of NPCs " + Str$(NUM_GUYS)
Print " "
Sync

If COINTOSS>60
   Print "The initiative is yours."
   Print " "
   Gosub MEFIRST:
Else
   Print "NPC(s) has initiative."
   Print " "
   Gosub NPCFIRST:
EndIf
     

   
;If COINTOSS>60
   ;Gosub MEFIRST:
;Else
   ;Gosub NPCFIRST   
;EndIf

Print "Press a key to go on."
Print " "
Sync
WaitKey
Cls ;clear screen for next round of combat.
Loop


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
For N = 1 To NUM_GUYS
PRINT Guys$(N)
Print " "
  If N < 1
  Print "The Mysterious Glitch attacks You."   
    PRINT " "
      sync
  ENDIF
ATTACK = RNDRANGE (1,6)+1
;Print "NPC Number " + Str$(N)+" attacks you!"
PRINT " "
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
Print "YOUR HIT POINTS " + Str$(HITPOINTS)
Print " "
Sync
Wait 2000
;if_dead
If HITPOINTS<1
  Print "You're DEAD!"
  Print " "
  Sync
    Wait 3000
    Gosub THE_END
EndIf

NEXT
   
RETURN

;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1
NUM_GUYS = NUM_GUYS - 1
   PRINT "ONE NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF

;When last npc is dead game over...
IF NUM_GUYS < 1
   PRINT "You win."
   GOSUB THE_END
ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "It's over boys."
PRINT " "
SYNC
WAITKEY
END
RETURN

;write this at the end of your Program
Data "The Mysterious Glitch attacks You.", "Bucktooth Sam Attacks.", "Bad Bob Attacks You.", "Wicked Wanda Attacks You."
Data "Evil Earl Attacks You.", "Hatchet Molly Attacks You.", "The Mysterious Glitch attacks You."


Big C.
Title: Re: Fight simulation perfected - for now.
Post by: LemonWizard on June 16, 2010, 06:29:11 PM

I don't get on here much, or that often anymore cause I work right now and I've moved around alot.
BUUUUUT


Here's some coding tips for you.

First of all try using functions.. things like kill_npc(npcnumber)
or like.. yeah.. other stuff
you could even create an array to store npc names, and then make the routine name specific based on the current npc number, so later you could refer to it and pull up the name like
[/color
print Npcname$(npcnumber)+" Has died"


I didn't really look at the code but what I'd reccomend is some really good core code that handles specific events. Ie.. is the npc stabbing, how much damage etc. You could really expand on how this engine works..

Also, try npc states.. like "Npc is wandering" etc.. I don't know just throwing ideas out there...

You can pretty much program anything you can imagine and make it as elaborate as you want so long as your willing to write the code for it.

You will only get as much as you put into your programming projects.


and you could even keep an array of how far away each npc is from another one so yeah.. just use your imagination.. and then make them act on whatever parameters you want to set up. also if you want to program npc behavior I'd look into tutorials about how basic battle engines work or even read some open source stuff, like maybe some dungeon crawler source code.. though that's probably more primitive

Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 16, 2010, 10:40:00 PM
Thanks for the advice.  I was reading articles on AI in game software but a lot of it was over my head.  I tried looking at how the ghosts in pacman worked.  That seemed simpler.  You're right.  I do need to study code more.  Up 'till now all of my programs have been simplistic.  I want to write something more complex and build on it.  I will take your advice.  Thanks.
Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 22, 2010, 03:40:15 AM
I have , somehow, managed to randomize the NPCs in the gangfight but cannot for the life of me do it the way I want.  It works but the npcs are too orderly yet.  Who attacks is random but the next attacker does not show up until the former npc is finished.  Still it works.  Will post again when I improve it.  Got to do a little at a time.


[pbcode]

; PROJECT : Random Gang_Fight
; AUTHOR  : Pagan Slim
; CREATED : 6/16/2010
; EDITED  : 6/22/2010
; ---------------------------------------------------------------------
; ---------------------------------------------------------------------

LoadFont "Arial",1,16,0

   SetFPS 30
   
Cls RGB(95,0,0)
   Print "You are walking the streets of a well known but feared neighborhood."
   Print "You usually avoid this part of town but today is different."
   Print "You feel braver today.  Braver and perhaps a bit more foolish."
   Print "You made your boast to your friends and they dared you to come here."
   Print "You feel a chill.  Maybe a shudder.  You hear a garbage pail being knocked over."
   Print "The sound jolts you to a higher awareness of your reality. "
   
   Print " "
   Print "You see someone ahead of you.  It is dark and foggy tonight."
   Print "Are you ready to throw down?  Well.  Are You?"
   Print " "
   Print "Press the ENTER key to get it on."
   Print " "
   Sync
   WaitKey

Cls


Dim Guys$(6) ; Array Indexes are zero inclusive. That means 0,1,2, etc .. up to the Number of Elements are valid Indexes

For Guys_Name = 0 To 6 ; 0 will be the 'The Mysterious Glitch'
    Guys$(Guys_Name) = ReadData$()
Next Guys_Name
 
;combat routine

;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = Rnd (5)+ 1


NPC_HITPOINTS = RndRange (2,10)

HITPOINTS = RndRange (7,18);ADJUSTED TO EQUAL THE ODDS.

Print "YOUR HIT POINTS " + Str$(HITPOINTS)
Print " "
Print "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
Print " "
Sync
Wait 3000

  ;Game Loop
  Do
;Initiative:
;who's first
COINTOSS=Rnd (120)

 
  Print "Number of NPCs " + Str$(NUM_GUYS)
Print " "
Sync

If COINTOSS>60
  Print "The initiative is yours."
  Print " "
  Gosub MEFIRST:
Else
  Print "NPC(s) has initiative."
  Print " "
  Gosub NPCFIRST:
EndIf
     
 
Print "Press a key to go on."
Print " "
Sync
WaitKey
Cls ;clear screen for next round of combat.
Loop


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
randomNPC = RndRange(1,6);randomNPC draws a random npc from the data.

For N = 1 To NUM_GUYS
   Print Guys$(randomNPC)
   Print " "
    
   ATTACK = RndRange (1,6)+1
      Print " "
   Sync
   ;damage (HEALTH-ATTACK)
   
   HITPOINTS=HITPOINTS-ATTACK
   
   ;adjust health
   ;report results
   Print "YOUR HIT POINTS " + Str$(HITPOINTS)
   Print " "
   Sync
   Wait 2000
   ;if_dead
   If HITPOINTS<1
       Print "You're DEAD!"
       Print " "
       Sync
     Wait 3000
     Gosub THE_END
   EndIf

Next
 
Return

;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RndRange (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
Print "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
Print " "
Sync
Wait 2000
;if_NPC_dead - GET RID OF HIM...
If NPC_HITPOINTS < 1
   NUM_GUYS = NUM_GUYS - 1
  Print "ONE NPC DEAD!"
  Print " "
  Sync
  Wait 3000
EndIf

;When last npc is dead game over...
If NUM_GUYS < 1
  Print "You win."
  Gosub THE_END
EndIf
Return


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
Print "It's over boys."
Print " "
Sync
WaitKey
End
Return


;write this at the end of your Program
Data "The Mysterious Glitch attacks You.", "Bucktooth Sam Attacks.", "Bad Bob Attacks You.", "Wicked Wanda Attacks You."
Data "Evil Earl Attacks You.", "Hatchet Molly Attacks You.", "The Mysterious Glitch attacks You."


[/pbcode]


Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 22, 2010, 04:03:25 AM
Strange, but when compiled this version doesn't run on windows 7 any longer.  All I changed was the randomNPC thing.
Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 22, 2010, 04:09:25 AM
O.K.  I'm an idiot.  It was already random.  I just screwed it up.  I'll crawl back into my cave now.  ;p
Title: Re: Fight simulation perfected - for now.
Post by: Big C. on June 22, 2010, 03:39:41 PM
hey slim,

First:
at me... your code runs very well under win7 :)

Second:
If I understand you right then you try to randomize the attacking NPC

I will give you a hint:

Quote;Number of NPC's that you will fight.
NUM_GUYS = Rnd (5)+ 1

As this line says here you randomize the guys that will attack the Player. The result will hold in the var NUM_GUYS.

Quote;N is which of the guys who attack.
randomNPC = RndRange(1,6);randomNPC draws a random npc from the data.

Here you determine from the available guys exactly one

QuoteFor N = 1 To NUM_GUYS

With this line you start a For/Next Loop which will run from 1 to NUM_GUYS. Remember the NUM_GUYS holds the Number of Guys which will attack the Player! For example: If the value of NUM_GUYS = 4 (= 4 Guys should attack the player) the for/next loop will go through four times. But remember: you define exactly one guy with the line above.

I think you want to do this (?)

NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
;randomNPC = RndRange(1,6);randomNPC draws a random npc from the data.

For N = 1 To NUM_GUYS
   randomNPC = RndRange(1,6); <----- put this line here to randomize the attacking guy from the group (remember NUM_GUYS)
   Print Guys$(randomNPC)


attached a hardcopy to see what the game will output

Big C.

P.S.: use the "insert Code" icon from the editor to post your code  ;)




Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 30, 2010, 02:52:52 PM
I have added a scoring system.  My intent is to have it written to an external file as in the help example.  Problem is it crashes on me so I have left it out until I can solve the problem.  It's the print thing that doesn't work.  It seems so simple and yet I can't get it.


[pbcode]
; PROJECT : Fight Simulation
; AUTHOR  : Pagan Slim
; CREATED : 6/16/2010
; EDITED  : 6/30/2010
; ---------------------------------------------------------------------
; ---------------------------------------------------------------------

LoadFont "Arial",1,16,0

   SetFPS 30
   
Cls RGB(95,0,0)
   Print "You are walking the streets of a well known but feared neighborhood."
   Print "You usually avoid this part of town but today is different."
   Print "You feel braver today.  Braver and perhaps a bit more foolish."
   Print "You made your boast to your friends and they dared you to come here."
   Print "You feel a chill.  Maybe a shudder.  You hear a garbage pail being knocked over."
   Print "The sound jolts you to a higher awareness of your reality. "
   
   Print " "
   Print "You see someone ahead of you.  It is dark and foggy tonight."
   Print "Are you ready to throw down?  Well.  Are You?"
   Print " "
   Print "Press the ENTER key to get it on."
   Print " "
   Sync
   WaitKey

Cls


Dim Guys$(6) ; Array Indexes are zero inclusive. That means 0,1,2, etc .. up to the Number of Elements are valid Indexes

For Guys_Name = 0 To 6 ; 0 will be the 'The Mysterious Glitch'
    Guys$(Guys_Name) = ReadData$()
Next Guys_Name
 
;combat routine

;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = Rnd (5)+ 1


NPC_HITPOINTS = RndRange (2,10)

HITPOINTS = RndRange (7,18);ADJUSTED TO EQUAL THE ODDS.
ScorePoints = 0 ; Your initial score.

Print "YOUR HIT POINTS " + Str$(HITPOINTS)
Print " "
Print "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
print " "
Print "YOUR SCORE " + Str$(ScorePoints)
Print " "
Sync
Wait 3000

  ;Game Loop
  Do
;Initiative:
;who's first
COINTOSS=Rnd (120)

;PRINT "* INITIATIVE * " + Str$(COINTOSS)
  ;PRINT " "
  ;SYNC
 
  Print "Number of NPCs " + Str$(NUM_GUYS)
Print " "
Print "YOUR SCORE " + Str$(ScorePoints)
Print " "

Sync

If COINTOSS>60
  Print "The initiative is yours."
  Print " "
  Gosub MEFIRST:
Else
  Print "NPC(s) has initiative."
  Print " "
  Gosub NPCFIRST:
EndIf
     
 
Print "Press a key to go on."
Print " "
Sync
WaitKey
Cls ;clear screen for next round of combat.
Loop


;NPCFIRST - npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
randInd = RndRange(1,6)

For N = 1 To NUM_GUYS
   Print Guys$(randInd)
   Print " "
    
   ATTACK = RndRange (1,6)+1
      Print " "
   Sync
   ;damage (HEALTH-ATTACK)
   
   HITPOINTS=HITPOINTS-ATTACK
   
   ;adjust health
   ;report results
   Print "YOUR HIT POINTS " + Str$(HITPOINTS)
   Print " "
   Sync
   Wait 2000
   ;if_dead
   If HITPOINTS<1
       Print "You're DEAD!"
       Print " "
       Sync
     Wait 3000
     Gosub THE_END
   EndIf

Next
 
Return

;ME FIRST - mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RndRange (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
Print "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
Print " "
Sync
Wait 2000
;if_NPC_dead - GET RID OF HIM...
If NPC_HITPOINTS < 1
   ScorePoints = ScorePoints + 10 ;Score adjustment for NPC Kills.
   NUM_GUYS = NUM_GUYS - 1
  Print "ONE NPC DEAD!"
  Print " "
  Sync
  Wait 3000
EndIf

;When last npc is dead game over...
If NUM_GUYS < 1
  Print "You win."
  Gosub THE_END
EndIf
Return


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
Print "It's over boys."
Print " "
Print "YOUR SCORE " + Str$(ScorePoints)
Print " "

Sync
WaitKey
End
Return

;write this at the end of your Program
Data "The Mysterious Glitch attacks You.", "Bucktooth Sam Attacks.", "Bad Bob Attacks You.", "Wicked Wanda Attacks You."
Data "Evil Earl Attacks You.", "Hatchet Molly Attacks You.", "The Mysterious Glitch attacks You."



[/pbcode]
Title: Re: Fight simulation perfected - for now.
Post by: kevin on June 30, 2010, 03:07:59 PM

Looks like it's coming nicely..

QuoteProblem is it crashes on me so I have left it out until I can solve the problem.

  Can you show us your code ?


Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 30, 2010, 03:17:03 PM
This is the code I'm working with now.  It prints a zero.  I don't even know if it creates a file.  I used the help example in PB.  I have been studying TDK's guide and I need to know how to print the contents of data files to the screen.  I have a lot of trouble learning this forum thing so please be patient.



[pbcode]

; PROJECT : MyScore
; AUTHOR  : Pagan Slim
; CREATED : 6/29/2010
; EDITED  : 6/30/2010
; ---------------------------------------------------------------------
Filename$="ScoreData.dat"
Scorepoints = 20
If FileExist(Filename$) Then DeleteFile Filename$
MatrixWidth=20000
MatrixHeight=20000
TilesX=70
TilesZ=70
FloatVar#=44.82

WriteFile Filename$,1
 WriteString 1,"Here Be the Score Board"
 WriteString 1,Str$(MatrixWidth)
 WriteString 1,Str$(MatrixHeight)
 WriteString 1,Str$(TilesX)
 WriteString 1,Str$(TilesZ)
 WriteString 1,Str$(FloatVar#)
CloseFile 1

;-------------------------------
Filename$="ScoreData.dat"
If FileExist(Filename$)
 ReadFile Filename$,1
   Header$         =ReadString$(1)
   MatrixWidth   =Val(ReadString$(1))
   MatrixHeight   =Val(ReadString$(1))
   MatrixTilesX   =Val(ReadString$(1))
   MatrixTilesY   =Val(ReadString$(1))
   FloatVar#      =Val#(ReadString$(1))
   Print ScorePoints
   Sync
   WaitKey
   
    CloseFile 1
EndIf






[/pbcode]

Title: Re: Fight simulation perfected - for now.
Post by: kevin on June 30, 2010, 03:30:17 PM
  The example works, but it wasn't displaying the information back to the user.  

 Here's a version with a few comments in it..  

[pbcode]

; PROJECT : MyScore
; AUTHOR  : Pagan Slim
; CREATED : 6/29/2010
; EDITED  : 6/30/2010
; ---------------------------------------------------------------------
Filename$="ScoreData.dat"

Scorepoints = 20

; Check for an old copy of the file,, If it exists.. delete it
; so we can write a new copy of it to disk
If FileExist(Filename$) Then DeleteFile Filename$


; The variables we'll be saving into our file
MatrixWidth   =20000
MatrixHeight=20000
TilesX=70
TilesZ=70
FloatVar#=44.82


; Start WriteFile the file using file channel #1
WriteFile Filename$,1
 ; write the string data to the open file channel  
 WriteString 1,"Here Be the Score Board"
 WriteString 1,Str$(MatrixWidth)
 WriteString 1,Str$(MatrixHeight)
 WriteString 1,Str$(TilesX)
 WriteString 1,Str$(TilesZ)
 WriteString 1,Str$(FloatVar#)

; we're done writing, so close it
CloseFile 1


;-------------------------------
; Read the File.. First we check if the file we're going to
; read actually exists..
If FileExist(Filename$)=true
 ; Print this message if the file exists
 Print "Found File.. Loading"

 ; Tell PB to start reading to file, using fiole channel #1     
 ReadFile Filename$,1

   ; read a line of the string data from the file..  
   Header$         =ReadString$(1)

   ; read the next line of string from next.  This time we're converting
   ; the text (characters) returned from ReadtString$(1) into a numeric
   ; value using the VAL() Function.  The result is assign to the variable
   ;  
   MatrixWidth   =Val(ReadString$(1))
   MatrixHeight   =Val(ReadString$(1))
   MatrixTilesX   =Val(ReadString$(1))
   MatrixTilesY   =Val(ReadString$(1))
   FloatVar#      =Val#(ReadString$(1))    

; we're done reading the file.. so now we close the file channel
CloseFile 1
EndIf


; DRaw the variables to the screen
print Header$
Print MatrixWidth
Print MatrixHeight
Print MatrixTilesX
Print MatrixTilesY
Print FloatVar#

; display the screen
Sync
waitkey

[/code]


 
and here's a second version to have a look at.


[code]


;  Insert folder name in front of the filename so you can view the file
; manually.   EG  Filename$= "C:\ScoreData.txt"  to save the file to
; the C drive

  Filename$="ScoreData.txt"


; Check for an old copy of the file,, If it exists.. delete it
; so we can write a new copy of it to disk

  If FileExist(Filename$) Then DeleteFile Filename$


;------------------------------------------------------------
; The variables we'll be saving into our file
;------------------------------------------------------------

  Name$         ="Bill"
  Scorepoints = 20



;------------------------------------------------------------
; Start WriteFile the file using file channel #1
;------------------------------------------------------------
WriteFile Filename$,1

 ; write the string data to the open file channel  
 WriteString 1,"My High Score Table"


 ; write the string data to the open file channel  
 WriteString 1,Name$
 

 ; convert our variable ScorePOints to a text representation
 ; and write it to the file channel #1
 WriteString 1,str$(ScorePoints)

; we're done writing, so close it
CloseFile 1


; Our file now has two rows of TEXT in it.  


;------------------------------------------------------------
; Read the File.. First we check if the file we're going to
; read actually exists..
;------------------------------------------------------------
If FileExist(Filename$)=true

 ; Print this message if the file exists
 Print "Found File.. Loading"

 ; Tell PB to start reading to file, using fiole channel #1     
 ReadFile Filename$,1

   ; read a line of the string data from the file..  
   Loaded_Header$         =ReadString$(1)

   ; read a line of the string data from the file..  
   Loaded_Name$         =ReadString$(1)

   ; read the value scorepoints from the file as text, and convert
   ; the text to a number and assign that number to the variable
   ; scorePoints
   Loaded_ScorePOints   =val(ReadString$(1))

; we're done reading the file.. so now we close the file channel
CloseFile 1
EndIf


;------------------------------------------------------------
; DRaw the variables to the screen
;------------------------------------------------------------
print Loaded_Header$
print Loaded_Name$
print Loaded_ScorePOints

; display the screen
Sync
waitkey

[/pbcode]





Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 30, 2010, 03:54:45 PM
I modified it and it isn't picking up the score.  

[pbcode]
; PROJECT : Project5
; AUTHOR  : Pagan Slim
; CREATED : 6/30/2010
; ---------------------------------------------------------------------

; PROJECT : MyScore
; AUTHOR  : Pagan Slim
; CREATED : 6/29/2010
; EDITED  : 6/30/2010
; ---------------------------------------------------------------------
Filename$="ScoreData.dat"

Scorepoints = 20

; Check for an old copy of the file,, If it exists.. delete it
; so we can write a new copy of it to disk
If FileExist(Filename$) Then DeleteFile Filename$


; The variables we'll be saving into our file



; Start WriteFile the file using file channel #1
WriteFile Filename$,1
 ; write the string data to the open file channel  
 WriteString 1,"Here Be the Score Board"
 WriteString 1,Str$(ScorePoints)
 

; we're done writing, so close it
CloseFile 1


;-------------------------------
; Read the File.. First we check if the file we're going to
; read actually exists..
If FileExist(Filename$)=true
 ; Print this message if the file exists
 Print "Found File.. Loading"

 ; Tell PB to start reading to file, using fiole channel #1     
 ReadFile Filename$,1

   ; read a line of the string data from the file..  
   Header$         =ReadString$(1)

   ; read the next line of string from next.  This time we're converting
   ; the text (characters) returned from ReadtString$(1) into a numeric
   ; value using the VAL() Function.  The result is assign to the variable
   ;  
   MatrixWidth   =Val(ReadString$(1))
   

; we're done reading the file.. so now we close the file channel
CloseFile 1
EndIf


; DRaw the variables to the screen
Print Header$


; display the screen
Sync
WaitKey



[/pbcode]


So... I wrote a little simple scoregame to test my ignorance.

[pbcode]
; PROJECT : Project4
; AUTHOR  : Pagan Slim
; CREATED : 6/30/2010
; EDITED  : 6/30/2010
; ---------------------------------------------------------------------
Filename$="ScoreData.dat"

; Check for an old copy of the file,, If it exists.. delete it
; so we can write a new copy of it to disk
If FileExist(Filename$) Then DeleteFile Filename$


ScorePoints =  0
Print "Silly Scorekeeping Game"
Print " "
Print " Press the enter key to score in the easiest game in the world."
Sync

Do
   
Print "Top of 'Do Loop'."   
WaitKey
ScorePoints = ScorePoints + 1
Print "ScorePoints:" + Str$ (ScorePoints)
Sync

; Start WriteFile the file using file channel #1
WriteFile Filename$,1
 ; write the string data to the open file channel  
 WriteString 1,"Here Be the Score Board"
 WriteString 1,Str$(ScorePoints)


Loop


ENDGAME:
Cls
Print "FINAL SCORE:"
WriteString 1,Str$(ScorePoints)
; we're done writing, so close it
CloseFile 1
WaitKey
End


READSCORE:
;-------------------------------
; Read the File.. First we check if the file we're going to
; read actually exists..
If FileExist(Filename$)=true
 ; Print this message if the file exists
 Print "Found File.. Loading"

 ; Tell PB to start reading to file, using fiole channel #1     
 ReadFile Filename$,1

   ; read a line of the string data from the file..  
   Header$         =ReadString$(1)

   ; read the next line of string from next.  This time we're converting
   ; the text (characters) returned from ReadtString$(1) into a numeric
   ; value using the VAL() Function.  The result is assign to the variable
   ;  
   MatrixWidth   =Val(ReadString$(1))
   MatrixHeight   =Val(ReadString$(1))
   MatrixTilesX   =Val(ReadString$(1))
   MatrixTilesY   =Val(ReadString$(1))
   FloatVar#      =Val#(ReadString$(1))    

; we're done reading the file.. so now we close the file channel
CloseFile 1
EndIf


; DRaw the variables to the screen
Print Header$
Print MatrixWidth
Print MatrixHeight
Print MatrixTilesX
Print MatrixTilesY
Print FloatVar#

; display the screen
Sync
WaitKey



[/pbcode]

It doesn't work yet.  I need to study this more, I know.  Any idea of which examples that came with PB that would best demonstrate what I need to know?
Title: Re: Fight simulation perfected - for now.
Post by: Pagan Slim on June 30, 2010, 04:05:06 PM
I forget to put print ScorePoints in there.  My mistake.
Title: Re: Fight simulation perfected - for now.
Post by: Big C. on June 30, 2010, 04:18:07 PM
Slim,

QuoteMy intent is to have it written to an external file

its not so difficult as you thing... Kevin gives you very good examples to study...

For your intent I would put the Checkcode for file at the beginning of your program and at the end you should update the scorefile...

After the line
HITPOINTS = RndRange (7,18);ADJUSTED TO EQUAL THE ODDS.

you would find the starting line which we should modify
ScorePoints = 0 ; Your initial score.


We should start to check if the scorfile exists... You know what to do and will hopfully get the following  :)

If FileExist("ScoreData.dat")

If the file exits you should open the file, read the needed score value and assign the readed value to the scorevar ScorePoints... It should look like this lines
OpenFile "ScoreData.dat",1
ScorePoints = Val(ReadString$(1))

at this point we shoul close the file access with the line
CloseFile 1
so the game can start

Ok but if the scoreData.dat doesn't exists we need do predefine the value of our var ScorePoints
We should expand the if-clause with the else-term like this lines
Else
ScorePoints = 0 ; Your initial score.
EndIf


If the game ends then we need either create the scoredata file or we need to write acess them...

I would change the "The_END" Section as follows..


THE_END:
Print "It's over boys."
Print " "
Print "YOUR SCORE " + Str$(ScorePoints)
Print " "


WriteFile "ScoreData.dat",1
WriteString 1, Str$(ScorePoints)
CloseFile 1

Sync
WaitKey
End
Return


Hope that helps yo a little bit... try to understand by reading the Help on Keyword reference...  ;)