Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector as mariadb
- import sys
- import wave
- import pygame
- import time
- import msvcrt as m
- import re
- #iskee pygamen tulille
- pygame.init()
- #karsii pois turhat sanat
- def imp(inps):
- if 'at' in inps:
- inps.remove('at')
- if "and" in inps:
- inps.remove('and')
- if 'or' in inps :
- inps.remove('or')
- if 'with' in inps :
- inps.remove('with')
- if 'to' in inps:
- inps.remove('to')
- if 'into' in inps :
- inps.remove('into')
- return inps
- #tulostaa tekstiä kirjain kerrallaan, ja odottaa painallusta
- def pri(str):
- string = (str)
- for char in string:
- sys.stdout.write(char)
- sys.stdout.flush()
- time.sleep(.02)
- m.getch()
- print("\n")
- #intro. lataa taustapopin
- def intro():
- music = "BGM"
- load_music(music)
- pri("You are 54 years old whitecollar worker Living in a highrise apartment located at Manhattan.")
- pri("Your career long ambition has been to become the Boss in place of the current Boss. And finally it's happening!")
- pri("The CEO announced his retirement and having brown nosed him for countless years, the job practically yours!")
- pri("You naturally spend your last sunday as a peon partying like it's 1984. In hindsight that might have been a mistake. As they say, don't count your snakes before they hatch.")
- pri("Can you make it without tanking your dreams? let's find out!")
- sound = "ALARM"
- pri("You are woken up by the incessent beeping of your alarm clock. Your head feels like it's being raided by army of tax collectors and there is a faint taste of ass in your mouth.")
- pri("You also appear to have slept in your suit, which is badly rumbled and smells quite ripe.")
- #......
- def com_eat(target):
- cur = db.cursor(target)
- # esitellaan suoritettava sql-lause
- sql = "SELECT name , look FROM objects WHERE name='"+target+"'";
- # suoritetaan sql-lause
- cur.execute(sql)
- # jos saatiin dataa / file, niin ajetaan se
- if cur.rowcount >= 1 :
- for look in cur :
- cur = db.cursor(look)
- sql = "SELECT description FROM results WHERE resultid='"+look+"'";
- cur.execute(sql)
- for description in cur :
- pri(descruption)
- #asettaa asian laukkuun
- def com_take(target):
- cur = db.cursor(target)
- # esitellaan suoritettava sql-lause
- sql = "SELECT name , look FROM objects WHERE name='"+target+"'";
- # suoritetaan sql-lause
- cur.execute(sql)
- #duns no.
- def com_time():
- print("no")
- #bob me olemme ongelma.
- def com_comb(target1, target2):
- cur1 = db.cursor(target1)
- # esitellaan suoritettava sql-lause
- sql = "SELECT name FROM objects WHERE name='"+target1+"'";
- cur1.execute(sql)
- cur2 = db.cursor(target2)
- sql = "SELECT name , look FROM rooms WHERE name='"+target+"'";
- cur2.execute(sql)
- # jos saatiin dataa / file, niin ajetaan se
- if cur1.rowcount >= 1 :
- print("no")
- if cur2.rowcount >= 1 :
- print("no")
- #go lauseke. ei käytössä
- def com_go(target):
- cur = db.cursor(target)
- sql = "SELECT name , FROM rooms WHERE name='"+target+"'";
- cur.execute(sql)
- # jos saatiin dataa / file, niin ajetaan se
- if cur.rowcount >= 1 :
- print("no")
- #... vaiheessa
- def com_wear(target):
- cur = db.cursor(target)
- # esitellaan suoritettava sql-lause
- sql = "SELECT name , look FROM objects WHERE name='"+target+"'";
- # suoritetaan sql-lause
- cur.execute(sql)
- # jos saatiin dataa / file, niin ajetaan se
- if cur.rowcount >= 1 :
- print("no")
- #hakee tietokannasta esineen, joka katsonnan kohteena. sitten hakee asiaan kuuluvan replyn tietokannasta ja tulostaa sen.
- def com_look(target):
- cur = db.cursor()
- cur.execute("SELECT name , look FROM objects WHERE name='"+target+"'")
- for look in cur:
- cur.execute("SELECT description FROM results WHERE resultid='"+str(look[1])+"'")
- for col in cur.fetchall():
- pri(col[0])
- #käyttölause... vaiheessa
- def com_use(obj):
- cur = db.cursor()
- cur.execute("SELECT state , use FROM objects WHERE name='"+obj+"'")
- # jos saatiin dataa / file, niin ajetaan se
- if cur.rowcount >= 1 :
- for col in cur :
- if col[2] == 1 :
- cur = db.cursor()
- sql = "UPDATE state FROM objects WHERE name='"+obj+"'";
- cur.execute(sql)
- if col[2] == 2:
- cur = db.cursor()
- sql = "UPDATE state FROM objects WHERE name='"+obj+"'";
- cur.execute(sql)
- if col[2] == 3:
- pri("can't do that anymore")
- break
- repl = col[3]
- cur = db.cursor()
- sql = "SELECT description FROM results WHERE resultid='"+repl+"'";
- cur.execute(sql)
- for col in cur:
- pri(col[0])
- return
- #hakee huoneen nimen ja sen sisältämät esineet ja tulostaa ne
- def load_room(loc):
- cur = db.cursor()
- cur.execute("SELECT name , ID , objects FROM rooms WHERE name='"+loc+"'")
- if cur.rowcount == 1 :
- for col in cur:
- pri("you are in " + col[0] + ".")
- cur.execute("SELECT name FROM objects WHERE location='"+col[1]+"'")
- for kek in cur.fetchall():
- temp.append(kek[0])
- pri("you see " + ' , '.join(temp) + " in the room.")
- else :
- print("DeprecationWarning")
- return
- #hakee halutun esineen ja palauttaa sen nimen, statuksen
- def load_obj(target):
- cur = db.cursor()
- cur.execute("SELECT name , state FROM objects WHERE name='"+target+"'")
- if cur.rowcount >= 1 :
- for col in cur:
- obj = col[0]
- state = col[1]
- return obj , state
- #hakee halutun komennon tietokannasta ja palauttaa sen
- def load_command(action):
- cur = db.cursor()
- cur.execute("SELECT id FROM commands WHERE name='"+action+"'")
- if cur.rowcount == 1 :
- for col in cur.fetchall() :
- command = col[0]
- return command
- else:
- print ("invalid command");
- return
- #lataa aanen ja alkaa soittamaan
- def load_sound(sound):
- cur = db.cursor()
- cur.execute("SELECT ID , path , rep FROM sound WHERE sound='"+sound+"'")
- if cur.rowcount >= 1 :
- for col in cur :
- pygame.mixer.sound.load(col[1])
- pygame.mixer.sound.play(col[2])
- #lopettaa soittamisen
- def unload_sound(sound):
- cur = db.cursor()
- cur.execute("SELECT ID , path , rep FROM sound WHERE sound='"+sound+"'")
- if cur.rowcount >= 1 :
- for col in cur :
- pygame.mixer.Sound.fadeout(col[2])
- #lataa äänen ja alkaa soittamaan
- def load_music(music):
- cur = db.cursor()
- cur.execute("SELECT ID , file , rep FROM sound WHERE id='"+music+"'")
- # jos saatiin dataa / file, niin ajetaan se
- if cur.rowcount >= 1 :
- for col in cur :
- pygame.mixer.music.load(col[1])
- pygame.mixer.music.play(col[2])
- db = mariadb.connect(user='root', password='password', database='mrss', buffered=True)
- # Initialize gameplay
- temp = []
- action = ""
- row = ""
- obj = ""
- loc = "bedroom"
- command = ""
- inps = ""
- target1 = ""
- target2 = ""
- status = ""
- state = ""
- # Clear console
- print("\n"*100)
- #lauch intro n room
- #~intro()
- load_room(loc)
- #mainloop
- while action!="quit" and loc != "out":
- #pyytää komennon ja shaissea
- inps=input("wat you want to do? \n:").split()
- imp(inps)
- #erittelee parserista komennon ja kohteen
- if len(inps)>=1:
- action = inps[0].lower()
- if action == "quit":
- pri("quitter, boo")
- break
- if len(inps)>=2:
- target = inps[1].lower()
- target1 = target
- print(target1)
- if len(inps)==3:
- target = inps[2].lower()
- target2 = target
- print(target2)
- command = load_command(action)
- #LOOK row 8
- if command == "LOOK":
- if len(inps) == 1:
- pri("you look around")
- load_room(loc)
- if len(inps) ==2:
- com_look(target)
- print("shit2")
- if len(inps) ==3:
- pri("you don't see shit")
- #use row 12
- if command == "USE" :
- if len(inps) == 1:
- target = input("what would you like to use? \n:")
- load_obj(target)
- com_use(obj)
- if len(inps) == 2:
- load_obj(target)
- com_use(obj)
- if len(inps) >= 3:
- pri("can't do that")
- #wear row13
- if command == "WEAR" :
- if len(inps) == 1:
- target = input("what would you like to wear? \n:")
- load_obj(target)
- com_wear(obj)
- if len(inps) == 2:
- load_obj(target)
- com_wear(obj)
- #goto row 7
- if command == "GO" :
- if len(inps) == 1:
- loc = input("where would you like to go? \n:")
- load_room(loc)
- if len(inps) >=2:
- loc = target
- load_room(loc)
- #time
- if command == "TIME" :
- com_time()
- #Put/add/insert/combine row 9
- if command == "PUT" :
- if len(inps) == 1:
- inps=input("what would you like to combine? \n:").split()
- imp(inps)
- if len(input) ==1:
- target1 = input
- input("what would you like to combine " + target1 + " with? \n:").split()
- if len(input) ==1:
- target2 = input
- if len(input) > 1 :
- pri("can't do that")
- if len(input) ==2:
- target1 = input[1].lower()
- target2 = input[2].lower()
- pri("you attempt to combine " +target1 + target2 + ".")
- com_comb(target1 , target2)
- if len(inps) == 2:
- target1 = inps[1].lower()
- target2 = input(pri("what would you like to combine " + target1 + "with? \n:"))
- pri("you attempt to combine " + target1 + "and" + target2 + ".")
- com_comb(target1 , target2)
- if len(inps) ==3 :
- target1 = input[1].lower()
- target2 = input[2].lower()
- pri("you attempt to combine " + target1 + "and" + target2 + ".")
- com_comb(target1 , target2)
- #help
- if command == "HELP" :
- pri("available commands are:")
- pri("help - prints command list")
- pri("look - look at stuff")
- pri("use - use or open stuff")
- pri("eat - eat stuff")
- pri("take - stuff into inv")
- pri("wear - equip stuff")
- #take row 10
- if command == "TAKE" :
- if len(inps) == 1:
- target = input("what would you like to take \n:")
- load_obj(target)
- com_take(obj)
- if len(inps) == 2:
- load_obj(target)
- com_take(obj)
- if len(inps) >= 3:
- pri("can't do that")
- #consume row 6
- if command =="CONSUME" :
- if len(inps) == 1:
- target = input("what would you like to eat? \n:")
- load_obj(target)
- com_eat(obj)
- if len(inps) == 2:
- load_obj(target)
- com_eat(obj)
- if len(inps) >= 3:
- pri("can't do that")
- else:
- print("")
- db.rollback()
- # status row5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement