官术网_书友最值得收藏!

Back to the Command Line – Basic Blackjack

Blackjack is a casino game involving just a deck of cards. The aim of the game is to get as close as possible to a hand worth 21 points but go over and you're out!

Number cards are worth their face value, picture cards are worth 10, and an ace is worth either 1 or 11 depending on your other cards. Players are initially dealt two cards and can either choose to hit (receive another card) or stick (submit their current hand).

Players face off against the dealer, who has one card face down and one face up. When all players have chosen to stick or are out (having a hand over 21), the winner is the one with a hand closest to 21.

Why am I telling you about blackjack? Because we're going to make a blackjack game using Tkinter! Not only will this chapter introduce you to powerful widgets, such as the canvas and Frame widgets, but it will also teach something that I come across a lot in the world of GUI programming—having a CLI program and the desire to make it a GUI, but not knowing how.

We will begin with a simple CLI version of blackjack that is playable, then build the interface around it, keeping the core functionality and logic the same.

Within this chapter, we will cover the following topics:

  • What a class is and how to create one in Python
  • How inheritance works
  • How to apply polymorphism
  • Using classes to model aspects of blackjack
  • Creating and exiting a game loop

Before we begin coding our blackjack game, it's important we clear up how object-oriented programming works, since we will need to utilize classes even for the command-line version of our game.

主站蜘蛛池模板: 宣城市| 梁山县| 吉安市| 七台河市| 巴东县| 遵义市| 绥德县| 开化县| 平潭县| 驻马店市| 黄梅县| 青河县| 辉县市| 昭平县| 汉源县| 犍为县| 邵阳县| 耒阳市| 浦县| 建德市| 泰州市| 鄂伦春自治旗| 桂平市| 建昌县| 孟村| 巴中市| 庄浪县| 上饶市| 怀安县| 习水县| 读书| 天等县| 和林格尔县| 房山区| 乐业县| 成安县| 南乐县| 若羌县| 兰溪市| 灵宝市| 晋中市|