Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Leplat committed Mar 5, 2023
0 parents commit e35eae7
Show file tree
Hide file tree
Showing 596 changed files with 4,083 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: starfighter_battlebook
on:
push:
tags:
- '*'

permissions:
contents: write

env:
config: release # or debug

jobs:
build:
name: Build for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
name: Linux
- os: macos-latest
name: MacOS
- os: windows-latest
name: Windows

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install system dependencies for Ubuntu
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get -y install autoconf libtool libx11-dev libxrandr-dev libxi-dev libudev-dev libgl1-mesa-dev

- name: Install latest CMake and Ninja
uses: lukka/get-cmake@latest

- name: Restore artifacts, or setup vcpkg for building artifacts
uses: lukka/run-vcpkg@v10
with:
vcpkgGitCommitId: 223d33be7d3ec6c3d64381ca37f501b8c87dda6a

- name: Run CMake+vcpkg+Ninja to generate/build
uses: lukka/run-cmake@v10
with:
configurePreset: '${{ env.config }}'
buildPreset: '${{ env.config }}'
buildPresetAdditionalArgs: '[`--target install`, `--config ${{ env.config }}`]'
env:
VCPKG_FORCE_SYSTEM_BINARIES: 1

- name: Create Zip files (Linux and MacOS)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: |
pushd bin/StarfighterBattlebook
zip -qr ../../StarfighterBattlebook-${{ matrix.name }}.zip .
popd
pushd bin/StarfighterBattlebookServer
zip -qr ../../StarfighterBattlebookServer-${{ matrix.name }}.zip .
popd
- name: Create Zip files (Windows)
if: matrix.os == 'windows-latest'
run: |
pushd bin\StarfighterBattlebook
7z a ..\..\StarfighterBattlebook-${{ matrix.name }}.zip .
popd
pushd bin\StarfighterBattlebookServer
7z a ..\..\StarfighterBattlebookServer-${{ matrix.name }}.zip .
popd
- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
StarfighterBattlebook-${{ matrix.name }}.zip
StarfighterBattlebookServer-${{ matrix.name }}.zip
draft: false
prerelease: false
generate_release_notes: true
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
build
vcpkg
vcpkg_installed
bin
.vscode/*
53 changes: 53 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.19)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")

project(StarfighterBattlebook VERSION 1.0
LANGUAGES CXX)

if (MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()

set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2.5 COMPONENTS audio network graphics window system REQUIRED)
find_package(Threads)

add_subdirectory(src)
add_subdirectory(include)

add_subdirectory(ui)
target_link_libraries(StarfighterBattlebook PUBLIC Ui)

add_subdirectory(server)
target_link_libraries(StarfighterBattlebook PUBLIC Server)

add_subdirectory(utils)
target_link_libraries(StarfighterBattlebook PUBLIC Utils)

FILE(COPY res DESTINATION "${CMAKE_BINARY_DIR}")
install(DIRECTORY res DESTINATION StarfighterBattlebook)
install(DIRECTORY server/res DESTINATION StarfighterBattlebook)
if (WIN32)
install(TARGETS StarfighterBattlebook
RUNTIME_DEPENDENCIES
PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-" "hvsifiletrust.dll" "wpaxholder.dll"
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
DESTINATION StarfighterBattlebook
)
endif()

FILE(COPY server/res DESTINATION "${CMAKE_BINARY_DIR}")
install(DIRECTORY server/res DESTINATION StarfighterBattlebookServer)
if (WIN32)
install(TARGETS StarfighterBattlebookServer
RUNTIME_DEPENDENCIES
PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-" "hvsifiletrust.dll" "wpaxholder.dll"
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
DESTINATION StarfighterBattlebookServer
)
endif()
31 changes: 31 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version": 3,
"configurePresets": [
{
"name": "debug",
"binaryDir": "${sourceDir}/build/debug",
"installDir": "${sourceDir}/bin",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"binaryDir": "${sourceDir}/build/release",
"installDir": "${sourceDir}/bin",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "release",
"configurePreset": "release"
}
]
}
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Léo Leplat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Starfigher Battle Book

The **Star Wars: Starfighter Battle Book** is a in-cockpit flight simulation game using the page-flipping Ace of Aces game format, made in 1989 by West End Games. You can find more information on the book [here](https://boardgamegeek.com/boardgame/3152/star-wars-starfighter-battle-book).

<p align="center"><img src="./res/game.png" width="200"></p>

As the book has become quite rare and expensive, I created a video game version that uses the visual aspect of it. Two players can compete locally or online. The game runs on Linux, Windows, and MacOS.

## Installation

* Go to the latest [release page](https://github.com/Rylern/test/releases/latest), download and unzip one of the file corresponding to your operating system:
* *StarfighterBattlebook-Linux.zip* for Linux.
* *StarfighterBattlebook-Windows.zip* for Windows.
* *StarfighterBattlebook-MacOS.zip* for MacOS.
* Double click on the *StarfighterBattlebook* executable file.

## Usage
The game uses the client-server architecture, which means that one of the player will have to **host** the game, and the other player will have to **join** the hosted game.

* To play locally (on the same network):
* One player has to host the game by clicking on *Host game*. He then needs to find his local IP address. You can find instructions on how to get the local IP address on this [link](https://www.med.unc.edu/it/guide/operating-systems/how-do-i-find-the-host-name-ip-address-or-physical-address-of-my-machine/) for Windows, and [here](https://www.ionos.com/digitalguide/hosting/technical-matters/get-linux-ip-address/) for Linux and MacOS (on the *Displaying a private IP address in Linux* part).
* The other player has to join the previously hosted game, by clicking on *Join game*, writing the local IP address of the host, and clicking on *Connect*.
* To play online (on a different network):
* One player has to set up port forwarding on his/her router. The procedure depends on each router, but you can find instructions [here](https://www.belkin.com/support-article/?articleNum=10790). The port to forward is **55001** (**TCP**). Port forwarding may also have to been done on the firewall of the host computer.
* The player who set up port forwarding has to host the game by clicking on *Host game*. He then has to find his/her IPv4 address by visiting [this website](https://whatismyipaddress.com/) for example.
* The other player has to join the previously hosted game, by clicking on *Join game*, writing the IP address of the host, and clicking on *Connect*.

You also have the possibility to host a game from a remote server. To do this, grab the _StarfighterBattlebookServer-*.zip_ file from the latest release and run the *StarfighterBattlebookServer* file from a console. On this server, you also have to set up port forwarding as described above.

## Development
The game is a **C++** application using:
* The [Simple and Fast Multimedia Library (SFML)](https://www.sfml-dev.org/index-fr.php) library for everything related to graphics, audio, and network.
* [Cmake](https://cmake.org/) for the compilation process.
* [vcpkg](https://vcpkg.io/en/index.html) for acquiring and managing libraries (which actually only consists of SFML).
* [GitHub Actions](https://docs.github.com/en/actions) for automatically deploying and releasing the application.

The game also use images of the *Star Wars: Starfighter Battle Book*, and sound effects and musics of the original *Star Wars* trilogy. As I don't own any rights on these resources, I can unpublish them if requested.

To build the application (on Linux, the process should be similar on Windows and MacOS):
* Download C++ development tools (e.g. *g++*) and CMake.
* Run the following commands (in the project directory):
```
git clone https://github.com/Microsoft/vcpkg.git
./vcpkg/bootstrap-vcpkg.sh
vcpkg/vcpkg install
sudo apt-get -y install autoconf libtool libx11-dev libxrandr-dev libxi-dev libudev-dev libgl1-mesa-dev pkg-config # on Ubuntu
# release can be replaced by debug
cmake --preset=release
cmake --build --preset=release --target install --config release
```

After the build, the game can be found in the *bin/StarfighterBattlebook* directory, and the server in the *bin/StarfighterBattlebookServer* directory.

The code is organized as follow:
* The *server* folder contains the code for the *StarfighterBattlebookServer* executable, as well as the *Server* internal library used by the *StarfighterBattlebook* executable. This library handles the creation of the server when a player clicks on "Host game".
* The *utils* folder contains the code for the *Utils* internal library used by the *StarfighterBattlebook* executable. This library contains one utility function.
* The *ui* folder contains the code for the *Ui* internal library used by the *StarfighterBattlebook* executable. This library contains several classes to easily draw UI elements.
* The *include* folder contains the header files of the *StarfighterBattlebook* executable.
* The *src* folder contains the source files of the *StarfighterBattlebook* executable.
7 changes: 7 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
target_include_directories(StarfighterBattlebook PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_include_directories(StarfighterBattlebook PUBLIC ${PROJECT_BINARY_DIR}/include)

configure_file (
"${PROJECT_SOURCE_DIR}/include/version.hpp.in"
"${PROJECT_BINARY_DIR}/include/version.hpp"
)
25 changes: 25 additions & 0 deletions include/client.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef CLIENT_H
#define CLIENT_H

#include <SFML/Network.hpp>
#include <thread>
#include <future>
#include "msgqueue.hpp"

class Client {

public:
Client(MsgQueue<std::string>& msgQueue, std::string ip);
~Client();
void checkForMessages();
void sendMessage(std::string message);
private:
static const int PORT = 55001;
MsgQueue<std::string>* msgQueue;
sf::TcpSocket socket;
std::thread thread;
};



#endif
45 changes: 45 additions & 0 deletions include/endgame.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef ENDGAME_H
#define ENDGAME_H

#include "layout.hpp"
#include "button.hpp"
#include "image.hpp"
#include "msgqueue.hpp"
#include "game.hpp"


enum GameResult {
DRAW,
WIN,
LOSE
};


class EndGame: public Ui::Layout {

public:
EndGame(MsgQueue<std::string>& msgQueue, Widget* parent = nullptr);
~EndGame();
void handleEvent(const sf::Event& event);
void setResult(GameResult gameResult, std::string team);

private:
inline static const std::string DRAW_PAGE = "223";
inline static const std::string WIN_PAGE_REBELLION = "16";
inline static const std::string WIN_PAGE_EMPIRE = "2";
inline static const std::string LOSE_PAGE_REBELLION = "2";
inline static const std::string LOSE_PAGE_EMPIRE = "16";
MsgQueue<std::string>* msgQueue;

Ui::Image cockpit;
Ui::Layout buttons;
Ui::Button restart;
Ui::Button quit;

void restartClicked();
void quitClicked();
};



#endif
Loading

0 comments on commit e35eae7

Please sign in to comment.