help puting high scores in
Author |
Message |
roosterfest123
|
Posted: Mon Jun 20, 2011 3:07 pm Post subject: help puting high scores in |
|
|
hi im trying to put highscores in my program but cant figure out how, plz help
Turing: |
< loop
loop %opens the loop
put "This coarse tests your ability to dodge" % tells user what minigame does
colorback (white) %makes background white
View.Set ("offscreenonly") %makes the screen offscreenonly
Pic.Draw (dhalismjump, x, y, picMerge) %picture of guy jumping
View.Set ("offscreenonly") %makes the screen offscreenonly
Pic.Draw (dhalismjump, x, y, picMerge) %picture of guy jumping
x1 := x1 - 10 %makes x1 go left 10 spots
if x1 < 0 then %if x1 is lower than 0 then
x1 := 1100 %x1 resets to 1100
count := count + 1
end if %ends if statement
Input.KeyDown (keys ) %allows keys to be pressed
if keys (KEY_UP_ARROW) then % if up key is pressed then
jump23 % man jumps up
end if %ends if statement
if keys (KEY_RIGHT_ARROW) then % if right arrow key is pressed then
delay (100) %delay the program
walkRight4 % man walks to the right
delay (50) %delays program
Pic.Draw (dhalism, x, y, picMerge) %draws man base picture
Pic.Draw (bomb, x1, 1, picMerge) %draws the plasma ball
end if %ends if statement
if keys (KEY_LEFT_ARROW) then % if left arrow key is presses then
delay (100) %delay the program
walkLeft5 %man walks left
delay (50) %delays the program
Pic.Draw (dhalism, x, y, picMerge) %draws man base picture
Pic.Draw (bomb, x1, 1, picMerge) %draws the plasma ball
end if %ends if statement
cls
Pic.Draw (background1, 1, 1, picXor) %draws the background
Pic.Draw (dhalism, x, y, picMerge) %draws man base picture
Pic.Draw (bomb, x1, 1, picMerge) %draws the plasma ball
if keys ('1') then
cls
Pic.Draw (background1, 1, 1, picXor) %draws the background
Pic.Draw (dhalism1, x, y, picMerge) %picture of guy punshing
Pic.Draw (bomb, x1, 1, picMerge) %draws the plasma ball
end if %ends if statement
if keys ('e') then %if e key is pressed then
jump24 % make the man jump to the right
end if % ends if statement
if keys ('q') then %if q key is pressed then
jump25 % make the man jump to the left
end if % ends if statement
if keys ('2') then %if 2 key is pressed then
cls %clears the screen
Pic.Draw (background1, 1, 1, picXor) %draws the background
Pic.Draw (dhalismpunch, x, y, picMerge) %picture of guy punshing
Pic.Draw (bomb, x1, 1, picMerge) %draws the plasma ball
end if %ends if statement
if keys ('3') then %if 3 key is pressed then
cls %clears teh screen
Pic.Draw (background1, 1, 1, picXor) %draws the background
Pic.Draw (dhalismkick, x, y, picMerge) %picture of guy kicking
Pic.Draw (bomb, x1, 1, picMerge) %draws the plasma ball
end if %ends if statement
if keys (KEY_DOWN_ARROW) then %if Down arrow key is pressed then
cls %clears the screen
Pic.Draw (background1, 1, 1, picXor) %draws the background
Pic.Draw (dhalismduck, x, y, picMerge) %outputs picture of man ducking
Pic.Draw (bomb, x1, 1, picMerge) %draws the plasma ball
end if %ends if statement
View.Update %refreshes the screen
if x1 = x then % if x1 is the same as x then
View.Set ("nooffscreenonly") %teurs offscreen only off
Pic.Draw (loser, 1, 1, picMerge) % outputs picture of loser sign
delay (1000) %delays the program
cls %clears the screen
put "would you like to play again?" % asks user if he/she wants to play again
get answer3 %gets the answer
if answer3 = "y" or answer3 = "Y" %if the answer if yes then
then % then
x := 0 % resets x coordinate
x1 := 1100 %resets x1 coordiante
cls %clears the screen
%loops to top of the game
elsif answer3 = "n" or answer3 = "N" % if asnweer is no then
then %then
exit %program exits
%goes to top of program
end if %ends if statement
elsif x1 > x and x1 < x + 150 then %if x1 is greater then x and x1 is less then x + 150 then
View.Set ("nooffscreenonly") %turns offscreen only off
Pic.Draw (loser, 1, 1, picMerge) %outputs loser sign picture
delay (1000) %delays the program
cls %clears the screen
put "your score was", count
put "would you like to play again?" % asks user if he/she wants to play again
get answer3 %gets the answer
if answer3 = "y" or answer3 = "Y" %if the answer if yes then
then %then
cls %lears the screen
x := 0 % resets x coordinate
x1 := 1100 %resets x1 coordiante
%loops to top of the game
elsif answer3 = "n" or answer3 = "N" % if asnweer is no then
then %then
x := 0 % resets x coordinate
x1 := 1100 %resets x1 coordiante
exit %program exits
end if %ends if statement
end if %ends if statement
end loop %ends the loop
if answer3 = "n" then % if answer is no then
exit %program exits and goes to top of program
end if %ends if statement
end loop %ends the loop
end if %ends if statement
end loop %ends loop
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
ProgrammingFun
![](http://compsci.ca/v3/uploads/user_avatars/11682880074bcb590d30b0a.png)
|
|
|
|
![](images/spacer.gif) |
roosterfest123
|
Posted: Mon Jun 20, 2011 3:26 pm Post subject: RE:help puting high scores in |
|
|
iv tried putting in an input file and putting the information to it but it didn't work so i basically rage quit |
|
|
|
|
![](images/spacer.gif) |
roosterfest123
|
Posted: Mon Jun 20, 2011 3:30 pm Post subject: RE:help puting high scores in |
|
|
so yes but i guess i did it wrong |
|
|
|
|
![](images/spacer.gif) |
ProgrammingFun
![](http://compsci.ca/v3/uploads/user_avatars/11682880074bcb590d30b0a.png)
|
Posted: Mon Jun 20, 2011 3:32 pm Post subject: Re: RE:help puting high scores in |
|
|
roosterfest123 @ Mon Jun 20, 2011 3:26 pm wrote: iv tried putting in an input file and putting the information to it but it didn't work so i basically rage quit
Not the best way to go about programming lol
Can you describe/code what you did so we can see what didn't work?
Were you getting an error or did it just not function properly?
You would have to follow the following order:
pseudocode: |
**create a txt file in the directory of you program and write some names + highscores into it**
user plays game - score is recorded
at end of game, program loads highscores
if user's score is higher than a highscore (go bottom to up), write user score into it and move other scores down
display highscores
|
EDIT: Please don't double post, just use the EDIT button |
|
|
|
|
![](images/spacer.gif) |
roosterfest123
|
Posted: Mon Jun 20, 2011 3:48 pm Post subject: RE:help puting high scores in |
|
|
iv tried what u said before and it didn't work |
|
|
|
|
![](images/spacer.gif) |
ProgrammingFun
![](http://compsci.ca/v3/uploads/user_avatars/11682880074bcb590d30b0a.png)
|
Posted: Mon Jun 20, 2011 3:58 pm Post subject: Re: RE:help puting high scores in |
|
|
ProgrammingFun @ Mon Jun 20, 2011 3:32 pm wrote: Can you describe/code what you did so we can see what didn't work?
Please give the code that didn't work... |
|
|
|
|
![](images/spacer.gif) |
roosterfest123
|
Posted: Mon Jun 20, 2011 4:11 pm Post subject: RE:help puting high scores in |
|
|
lol i deleted the code and raged quit. so its long gone
but what i did was
open: inputfile,"highscore.txt" - makes new file
put inputfile, count
put inputfile, name
close (input file)
then i opened the file and got the information then put in the program |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Jun 20, 2011 4:27 pm Post subject: RE:help puting high scores in |
|
|
Ok. That works for the first play. On the second play, how would you figure out if the new score is better than what's in the file? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
roosterfest123
|
Posted: Mon Jun 20, 2011 4:42 pm Post subject: RE:help puting high scores in |
|
|
well i would sort it right
but the thing is when i run the program it doesnt even enter the info into the .txt file it makes a different one and keeps it empty |
|
|
|
|
![](images/spacer.gif) |
roosterfest123
|
Posted: Mon Jun 20, 2011 4:46 pm Post subject: RE:help puting high scores in |
|
|
open : inputFile, "highscore.txt", put
put inputFile, count
put inputFile, name
close (inputFile) |
|
|
|
|
![](images/spacer.gif) |
RandomLetters
|
Posted: Mon Jun 20, 2011 5:15 pm Post subject: Re: RE:help puting high scores in |
|
|
ProgrammingFun @ Mon Jun 20, 2011 3:32 pm wrote: roosterfest123 @ Mon Jun 20, 2011 3:26 pm wrote: iv tried putting in an input file and putting the information to it but it didn't work so i basically rage quit
Not the best way to go about programming lol
What are you talking about? I do it all the time, and my programs turn out half complete.
open : inputFile, "highscore.txt", put
put inputFile, count
put inputFile, name
close (inputFile)
That's not the right syntax for reading files.
open |
|
|
|
|
![](images/spacer.gif) |
crossley7
|
Posted: Mon Jun 20, 2011 8:51 pm Post subject: Re: help puting high scores in |
|
|
it is put : inputFile, (insert variable here) which will put that variable into the file.
Here is an example of the relevant code from one of my games that i made last year in spare time (I tend to make a lot of crappy games incorporating random features... this one had highscores). It should show you how to do your own highscores
Turing: |
var hsS, hsN : int
var highSc : array 1 .. 10 of int
var highScName : array 1 .. 10 of string
open : hsS, "Highscores.txt", get
open : hsN, "Highscore Names.txt", get
for d : 1 .. 10
get : hsS, highSc (d)
get : hsN, highScName (d) : *
end for
close : hsS
close : hsN
open : hsS, "Highscores.txt", put
open : hsN, "Highscore Names.txt", put
for j : 1 .. 10
if score >= highSc (j) then
for decreasing k : 9 .. j
highSc (k + 1) := highSc (k)
highScName (k + 1) := highScName (k)
end for
highSc (j) := score
put "What is your name?"
get holder2 : *
highScName (j) := holder2
exit
end if
end for
for n : 1 .. 10
put : hsS, highSc (n)
put : hsN, highScName (n)
end for
close : hsS
close : hsN
|
|
|
|
|
|
![](images/spacer.gif) |
|
|