The Student Room Group

Computing pre-release material AQA A

Scroll to see replies

Reply 21
i like the teleport idea. a once per game magic spell (to stay in context) that either lets you choose where to teleport to or which picks a place at random. could include that the target shouldn't be occupied already by one or more of the game elements - that would need a while loop until the target square was free.

another possibility could be more than one floor. you could have to find your way to a ladder to change floors. each floor might be a duplicate of the original ie with 2 traps and a monster randomly placed.

remember that in the past, the hard tasks (like this would be) needed to be described but not programmed.
Reply 22
It already has a get random position which I think is where that would be used again.

I doubt they will make it too complicated though - remembering its only a 50 minute part of the exam which you will have to screenshot to death in and answer a load of 1 markers on variable roles etc.
Reply 23
I'd be really grateful if anyone could send me the pre-release? :smile: I'm doing the exam in VB.NET (God help me! haha) so if you have the skeleton code in that too that would be even better! Thanks in advance.
Reply 24
Original post by Robskeh
I'd be really grateful if anyone could send me the pre-release? :smile: I'm doing the exam in VB.NET (God help me! haha) so if you have the skeleton code in that too that would be even better! Thanks in advance.


I've sent you a PM.
Reply 25
Original post by jsmith1299
It already has a get random position which I think is where that would be used again.

I doubt they will make it too complicated though - remembering its only a 50 minute part of the exam which you will have to screenshot to death in and answer a load of 1 markers on variable roles etc.


the 50 mins are programming and expansion design. The one markers are in section C: "Questions will refer to the Preliminary Material and the Skeleton Program, but will not require programming"

Just remember that something that is too complicated to code might still come up as a "how would you solve this problem" type question. The last two comp1 exams had 2 marks at the end for this type of thing - noughts and crosses in a cube or altering the probability of dice rolls in cricket.

You're right about the screenshot issue though :smile:
Sorry to be a bit repetetive, but could somebody please send me the pre release for pascal.

Thanks.
Reply 27
Original post by Davies.Nathan
Sorry to be a bit repetetive, but could somebody please send me the pre release for pascal.

Thanks.


program prereleasematerial2012;

{$APPTYPE CONSOLE}

{Skeleton Program code for the AQA COMP1 Summer 2012 examination
this code should be used in conjunction with the Preliminary Material
written by the AQA COMP1 Programmer Team developed in the
Turbo Pascal v7 programming environment}

{Centres using Delphi should add the compiler directive that sets
the application type to Console (other centres can ignore this
comment). Centres may also add the SysUtils library if their
version of Pascal uses this}

{Permission to make these changes to the Skeleton Program does not
need to be obtained from AQA/AQA Programmer - just remove the \ symbol from
the next line of code and remove the braces around Uses SysUtils;}


Uses
SysUtils;

Const NoOfTraps = 2;
Const NSDistance = 5;
Const WEDistance = 7;

Type
TCellReference = Record
NoOfCellsSouth : Integer;
NoOfCellsEast : Integer;
End;
TCavern = Array[1..NSDistance, 1..WEDistance] Of Char;
TTrapPositions = Array[1..NoOfTraps] Of TCellReference;
TGameData = Record
TrapPositions : TTrapPositions;
MonsterPosition : TCellReference;
PlayerPosition : TCellReference;
FlaskPosition : TCellReference;
MonsterAwake : Boolean;
End;

Var
Cavern : TCavern;
Choice : Integer;
FlaskPosition : TCellReference;
MonsterAwake : Boolean;
MonsterPosition : TCellReference;
PlayerPosition : TCellReference;
TrapPositions : TTrapPositions;

Procedure DisplayMenu;
Begin
Writeln('MAIN MENU');
Writeln;
Writeln('1. Start new game');
Writeln('2. Load game');
Writeln('3. Save game');
Writeln('4. Play training game');
Writeln('9. Quit');
Writeln;
Write('Please enter your choice: ');
End;

Function GetMainMenuChoice : Integer;
Var
Choice : Integer;
Begin
Readln(Choice);
Writeln;
GetMainMenuChoice := Choice;
End;

Procedure ResetCavern(Var Cavern : TCavern);
Var
Count1 : Integer;
Count2 : Integer;
Begin
For Count1 := 1 to NSDistance
Do
For Count2 := 1 to WEDistance
Do Cavern[Count1, Count2] := ' ';
End;

Procedure GetNewRandomPosition(Var NewPosition : TCellReference);
Var
Position : TCellReference;
Begin
Repeat
Position.NoOfCellsSouth := Random(NSDistance) + 1;
Position.NoOfCellsEast := Random(WEDistance) + 1;
Until (Position.NoOfCellsSouth > 1) Or (Position.NoOfCellsEast > 1);
{a random coordinate of (1,1) needs to be rejected as this is the starting position of the player}
NewPosition := Position;
End;

Procedure SetPositionOfItem(Var Cavern : TCavern; Var ObjectPosition : TCellReference; Item : Char; NewGame : Boolean);
Var
Position : TCellReference;
Begin
If NewGame And (Item <> '*')
Then
Begin
Repeat
GetNewRandomPosition(Position);
Until Cavern[Position.NoOfCellsSouth, Position.NoOfCellsEast] = ' ';
ObjectPosition := Position;
End;
Cavern[ObjectPosition.NoOfCellsSouth, ObjectPosition.NoOfCellsEast] := Item;
End;

Procedure SetUpGame(Var Cavern : TCavern; Var TrapPositions : TTrapPositions; Var MonsterPosition,
PlayerPosition , FlaskPosition: TCellReference; Var MonsterAwake : Boolean; NewGame : Boolean);
Var
Count : Integer;
Begin
ResetCavern(Cavern);
If NewGame
Then
Begin
PlayerPosition.NoOfCellsSouth := 1;
PlayerPosition.NoOfCellsEast := 1;
MonsterAwake := False;
End;
For Count := 1 To NoOfTraps
Do SetPositionOfItem(Cavern, TrapPositions[Count], 'T', NewGame);
SetPositionOfItem(Cavern, MonsterPosition, 'M', NewGame);
SetPositionOfItem(Cavern, FlaskPosition, 'F', NewGame);
SetPositionOfItem(Cavern, PlayerPosition, '*', NewGame);
End;

Procedure SetUpTrainingGame(Var Cavern : TCavern; Var TrapPositions : TTrapPositions; Var MonsterPosition,
PlayerPosition, FlaskPosition : TCellReference; Var MonsterAwake : Boolean);
Begin
ResetCavern(Cavern);
PlayerPosition.NoOfCellsSouth := 3;
PlayerPosition.NoOfCellsEast := 5;
MonsterAwake := False;
TrapPositions[1].NoOfCellsSouth := 2;
TrapPositions[1].NoOfCellsEast := 7;
TrapPositions[2].NoOfCellsSouth := 4;
TrapPositions[2].NoOfCellsEast := 5;
MonsterPosition.NoOfCellsSouth := 1;
MonsterPosition.NoOfCellsEast := 4;
FlaskPosition.NoOfCellsSouth := 5;
FlaskPosition.NoOfCellsEast := 6;
SetUpGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake, False);
End;

Procedure LoadGame(Var TrapPositions : TTrapPositions; Var MonsterPosition, PlayerPosition,
FlaskPosition : TCellReference; Var MonsterAwake : Boolean);
Var
CurrentFile : File Of TGameData;
Filename : String;
LoadedGameData : TGameData;
Begin
Write('Enter the name of the file to load: ');
Readln(Filename);
Writeln;
Assign(CurrentFile, Filename);
Reset(CurrentFile);
Read(CurrentFile, LoadedGameData);
Close(CurrentFile);
TrapPositions := LoadedGameData.TrapPositions;
MonsterPosition := LoadedGameData.MonsterPosition;
PlayerPosition := LoadedGameData.PlayerPosition;
FlaskPosition := LoadedGameData.FlaskPosition;
MonsterAwake := LoadedGameData.MonsterAwake;
End;

Procedure SaveGame(TrapPositions : TTrapPositions; MonsterPosition, PlayerPosition,
FlaskPosition : TCellReference; MonsterAwake : Boolean);
Var
CurrentFile : File Of TGameData;
Filename : String;
CurrentGameData : TGameData;
Begin
CurrentGameData.TrapPositions := TrapPositions;
CurrentGameData.MonsterPosition := MonsterPosition;
CurrentGameData.PlayerPosition := PlayerPosition;
CurrentGameData.FlaskPosition := FlaskPosition;
CurrentGameData.MonsterAwake := MonsterAwake;
Write('Enter new file name: ');
Readln(Filename);
Writeln;
Assign(CurrentFile, Filename);
Rewrite(CurrentFile);
Write(CurrentFile, CurrentGameData);
Close(CurrentFile);
End;

Procedure DisplayCavern(Cavern : TCavern; MonsterAwake : Boolean);
Var
Count1 : Integer;
Count2 : Integer;
Begin
For Count1 := 1 To NSDistance
Do
Begin
Writeln(' ------------- ');
For Count2 := 1 To WEDistance
Do
If (Cavern[Count1, Count2] In [' ','*']) Or ((Cavern[Count1,Count2] = 'M') And MonsterAwake)
Then Write('|',Cavern[Count1, Count2])
Else Write('| ');
Writeln('|');
End;
Writeln( ' ------------- ');
Writeln;
End;

Procedure DisplayMoveOptions;
Begin
Writeln;
Writeln('Enter N to move NORTH');
Writeln('Enter E to move EAST');
Writeln('Enter S to move SOUTH');
Writeln('Enter W to move WEST');
Writeln('Enter M to return to the Main Menu');
Writeln;
End;

Function GetMove : Char;
Var
Move : Char;
Begin
Readln(Move);
Writeln;
GetMove := Move;
End;

Procedure MakeMove(Var Cavern : TCavern; Direction : Char; Var PlayerPosition : TCellReference);
Begin
Cavern[PlayerPosition.NoOfCellsSouth, PlayerPosition.NoOfCellsEast] := ' ';
Case Direction Of
'N' : PlayerPosition.NoOfCellsSouth := PlayerPosition.NoOfCellsSouth - 1;
'S' : PlayerPosition.NoOfCellsSouth := PlayerPosition.NoOfCellsSouth + 1;
'W' : PlayerPosition.NoOfCellsEast := PlayerPosition.NoOfCellsEast - 1;
'E' : PlayerPosition.NoOfCellsEast := PlayerPosition.NoOfCellsEast + 1;
End;
Cavern[PlayerPosition.NoOfCellsSouth, PlayerPosition.NoOfCellsEast] := '*';
End;

Function CheckValidMove(PlayerPosition : TCellReference; Direction : Char) : Boolean;
Var
ValidMove : Boolean;
Begin
ValidMove := True;
If Not (Direction In ['N','S','W','E','M'])
Then ValidMove := False;
CheckValidMove := ValidMove;
End;

Function CheckIfSameCell(FirstCellPosition, SecondCellPosition : TCellReference) : Boolean;
Var
InSameCell : Boolean;
Begin
InSameCell := False;
If (FirstCellPosition.NoOfCellsSouth = SecondCellPosition.NoOfCellsSouth)
And (FirstCellPosition.NoOfCellsEast = SecondCellPosition.NoOfCellsEast)
Then InSameCell := True;
CheckIfSameCell := InSameCell;
End;

Procedure DisplayWonGameMessage;
Begin
Writeln('Well done! You have found the flask containing the Styxian potion.');
Writeln('You have won the game of MONSTER!');
Writeln;
End;

Procedure DisplayTrapMessage;
Begin
Writeln('Oh no! You have set off a trap. Watch out, the monster is now awake!');
Writeln;
End;

Procedure MoveFlask(Var Cavern : TCavern; NewCellForFlask : TCellReference; Var FlaskPosition : TCellReference);
Begin
Cavern[NewCellForFlask.NoOfCellsSouth, NewCellForFlask.NoOfCellsEast] := 'F';
Cavern[FlaskPosition.NoOfCellsSouth, FlaskPosition.NoOfCellsEast] := ' ';
FlaskPosition := NewCellForFlask;
End;

Procedure MakeMonsterMove(Var Cavern : TCavern; Var MonsterPosition, FlaskPosition : TCellReference;
PlayerPosition : TCellReference);
Var
OriginalMonsterPosition : TCellReference;
MonsterMovedToSameCellAsFlask : Boolean;
Begin
OriginalMonsterPosition := MonsterPosition;
Cavern[MonsterPosition.NoOfCellsSouth, MonsterPosition.NoOfCellsEast] := ' ';
If MonsterPosition.NoOfCellsSouth < PlayerPosition.NoOfCellsSouth
Then MonsterPosition.NoOfCellsSouth := MonsterPosition.NoOfCellsSouth + 1
Else
If MonsterPosition.NoOfCellsSouth > PlayerPosition.NoOfCellsSouth
Then MonsterPosition.NoOfCellsSouth := MonsterPosition.NoOfCellsSouth - 1
Else
If MonsterPosition.NoOfCellsEast < PlayerPosition.NoOfCellsEast
Then MonsterPosition.NoOfCellsEast := MonsterPosition.NoOfCellsEast + 1
Else MonsterPosition.NoOfCellsEast := MonsterPosition.NoOfCellsEast - 1;
MonsterMovedToSameCellAsFlask := CheckIfSameCell(MonsterPosition, FlaskPosition);
If MonsterMovedToSameCellAsFlask
Then MoveFlask(Cavern, OriginalMonsterPosition, FlaskPosition);
Cavern[MonsterPosition.NoOfCellsSouth, MonsterPosition.NoOfCellsEast] := 'M';
End;

Procedure DisplayLostGameMessage;
Begin
Writeln('ARGHHHHHH! The monster has eaten you. GAME OVER.');
Writeln('Maybe you will have better luck next time you play MONSTER!');
Writeln;
End;

Procedure PlayGame(Var Cavern : TCavern; TrapPositions : TTrapPositions; Var MonsterPosition, PlayerPosition,
FlaskPosition : TCellReference; Var MonsterAwake : Boolean);
Var
Count : Integer;
Eaten : Boolean;
FlaskFound : Boolean;
MoveDirection : Char;
ValidMove : Boolean;
Begin
Eaten:= False;
FlaskFound := False;
DisplayCavern(Cavern, MonsterAwake);
Repeat
Repeat
DisplayMoveOptions;
MoveDirection := GetMove;
ValidMove := CheckValidMove(PlayerPosition, MoveDirection);
Until ValidMove;
If MoveDirection <> 'M'
Then
Begin
MakeMove(Cavern, MoveDirection, PlayerPosition);
DisplayCavern(Cavern, MonsterAwake);
FlaskFound := CheckIfSameCell(PlayerPosition, FlaskPosition);
If FlaskFound
Then DisplayWonGameMessage;
Eaten := CheckIfSameCell(MonsterPosition, PlayerPosition);
If Not MonsterAwake And Not FlaskFound And Not Eaten
Then
Begin
MonsterAwake := CheckIfSameCell(PlayerPosition, TrapPositions[1]);
If Not MonsterAwake
Then MonsterAwake := CheckIfSameCell(PlayerPosition, TrapPositions[2]);
If MonsterAwake
Then
Begin
DisplayTrapMessage;
DisplayCavern(Cavern, MonsterAwake);
End;
End;
If MonsterAwake And Not Eaten And Not FlaskFound
Then
Begin
Count := 0;
Repeat
MakeMonsterMove(Cavern, MonsterPosition, FlaskPosition, PlayerPosition);
Eaten := CheckIfSameCell(MonsterPosition, PlayerPosition);
Writeln;
Writeln('Press Enter key to continue');
Readln;
DisplayCavern(Cavern, MonsterAwake);
Count := Count + 1;
Until (Count = 2) Or Eaten;
End;
If Eaten
Then DisplayLostGameMessage;
End;
Until Eaten Or FlaskFound Or (MoveDirection = 'M');
End;

Begin
Randomize;
Repeat
DisplayMenu;
Choice := GetMainMenuChoice;
Case Choice Of
1 : Begin
SetUpGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake, True);
PlayGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake);
End;
2 : Begin
LoadGame(TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake);
SetUpGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake, False);
PlayGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake);
End;
3 : SaveGame(TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake);
4 : Begin
SetUpTrainingGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake);
PlayGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake);
End;
End;
Until Choice = 9;
End.
Just a little Idea but:

you could add a "difficulty" setting into the menu or after you choose "start game"
then you could add however many difficulties you want therefore adding bigger grids/floors, leaving a clue on each level to the location of the potion

Was just a thought
let me know what you think
Reply 29
Original post by 12345678910
I am doing this exam in Visual Basic and my teacher for some reason says that they dont have the materials, please could someone upload the visual basic code. Thanks
Tell your teacher that it is on E-AQA along with the answer booklet and teachers' notes.
Reply 30
This is unlikely, but I was thinking there is the possibility that you'll need to add a multiplayer component.

Idea One - One player controls player, the other controls the monster
Idea Two - One player 'designs' the level (potion, monster and trap locations), kind of like a level editor.
Reply 31
Here's the vb.NET unedited code (I don't think it's against the rules to post it, but I'll remove it if it is):

'Skeleton Program code for the AQA COMP1 Summer 2012 examination'this code should be used in conjunction with the Preliminary Material
'written by the AQA COMP1 Programmer Team
'developed in the Visual Studio 2008 (Console Mode) programming environment (VB.NET)


Module Module1
Const NoOfTraps = 2
Const NSDistance = 5
Const WEDistance = 7


Structure CellReference
Dim NoOfCellsSouth As Integer
Dim NoOfCellsEast As Integer
End Structure


Structure GameData
Dim TrapPositions() As CellReference
Dim MonsterPosition As CellReference
Dim PlayerPosition As CellReference
Dim FlaskPosition As CellReference
Dim MonsterAwake As Boolean
End Structure


Sub Main()
Dim Cavern(NSDistance, WEDistance) As Char
Dim Choice As Integer
Dim FlaskPosition As CellReference
Dim MonsterAwake As Boolean
Dim MonsterPosition As CellReference
Dim PlayerPosition As CellReference
Dim TrapPositions(NoOfTraps) As CellReference
Randomize()
Do
DisplayMenu()
Choice = GetMainMenuChoice()
Select Case Choice
Case 1
SetUpGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake, True)
PlayGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake)
Case 2
LoadGame(TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake)
SetUpGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake, False)
PlayGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake)
Case 3 : SaveGame(TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake)
Case 4
SetUpTrainingGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake)
PlayGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake)
End Select
Loop Until Choice = 9
End Sub


Sub DisplayMenu()
Console.WriteLine("MAIN MENU")
Console.WriteLine()
Console.WriteLine("1. Start new game")
Console.WriteLine("2. Load game")
Console.WriteLine("3. Save game")
Console.WriteLine("4. Play training game")
Console.WriteLine("9. Quit")
Console.WriteLine()
Console.Write("Please enter your choice: ")
End Sub


Function GetMainMenuChoice() As Integer
Dim Choice As Integer
Choice = CInt(Console.ReadLine())
Console.WriteLine()
GetMainMenuChoice = Choice
End Function


Sub ResetCavern(ByRef Cavern(,) As Char)
Dim Count1 As Integer
Dim Count2 As Integer
For Count1 = 1 To NSDistance
For Count2 = 1 To WEDistance
Cavern(Count1, Count2) = " "
Next
Next
End Sub


Function GetNewRandomPosition() As CellReference
Dim Position As CellReference
Do
Position.NoOfCellsSouth = Int(Rnd() * NSDistance) + 1
Position.NoOfCellsEast = Int(Rnd() * WEDistance) + 1
Loop Until Position.NoOfCellsSouth > 1 Or Position.NoOfCellsEast > 1
'a random coordinate of (1,1) needs to be rejected as this is the starting position of the player
GetNewRandomPosition = Position
End Function


Sub SetPositionOfItem(ByRef Cavern(,) As Char, ByRef ObjectPosition As CellReference, ByVal Item As Char, ByVal NewGame As Boolean)
Dim Position As CellReference
If NewGame And Item <> "*" Then
Do
Position = GetNewRandomPosition()
Loop Until Cavern(Position.NoOfCellsSouth, Position.NoOfCellsEast) = " "
ObjectPosition = Position
End If
Cavern(ObjectPosition.NoOfCellsSouth, ObjectPosition.NoOfCellsEast) = Item
End Sub


Sub SetUpGame(ByRef Cavern(,) As Char, ByRef TrapPositions() As CellReference, ByRef MonsterPosition As CellReference, _
ByRef PlayerPosition As CellReference, ByRef FlaskPosition As CellReference, ByRef MonsterAwake As Boolean, ByVal NewGame As Boolean)
Dim Count As Integer
ResetCavern(Cavern)
If NewGame Then
PlayerPosition.NoOfCellsSouth = 1
PlayerPosition.NoOfCellsEast = 1
MonsterAwake = False
End If
For Count = 1 To NoOfTraps
SetPositionOfItem(Cavern, TrapPositions(Count), "T", NewGame)
Next
SetPositionOfItem(Cavern, MonsterPosition, "M", NewGame)
SetPositionOfItem(Cavern, FlaskPosition, "F", NewGame)
SetPositionOfItem(Cavern, PlayerPosition, "*", NewGame)
End Sub


Sub SetUpTrainingGame(ByRef Cavern(,) As Char, ByRef TrapPositions() As CellReference, ByRef MonsterPosition As CellReference, _
ByRef PlayerPosition As CellReference, ByRef FlaskPosition As CellReference, ByRef MonsterAwake As Boolean)
ResetCavern(Cavern)
PlayerPosition.NoOfCellsSouth = 3
PlayerPosition.NoOfCellsEast = 5
MonsterAwake = False
TrapPositions(1).NoOfCellsSouth = 2
TrapPositions(1).NoOfCellsEast = 7
TrapPositions(2).NoOfCellsSouth = 4
TrapPositions(2).NoOfCellsEast = 5
MonsterPosition.NoOfCellsSouth = 1
MonsterPosition.NoOfCellsEast = 4
FlaskPosition.NoOfCellsSouth = 5
FlaskPosition.NoOfCellsEast = 6
SetUpGame(Cavern, TrapPositions, MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake, False)
End Sub


Sub LoadGame(ByRef TrapPositions() As CellReference, ByRef MonsterPosition As CellReference, ByRef PlayerPosition As CellReference, _
ByRef FlaskPosition As CellReference, ByRef MonsterAwake As Boolean)
Dim Filename As String
Dim LoadedGameData As GameData
Console.Write("Enter the name of the file to load: ")
Filename = Console.ReadLine
Console.WriteLine()
FileOpen(1, Filename, OpenMode.Binary, OpenAccess.Read)
FileGet(1, LoadedGameData)
FileClose(1)
TrapPositions = LoadedGameData.TrapPositions
MonsterPosition = LoadedGameData.MonsterPosition
PlayerPosition = LoadedGameData.PlayerPosition
FlaskPosition = LoadedGameData.FlaskPosition
MonsterAwake = LoadedGameData.MonsterAwake
End Sub


Sub SaveGame(ByVal TrapPositions() As CellReference, ByVal MonsterPosition As CellReference, ByVal PlayerPosition As CellReference, _
ByVal FlaskPosition As CellReference, ByVal MonsterAwake As Boolean)
Dim Filename As String
Dim CurrentGameData As GameData
CurrentGameData.TrapPositions = TrapPositions
CurrentGameData.MonsterPosition = MonsterPosition
CurrentGameData.PlayerPosition = PlayerPosition
CurrentGameData.FlaskPosition = FlaskPosition
CurrentGameData.MonsterAwake = MonsterAwake
Console.Write("Enter new file name: ")
Filename = Console.ReadLine
Console.WriteLine()
FileOpen(1, Filename, OpenMode.Binary, OpenAccess.Write)
FilePut(1, CurrentGameData)
FileClose(1)
End Sub


Sub DisplayCavern(ByVal Cavern(,) As Char, ByVal MonsterAwake As Boolean)
Dim Count1 As Integer
Dim Count2 As Integer
For Count1 = 1 To NSDistance
Console.WriteLine(" ------------- ")
For Count2 = 1 To WEDistance
If Cavern(Count1, Count2) = " " Or Cavern(Count1, Count2) = "*" Or (Cavern(Count1, Count2) = "M" And MonsterAwake) Then
Console.Write("|" & Cavern(Count1, Count2))
Else
Console.Write("| ")
End If
Next
Console.WriteLine("|")
Next
Console.WriteLine(" ------------- ")
Console.WriteLine()
End Sub


Sub DisplayMoveOptions()
Console.WriteLine()
Console.WriteLine("Enter N to move NORTH")
Console.WriteLine("Enter E to move EAST")
Console.WriteLine("Enter S to move SOUTH")
Console.WriteLine("Enter W to move WEST")
Console.WriteLine("Enter M to return to the Main Menu")
Console.WriteLine()
End Sub


Function GetMove() As Char
Dim Move As Char
Move = Console.ReadLine
Console.WriteLine()
GetMove = Move
End Function


Sub MakeMove(ByRef Cavern(,) As Char, ByVal Direction As Char, ByRef PlayerPosition As CellReference)
Cavern(PlayerPosition.NoOfCellsSouth, PlayerPosition.NoOfCellsEast) = " "
Select Case Direction
Case "N"
PlayerPosition.NoOfCellsSouth = PlayerPosition.NoOfCellsSouth - 1
Case "S"
PlayerPosition.NoOfCellsSouth = PlayerPosition.NoOfCellsSouth + 1
Case "W"
PlayerPosition.NoOfCellsEast = PlayerPosition.NoOfCellsEast - 1
Case "E"
PlayerPosition.NoOfCellsEast = PlayerPosition.NoOfCellsEast + 1
End Select
Cavern(PlayerPosition.NoOfCellsSouth, PlayerPosition.NoOfCellsEast) = "*"
End Sub


Function CheckValidMove(ByVal PlayerPosition As CellReference, ByVal Direction As Char) As Boolean
Dim ValidMove As Boolean
ValidMove = True
If Not (Direction = "N" Or Direction = "S" Or Direction = "W" Or Direction = "E" Or Direction = "M") Then
ValidMove = False
End If
CheckValidMove = ValidMove
End Function


Function CheckIfSameCell(ByVal FirstCellPosition As CellReference, ByVal SecondCellPosition As CellReference) As Boolean
Dim InSameCell As Boolean
InSameCell = False
If FirstCellPosition.NoOfCellsSouth = SecondCellPosition.NoOfCellsSouth And FirstCellPosition.NoOfCellsEast = SecondCellPosition.NoOfCellsEast Then
InSameCell = True
End If
CheckIfSameCell = InSameCell
End Function


Sub DisplayWonGameMessage()
Console.WriteLine("Well done! You have found the flask containing the Styxian potion.")
Console.WriteLine("You have won the game of MONSTER!")
Console.WriteLine()
End Sub


Sub DisplayTrapMessage()
Console.WriteLine("Oh no! You have set off a trap. Watch out, the monster is now awake!")
Console.WriteLine()
End Sub


Sub MoveFlask(ByRef Cavern(,) As Char, ByVal NewCellForFlask As CellReference, ByRef FlaskPosition As CellReference)
Cavern(NewCellForFlask.NoOfCellsSouth, NewCellForFlask.NoOfCellsEast) = "F"
Cavern(FlaskPosition.NoOfCellsSouth, FlaskPosition.NoOfCellsEast) = " "
FlaskPosition = NewCellForFlask
End Sub


Sub MakeMonsterMove(ByRef Cavern(,) As Char, ByRef MonsterPosition As CellReference, ByRef FlaskPosition As CellReference, ByVal PlayerPosition As CellReference)
Dim OriginalMonsterPosition As CellReference
Dim MonsterMovedToSameCellAsFlask As Boolean
OriginalMonsterPosition = MonsterPosition
Cavern(MonsterPosition.NoOfCellsSouth, MonsterPosition.NoOfCellsEast) = " "
If MonsterPosition.NoOfCellsSouth < PlayerPosition.NoOfCellsSouth Then
MonsterPosition.NoOfCellsSouth = MonsterPosition.NoOfCellsSouth + 1
Else
If MonsterPosition.NoOfCellsSouth > PlayerPosition.NoOfCellsSouth Then
MonsterPosition.NoOfCellsSouth = MonsterPosition.NoOfCellsSouth - 1
Else
If MonsterPosition.NoOfCellsEast < PlayerPosition.NoOfCellsEast Then
MonsterPosition.NoOfCellsEast = MonsterPosition.NoOfCellsEast + 1
Else
MonsterPosition.NoOfCellsEast = MonsterPosition.NoOfCellsEast - 1
End If
End If
End If
MonsterMovedToSameCellAsFlask = CheckIfSameCell(MonsterPosition, FlaskPosition)
If MonsterMovedToSameCellAsFlask Then
MoveFlask(Cavern, OriginalMonsterPosition, FlaskPosition)
End If
Cavern(MonsterPosition.NoOfCellsSouth, MonsterPosition.NoOfCellsEast) = "M"
End Sub


Sub DisplayLostGameMessage()
Console.WriteLine("ARGHHHHHH! The monster has eaten you. GAME OVER.")
Console.WriteLine("Maybe you will have better luck next time you play MONSTER!")
Console.WriteLine()
End Sub


Sub PlayGame(ByRef Cavern(,) As Char, ByVal TrapPositions() As CellReference, _
ByRef MonsterPosition As CellReference, ByRef PlayerPosition As CellReference, ByRef FlaskPosition As CellReference, ByRef MonsterAwake As Boolean)
Dim Count As Integer
Dim Eaten As Boolean
Dim FlaskFound As Boolean
Dim MoveDirection As Char
Dim ValidMove As Boolean
Eaten = False
FlaskFound = False
DisplayCavern(Cavern, MonsterAwake)
Do
Do
DisplayMoveOptions()
MoveDirection = GetMove()
ValidMove = CheckValidMove(PlayerPosition, MoveDirection)
Loop Until ValidMove
If MoveDirection <> "M" Then
MakeMove(Cavern, MoveDirection, PlayerPosition)
DisplayCavern(Cavern, MonsterAwake)
FlaskFound = CheckIfSameCell(PlayerPosition, FlaskPosition)
If FlaskFound Then
DisplayWonGameMessage()
End If
Eaten = CheckIfSameCell(MonsterPosition, PlayerPosition)
If Not MonsterAwake And Not FlaskFound And Not Eaten Then
MonsterAwake = CheckIfSameCell(PlayerPosition, TrapPositions(1))
If Not MonsterAwake Then
MonsterAwake = CheckIfSameCell(PlayerPosition, TrapPositions(2))
End If
If MonsterAwake Then
DisplayTrapMessage()
DisplayCavern(Cavern, MonsterAwake)
End If
End If
If MonsterAwake And Not Eaten And Not FlaskFound Then
Count = 0
Do
MakeMonsterMove(Cavern, MonsterPosition, FlaskPosition, PlayerPosition)
Eaten = CheckIfSameCell(MonsterPosition, PlayerPosition)
Console.WriteLine()
Console.WriteLine("Press Enter key to continue")
Console.ReadLine()
DisplayCavern(Cavern, MonsterAwake)
Count = Count + 1
Loop Until Count = 2 Or Eaten
End If
If Eaten Then
DisplayLostGameMessage()
End If
End If
Loop Until Eaten Or FlaskFound Or MoveDirection = "M"
End Sub
End Module
(edited 12 years ago)
Reply 32
Has anyone found anymore problems/solutions for the problems?
Reply 34
What value should LoadedGameData be assigned?

ByRef LoadedGameData As....
Reply 35
Original post by 12345678910
THANKS :smile: You dont have the instructions and answer booklet that come with as well by any chance do you, it would be much appreciated

I've got the pre-release as a pdf only so I can't post it, I'll inbox it and no worries
Reply 36
Do any of you think that they will ask us to make it a 3d array and we will have to make rooms up a ladder for example or not?
Reply 37
Original post by Ali_1
I've got the pre-release as a pdf only so I can't post it, I'll inbox it and no worries


Can you send it to me as well, please? :smile:
Reply 38
Original post by ElMoro
Can you send it to me as well, please? :smile:


Student room doesn't let me lol sorry there's no button to attach files :s
Reply 39
Original post by Ali_1
Student room doesn't let me lol sorry there's no button to attach files :s


Use this. it's free :biggrin: Thanks :smile:

Quick Reply