Crossfire Server, Trunk
CFGamble.py
Go to the documentation of this file.
1 #CFGamble
2 # Todd Mitchell
3 #The Python control file for Slot Machines and other such nonsense
4 #Please do not put CFPython functions in this file,
5 #but rather place these in the calling file (don't ask me why - it just feels right)
6 
7 import os.path
8 import shelve
9 import random
10 
11 import Crossfire
12 
14  #sets up the file that holds all the slotmachine jackpots
15  #make sure this points to your writable var/crossfire directory
16  #you can delete that file to reset all the slotmachine jackpots
17  slotfile = os.path.join(Crossfire.LocalDirectory(),'SlotMachine_file')
18  slotdb = {}
19  def __init__(self,slotname,slotlist,minpot,maxpot):
20  slotdb = shelve.open(self.slotfile)
21  self.slotname = slotname
22  self.slotlist = slotlist
23  self.minpot = minpot
24  self.maxpot = maxpot
25 
26  def placebet(self,amount):
27  if self.slotname not in self.slotdb:
28  self.slotdb[self.slotname] = self.minpot+amount
29  else:
30  temp=self.slotdb[self.slotname]
31  self.slotdb[self.slotname]=temp+amount
32 
33  def payoff(self,amount):
34  temp=self.slotdb[self.slotname]
35  self.slotdb[self.slotname] = temp-amount
36 
37  def spin(self,slotnum):
38  result=[]
39  while slotnum >=1:
40  r = self.slotlist[random.randint(0,len(self.slotlist)-1)]
41  result.append(r)
42  slotnum=slotnum-1
43  return result
44 
45  def checkslot(self):
46  limit = self.slotdb[self.slotname]
47  if limit >= self.maxpot:
48  self.slotdb[self.slotname] = self.maxpot
49  elif limit < self.minpot:
50  self.slotdb[self.slotname] = self.minpot
51  return self.slotdb[self.slotname]
CFGamble.SlotMachine.spin
def spin(self, slotnum)
Definition: CFGamble.py:37
CFGamble.SlotMachine.minpot
minpot
Definition: CFGamble.py:23
CFGamble.SlotMachine.placebet
def placebet(self, amount)
Definition: CFGamble.py:26
CFGamble.SlotMachine.checkslot
def checkslot(self)
Definition: CFGamble.py:45
CFGamble.SlotMachine.__init__
def __init__(self, slotname, slotlist, minpot, maxpot)
Definition: CFGamble.py:19
CFGamble.SlotMachine.payoff
def payoff(self, amount)
Definition: CFGamble.py:33
CFGamble.SlotMachine.slotdb
dictionary slotdb
Definition: CFGamble.py:18
CFGamble.SlotMachine
Definition: CFGamble.py:13
CFGamble.SlotMachine.slotlist
slotlist
Definition: CFGamble.py:22
CFGamble.SlotMachine.slotname
slotname
Definition: CFGamble.py:21
CFGamble.SlotMachine.slotfile
slotfile
Definition: CFGamble.py:17
CFGamble.SlotMachine.maxpot
maxpot
Definition: CFGamble.py:24