An implementation of the popular Wordle game using WinUI 3.0 and C++/WinRT
GPL-3.0 License
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:
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:
MVVM
MainPage
code behind handles the construction of the view model and the keyboard 'tapped' event.MainPage
(the view) from the model (Letters
, WordRow
) using the model view (MainViewModel
) as the intermediary.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:
ContentDialog
and a custom MessageBox (this is still a work in progress).MainPage
.LightTheme
setting from local application settings.The project can be downloaded from the GitHub repository in the usual way.
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.
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.
See the open issues for a full list of proposed features (and known issues).
Distributed under the GPL-3.0 License. See LICENSE.md
for more information.
Adam Gladstone - (https://www.linkedin.com/in/adam-gladstone-b6458b156/)
Project Link: https://github.com/Adam-Gladstone/Wordle
Helpful resources