我是Python的初学者。我正在关注“艰苦学习Python”。
在练习43中,我尝试编写一个简短的代码,但出现错误。请帮助我:(我遇到错误:
type object()不带参数
请帮助我解决此代码问题。我在这个阶段陷入困境:
from sys import exit
from random import randint
class GoldRush(object):
def enter(self):
print("you have found a map of Gold Rush")
print("there is a huge gold locked in the old temple of theses")
print("now you are on a mission to find the hidden gold")
class Engine(object):
def __int__(self, scene_map):
self.scene_map = scene_map
def play(self):
current_scene = self.scene_map.opening_scene()
last_scene = self.scene_map.next_scene('Finished')
while current_scene != last_scene:
next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name)
#be sure to print out the last scene
current_scene.enter()
#export death scene
class Death(GoldRush):
yam = [
"you died. you kind a suck at this"
"shame on you !!! you cant solve this "
"such a luster"
"even small kids are better than you "
"you where given fucking one jo and you sucked in that also"
]
def enter(self):
print(Death.yam[randint(0, len(self.yam)-1)])
exit(1)
class FightingDragon(GoldRush):
def enter(self):
print("finally you had left for the expedition ")
print("you are crossing the narrow sea ")
print("after crossing the sea you are on the mountain")
print("in the mountain finally you find the cave ")
print("in that cave you found a dragon")
print("you had to cross the dragon to get to the Gold Rush")
action = input("> ")
if action == "attack":
print("entering in the cave you found a dragon")
print("after seeing the dragon you are stoned ")
print("you have no idea what to do now ")
print("you take out the gun and started firing at Dragon ")
print("but nothing is working ")
print("there is not even a single scratch on the dragon ")
print("the dragon gets pissied ")
print("Dracarys and the dragon burn you down")
return 'death'
elif action == "dodge":
print("you see the dragon in the cave")
print("and the dragon started to attack on you ")
print("the dragon is very fevrious now ")
print("he is burning the entire cave")
print("there is fire every where ")
print("you sucessfully dodge the dragon 3-4 times ")
print("but in the 5th attemp the dragon burn you down")
print("and you died")
return 'death'
elif action == "wait":
print("you see the dragon in the cave")
print("and you a stuned by seeing it")
print("you not able do anything ")
print("you know you cannot defeat the dragon")
print("so you are just waiting for dragon to move ")
print("after hours of waiting finally the dragon moves ")
print("you surpass the dragon sucessfuly ")
return 'defeating_dragon'
else:
print("invaid move ")
return 'fighting_dragon'
#exporting another scene to the game
class DefeatingDragon(GoldRush):
def enter(self):
print("finally you surpass the dragon")
print("but the challange are not over yet ")
print("as you move to next step it is going to be more complex")
print("then you started to move forward")
action = input("> ")
if action == "walk":
print("in the cave you stated to move slowely ")
print("by going little ahead to put the leg on land mine")
print("now you cannot move ")
print("you moved little and the mine blows away")
return 'death'
elif action == "run":
print("you go ahead in the cave")
print("and you see the dragon is coming again ")
print("and started running out very fast")
print("you are just running with out any fear just running")
print("and you see the bridge there then you stop for a while ")
print("and again started running from the bridge")
print("finally you cross all the obstracals")
return 'select_door'
else:
print("invalid input")
return 'fighting_dragon'
# exporting frurther part of map
class SelectingDoor(GoldRush):
def enter(self):
print("you surpass all the obstracal")
print("you are moving forward now ")
print("after moving forward you see three doors")
print("now is very difficult task for you to choise one door")
action = input("> ")
if action == "door one":
print("you select door one")
print("started walking further ")
print("there is total dark")
print("and you get into the trap")
print("Bammp !!! a arrow is shot ")
print("the arrow bursts your head")
return 'death'
elif action == "door two":
print("you select door two")
print("but door two is having lock ")
print("and you don't know the password of the door")
print("you have 10 attemps to unlock the door")
return 'door_two'
elif action == "door three":
print("you select door three ")
print("enter into the door and the land slides ")
print("you are falling from up to down somewhere ")
print("you fall onto the spikes")
print("you die")
return 'death'
else:
print("invalid input")
return 'selecting_door'
#selecting the door two which is locked
class DoorTwo(GoldRush):
def enter(self):
print("you selected the door two")
print("there are 10 attemps to unlock the door")
print("you started trying")
code = f"{randint(1, 9)}{randint(1, 9)}{randint(1, 9)}"
guess = input("> ")
guesses = 0
while guess != code and guesses < 9:
print("BUZZZEEED")
guesses += 1
guess = input("[Key]- ")
if guess != code:
print("you started to guess the pin code on the lock")
print("The Door open and the seal breaks, letting gas out.")
print("You grab everything and run as fast as you can to the")
print("other sie of the door .")
return 'escape'
else:
print("The lock buzzes one last time and then you hear a sickening")
print("melting sound as the mechanism is fused together.")
print("You decide to sit there, and finally the cave started")
print("to blow up and you die.")
return 'death'
#this this the final senerio
class Escape(GoldRush):
def enter(self):
print("You rush through the door desperately trying to make it to")
print("you finally cant belive on your eyes ")
print("you are all surrounded by the golds and the diamonds ")
print("you are stunned by all this treasure")
print("you grabe a bag and started to collect all the items ")
print("from the Gold Rush ")
print("you have collected all the items and started to go to the exit")
return 'finished'
#this is the final output
class Finished(GoldRush):
def enter(self):
print("You won! Good job.")
return 'finished'
#map class dict
class Map(object):
scenes = {
'fighting_dragon': FightingDragon(),
'defeating_dragon': DefeatingDragon(),
'selecting_door': SelectingDoor(),
'door_two': DoorTwo(),
'escape': Escape(),
'death': Death(),
'finished': Finished(),
}
def __int__(self, start_scene):
self.start_scene = start_scene
def next_scene(self, scene_name):
val = Map.scenes.get(scene_name)
return val
def opening_scene(self):
return self.next_scene(self.start_scene)
#exporting to a map
a_map = Map('fighting_dragon')
a_game = Engine(a_map)
a_game.play()
答案 0 :(得分:0)
您的类import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {LoginComponent} from './modules/login/login.component';
import {UserComponent} from './modules/user/user.component';
import {AuthService} from './common-modules/auth/auth.guard';
const routes: Routes = [
{
path: '',
redirectTo: 'login',
pathMatch: 'full'
},
{
path: 'login',
component: LoginComponent
},
{
path: 'me',
component: UserComponent,
canActivate: [AuthService]
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
的构造函数有错字:
Map
将其名称编辑为def __int__(self, start_scene):
self.start_scene = start_scene
,而不是__init__
。
发生错误是因为您正在继承__int__
类,该类没有采用参数的构造函数,并且实际上没有为object
定义新的构造函数(由于该错字)。