Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- players={}
- myName=""
- function wrapP(peripheralName)
- if os.version()~="CraftOS 1.5" then
- if peripheralName==nil then
- print("Fehler")
- end
- local peripherals = peripheral.getNames()
- local i = 1
- while i < #peripherals and peripheral.getType(peripherals[i])~=peripheralName do
- i=i+1
- end
- if peripheral.getType(peripherals[i])==peripheralName then
- return peripheral.wrap(peripherals[i]),peripherals[i]
- else
- return nil
- end
- else
- local sides={"top","bottom","left","right","front","back"}
- for i=1,#sides do
- if peripheral.getType(sides[i])==peripheralName then
- return peripheral.wrap(sides[i]),sides[i]
- end
- end
- end
- end
- function delStringFromTable(tab1)
- it=1
- while tab1[i]~=str do
- it=it+1
- end
- for it2=it,#tab1-1 do
- tab1[it2]=tab1[it2+1]
- end
- tab1[#tab1]=nil
- end
- function delElementFromTable(tab1,num)
- for it2=num,#tab1-1 do
- tab1[it2]=tab1[it2+1]
- end
- tab1[#tab1]=nil
- end
- tb=wrapP("openperipheral_bridge")
- function addPlayer(name)
- player={}
- player.name=name
- player.money=30000
- player.streets={}
- player.stations={}
- player.position=1
- player.jail=0
- player.joker=0
- players[#players+1]=player
- end
- function addStreet(name, propertyCost, houseCost0, houseCost1, houseCost2, houseCost3, houseCost4, houseCost5, addHouseCost, member1, member2,color)
- street={}
- street.type="street"
- street.name=name
- street.owner="none"
- street.propertyCost=propertyCost
- street.credit=propertyCost/2
- street.addHouseCost=addHouseCost
- street.houseCost0=houseCost0
- street.houseCost1=houseCost1
- street.houseCost2=houseCost2
- street.houseCost3=houseCost3
- street.houseCost4=houseCost4
- street.houseCost5=houseCost5
- street.houses=0
- street.members={member1,member2}
- street.color=color
- board[#board+1]=street
- end
- function addStart()
- field={}
- field.type="start"
- board[#board+1]=field
- end
- function addField(name, type) --event, community, jail, freeparking, goToJail
- field={}
- field.name=name
- field.type=type
- board[#board+1]=field
- end
- function addStation(name,propertyCost, cost)
- field={}
- field.name=name
- field.type="station"
- field.owner="none"
- field.propertyCost=propertyCost
- field.cost=cost
- field.color=0x000000
- board[#board+1]=field
- end
- function addTax(name,cost)
- field={}
- field.name=name
- field.type="tax"
- field.cost=cost
- board[#board+1]=field
- end
- function generateBoard()
- board={}
- addField("Los","start")
- addStreet("Badstrasse", 1200, 40, 200, 600, 1800, 3200, 5000, 1000, "Turmstrasse",0x775745)
- addField("Gemeinschaftsfeld","community")
- addStreet("Turmstrasse", 1200, 80, 400, 1200, 3600, 6400, 9000, 1000, "Badstrasse",0x775745)
- addTax("Einkommensteuer",4000)
- addStation("Suedbahnhof",4000,500)
- addStreet("Chauseestrasse", 2000, 120, 600, 1800, 5400, 8000, 11000, 1000, "Elisenstrasse", "Poststrasse",0x41e8f4)
- addField("Ereignis Feld","event")
- addStreet("Elisenstrasse", 2000, 120, 600, 1800, 5400, 8000, 11000, 1000, "Chauseestrasse", "Poststrasse",0x41e8f4)
- addStreet("Poststrasse", 2400, 160, 800, 2000, 6000, 9000, 12000, 1000, "Chauseestrasse", "Elisenstrasse",0x41e8f4)
- addField("Im Gefaengnis zu Besuch", "jail")
- addStreet("Seestrasse", 2800, 200, 1000, 3000, 9000, 12500, 15000, 2000, "Hafenstrasse", "Neuestrasse",0x8942f4)
- addField("Gemeinschaftsfeld","community")
- addStreet("Hafenstrasse", 2800, 200, 1000, 3000, 9000, 12500, 15000, 2000, "Seestrasse", "Neuestrasse",0x8942f4)
- addStreet("Neuestrasse", 3200, 240, 1200, 3600, 10000, 14000, 18000, 2000, "Seestrasse", "Hafenstrasse",0x8942f4)
- addStation("Westbahnhof",4000,500)
- addStreet("Muenchnerstrasse", 3600, 280, 1400, 4000, 11000, 15000, 19000, 2000, "Wienerstrasse", "Berlinerstrasse",0xff813a)
- addField("Gemeinschaftsfeld Feld","community")
- addStreet("Wienerstrasse", 3600, 280, 1400, 4000, 11000, 15000, 19000, 2000, "Muenchnerstrasse", "Berlinerstrasse",0xff813a)
- addStreet("Berlinerstrasse", 3600, 320, 1600, 4400, 12000, 16000, 20000, 2000, "Muenchnerstrasse", "Wienerstrasse",0xff813a)
- addField("Frei Parken","freeparking")
- addStreet("Theaterstrasse", 4400, 360, 1800, 5000, 14000, 17500, 21000, 3000, "Museumstrasse", "Opernplatz",0xff0000)
- addStreet("Museumstrasse", 4400, 360, 1800, 5000, 14000, 17500, 21000, 3000, "Opernplatz", "Theaterstrasse",0xff0000)
- addField("Ereignis Feld","event")
- addStreet("Opernplatz", 4800, 400, 2000, 6000, 15000, 18500, 22000, 3000, "Museumstrasse", "Theaterstrasse",0xff0000)
- addStation("Nordbahnhof",4000,500)
- addStreet("Lessingstrasse", 5200, 480, 2200, 6600, 16000, 19500, 23000, 3000, "Schillerstrasse", "Goetestrasse",0xffff00)
- addStreet("Schillerstrasse", 5200, 480, 2200, 6600, 16000, 19500, 23000, 3000, "Lessingstrasse", "Goetestrasse",0xffff00)
- addField("Gemeinschaftsfeld","community")
- addStreet("Goetestrasse", 5200, 480, 2200, 6600, 16000, 19500, 23000, 3000, "Lessingstrasse", "Schillerstrasse",0xffff00)
- addField("Gehe ins Gefaengnis","goToJail")
- addStreet("Rathausplatz", 6000, 520, 2600, 7800, 18000, 22000, 25000, 4000, "Hauptstrasse", "Bahnhofstrasse",0x1b991d)
- addStreet("Hauptstrasse", 6000, 520, 2600, 7800, 18000, 22000, 25000, 4000, "Bahnhofstrasse", "Rathausplatz",0x1b991d)
- addField("Gemeinschaftsfeld","community")
- addStreet("Bahnhofstrasse", 6400, 560, 3000, 9000, 20000, 24000, 28000, 4000, "Hauptstrasse", "Rathausplatz",0x1b991d)
- addStation("Hauptbahnhof",4000,500)
- addField("Ereignis Feld","event")
- addStreet("Parkstrasse", 7000, 700, 3500, 10000, 22000, 26000, 30000, 4000, "Schlossallee",0x0000ff)
- addTax("Zusatzsteuer",2000)
- addStreet("Schlossallee", 8000, 1000, 4000, 12000, 28000, 34000, 40000, 4000, "Parkstrasse",0x0000ff)
- stationPositions={6,16,26,36}
- end
- function pay(player,amount)
- player.money=player.money-amount
- end
- generateBoard()
- function initializeCards()
- eCards={
- function(player) say("Die Bank zahlt dir eine Dividente von 1000$") pay(player,-1000) end,
- function(player) say("Ruecke bis zum naechsten Bahnhof vor")
- while board[player.position].type~="station" do
- rollDice(player,1)
- end
- enterField(player)
- end,
- function(player) say("Lasse alle Deine Haeuser renovieren Zahle an die Bank je Haus 500$")
- for ie1=1,#player.streets do
- for ie2=1,#board do
- if board[ie2].name==player.streets[ie1].name then
- pay(player,board[ie2].houses*500)
- end
- end
- end
- end,
- function(player) say("Du kommst aus dem Gefaengnis frei") player.joker=1 end,
- function(player) say("Mache einen Ausflug nach dem Suedbahnhof, wenn du ueber los kommst ziehe 4000$ ein")
- while board[player.position].name~="Suedbahnhof" do
- rollDice(player,1)
- end
- enterField(player)
- end,
- function(player) say("Strafe fuer zu schnelles Fahren") pay(player,300) end,
- function(player) say("Gehe zurueck zur Badstraße") player.position=2 end,
- function(player) say("Du wurdest zum Vorstand gewaehlt") pay(player,-1000) end,
- function(player) say("Gehe ins Gefaengnis") player.position=11 jail=3 end,
- function(player) say("Ruecke vor bis zur Schlossallee")
- while board[player.position].name~="Schlossallee" do
- rollDice(player,1)
- end
- enterField(player)
- end,
- function(player) say("Ruecke vor bis zur Seestrasse")
- while board[player.position].name~="Seestrasse" do
- rollDice(player,1)
- end
- enterField(player)
- end,
- function(player) say("Ruecke aus Los vor") rollDice(player,#board-player.position) end,
- function(player) say("Opernplatz")
- while board[player.position].name~="Seestrasse" do
- rollDice(player,1)
- end
- enterField(player)
- end,
- function(player) say("Gehe 3 Felder vor") rollDice(player,3) end,
- function(player) say("Zahle 200$") pay(player,200) end,
- function(player) say("Miete und Anleihezinsen werden faellig") pay(player,-3000) end,
- }
- gCards={
- function(player) say("Einkommensteuer Rueckzahlung") pay(player,-400) end,
- function(player) say("Zahle Schulgeld 3000$") pay(player,-3000) end,
- function(player) say("Aus Lagerverkaeufen erhaelst du 500$") pay(player,-500) end,
- function(player) say("Zahle an das Krankenhaus 2000") pay(player,2000) end,
- function(player) say("Du hast bei einem Kreuzwortraetsel Wettbewerb gewonnen! Du bekommst 2000$") pay(player,-2000) end,
- function(player) say("Arzt Kosten 1000$") pay(player,1000) end,
- function(player) say("Ruecke vor bis auf Los") player.position=1 pay(player,-8000) end,
- function(player) say("Gehe ins Gefaengnis") player.position=11 jail=3 end,
- function(player) say("Es ist dein Geburtstag Ziehe von jedem Spieler 1000$ ein")
- for ie1=1,#players do
- if players.name~= player.name then
- pay(player,-1000)
- pay(players[ie1],1000)
- end
- end
- end,
- function(player) say("Du erhaelst vorzugs Aktien 7% Dividente 900$") pay(player,-900) end,
- function(player) say("Du wirst zu Strassenverbesserungen herrangezohen, zahle pro haus 800$")
- for ie1=1,#player.streets do
- for ie2=1,#board do
- if board[ie2].name==player.streets[ie1].name then
- pay(player,board[ie2].houses*800)
- end
- end
- end
- end,
- function(player) say("Die Jahresrente wird faellig. 2000$") pay(player,-2000) end,
- function(player) say("Du hast den II. Platz beim Schoenheitswettbewerb gewonnen. Du bekommst 200$") pay(player,-200) end,
- function(player) say("Du erbst 2000$") pay(player,-2000) end,
- function(player) say("Bank Irrtum zu deinem Gunsten. Du bekommst 4000$") pay(player,-4000) end,
- function(player) say("Du kommst aus dem Gefaengnis frei") player.joker=1 end}
- end
- initializeCards()
- chatLog={}
- chatLogColor={}
- function say(message,color)
- print(message)
- if c~=nil then c.say(myName..": "..message) sleep(0.5) end
- if tb~=nil then
- glassesChat(message,color)
- if os.version()=="CraftOS 1.7" then
- tb.sync()
- end
- end
- if sp~=nil then sp.speak(message) end
- end
- function glassesChat(message,color)
- if color==nil then
- color=0xffffff
- end
- if message then
- if #chatLog >= 21 then
- for i=1, #chatLog do
- chatLog[i]=chatLog[i+1]
- chatLogColor[i]=chatLogColor[i+1]
- end
- end
- chatLogColor[#chatLogColor+1]=color
- chatLog[#chatLog+1]=message
- else
- if event=="chat_command" then
- if #chatLog >= 21 then
- for i=1, #chatLog do
- chatLog[i]=chatLog[i+1]
- chatLogColor[i]=chatLogColor[i+1]
- end
- end
- chatLogColor[#chatLogColor+1]=color
- chatLog[#chatLog+1]=arg1
- end
- if event=="glasses_chat_command" then
- if #chatLog >= 21 then
- for i=1, #chatLog do
- chatLog[i]=chatLog[i+1]
- chatLogColor[i]=chatLogColor[i+1]
- end
- end
- chatLog[#chatLog+1]=arg4
- chatLogColor[#chatLogColor+1]=color
- end
- end
- tb.clear()
- for i=1,#chatLog do
- tb.addBox(1,1,400,200,0x000000,0.1)
- tb.addText(1,i*8,chatLog[i],chatLogColor[i])
- end
- if #players then
- showPlayerInfo()
- end
- if os.version()=="CraftOS 1.7" then
- tb.sync()
- end
- end
- function showPlayerInfo()
- tb.addBox(1,400,800,8*#players,0x000000,0.1)
- for iPI=1, #players do
- tb.addText(400,iPI*8,players[iPI].name..": "..players[iPI].money,0xffffff)
- end
- end
- function ask(playerToAsk, question)
- say(question)
- event, arg1, arg2, arg3, arg4 = os.pullEvent()
- if event=="chat_message" then playerName=arg2 message=arg3 end
- if event=="glasses_chat_command" then playerName=arg2 message=arg4 end
- if playerName==playerToAsk or playerToAsk=="all" then
- say(message)
- return message
- else
- ask(playerToAsk, question)
- end
- end
- function initGame()
- message=nil
- while message~="ja" and message~="nein" do
- message=ask("all","Moechtest du ein Spiel Laden? $$ja/$$nein")
- end
- if message=="nein" then
- message=ask("all","wie soll der Spielstand heissen?")
- saveName=message
- users=tb.getUsers()
- if #users > 1 then
- for i=1,#users do
- say("Spieler "..i..": "..users[i].name)
- addPlayer(users[i].name)
- end
- return true
- else
- say("zu wenig Spieler")
- return false
- end
- end
- if message=="ja" then
- message=ask("all","wie heisst der Spielstand?")
- saveName=message
- loadGame(saveName)
- return true
- end
- end
- function rollDice(player,eyes)
- if player.position+eyes>#board then
- player.position=player.position+eyes-#board
- if player.position>1 then
- player.money=player.money+4000
- else
- player.money=player.money+8000
- end
- else
- player.position=player.position+eyes
- end
- end
- function streetInfo(cfield)
- say("Besitzer "..cfield.owner)
- say("Gundstueckswert: "..cfield.propertyCost)
- say("Miete normal: "..cfield.houseCost0)
- say("Miete 1 Haus: "..cfield.houseCost1)
- say("Miete 2 Haeuser: "..cfield.houseCost2)
- say("Miete 3 Haeuser: "..cfield.houseCost3)
- say("Miete 4 Haeuser: "..cfield.houseCost4)
- say("Miete Hotel: "..cfield.houseCost5)
- say("Haeuser momentan: "..cfield.houses)
- say("Kosten 1 Haus: "..cfield.addHouseCost)
- end
- function stationInfo(cfield)
- say("Besitzer "..cfield.owner)
- say("Gundstueckswert: "..cfield.propertyCost)
- say("Miete normal: "..cfield.cost)
- say("Miete 2 Bahnhoefe: "..cfield.cost*2)
- say("Miete 3 Bahnhoefe: "..cfield.cost*3)
- say("Miete 4 Bahnhoefe: "..cfield.cost*4)
- end
- function saveGame(saveName)
- fp=fs.open(saveName,"w")
- fp.write("board="..textutils.serialize(board))
- fp.write("players="..textutils.serialize(players))
- fp.close()
- end
- function loadGame(saveName)
- shell.run(saveName)
- end
- function enterField(player)
- cfield=board[player.position]
- say(cfield.name,cfield.color)
- if cfield.type=="street" then
- streetInfo(cfield)
- if cfield.owner=="none" then
- message=nil
- while message~="ja" and message~="nein" do
- message=ask(player.name,"Moechtest du die Strasse kaufen? $$ja/$$nein")
- end
- if message=="ja" then
- player.money=player.money-cfield.propertyCost
- if player.money>=0 then
- cfield.owner=player.name
- player.streets[#player.streets+1]=cfield.name
- end
- end
- end
- if cfield.owner==player.name then
- say("Diese Strasse gehoert dir")
- streetFull=0
- for i1=1, #cfield.members do
- for i2=1, #player.streets do
- if cfield.members==player.streets[i2] then
- streetFull=streetFull+1
- end
- end
- end
- if streetFull==#cfield.members then
- message=nil
- while message~="ja" and message~="nein" do
- message=ask(player.name,"Wie viele Haeuser/Hotels moechtest du bauen? nein oder 1-5")
- end
- if message~="nein" then
- amount=tonumber(message)
- if amount<6 and amount>0 then
- player.money=player.money-cfield.addHouseCost*amount
- if player.money>=0 then
- cfield.houses=cfield.houses+amount
- end
- end
- end
- end
- else
- if cfield.houses==0 then
- player.money=player.money+cfield.houseCost0
- end if cfield.houses==1 then
- player.money=player.money+cfield.houseCost1
- end if cfield.houses==2 then
- player.money=player.money+cfield.houseCost2
- end if cfield.houses==3 then
- player.money=player.money+cfield.houseCost3
- end if cfield.houses==4 then
- player.money=player.money+cfield.houseCost4
- end if cfield.houses==5 then
- player.money=player.money+cfield.houseCost5
- end
- end
- end
- if cfield.type=="station" then
- if cfield.owner=="none" then
- message=nil
- while message~="ja" and message~="nein" do
- message=ask(player.name,"Moechtest du den Bahnhof kaufen? ja/nein")
- end
- if message=="ja" then
- player.money=player.money-cfield.propertyCost
- if player.money>=0 then
- cfield.owner=player.name
- player.stations[#player.stations+1]=cfield.name
- end
- end
- else
- for i0=1,#players do
- if players[i0].name==cfield.owner then
- player.money=player.money-#players[i0].stations*cfield.cost
- end
- end
- end
- end
- if cfield.type=="tax" then
- player.money=player.money-cfield.cost
- end
- if cfield.type=="event" then
- eCards[math.random(1,#eCards)](player)
- end
- if cfield.type=="community" then
- gCards[math.random(1,#gCards)](player)
- end
- if cfield.type=="goToJail" then
- if player.joker==0 then
- say("Du kommst ins Gefaengnis")
- player.position=11 player.jail=3
- else
- say("Du hast deine Frei-Karte benutzt")
- player.joker=0
- end
- end
- end
- function showStreets(player)
- for is=1,#player.streets do
- say(player.streets[is].name,player.streets[is].color)
- end
- end
- function menu(player)
- say(player.name.." ist am Zug.")
- say("Optionen:")
- if player.jail==0 then
- say("wuerfeln: $$w")
- end
- say("handeln: $$h")
- message=nil
- message=ask(player.name,"Was moechtest du tun?")
- --Würfeln
- if message=="w" then
- dice1=math.random(1,6)
- dice2=math.random(1,6)
- eyes=dice1+dice2
- pasch=dice1==dice2
- rollDice(player,eyes)
- say(player.name.." wuerfelt "..dice1.." + "..dice2.." = "..eyes)
- enterField(player)
- if pasch then
- menu(player)
- end
- end
- --Straßen Handeln
- if message=="h" then
- message=ask(player.name,"Mit wem moechtest du Handeln?")
- for i=1, #players do
- if players[i].name==message then
- playerToBuyFrom=players[i]
- showStreets(players[i])
- end
- message=ask(player.name,"Welche Strasse moechtest du haben?")
- streetToBuy=message
- message=ask(player.name,"Welche Strasse moechtest du dafür geben?")
- streetToGive=message
- message=ask(playerToBuyFrom.name,playerToBuyFrom.name.." bist du damit einverstanden? ja/nein")
- if message=="ja" then
- for i2=1,#playerToBuyFrom.streets do
- if playerToBuyFrom.streets[i2].name==streetToBuy then
- delElementFromTable(playerToBuyFrom.streets,i2)
- end
- end
- for i2=1,#player.streets do
- if player.streets[i2].name==streetToGive then
- delElementFromTable(player.streets,i2)
- end
- end
- for i2=1,#board do
- if board[i2].name==streetToGive then
- board[i2].owner=playerToBuyFrom.name
- playerToBuyFrom.streets[#playerToBuyFrom.streets+1]=board[i2]
- end
- end
- for i2=1,#board do
- if board[i2].name==streetToBuy then
- board[i2].owner=player.name
- player.streets[#player.streets+1]=board[i2]
- end
- end
- say("Deal Erfolgreich")
- else
- say("Deal Fehlgeschlagen")
- end
- end
- end
- end
- function game()
- if initGame() then
- while true do
- for iP=1,#players do
- --Testen ob Spieler im Jail ist
- if players[iP].jail<1 then
- --Menue
- menu(players[iP])
- --Testen ob der Spieler Bankrott ist
- if players[iP].money<=0 then
- say(players[iP].name.." ist Bankrott")
- playersBackup=players
- players={}
- for i1=1,#playersBackup do
- if playersBackup[i1].name~=players[iP].name then
- players[#players]=playersBackup[i1]
- end
- end
- if #players==1 then
- say(players[1].name.." hat gewonnen")
- end
- end
- else
- players[iP].jail=players[iP].jail-1
- end
- end
- saveGame(saveName)
- end
- end
- end
Add Comment
Please, Sign In to add comment