From 312752380b3a9fd810c6305330307cc17616efc3 Mon Sep 17 00:00:00 2001 From: BigGamerGary Date: Wed, 23 Nov 2022 21:07:27 +1000 Subject: [PATCH] Black Jack works --- Acronymbot.py | 10 ++++++---- BlackJack.py | 26 ++++++++------------------ __pycache__/BlackJack.cpython-310.pyc | Bin 6701 -> 6759 bytes 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Acronymbot.py b/Acronymbot.py index 966a956..1caa3ca 100644 --- a/Acronymbot.py +++ b/Acronymbot.py @@ -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') \ No newline at end of file diff --git a/BlackJack.py b/BlackJack.py index a3e5a59..770fdb1 100644 --- a/BlackJack.py +++ b/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() diff --git a/__pycache__/BlackJack.cpython-310.pyc b/__pycache__/BlackJack.cpython-310.pyc index 2351a17e4063f15699a044042cfa9a64f1dd75c8..85398a4291f34c1a1469ba9a86d290b194368ca1 100644 GIT binary patch delta 465 zcmZXRJ4*vW6ou!puWWWUn}-+`8zqQfVUZtTVUY!~(8k6p(`dku-AbG#NntDM)Pg|~ z8w&~kg7p3Zd%@C5w1_9Gi>M11cFuS1ox`2G`g2{hg>VVJhmWK=yceOE8{rg}7$JQs zX~Iw(Whfrs=(ebp=R39{mt0u`5XGZf$JQ7Al71A^-H=GqAe6w6lg@yCofBKJxTS2F zYq4k-%pJfZ-Gm)@Q1ejtpyo3b#852Sf`&=^6c?HJ=gR!P@(>Y>=v-OSL+@EOQRy9j zmUeaQFWT3z@F<65jh|Ge^x=Pk-;jkY9g>i3qD&cpy`-%8hgoUgTgpoR82V0WG+Bxv z%fIPl^73%Ka73*Wtd;fjC|Kd%IMA;_SoFpYtI(`mRvB&-eLJ5%z$)y0s+-k?LblX& an7OIfoGE=(eNW$w^&IL@msa%c%<(63#cwzO delta 359 zcmYk2y-LJD6ou#JXOhkC%qFHV3pVa5x*%5j1~#siik*!P2ntG)LW|kLLJQY!uoO)# z7LwX$(ArWITfqldPlCt}oZ^1x+HCHX9ugtFO(V01yJ?|Edo%yI;-$tdYBmys3 zc2v6{)Ud6JhM;dXjs7XGv!6AcnW9zpyQXnLPUJfbX;e-%HAa1@;OPU>0|QAr+}n+?_B%>J@Hus