repl.it
@Gentrix/

The Command Code - Function

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#Room Dictionary
rooms = {

    'T1':{
      'north' : 'FR',
      'south' : 'FR2',
      'east' : 'T2',
    },

    'FR':{
      'south':'T1',
    },

    'FR2':{
      'north':'T1',
    }, 
    
    'T2':{
      'east': 'T3',
      'object': 'drawers',
      'item':'key',
    }
}


currentroom = "T1"
inventory =[]

#asks first command
#Asks player for a command and then splits it into multiple items in array/list and makes it lowercase.



#If the command is a 'go' command do............
def command_game():
  command = input().lower()
  seperator = " "
  answer = command.split(seperator)
  global currentroom
  global inventory
    #If you want to move somewhere
  if "go" in answer:
    if "east" in answer and "east" in rooms[currentroom]:
      currentroom = rooms[currentroom]["east"]
      print (currentroom)
      answer = []
    if "west" in answer and "west" in rooms[currentroom]:
      currentroom = rooms[currentroom]["west"]
      print (currentroom)
      answer = []
    if "south" in answer and "south" in rooms[currentroom]:
      currentroom = rooms[currentroom]["south"]
      print (currentroom)
      answer = []
    if "north" in answer and "north" in rooms[currentroom]:
      currentroom = rooms[currentroom]["north"]
      print (currentroom)
      answer = []
  if "examine" in answer:
    #Objects in the room [T2]
    if "object" in rooms[currentroom]:
      if "drawers" in answer:
        print("You see a key in the drawers")
  if "get" in answer:
    #Items in the room [T2]
    if "item" in rooms[currentroom]:
      if "key" in answer:
        inventory.append("key")
#The code in the function above this comment has been added to the main game. Anything below must be added soon.\




command_game()
command_game()
command_game()
print (inventory)