Category: Python

  • Creating a Chessboard with Pygame Part 1

    I mentioned recently that I was learning Python. I’m working with a few friends on learning the basics. My background is mostly Objective-C and in recent years, Swift. I also programmed in PHP last year for several months working with Laravel, Lumen, Lighthouse, and GraphQL.

    To learn Python we decided to begin looking at making a chess game using Pygame. This post shows my attempt to get the chessboard on the screen. I opted to store the coordinates of each square in a class along with their size and if they are black or white. I don’t yet know if this is an efficient way, but for now, it’s helping me learn the Python syntax and work with a few nested loops and a multidimensional list.

    (more…)
  • Installing PIP/pygame on macOS

    I recently started to learn Python, and by recently, I mean I started mostly with it today. To get familiar with Python a friend showed me a simple tic-tac-toe tutorial which I saved in to a .py file and tried to run from the terminal. After fixing an error due to a / being inserted on a line-break, all went well, mostly, with the exception of getting the package installer for Python working (pip), and also getting pygame downloaded.

    Running pip install pygame threw an error saying that pip wasn’t found.

    I was sent a command by my friend to download get-pip.py using curl. The instructions are found here.

    curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

    After downloading with curl you can then run:

    python get-pip.py

    This installs pip.

    When done, I had to run the following command to install pygame:

    python -m pip install pygame

    This command is obviously different to the initial pip install pygame command earlier in the tutorial, and perhaps using the command pasted just above this paragraph would have worked all along. I certainly don’t know, but either way, it works now with the commands issued above.

    Hopefully this helps you if you trip up on trying to get pygame setup.