コード例 #1
0
	def trade(cls, s, r):
		''' Displays a series of menus to coordinate
		a trade between two players, confirms actions,
		manages transaction and then logs trade.
		'''

		# load items into trade box - sender
		sender_trade_box = cls.trade_box(s)
		if sender_trade_box is None:
			return	 # Trade is cancelled

		# load items into trade box - receiver
		print "Sending offer to %s ...\n" % r.name
		if cls.trade_accept(sender_trade_box, r) is False:
			print 'Trade declined.'
			return
		receiver_trade_box = cls.trade_box(r)

		# confirm
		sc, rc = cls.trade_confirm(sender_trade_box, receiver_trade_box)

		# trade
		if (sc and rc) == 'y':
			print "Processing ... one moment."
			for prop in sender_trade_box['properties']:
				r.properties[prop.name] = s.properties[prop.name]
				cls.board.tiles[prop.name]['owner'] = r.name
				del s.properties[prop.name]

			s.money -= sender_trade_box['money']
			r.money += sender_trade_box['money']

			for prop in receiver_trade_box['properties']:
				s.properties[prop.name] = r.properties[prop.name]
				cls.board.tiles[prop.name]['owner'] = s.name
				del r.properties[prop.name]

			s.money += receiver_trade_box['money']
			r.money -= receiver_trade_box['money']

			# Log transaction
			print 'Transaction Complete - see log\n'

			m1 = sender_trade_box['money']
			m2 = receiver_trade_box['money']
			i1 = [prop.name for prop in sender_trade_box['properties']]
			i2 = [prop.name for prop in receiver_trade_box['properties']]

			GameLogger.add_log(msgtype='trade', p1=s.name, p2=r.name, i1=i1, m1=m1, i2=i2, m2=m2)
			return
		print "Trade has been rejected.\n"
		return
コード例 #2
0
	def card_event(cls, player, current_location):
		''' Carries out effects from Chance and Community Chest cards.'''

		db = DbInterface()
		p = cls.players[player]
		with db.conn as conn:
			# select a card from top of the deck
			card = cls.cards.select(current_location.lower())
			if db.card_info(conn, current_location, card):
				received_card = db.card_info(conn, current_location, card)
			print "Drew card: ", card
			print "-- ", received_card.description
			GameLogger.add_log(msgtype='card event', name=p.name, card=card, desc=received_card.description)
			# for general 'money' type cards
			if received_card.category == "money":

				# calls card_repairs - works
				assets = p.total_assets()
				if received_card.tag == "GENRP":
					print "You own %s houses, and %s hotels" % (assets['houses'], assets['hotels'])
					p.money -= (assets['houses'] * 25)
					p.money -= (assets['hotels'] * 100)
					msg = "'%s' paid $%s and $%s for repairs to houses and hotels, respectively." % (p.name,
																assets['houses'] * 25, assets['hotels'] * 100)
					GameLogger.add_log(msg=msg)

				# assessed for street repairs
				elif received_card.tag == "STRRP":
					print "You own %s houses, and %s hotels" % (assets['houses'], assets['hotels'])
					p.money -= (assets['houses'] * 40)
					p.money -= (assets['hotels'] * 115)
					msg = "'%s' paid $%s and $%s for repairs to houses and hotels, respectively." % (p.name,
																assets['houses'] * 25, assets['hotels'] * 100)
					GameLogger.add_log(msg=msg)

				# you have been elected chairman of the board
				elif received_card.tag == "CHBRD":
					for other in p.others:
						p.money -= received_card.effect
						other.money += received_card.effect
					msg = "'%s' received $%s from other players." % (p.name,
											len(p.others) * received_card.effect)
					GameLogger.add_log(msg=msg)

				# grand opera night
				elif received_card.tag == "GRDON":
					for other in p.others:
						p.money += received_card.effect
						other.money -= received_card.effect
					msg = "'%s' received $%s from other players." % (p.name,
											len(p.others) * received_card.effect)
					GameLogger.add_log(msg=msg)

				# it is your birthday
				elif received_card.tag == "YBDAY":
					for other in p.others:
						p.money += received_card.effect
						other.money -= received_card.effect
					msg = "'%s' received $%s from other players." % (p.name,
											len(p.others) * received_card.effect)
					GameLogger.add_log(msg=msg)

				# normal 'Money' card
				else:
					p.money += received_card.effect
					msg = "'%s' gained $%s." % (p.name, received_card.effect)
					GameLogger.add_log(msg=msg)

				return p.post_interact(cls.board, cls.bank)
			if received_card.category == "move":

				# Go to jail
				if received_card.tag == "GOTOJ":
					p.position = received_card.effect
					p.jail = True
					p.jail_duration = 3
					msg = "'%s' went to '%s'." % (p.name, 'Jail')
					GameLogger.add_log(msg=msg)
					p.post_interact(cls.board, cls.bank)

				# Go back 3 spaces
				elif received_card.tag == "GOBTS":
					p.position += received_card.effect
					print "You've now on ...", cls.board.layout[p.position]
					current_location = cls.board.layout[p.position]
					msg = "'%s' moved back 3 spaces to '%s'." % (p.name, current_location)
					GameLogger.add_log(msg=msg)
					p.interact(current_location, cls.board, cls.bank)

				# Advance to nearest Railroad
				elif received_card.tag == "ADVNR":
					if 0 <= p.position < 10:
						p.position = 5
					elif 10 < p.position < 20:
						p.position = 15
					elif 20 < p.position < 30:
						p.position = 25
					elif 30 < p.position < 40:
						p.position = 35
					new_location = cls.board.layout[p.position]
					print "You moved to nearest railroad, %s." % new_location
					msg = "'%s' moved to nearest railroad, '%s'." % (p.name, new_location)
					GameLogger.add_log(msg=msg)

					if new_location in p.properties:
						print "You already own this property."
						return

					for other in p.others:
						if new_location in other.properties:
							rent = cls.bank.rent_table[new_location]['rent'] * 2
							p.money -= rent
							other.money += rent
							print "You owe %s $%s in rent." % (other.name, rent)
							GameLogger.add_log(msgtype='rent', p1=p.name,
												p2=other.name, m=rent)
							return

					p.purchase(cls.board, cls.bank.all_properties[new_location])
					p.post_interact(cls.board, cls.bank)
					return

				# Advance to nearest Utility
				elif received_card.tag == "ADVNU":
					if 0 <= p.position < 21:
						p.position = 12
					elif 22 <= p.position < 40:
						p.position = 28
					new_location = cls.board.layout[p.position]
					print "You moved to nearest utility, %s." % new_location
					msg = "'%s' moved to nearest utility, '%s'." % (p.name, new_location)
					GameLogger.add_log(msg=msg)

					if new_location in p.properties:
						print "You already own this property."
						return

					for other in p.others:
						if new_location in other.properties:
							die1 = choice(range(1, 7))
							die2 = choice(range(1, 7))
							rent = ((die1 + die2) * 10)
							p.money -= rent
							other.money += rent
							print "You paid %s $%s!" % (other.name, ((die1 + die2) * 10))
							GameLogger.add_log(msgtype='rent', p1=p.name,
											p2=other.name, m=((die1 + die2) * 10))
							return

					p.purchase(cls.board,
								cls.bank.all_properties[new_location])
					p.post_interact(cls.board, cls.bank)
					return

				# Normal 'move' card
				else:
					if received_card.effect - p.position < 0:
						print "You've passed Go! collect $200."
						p.money += 200
					p.position = received_card.effect
					new_location = cls.board.layout[p.position]
					p.interact(new_location, cls.board, cls.bank)

			if received_card.category == "item":
				p.passes.append(card)
				msg = "'%s' received a 'Get Out of Jail Free' card!" % p.name
				GameLogger.add_log(msg=msg)
				p.post_interact(cls.board, cls.bank)