- 0
how do i write this in pseudocode?
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Unified Copilot experience will land in Visual Studio 17.10, due in May
By zikalify,
- microsoft
- visual studio
- (and 9 more)
- 3 replies
- 4 views
-
Python Deep Learning - Third Edition ($39.99 Value) — Free, in exchange for your Email
By News Staff,
- ebook offer
- sponsored
- (and 2 more)
- 0 replies
- 1 view
-
Microsoft introduces TypeScript 5.4: Explore the latest features and enhancements
By zikalify,
- microsoft
- typescript
- (and 4 more)
- 11 replies
- 2 views
-
Python Real-World Projects ($36.99 Value) FREE eBook download offer ends Jan 2
By News Staff,
- ebook offer
- sponsored
- (and 2 more)
- 0 replies
- 3 views
-
Python for Security and Networking - Third Edition ($39.99 Value) FREE download
By News Staff,
- ebook offer
- sponsored
- (and 2 more)
- 0 replies
- 3 views
-
Question
jacobace
i understand this is not vb or c++ or anything, i used a program called python and its pretty simple to understand if someone could help me write it in pseudocode that would be awesome thankyou.
#version 0.0.5
class Game:
# Initialises variables
def __init__(self):
self._exit = False
# Array of known commands
self._commands = {
'go': self._go,
'quit': self._quit,
"look" : self._look}
# Array of go sub commands, used by _go
self._commands_go = {"north": self._go_north,
"south" : self._go_south,
"east" : self._go_east,
"west" : self._go_west,
"up" : self._go_up,
"down" : self._go_down}
# Method for parsing command, if it gets "comamnd" returns ("command",None)
@staticmethod
def parse_command(string):
index = string.find(' ')
if index < 0:
return (string, None)
return (string[:index], string[index+1:])
# This is main method; the only one which should be called from outside
# It will just read data from input in never ending loop and parse commands
def run(self):
while not self._exit:
src = input('> ')
(command,args) = Game.parse_command( src)
# Do we have this command, execute it
if command in self._commands:
self._commands[command](args)
else:
print("huh?")
#######################################################
############## All game commands go here ##############
#######################################################
def _quit(self,args):
self._exit = True
print("OK ... but a small part of you may never leave until you have personally saved Muirfieland from the clutches of evil .. Bwahahahahahah (sinister laugh)")
def _look(self,args):
print("You see nothing but endless void stretching off in all directions")
# movement handling, will get executed when user types 'go ...' and '...' will be in arg
def _go(self,args):
if args is None:
print("please tell me more",)
return False
# splits sub command and arguments
(command,args) = Game.parse_command(args)
if command not in self._commands_go:
print( "Sorry, I'm afraid I can't do that !")
return False
self._commands_go[command](args)
return True
# directions
def _go_north(self, args):
print("You wander of in the direction of north")
def _go_south(self, args):
print("You wander of in the direction of south")
def _go_east(self, args):
print("You wander of in the direction of east")
def _go_west(self, args):
print("You wander of in the direction of west")
def _go_up(self, args):
print("You wander of in the direction of up")
def _go_down(self, args):
print("You wander of in the direction of down")
#runs the game
game = Game()
game.run()
Link to comment
Share on other sites
15 answers to this question
Recommended Posts