Thursday, 5 May 2011

file saving


Program Lesson9_Program2;
Var FName, Txt : String[10];
    UserFile   : Text;
Begin
 FName := 'Textfile';
 Assign(UserFile,'C:\'+FName+'.txt'); {assign a text file}
 Rewrite(UserFile); {open the file 'fname' for writing}
 Writeln(UserFile,'PASCAL PROGRAMMING');
 Writeln(UserFile,'if you did not understand something,');
 Writeln(UserFile,'please send me an email to:');
 Writeln(UserFile,'victorsaliba@hotmail.com');
 Writeln('Write some text to the file:');
 Readln(Txt);
 Writeln(UserFile,'');
 Writeln(UserFile,'The user entered this text:');
 Writeln(UserFile,Txt);
 Close(UserFile);
End.


Sub saveTopScores(ByRef TopScores() As TTopScore)
        Dim file As New System.IO.StreamWriter("HiScores.txt")
        For i = 1 To MaxSize
            file.WriteLine(TopScores(i).Name + "," + TopScores(i)
.Score.ToString())
        Next i
        file.Close()
    End Sub




Tuesday, 3 May 2011

for information

http://www.thestudentroom.co.uk/showthread.php?t=1566252

more

Our teachers said we'd be adding in functionality, so i'm guessing the more players is a good idea. checking a user input is valid (in the real dice mode, from the code i think i recall there not being a check to see if the user input was > 0 or < 6. Also, 4 sided dice? someone pointed out, can't remember completely. I'll take a look tomorrow if i'm free
- Increase the top scores to more than 4 players (MaxSize)
- Saving the top scores to a file
- Validating various data entries e.g. name to 20 characters length
- Resetting the hiscores using the function already written in the code

One thing that my class has been thinking about is that it may ask you to write the highscores to a text file
- Currently it just saves them locally, and when you reload the program it clears the highscores ( ResetTopScores() )
- Advice. "FileStream.Writer()" -> I will add the whole writing to a text file code tomorrow

Another thing it may ask us to do is add more players possibly?
So make it so you can have 3 or 4 players playing at one time...not hard...Just add "Dim PlayerThreeName As String" and all the other stuff that has PlayerOne and PlayerTwo

Like jsmith said in the first post, it could ask us to make it so they can choose the amount of hiscores it saves. Quite easy really. In the "Sub Main()" just add
Console.Write("How many hiscores would you like to save: ")
MaxSize = Console.Readline()

If I get any more ideas from classmates then I will post it here.
I will also add the ways to add my ideas

Post any questions on the code that you have to add...I will look into it...write it...and post it for you

This will be fun

dice cricket

Dice Cricket Game
The Skeleton Program is a program for the two-player game of Dice Cricket. Dice Cricket is a simple game based on the sport of cricket. When playing Dice Cricket, players use two special dice called the Bowl Die1 and the Appeal Die.

The Bowl Die is a 6-sided die where, instead of the numbers 1 to 6, the sides have "0", "1", "2", "4","6", and "OUT" written on them. The player whose turn it is rolls the Bowl Die. If the result is one of the numeric values then this is added to their score (the number of runs they have got) and they continue to roll the Bowl Die until "OUT" is rolled. If the result is "OUT" then they roll the Appeal Die to see what happens next.

The Appeal Die is a 4-sided die where the numbers 1 to 4 have been replaced with different values. The values on the Appeal Die are "NOT OUT", "CAUGHT", "LBW" and "BOWLED". If when a player rolls the Appeal Die they get a result of "NOT OUT" then their turn continues and they can roll the Bowl Die again. Any other result on the Appeal Die means that they are out and their turn finishes. When player one's turn is over player two has their turn. When player two is out the two players' scores are compared and the winner is the one with the highest score.

In the Skeleton Program players can choose to play with real dice or virtual dice. If real dice are used then the two players have actually got a Bowl Die and an Appeal Die and enter the values they roll into the program. If virtual dice are used then the program simulates the rolling of the Bowl Die and Appeal Die by generating random numbers. There are 6 different values on the Bowl Die and 4 different values on the Appeal Die.

The Skeleton Program also stores the names and scores of the four highest results obtained by players playing Dice Cricket. After each game the scores of the two players are compared with the previous top scores. The winner's details, if their score is higher, will replace those of the player with the lowest top score. The loser's details, if their score is high enough, could also replace one of the previous player’s details. If the winning player’s score is the same as the lowest top score their details are not stored. If a game is drawn with a score lower than three of the top four scores then only player one’s details will be stored.

In the Skeleton Program there is a menu containing five options:
  Play game version with virtual dice
  Play game version with real dice
  Load top scores
  Display top scores
Quit
If the user chooses to load top scores from a file then the file HiScores.txt is opened and the contents placed in the array TopScores.

The Data File
Ricky,12
Sachin,45
Brian,2
Monty,1
The data file HiScores.txt will be available to you at the start of the examination.

more

1. Validate Get Menu choice so it does not crash
2. Load Top Scores on start up
3. Validate manual entry: AppealDie and BowlDie entries (Validation + CaseElse)
4. Add extra scoring rules: as mentioned in pre-release (DONT GET HOW)
5. Write scores to disk (array) as CSV

Other possible:
- Change maximum players
- Change scores on disk to more (increase the value of maxsize)
- Make maxsize local and pass it

more

more programming

It is possible that you may be asked to write a save routine, possibly as an additional menu option. If you search this site there are already several threads about this exam and lots of suggestions as to what may or may not come up on the exam.