Black Jack works
This commit is contained in:
@@ -47,15 +47,17 @@ async def bj(interaction: discord.Interaction):
|
||||
discinput = lambda m: discordInput(interaction, m)
|
||||
discoutput = lambda m: discordOutput(interaction, m)
|
||||
blackJack = BlackJack(discinput, discoutput)
|
||||
blackJack.play_game(100)
|
||||
await interaction.response.send_message("Let's play Black Jack!")
|
||||
await blackJack.play_game(100)
|
||||
|
||||
async def discordInput(interaction: discord.Interaction, message:str):
|
||||
await interaction.response.send_message(message)
|
||||
await interaction.followup.send(message)
|
||||
def check(m):
|
||||
return m.content in ["h", "s"] and m.channel == interaction.channel
|
||||
msg = await client.wait_for('message', check=check)
|
||||
return msg.content
|
||||
|
||||
async def discordOutput(interaction, message):
|
||||
await interaction.response.send_message(message)
|
||||
async def discordOutput(interaction: discord.Interaction, message):
|
||||
await interaction.followup.send(message)
|
||||
|
||||
client.run('NzgwNzg4NDIwMjkzMDM0MDA0.GEKkUB.Bbl09D3lWMGea_mcIESPMLUyGlkW-6N53BPFjI')
|
||||
26
BlackJack.py
26
BlackJack.py
@@ -138,7 +138,7 @@ class BlackJack:
|
||||
gameOver = True
|
||||
return gameOver
|
||||
|
||||
def play_game(self, bet):
|
||||
async def play_game(self, bet):
|
||||
validInput = False
|
||||
gameOver = False
|
||||
playerStood = False
|
||||
@@ -161,9 +161,9 @@ class BlackJack:
|
||||
if gameOver:
|
||||
continue
|
||||
|
||||
self.send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(
|
||||
await self.send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(
|
||||
self.playerHand) + "\n" + "Dealers hand = ??: " + convertNumberToCard(self.dealerHand[0]) + "??")
|
||||
play = self.recv("Hit or Stand? (h/s)")
|
||||
play = await self.recv("Hit or Stand? (h/s)")
|
||||
while not validInput:
|
||||
if play == "h":
|
||||
self.hit()
|
||||
@@ -195,19 +195,19 @@ class BlackJack:
|
||||
if gameOver:
|
||||
continue
|
||||
|
||||
self.send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(self.playerHand) +
|
||||
await self.send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(self.playerHand) +
|
||||
"\n" + "Dealers hand = " + str(getHandTotal(self.dealerHand)) + ": " + handNumbersToCards(self.dealerHand))
|
||||
if playerWinState == "w":
|
||||
self.send("You won!")
|
||||
await self.send("You won!")
|
||||
# self.writeLedger(ID, 2*bet, True)
|
||||
elif playerWinState == "l":
|
||||
self.send("You busted!")
|
||||
await self.send("You busted!")
|
||||
# self.writeLedger(ID, -bet, False)
|
||||
elif dealerWinState == "w":
|
||||
self.send("The Dealer reached 21 before you!")
|
||||
await self.send("The Dealer reached 21 before you!")
|
||||
# self.writeLedger(ID, -bet, False)
|
||||
elif dealerWinState == "l":
|
||||
self.send("The Dealer busted before you!")
|
||||
await self.send("The Dealer busted before you!")
|
||||
# self.writeLedger(ID, 2*bet, True)
|
||||
|
||||
def findID(self, ID):
|
||||
@@ -263,13 +263,3 @@ class BlackJack:
|
||||
with open("ledger.txt", "a") as ledger:
|
||||
ledger.write("{ID}:{Money}:0:0\n".format(ID=ID, Money=starterCash))
|
||||
|
||||
|
||||
def main():
|
||||
terminput = lambda message: input(message)
|
||||
termoutput = lambda message: print(message)
|
||||
bj = BlackJack(terminput, termoutput)
|
||||
bj.play_game(100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user