Computing pre-release material AQA A
Computer Science and ICT discussion, revision, exam and homework help.
-
Re: Computing pre-release material AQA A
Potential Changes to Code:
-Update the code to accept upper and lower case direction inputs
-Stop player moving off edge of map, catch the error
-Collect menu choices as char rather than integer so that they can be validated and letter entry doesn't crash the program
-Make it so an innapropriate menu entry brings up an error message
-When saving in the main menu give the option to resume the game
-Allow the player to move diagonally
-Count the number of moves taken before the player is eaten or finds the lamp and display this
-During a game press "T" to teleport, this can only be used once
-"display story" menu item
-Add an option to the menu that resumes a game if they are in save mode
-Change the size of the map
-Make it so selecting to load a non-existent file doesn't crash the program -
Re: Computing pre-release material AQA A
This is the pre-release material as a pdf:
http://www.2shared.com/document/L2zs...2012__1_.html? -
Re: Computing pre-release material AQA AThank you very much!(Original post by Ali_1)
This is the pre-release material as a pdf:
http://www.2shared.com/document/L2zs...2012__1_.html?
-
Re: Computing pre-release material AQA AThis is all from wikibooks, where there are now a few solutions as well that you can test yourself with.(Original post by Topgeeza)
Potential Changes to Code:
-Update the code to accept upper and lower case direction inputs
-Stop player moving off edge of map, catch the error
-Collect menu choices as char rather than integer so that they can be validated and letter entry doesn't crash the program
-Make it so an innapropriate menu entry brings up an error message
-When saving in the main menu give the option to resume the game
-Allow the player to move diagonally
-Count the number of moves taken before the player is eaten or finds the lamp and display this
-During a game press "T" to teleport, this can only be used once
-"display story" menu item
-Add an option to the menu that resumes a game if they are in save mode
-Change the size of the map
-Make it so selecting to load a non-existent file doesn't crash the program -
Re: Computing pre-release material AQA A
To anyone doing python:
Line 58:
I dont understand the purpose of 'eval' here. On the main menu if you type in textPHP Code:def GetMainMenuChoice():
Choice = eval(input())
print('')
return Choice
instead of a number the program crashes.
However if you type in one of the fixed variables exactly, for example "NO_OF_TRAPS = 2". The program then goes on to lead menu option 2, which is load a file. This happens as the variable is set to 2.
Why have they coded the "eval" line to produce that result, must be to do with something they want us to do. -
Re: Computing pre-release material AQA Aeval is an alternative to int(). if you use eval on a string, it returns a numeric evaluation. so you could say:(Original post by 101101)
To anyone doing python:
Line 58:
I dont understand the purpose of 'eval' here. On the main menu if you type in textPHP Code:def GetMainMenuChoice():
Choice = eval(input())
print('')
return Choice
instead of a number the program crashes.
However if you type in one of the fixed variables exactly, for example "NO_OF_TRAPS = 2". The program then goes on to lead menu option 2, which is load a file. This happens as the variable is set to 2.
Why have they coded the "eval" line to produce that result, must be to do with something they want us to do.
a = "1+1"
b = eval(a)
b will now equal 2. you can test this, on the menu, instead of entering 4, enter "2+2" and you'll get option 4.
i rather suspect that the python code wasn't written by a native python programmer, rather translated from a different language hence the use of eval() rather than int() and the Logical() class for Monster.Is which seems totally unnecessary to me, lastly using pickle instead of writing a CSV text file which would be more in keeping with the spec " Read/write from/to a text file (including csv file)"
i digress (rant over)
to summarise, i don't think it's going to be significant that they used eval rather than int. they both crash for the same reason and since the menu choices aren't treated numerically, it's totally pointless to convert them to integers. They could have just had the menu saying if Choice == "1". If I was writing the exam, I'd ask about this. -
Re: Computing pre-release material AQA Asuch a great idea. Youre my hero.:d(Original post by aidenbains)
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. -
Re: Computing pre-release material AQA AThanks for the help, I was getting quite confused as to why that was done, but you make a good point.(Original post by mister c)
eval is an alternative to int(). if you use eval on a string, it returns a numeric evaluation. so you could say:
a = "1+1"
b = eval(a)
b will now equal 2. you can test this, on the menu, instead of entering 4, enter "2+2" and you'll get option 4.
i rather suspect that the python code wasn't written by a native python programmer, rather translated from a different language hence the use of eval() rather than int() and the Logical() class for Monster.Is which seems totally unnecessary to me, lastly using pickle instead of writing a CSV text file which would be more in keeping with the spec " Read/write from/to a text file (including csv file)"
i digress (rant over)
to summarise, i don't think it's going to be significant that they used eval rather than int. they both crash for the same reason and since the menu choices aren't treated numerically, it's totally pointless to convert them to integers. They could have just had the menu saying if Choice == "1". If I was writing the exam, I'd ask about this. -
Re: Computing pre-release material AQA A
I'm doing this exam using Java. One of the classes used is Logical.is as a boolean for checking if the monster is awake. My teacher rewrote the code to see if you can just use a normal boolean variable rather than a class. It worked fine. Does anyone have any idea why they would use a class rather than just a boolean variable?
-
Re: Computing pre-release material AQA Awe fixed this today by not using eval at all. there is no need to have the menu input converted to an integer, leave it as a string then look at the last part of the code where the menu choice is implemented and change(Original post by sean_bulley)
I noticed that if you don't use a valid letter in the menu it will break the code and the game will stop functioning.
Perhaps they will ask that we ad an error check to make sure the menu choice is part of the options.
(Python)
if Choice == 1
to
if Choice == "1"
and everything works fine again (if you apply that method to all the IF statements). Oh yeah, you have to change the while loop as well to while Choice != "9" -
Re: Computing pre-release material AQA A
Right. Here's a high probability question for you all. The function/procedure CheckValidMove seems to take two arguments - PlayerPosition and Direction. It returns a boolean but currently it does so only by checking that Direction is N, S, E or W.
This is clearly going to be asked about, they've done this in the past with a validation question where a function took two arguments but didn't use one of them.
You're going to have to add validation that checks where the player is and returns False if the direction given means that they walk off the edge of the map.
Make sure that you do this using the global variables for N_S_DISTANCE and W_E_DISTANCE so you're not hard coding the current size of the game only.
If this doesn't come up in the exam, I'll eat a raspberry pi -
Re: Computing pre-release material AQA Anot sure that's right. this is from the python version. function SetPositionOfItem(Original post by D-Box)
When the traps are generated, there's a possibility that it will generate more than one in the same spot (might be useful if you have to add more traps).
while Cavern[Position.NoOfCellsSouth][Position.NoOfCellsEast] != ' ':
Position = GetNewRandomPosition()
this loops until the random position is empty. try reducing the map size to 3x2, you always get two traps.
also, if you want to see where everything is, look at the function DisplayCavern. there will be a line in there somewhere to match this python line:
if Cavern[Count1][Count2] in [' ','*'] or ((Cavern[Count1][Count2] == 'M') and MonsterAwake.Is):
so basically, if the Cavern item is a space or an * or if the monster is awake and the item is an M, it gets printed. Just update this line so that it includes all the other items. in python, that means the line starts like this:
if Cavern[Count1][Count2] in [' ','*','M','T','F']
alternatively just add another OR statement that says or True at the end or comment out that IF statement altogether. some of these methods will be easier than others depending on the language you're using.Last edited by mister c; 09-03-2012 at 22:49. -
Re: Computing pre-release material AQA AI've been using the vb.NET code, and it's something I came across earlier today. I edited the amount of traps to something in double figures to test it, then looked at the stored positions and some overlapped.(Original post by mister c)
not sure that's right. this is from the python version....
It might be a mistake I've made though, so I'll check again tomorrow.
EDIT: Yeah, I was wrong. Thanks for explaining the code!Last edited by D-Box; 15-03-2012 at 20:58. -
Re: Computing pre-release material AQA A
Sub LoadGame(ByRef TrapPositions() As CellReference, ByRef MonsterPosition As CellReference, ByRef PlayerPosition As CellReference, _
ByRef FlaskPosition As CellReference, ByRef MonsterAwake As Boolean) ' If the user selects LoadGame then this subroutine will load a game from the users local area
Dim Filename As String
Dim LoadedGameData As GameData
Dim Valid As Boolean
Do
Console.Write("Enter the name of the file to load: ")
Try
Filename = Console.ReadLine
Console.WriteLine()
FileOpen(1, Filename, OpenMode.Binary, OpenAccess.Read)
FileGet(1, LoadedGameData)
FileClose(1)
Valid = True ' This section attempts to read the proposed file name
Catch
Console.WriteLine("Invalid file name") ' If it is an invalid file name it will loop
Valid = False
End Try
Loop Until Valid = True
TrapPositions = LoadedGameData.TrapPositions
MonsterPosition = LoadedGameData.MonsterPosition
PlayerPosition = LoadedGameData.PlayerPosition
FlaskPosition = LoadedGameData.FlaskPosition
MonsterAwake = LoadedGameData.MonsterAwake ' The parameters from the file will then be implemented into a new game
End Sub