Challenges in the world of Dungeons & Dragons gaming

This is the main function that will execute everything

import GameClass

def callMain():
    game = GameClass
    game.Run()
    #GameClass.Run()

callMain()

Upon executing the main function that triggers everything, an error occurred:"

Traceback (most recent call last):
  File "C:\Python34\D & D game\D&D game.py", line 13, in <module>
    callMain()
  File "C:\Python34\D & D game\D&D game.py", line 10, in callMain
    game.Run()
AttributeError: 'module' object has no attribute 'Run'

Not entirely certain how to proceed.

GameClass being invoked

import random

import EnemyBaseClass
import PlayerClass
import OgreClass
import TrollClass
import DragonClass
import GoblinClass

#Game Class

class GameClass():
    def __init__(self):
        self.PlayerCharacter = PlayerClass.Player()
        self.Location = ['You have entered the frozen slopes of the ice everyglades',
                         'You have entered the enchanted forest of the elves',
                         'You decided to enter the dragons mountains',
                         'you saild across the frozen seas of everyfrost',
                         'Your home has become covered ina thick fog',
                         'You come across a small village']
        self.Score = 0
        self.Enemies = [TrollClass.Troll(), OgreClass.Ogre(), DragonClass.Dragon(),      GoblinClass.Goblin()]
    self.EnemySelected = self.Enemies[0]

def PlayerAttack(self):
    self.PlayerCharacter.DetermineDamage()
    self.Enemies[self.EnemySelected].Life -= self.PlayerCharacter.Damage

    if self.PlayerCharacter.Damage == 0:
        print("The player Goes for a strike but misses.")
    else:
        print("The player attacks and Does " +str(self.PlayerCharacter.Damage) + "damage.")
        self.Score +=10

    print("The " + self.Enemies[self.EnemiesSelected].Name + " now has " + str(self.Enemies[self.EnemySelected].Life))

def EnemyAttack(self):
    self.Enemies[self.EnemySelected].DetermineDamage()
    self.PlayerCharacter.Life -= self.Enemies[self.EnemySelected].Damage

    if self.Enemies[self.EnemiesSelected].Damage == 0:
        print("The " + self.Enemies[self.EnemySelected].Name + " goes for a strike but misses.")
    else:
        print("The " + self.Enemies[self.EnemySelected].Name + " attacks and does " + str(self.Enemies[self.EnemySelected].Damage) + "damage.")

    print("The player now has " + str(self.PlayerCharacter.Life) + " life left.")

...

...

Answer №1

Take a second look at the error message:

AttributeError: 'module' object has no attribute 'Run'

When you import the module GameClass, you will find the class GameClass inside it. You want to create an instance of this class and utilize its methods. Here are two ways to achieve this:

import GameClass # import the module

GameClass.GameClass().Run() # accessing class through the module

or:

from GameClass import GameClass # import the class

GameClass().Run() # direct access to the class

If you prefer following Python's style guide:

from game import Game

Game().run()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Delaying between typed characters in Selenium SendKeys can be achieved by implementing a small pause

I have encountered an issue while using an actions chain to input text, where duplicate characters appear. I suspect this might be due to the lack of delay. How can I fix this problem? Here is an example code snippet: big_text = "Lorem ipsum dolor sit ...

Is there a way to extract the text that is displayed when I hover over a specific element?

When I hover over a product on the e-commerce webpage (), the color name is displayed. I was able to determine the new line in the HTML code that appears when hovering, but I'm unsure how to extract the text ('NAVY'). <div class="ui ...

What steps should I follow to activate the Terminal plugin on Pycharm Edu version 3.5.1?

On a recent visit to JetBrains, the recommendation was to enable the Terminal plugin in Pycharm. However, I am unable to locate it anywhere within my application. This has become quite problematic as I urgently need access to the Terminal for an ongoing ...

Creating structure in pandas(Note: this response is generated

I am in search of a way to establish a hierarchy within my organization and design the reporting structure for each individual entry. My initial dataset will have two columns: e_id and s_id: What I aim to achieve is creating a variable that contains a di ...

Creating a visual representation of geographical data with Python: A step-by-step

I am interested in creating a map using Python that represents land use through a series of small shapes, rather than full detailed information. Here is the data: 1 2 2 3 3 2 2 3 3 1 1 2 1 1 1 1 3 3 3 3 3 3 4 1 Each number corresponds to a different typ ...

Carry on executing Python Selenium script even after manually solving Captcha

As I am trying to register numerous individuals in a company's system, I encounter a captcha on the login screen. Before proceeding with automatically populating the data into the system, I prefer solving the captcha manually. Is there a method for th ...

Tips for creating a Scrapy spider to extract .CSS information from a table

Currently, I am utilizing Python.org version 2.7 64-bit on Windows Vista 64-bit for building a recursive web scraper using Scrapy. Below is the snippet of code that successfully extracts data from a table on a specific page: rows = sel.xpath('//table ...

In lxml, HTML elements may be encoded incorrectly, such as displaying as &#x41D;&#x430;&#x439; instead

Having trouble printing the RSS link from a webpage because it's being decoded incorrectly. Check out the snippet of code below: import urllib2 from lxml import html, etree import chardet data = urllib2.urlopen('http://facts-and-joy.ru/') ...

Passing JSON data from template to view in Django

I'm facing an issue with sending JSON data via AJAX from the template to the view and storing it directly in the database. The problem lies in the data not reaching the view successfully. When I try to insert my JSON data (json_data['x'], js ...

Create a new column in the Pandas dataframe labeled as "category" that corresponds to the values falling within a specified

Looking to create a new column that categorizes an existing column based on specific values in the DataFrame. The current DataFrame is as follows: from io import StringIO import pandas as pd import numpy as np csvStringIO = StringIO("""Acc ...

Using Python's pandas library, merging data from sheet1 and sheet2 to an existing Excel file

I have successfully extracted data from a website and saved it to sheet 1 in an Excel file using pandas. Now, I am looking to retrieve a specific column of data and save it to sheet 2 within the same Excel file. However, when I run the code, instead of cr ...

Why is sympy struggling to integrate this when Mathematica can do it effortlessly?

What is the reason that sympy fails to compute this particular integral? import sympy as sp x = sp.symbols('x', real=True, nonzero=True) sp.integrate(x**3/(sp.exp(x)-1), (x, 0, sp.oo)) The expected result for this integral is pi^4/15. ...

Python Script for Automatically Following and Liking on Instagram

I'm experimenting with an Instagram follow/like bot as a Python beginner. Here is a snippet of code that I have been using: try: time.sleep(15) driver.refresh() time.sleep(3) if len(driver.find_elements_by_class_name('fr66n')) > 0: p ...

Spin list in Python

There is a question on Leetcode called 189 Rotate Array. Check it out here. The task is to rotate an array to the right by k steps, where k is a non-negative integer. To illustrate better, here's an example image: See visual representation here I ha ...

Analyzing data using Python regex and saving it in a list

Hey there! I've got a query related to utilizing regex in python. Imagine having a string code comprising multiple lines of formulas with variables or numeric values. For instance: code1 = ''' g = -9 h = i + j year = 2000 month = 0xA d ...

Converting object to string does not yield the desired outcome

I am working with Selenium in Python and I am encountering an issue when trying to convert the result of name = browser.find_element_by_css_selector('elementname') into a string. The output is 'WebElement' instead of the actual eleme ...

In Python, what is the maximum number of processes that can simultaneously access a PostgreSQL database table?

In this code snippet, each process is responsible for crawling a link, extracting data, and then storing it in a database simultaneously. def crawl_and_save_data(url): while True: res = requests.get(url) price_list = res.json() ...

Locate the text of an element that is not visible on the screen while the code is running

Currently, I am diving into the world of web scraping using Selenium. To get some practical experience, I decided to extract promotions from this specific site: https://i.stack.imgur.com/zKEDM.jpg This is the code I have been working on: from selenium im ...

the gravitational center of every cell within an N-dimensional grid of right angles

In a multi-dimensional rectilinear grid, the edges in each dimension 'i' are defined as x_i = {x[i, 0], x[i,1], ..., x[i, Ni-1], x[i, Ni]}, with 'N_i' edges in that specific dimension. A density y of shape (N0, N1, ... Ni, ... Nn-1) is ...

Exiting early from a complete test suite in Pytest based on conditions

I am managing a parameterized pytest test suite where each parameter represents a specific website, and the automation is done using Selenium. With numerous tests in total once parameters are taken into account, they all run one after another. However, th ...