Pseudo-code for Virtual Robot Treasure Hunt: Part 2



Pseudo-code for Virtual Robot Treasure Hunt: Part 2Import modules GET Tkinter ModuleGET ttk ModuleGET random ModuleGET time ModuleSet CanvasINITILISE windowCREATE canvas with resolution 854x480 and white backgroundDISPLAY "Sloths - Virtual Robot Treasure Hunt: Part 2" as window nameCREATE window with resolution 874x670SET window as not resizableSET window in centreCreate GUICREATE Start ButtonCREATE 1, 2, 3, 4, 5, 6 ButtonsPLACE Start Button in correct placePLACE 1, 2, 3, 4, 5, 6 Buttons in correct placeCREATE Robot Info LabelsCREATE Wish List LabelCREATE Treasure Selection LabelCREATE Countdown LabelCREATE Treasure imagesPLACE Robot Info Labels in correct placePLACE Countdown Label in correct placePLACE Wish List Label in correct placePLACE Treasure Selection Label in correct placeDISPLAY Robot LogoDISPLAY Treasure images in Selected TreasureDRAW Traffic light objectsDeclare Robot Class VariablesRobot = Robot Robot X Velocity = Robot X Velocity Robot Y Velocity = Robot Y Velocity Robot X Position = Robot X Position Robot Y Position = Robot Y Position Robot Status = Robot Status Robot Track ID = Robot Track ID Visited Landmarks = Visited Landmarks Robot Score = Robot Score Robot Spawn FunctionIF button 1 pressedSET ‘X Position’ SET ‘Y Position’ DISPLAY ‘Robot’ image with the parameters ‘Robot X Position’ and ‘Robot Y Position’ ELSE IF button 2 pressedSET ‘X Position’ SET ‘Y Position’ DISPLAY ‘Robot’ image with the parameters ‘Robot X Position’ and ‘Robot Y Position’ ELSE IF button 3 pressedSET ‘X Position’ SET ‘Y Position’ DISPLAY ‘Robot’ image with the parameters ‘Robot X Position’ and ‘Robot Y Position’ ELSE IF button 4 pressedSET ‘X Position’ SET ‘Y Position’ DISPLAY ‘Robot’ image with the parameters ‘Robot X Position’ and ‘Robot Y Position’ ELSE IF button 5 pressedSET ‘X Position’ SET ‘Y Position’ DISPLAY ‘Robot’ image with the parameters ‘Robot X Position’ and ‘Robot Y Position’ ELSE button 6 pressedSET ‘X Position’ SET ‘Y Position’ DISPLAY ‘Robot’ image with the parameters ‘Robot X Position’ and ‘Robot Y Position’ END IFRobot Movement FunctionIF ‘Treasure X Position’ is greater than ‘Robot X Position’ SET ‘Robot X Velocity’ to 10.0 ELSESET ‘Robot X Velocity’ to -10.0END IFIF ‘Treasure Y Position’ is greater than ‘Robot Y Position’SET ‘Robot Y Velocity’ to 5.0 ELSESET ‘Robot Y Velocity’ to -5.0END IFIF ‘Robot’ is in ‘Red Traffic Light Zone’SET ‘Robot X Velocity’ and ‘Robot Y Velocity’ to 0.0END IFIF ‘Robot’ is in ‘Amber Traffic Light Zone’SET ‘Robot X Velocity’ to 5.0SET ‘Robot Y Velocity’ to 2.5END IFRobot Detection of Treasure FunctionIF ‘Robot X Position’ and ‘Robot Y Position’ are in range of ‘Treasure Position’RUN ‘Clear Treasure’ FunctionADD treasure point value to ‘Robot Score’ADD treasure to Collected TreasureDISPLAY happy pirate thoughtEND IFRobot Detection of Trap FunctionIF ‘Robot X Position’ and ‘Robot Y Position’ are in range of ‘Trap Position’DECREASE ‘Robot Score’ by the last collected treasure’s point valueREMOVE last added treasure from the collected listDISPLAY sad pirate thoughtEND IFRobot Collected Treasure Bubble SortIF countdown is zeroREPEAT until the list is sortedPUT 1 into iREPEAT WHILE I < NIF A[i] > A[i+1]SWAP A[i], A[i+1]END IFADD 1 to iEND WHILEEND REPEATLandmark Class Being DeclaredLandmark Object = Landmark ObjectLandmark Size = Landmark SizeLandmark ID = Landmark IDLandmark Colour = Landmark ColourLandmark Treasure = Landmark TreasureLandmark Position = Landmark PositionLandmark Check = Landmark CheckDraw Landmark FunctionIF button 1-6 pressed DRAW ‘Landmark Object’ with coordinates that have been pre-given END IFCountdown: Start Button SET countdownIF start button is pressed REPEAT countdown - 1 and PRINT countdown - 1UNTIL robot has found all treasuresELSEPRINT countdown valueEND IFCountdown: Red Traffic LightIF start button is pressedREPEAT change random block colour to red every 5 secondsUNTIL robot has found all treasuresEND IFCountdown: Amber Traffic LightIF start button is pressedREPEAT change random block colour to amber every 5 secondsUNTIL robot has found all treasuresEND IFCountdown: Green Traffic LightIF start button is pressedREPEAT change random block colour to green every 5 secondsUNTIL robot has found all treasuresEND IFTraffic LightsChange LightsWHILE running = trueIF countdown % 5 equals 0CREATE random number between 1 and 3IF random number equals 1CHANGE light to redSET status = redELSE IF random number equals 2CHANGE light to amberSET status = amberELSE IF random number equals 3CHANGE light to greenSET status = greenEND IFEND IFEND WHILEStartCHANGE light to greenSET status = greenSET running = trueCreate LightsCHECK for other traffic lightsIF no other traffic lightsCREATE light zone far leftSET size as quarter of canvas sizeELSE IF 1 other traffic lightCREATE light zone 2nd leftSET size as quarter of canvas sizeELSE IF 2 other traffic lightCREATE light zone 2nd rightSET size as quarter of canvas sizeELSE IF 3 other traffic lightCREATE light zone far rightSET size as quarter of canvas sizeEND IFDeclare Treasure Class Variable Treasure1 = Treasure 1Treasure2 = Treasure 2Treasure3 = Treasure 3Treasure4 = Treasure 4Treasure1.Size = 0Treasure2.Size = 0Treasure3.Size = 0Treasure4.Size = 0Treasure1.ID = 1Treasure2.ID = 2Treasure3.ID = 3Treasure4.ID = 4Selection of TreasureIF treasure selectedDISPLAY treasure in Wish ListSET the selected treasure image to turn grey in the Treasure Selection boxELSEDISPLAY treasure in the Treasure Selection boxEND IFDrag and Drop TreasureSET ‘Treasure1’ Position by drag and dropCHECK no other Treasure is present; Treasure 2, Treasure 3, Treasure 4SET ‘Treasure2’ Position by drag and dropCHECK no other Treasure is present; Treasure 1, Treasure 3, Treasure 4SET ‘Treasure3’ Position by drag and dropCHECK no other Treasure is present; Treasure 1, Treasure 2, Treasure 4SET ‘Treasure4’ Position by drag and dropCHECK no other Treasure is present; Treasure 1, Treasure 2, Treasure 3DISPLAY Treasure1,’Treasure1.ID’,Treasure ImageDISPLAY Treasure2,’Treasure2.ID’, Treasure ImageDISPLAY Treasure3,’Treasure3.ID’, Treasure ImageDISPLAY Treasure4,’Treasure4.ID’, Treasure ImageDeletion of Treasure once Collected by RobotIF Treasure1 position within range of Robot PositionDELETE Treasure 1 ELSE DO nothingEND IFIF Treasure 2 position within range of Robot PositionDELETE Treasure 2 ELSE DO nothingEND IFIF Treasure3 position within range of Robot PositionDELETE Treasure 3 ELSE DO nothingEND IFIF Treasure4 position within range of Robot PositionDELETE Treasure 4 ELSE DO nothingEND IFDeclare Trap Class Variable Trap1 = Trap 1Trap2 = Trap 2Trap3 = Trap 3Trap4 = Trap 4Trap1.Size = 0Trap2.Size = 0Trap3.Size = 0Trap4.Size = 0Trap1.ID = 1Trap2.ID = 2Trap3.ID = 3Trap4.ID = 4Spawn Trap FunctionSET ‘Trap1 Position’ to randomly choose a space not within a landmark by its coordinatesCHECK no other Trap is present; Trap 2, Trap 3, Trap 4SET ‘Trap2 Position’ to randomly choose a space not within a landmark by its coordinates CHECK no other Trap is present; Trap 1, Trap 3, Trap 4SET ‘Trap3 Position’ to randomly choose a space not within a landmark by its coordinates CHECK no other Trap is present; Trap 1, Trap 2, Trap 4SET ‘Trap4 Position’ to randomly choose a space not within a landmark by its coordinates CHECK no other Trap is present; Trap 1, Trap 2, Trap 3DISPLAY Trap1,’Treasure1.ID’, Trap ImageDISPLAY Trap2,’Treasure2.ID’, Trap ImageDISPLAY Trap3,’Treasure3.ID’, Trap ImageDISPLAY Trap4,’Treasure4.ID’, Trap ImageDeletion of Treasure once Encountered by RobotIF Trap1 position within range of Robot 1 PositionDELETE Trap 1SET the screen to turn red for 2 secondsELSE DO nothingEND IFIF Trap2 position within range of Robot 1 PositionDELETE Trap 2 SET the screen to turn red for 2 secondsELSE DO nothingEND IFIF Trap3 position within range of Robot 1 PositionDELETE Trap 3 SET the screen to turn red for 2 secondsELSE DO nothingEND IFIF Trap4 position within range of Robot 1 PositionDELETE Trap 4 SET the screen to turn red for 2 secondsELSE DO nothingEND IF ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download