[Codesnip] Password for a level idenification

Share your advanced PureBasic knowledge/code with the community.
User avatar
IceSoft
Addict
Addict
Posts: 1695
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

[Codesnip] Password for a level idenification

Post by IceSoft »

Only a simple example:

Code: Select all

;
; Password for a level idenification
;
#maxLevel = 100

; Get the corresponding Level from Password
Procedure.l CreateLFP(sPWD$)
  For nl = 1 To #maxLevel
    RandomSeed(nl)
    retPWD$ = ""
    For n = 1 To 5
      retPWD$ + Chr(Random(25)+65)
    Next n
    If retPWD$ = sPWD$
      ProcedureReturn nl
    EndIf
  Next nl
  ProcedureReturn -1
EndProcedure

; Create a corresponding Password for Level
Procedure.s CreatePFL(lLevel)
  RandomSeed(lLevel)
  For n = 1 To 5
      retPWD$ + Chr(Random(25)+65)
  Next n
  ProcedureReturn retPWD$
EndProcedure


; 
; Example
;
pwd.s = CreatePFL(10)
Debug "Password for Level 10: " + pwd
MessageRequester("","Password for Level 10: " + pwd)
pwd = InputRequester("Input password for level.","Enter password (Default: Level 1):", CreatePFL(1))
MessageRequester("","You start with level: " + Str(createLFP(pwd)) + " now.")
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...