- 0
how do i write this in pseudocode?
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Offensive Security Using Python eBook (worth $39.99) free download ends today
By News Staff,
- ebook offer
- sponsored
- (and 4 more)
- 0 replies
- 0 views
-
Offensive Security Using Python eBook (worth $39.99) is still free to download
By Steven P.,
- ebook offer
- sponsored
- (and 2 more)
- 0 replies
- 0 views
-
Download Offensive Security Using Python: A hands-on guide ($39.99 Value, now FREE)
By News Staff,
- ebook offer
- sponsored
- (and 2 more)
- 0 replies
- 0 views
-
JetBrains releases IntelliJ IDEA 2025.1.1, bringing multiple bug fixes and improvements
By David Uzondu,
- jetbrains
- intellij idea
- (and 6 more)
- 0 replies
- 0 views
-
Save 96% off this All-In-One 2021 Super-Sized Ethical Hacking Bundle
By News Staff,
- neowin deals
- online courses
- (and 2 more)
- 0 replies
- 0 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
https://www.neowin.net/forum/topic/1149082-how-do-i-write-this-in-pseudocode/Share on other sites
15 answers to this question
Recommended Posts