This is a modified, two-player Tic Tac Toe game written in C and GTK+3. It runs in two instances communicating with each other through local files.
You can run it by downloading the compiled build from builds/
folder or by compiling from source. Provided binaries might still require having GTK installed though.
There are two types of moves you can make:
- Click an empty square to place your piece on top of the selected column.
- Click a filled square to move the piece from the column's bottom to it's top, then place your piece on top of the selected column.
First player to get 4 or 5 (chosen at the start of the game) of his own pieces in a row, column or a diagonal wins.
The project is split into following modules (inside src/
directory)
app
handles initializing the window and loading theUITemplate.glade
withstyle.css
. It also exposes functions to show/hide all pages.connection
takes care of sending and receiving messages between two instances of the program by writing and reading to a file (both instances need to run in the same directory). It useslin_fifo.c
orwin_fifo.c
as a backend on Linux and Windows appropriately.constants
stores useful constants and enums including strings passed between program instances as messages.game
initializes the gameplay page and handles gameplay logic. It uses two submodules:game_utils
with functions checking the game's winner and a few smaller board utilities.game_gtk_utils
with utility functions for interacting with GTK objects.
how_to_play
initializes the "how to play" page.lobby
initializes the lobby page and handles logic for connecting players with chosen number of elements to win.menu
initializes the menu page.modals
include logic for showing popup windows (for instance when the game ends).
Also, inside resources/
there are:
UITemplate.glade
which is a static description of the UI (Created with Glade).style.css
containing basic styles to make the game look more or less the same on different platforms.gresource.xml
which tellsglib
what resources it should include in the project. The resources can be compiled to C by running thecompile_resources.sh
script. The resultingresources.c
is then compiled with the rest of the project.
- Make sure GCC, GTK and CMake are installed. On Ubuntu:
sudo apt-get install gcc
sudo apt-get install libgtk-3-dev
with all dependencies
sudo apt-get install cmake
- Compile resources:
cd resources
./compile_resources.sh
cd ..
- Build the project (inside project's root):
cmake -S . -B cmake-build-debug/
cmake --build cmake-build-debug/ --target Tic_Tac_Toe_C
- Run the game (You should run it in two instances):
cd cmake-build-debug
./Tic_Tac_Toe_C
- Install GCC, GTK and CMake using MSys2 (https://www.gtk.org/docs/installations/windows/)
Especially run:
pacman -S mingw-w64-x86_64-gtk3
pacman -S base-devel mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-cmake
- Add
C:\msys64\mingw64\bin
toPATH
- In
CMakeLists.txt
changeADD_EXECUTABLE(... src/connection/lin_fifo.c ...)
toADD_EXECUTABLE(... src/connection/win_fifo.c ...)
- Compile resources:
cd resources
"C:\msys64\mingw64\bin\glib-compile-resources.exe" gresource.xml --target=resources.c --generate-source
- Build the project (inside project's root):
C:\msys64\mingw64\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/msys64/mingw64/bin/make.exe -DCMAKE_C_COMPILER=C:/msys64/mingw64/bin/gcc.exe -G "CodeBlocks - MinGW Makefiles" .
C:\msys64\mingw64\bin\cmake.exe --build . --target Tic_Tac_Toe_C -- -j 4
- Run the game (You should run it in two instances):
cd cmake-build-debug
Tic_Tac_Toe_C.exe