Wordle

An implementation of the popular Wordle game using WinUI 3.0 and C++/WinRT

GPL-3.0 License

Stars
0

About The Project

This project started out as a simple console based clone of the Wordle game. The console application has no graphics, just keyboard input and the console window to output the result of each guess. It is written in C++20 and I used it as a test bed for some of the C++20 features. I was particularly interested in creating a constexpr game. This mostly worked except for the random number generation.

I then decided that it might be nice to add a UI to the project. So, I refactored the original console project into a static library WordleLib, the console application WordleConsole and a test harness WordleTest:

  • WordleLib: contains the core game functionality (i.e. checking the user's guess in terms of the letters and their positions) and the collection of words.
  • WordleConsole: contains the main game loop.
  • WordleTest: contains unit tests for the game functions. It is based on GTest and provides a simple way to check the API.

Finally, on top of WordleLib, I built a WordleWinUI project. This is a Windows Desktop application written in C++/WinRT. It consists of a single page which displays a board of tiles and a keyboard for selecting letters.

This project demonstrates:

  • XAML:

    • Using the ItemsRepeater to display the keyboard rows and keys.
    • Using a nested DataTemplate with an ItemsRepeater to display the grid.
    • Using DataTemplate's to simplify applying styles to controls.
  • MVVM

    • The MainPage code behind handles the construction of the view model and the keyboard 'tapped' event.
    • Separation of the MainPage (the view) from the model (Letters, WordRow) using the model view (MainViewModel) as the intermediary.
    • The MainViewModel handles initialising the game and processing the game turns. The underlying WordleLib handles the selection of the target word, retrieving results and checking if the game is won/lost.
  • C++/WinRT:

    • Resizing the main application window; setting an application icon.
    • Using Package.appxmanifest to generate icons for the taskbar.
    • Defining models using MIDL3.0, and providing implementations and type conversions.
    • ContentDialog and a custom MessageBox (this is still a work in progress).
    • Support for Light/Dark mode via a toggle button on the MainPage.
    • Support for persisting and retrieving the LightTheme setting from local application settings.

Built With

  • Visual Studio 2022
  • C++20
  • C++/WinRT
  • WinUI 3.0

Getting Started

The project can be downloaded from the GitHub repository in the usual way.

Prerequisites

Installation

Usage

WordleConsole

The console application (and the static WordleLib) is small: only ~200 lines of code. It has a small set of possible words (463). The game begins by the code choosing one word at random (see below). The user then proceeds to make guesses (up to a maximum of 5) using the report from each word to refine his/her guess. The 'report' basically says, for each letter whether the letter is correct in the position (Green), correct but not in that position (Orange) and incorrect (Grey). There are only two outcomes: you guess the word (in up to 5 guesses) or you lose.

The console application allows you to play the game.

Of course, there is a 'cheat' mode that allows you to display the target word.

WordleWinUI

The intention of WordleWinUI was to use both WinUI 3.0 and XAML for the UI, but more importantly to write a Windows Desktop application in C++/WinRT. A more natural choice may have been to use C# (and I'm certain the development would have been easier). However, the underlying WordleLib is written in C++20 and I did not want to wrap this with a Windows Runtime Component in order to use C# (as I have done in the past in the Software Interoperability project).

The screenshots below show a couple of typical game turns.

Roadmap

See the open issues for a full list of proposed features (and known issues).

License

Distributed under the GPL-3.0 License. See LICENSE.md for more information.

Contact

Adam Gladstone - (https://www.linkedin.com/in/adam-gladstone-b6458b156/)

Project Link: https://github.com/Adam-Gladstone/Wordle

Acknowledgments

Helpful resources

Badges
Extracted from project README
Issues GPL-3 License LinkedIn
Related Projects