flushing out a python error.
if you haven't seen my previous topic here i'm working on a monopoly game. i have since resolved, or hopefully, my issues in that thread. however like it often does more errors and things have cropped up since.
my current issue i'm trying to plow my way through is how to see what the arguments are when an object is initialized.
my error here is on line 68. it says type error __init takes 4 arguments 2 given. i'm not sure why this is saying it. any help on this would really be greatly appreciated. also, if anyone could elp me with my global variables. i know i use them all the time in this. not really sure if i should be using return. and if so how to implement it in my case.
code follows:
from random import randint
from sys import exit
board = ("Go", "Mediterranean Avenue", "Community Chest", "Baltic Avenue", "Income Tax", "Reading Railroad", "Oriental Avenue ", "Chance", "Vermont Avenue", "Connecticut Avenue", "Jail", "St. Charles Place", "Eletric Company", "States Avenue", "Virginia Avenue", "Pennsylvania Railroad", "St. James Place", "Community Chest", "Tennessee Avenue", "New York Avenue", "Free Parking", "Kentucky Avenue", "Chance", "Indiana Avenue", "Illinois Avenue", "B. & O. Railroad", "Atlantic Avenue", "Ventnor Avenue", "Water Works", "Marvin Gardens", "Go to Jail", "Pacific Avenue", "North Carolina Avenue", "Community Chest", "Pennsylvania Avenue", "Short Line Rail Road", "Chance", "Park Place", "Luctury Tax", "Boardwalk")
#main player class
class Player(object):
#main pl
ayer init function. will be expanded later. just basics for now.
def __init__(self, name, cash, position):
self.name = name
self.cash = cash
self.position = position
#Player method handling piece movement around the board.
def movement(self):
global die1
global player
global current_position
new_position = die1 + self.position
if new_position >= 40:
temp = self.position + die1 - 40
new_position = temp
else:
pass
print "you move %d squares and are now on square %s."
% (die1, board[new_position])
current_position = new_position
print "now you are on square %s for your next roll." % board[current_position]
self.position = new_position
game.change_turn()
#Player method handling die rolling. will be expanded later to include 2 dice with logic for playing more turns if player rolls #doubles.
def roll(self):
global die1
die1 = randint(1,6)
#player method for handling input as to what the player wants to do on his or her turn. will be more robust later.
def turn(self):
global current_position
global player
current_position = bo
ard[self.position]
print "okay %S. you are on square %s." % (self.name, current_position)
choice = raw_input("what would you like to do?")
if choice == "roll":
player.roll()
else:
print "woops. don't understand."
player.turn()
print "you rolled a %d. great job! now lets see what we can do with it." % die1
player.movement()
#main class for setting up a game of monopoly.
class Session(object):
#init function for setting up the list that players will be put into in order for them to be cycled through during gameplay.
def __init__(self):
se
lf.player_list = []
#method for adding players to the list
def add_player(self, player):
self.player_list.append(player)
#method for removing players from the list when out of the game.
def remove_player(self, player):
self.player_list.remove(player)
#method for setting who's playing to pass it off to the player class. contains error. see above.
def set_turn(self):
global current_player
global player
global p1
global p2
player = Player(self.player_list[current_player])
print "now its %r." % current_player
#method for changing players to move the game along.
def change_turn(self):
global current_player
next_player = (current_player + 1) % len(self.player_list)
current_player = next_player
game.set_turn()
#starting method to begin gameplay
def start(self):
global current_player
print "lets start the game."
print "we have %r players playing." % len(self.player_list)
print "player 1 will start for now."
current_player = 0
game.set_turn()
#initializing my players
p1 = Player("kyle", 1500, 0)
p2 = Player("computer", 1500, 0)
#initializing game session and adding the players to the list
game = Session()
game.add_player(p1)game.add_player(p2)
game.start()
_______________________________________________ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector