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