generated from mwc/project_game
wip
This commit is contained in:
BIN
__pycache__/bunco.cpython-312.pyc
Normal file
BIN
__pycache__/bunco.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/config.cpython-312.pyc
Normal file
BIN
__pycache__/config.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/roll.cpython-312.pyc
Normal file
BIN
__pycache__/roll.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/score.cpython-312.pyc
Normal file
BIN
__pycache__/score.cpython-312.pyc
Normal file
Binary file not shown.
34
bunco.py
Normal file
34
bunco.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
from retro.game import Game
|
||||||
|
from random import randint
|
||||||
|
import score
|
||||||
|
import config
|
||||||
|
import roll
|
||||||
|
|
||||||
|
state = {
|
||||||
|
#state displayed in the bootom section of the game
|
||||||
|
"1. Current Team": 1,
|
||||||
|
"2. Current Round": 1,
|
||||||
|
"3. Blue Team Score": 0,
|
||||||
|
"4. Red Team Score": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
agents = [
|
||||||
|
roll.Roller(),
|
||||||
|
roll.Die((20, 15), "die1"),
|
||||||
|
roll.Die((30, 15), "die2"),
|
||||||
|
roll.Die((40, 15), "die3"),
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
game = Game(agents, state, color="black_on_white")
|
||||||
|
game.play()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
12
die.py
Normal file
12
die.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from random import randint
|
||||||
|
|
||||||
|
class Die:
|
||||||
|
def __init__(self):
|
||||||
|
self.roll()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.face)
|
||||||
|
|
||||||
|
def roll(self):
|
||||||
|
self.face = randint(1, 6)
|
||||||
|
return self.face
|
||||||
12
display.py
Normal file
12
display.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class BG:
|
||||||
|
|
||||||
|
def __init__(self, position, name):
|
||||||
|
self.position = position
|
||||||
|
self.name = name
|
||||||
|
self.draw_bg()
|
||||||
|
|
||||||
|
def draw_bg(self):
|
||||||
|
bg1 = "-"
|
||||||
|
bg2= "|"
|
||||||
|
bg = bg1 + bg2 + bg2 + bg1
|
||||||
|
return bg
|
||||||
@@ -18,7 +18,7 @@ Display roll button for each team with an indicator for whose turn it is.
|
|||||||
Recalculate and display score after each roll.
|
Recalculate and display score after each roll.
|
||||||
|
|
||||||
Milestones -
|
Milestones -
|
||||||
1. Start with a display of three blank dice on the screen and a roll button as well as non-functioning Score display.
|
1. Start with a screen and a roll button as well as non-functioning Score display.
|
||||||
2. When the roll button is pressed, the dice are rolled and a value is displayed on them.
|
2. When the roll button is pressed, the dice are rolled and a value is displayed on them.
|
||||||
3. A change in turn changes the label over the button to the appropriate team and player - Team 1 player 1 - Team 2 player 2 - Team 1 player 3 Team 2 player 4 so they know who should press the "roll" button.
|
3. A change in turn changes the label over the button to the appropriate team and player - Team 1 player 1 - Team 2 player 2 - Team 1 player 3 Team 2 player 4 so they know who should press the "roll" button.
|
||||||
4. Later phases would populate the score and determine Buncos and Winners.
|
4. Later phases would populate the score and determine Buncos and Winners.
|
||||||
|
|||||||
51
roll.py
Normal file
51
roll.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
from retro.game import Game
|
||||||
|
from random import randint
|
||||||
|
import config
|
||||||
|
|
||||||
|
class Die:
|
||||||
|
#rolls a die and returns the result for display
|
||||||
|
color = "white_on_black"
|
||||||
|
def __init__(self, position, name):
|
||||||
|
self.position = position
|
||||||
|
self.name = name
|
||||||
|
self.roll_die()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.face)
|
||||||
|
|
||||||
|
def roll_die(self):
|
||||||
|
self.face = randint(1, 6)
|
||||||
|
self.character = str(self.face)
|
||||||
|
|
||||||
|
|
||||||
|
class Roller:
|
||||||
|
display = False
|
||||||
|
|
||||||
|
def handle_keystroke(self, keystroke, game):
|
||||||
|
if keystroke == " ":
|
||||||
|
|
||||||
|
die1 = game.get_agent_by_name("die1")
|
||||||
|
die1.roll_die()
|
||||||
|
die2 = game.get_agent_by_name("die2")
|
||||||
|
die2.roll_die()
|
||||||
|
die3 = game.get_agent_by_name("die3")
|
||||||
|
die3.roll_die()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
three_dice = [1,3,4]
|
||||||
|
roll_score = score.RollScore().get_score(three_dice, game.state['Current Round'])
|
||||||
|
print (roll_score)
|
||||||
|
|
||||||
|
if roll_score < 21:
|
||||||
|
#is the round over?
|
||||||
|
if game.state['Current Team'] == 1:
|
||||||
|
#Add the score for the roll to the approriate team
|
||||||
|
game.state['Blue Team Score'] += roll_score
|
||||||
|
else:
|
||||||
|
game.state['Red Team Score'] += roll_score
|
||||||
|
else:
|
||||||
|
game.end()"""
|
||||||
97
score.py
Normal file
97
score.py
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
from retro.game import Game
|
||||||
|
import config
|
||||||
|
import bunco
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
class Score:
|
||||||
|
def score_display(self, team):
|
||||||
|
score = RollScore.get_score()
|
||||||
|
|
||||||
|
|
||||||
|
class RollScore:
|
||||||
|
# takes the values from three rolled die and returns the score for the roll
|
||||||
|
def get_score(self, dice, round_number):
|
||||||
|
score = 0
|
||||||
|
|
||||||
|
for die in dice:
|
||||||
|
if die.face == round_number:
|
||||||
|
score += round_number
|
||||||
|
if score == score/round_number:
|
||||||
|
#bunco
|
||||||
|
score += 21
|
||||||
|
if ThreeDice.is_three_of_a_kind() == True:
|
||||||
|
score += 5
|
||||||
|
|
||||||
|
return score
|
||||||
|
|
||||||
|
|
||||||
|
class ThreeDice:
|
||||||
|
def __init__(self):
|
||||||
|
self.dice = [Die() for number in range(3)]
|
||||||
|
|
||||||
|
def roll(self):
|
||||||
|
for die in self.dice:
|
||||||
|
die.roll()
|
||||||
|
return self.faces()
|
||||||
|
|
||||||
|
def faces(self):
|
||||||
|
return [die.face for die in self.dice]
|
||||||
|
|
||||||
|
def value_count(self):
|
||||||
|
#will count how many of each kind of dice and return a list of how many of each value
|
||||||
|
count_ones = 0
|
||||||
|
count_twos = 0
|
||||||
|
count_threes = 0
|
||||||
|
count_fours = 0
|
||||||
|
count_fives = 0
|
||||||
|
count_sixes = 0
|
||||||
|
|
||||||
|
for face in self.faces():
|
||||||
|
if face == 1:
|
||||||
|
count_ones += 1
|
||||||
|
if face == 2:
|
||||||
|
count_twos += 1
|
||||||
|
if face == 3:
|
||||||
|
count_threes += 1
|
||||||
|
if face == 4:
|
||||||
|
count_fours += 1
|
||||||
|
if face == 5:
|
||||||
|
count_fives += 1
|
||||||
|
if face == 6:
|
||||||
|
count_sixes += 1
|
||||||
|
counts = {
|
||||||
|
"ones": count_ones,
|
||||||
|
"twos": count_twos,
|
||||||
|
"threes": count_threes,
|
||||||
|
"fours": count_fours,
|
||||||
|
"fives": count_fives,
|
||||||
|
"sixes": count_sixes}
|
||||||
|
# print (counts)
|
||||||
|
return counts
|
||||||
|
|
||||||
|
def is_three_of_a_kind(self):
|
||||||
|
#determine if the dice roll is three of a kind
|
||||||
|
value_count = None
|
||||||
|
value_count = self.value_count()
|
||||||
|
for value in value_count.values():
|
||||||
|
if value > 3:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user