Skip to content

Commit bf10bb3

Browse files
authored
Add files via upload
Signed-off-by: Bubbles The Dev <152947339+KernFerm@users.noreply.github.com>
1 parent e6071b7 commit bf10bb3

File tree

6 files changed

+216
-0
lines changed

6 files changed

+216
-0
lines changed

War-Card-Game-Linux+MacOs/LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
MIT License
2+
3+
Copyright (c) 2025 bubblesthedev
4+
5+
This license applies to the Card Game War project, including all source code, assets, and documentation contained in this repository.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Card Game War
2+
3+
![Python](https://img.shields.io/badge/Python-3.11.9-blue?logo=python)
4+
![Windows](https://img.shields.io/badge/Windows-Supported-blue?logo=windows)
5+
![Cross-Platform](https://img.shields.io/badge/Cross--Platform-Yes-green?logo=linux)
6+
![Encryption](https://img.shields.io/badge/Security-Fernet-green?logo=lock)
7+
![Pyarmor](https://img.shields.io/badge/Obfuscated-Pyarmor%209.1.9-orange?logo=python)
8+
9+
## 🎮 Overview
10+
11+
Welcome to the Card Game War project! This project provides a secure, cross-platform implementation of the classic card game "War" with a graphical interface and encrypted results storage.
12+
13+
14+
**How it works:**
15+
- Key files (`war.py`, etc.) are obfuscated and require the `pyarmor_runtime_007668` runtime folder to run.
16+
- The runtime is included in the project and loaded automatically.
17+
- This helps protect your code and intellectual property.
18+
19+
**How to use:**
20+
- Run scripts as usual (e.g., `python war.py`).
21+
- Do not delete or move the `pyarmor_runtime_007668` folder.
22+
23+
24+
| File | Purpose |
25+
|---------------------|------------------------------------------------------------------------|
26+
| `war.py` | Main GUI for playing War. Handles game logic, encryption, user input. Obfuscated with Pyarmor.|
27+
| `generate_key.py` | Generates a secure Fernet key for encrypting results. |
28+
| `decrypt_results.py`| Decrypts and reads the encrypted results file. |
29+
| `win-results.json` | Stores encrypted game results. |
30+
| `win-results.key` | Stores the Fernet encryption key. |
31+
32+
## 🚀 How to Use
33+
34+
35+
### 1️⃣ Setup
36+
1. **Install Python 3.8+**
37+
38+
#### 🪟 Windows
39+
- Download Python from the official website: [python.org/downloads](https://www.python.org/downloads/windows/)
40+
- Run the installer and check "Add Python to PATH" during setup.
41+
- Verify installation:
42+
```powershell
43+
python --version
44+
```
45+
46+
47+
#### 🐧 Linux
48+
- Most Linux systems already come with Python pre-installed. You can use the default version that comes with your distribution.
49+
- To check your Python version:
50+
```bash
51+
python3 --version
52+
```
53+
- If you need to install or upgrade Python, use your package manager (example for Ubuntu/Debian):
54+
```bash
55+
sudo apt update
56+
sudo apt install python3 python3-pip
57+
python3 --version
58+
```
59+
60+
#### 🍎 macOS
61+
- Download Python from [python.org/downloads](https://www.python.org/downloads/macos/)
62+
- Or use Homebrew:
63+
```bash
64+
brew install python
65+
python3 --version
66+
```
67+
68+
2. Install required packages:
69+
```bash
70+
pip install -r requirements.txt
71+
```
72+
73+
### 2️⃣ Generate Encryption Key
74+
Run the key generator:
75+
```bash
76+
python generate_key.py
77+
```
78+
79+
80+
### 3️⃣ Play the Game
81+
Start the GUI:
82+
```bash
83+
python war.py --gui
84+
```
85+
86+
### 🖥️ Play the Console Version
87+
To play the classic text-based version in your terminal:
88+
```bash
89+
python war.py
90+
```
91+
92+
### 4️⃣ View Results
93+
Decrypt and view results:
94+
```bash
95+
python decrypt_results.py
96+
```
97+
98+
99+
## 🖥️ Windows Quick Start
100+
Double-click `run.bat` to:
101+
- Generate the key (if missing)
102+
- Choose to play the GUI or Console version from a menu
103+
104+
## 🏁 Cross-Platform Support
105+
All `.py` files use `os` and `sys` for path handling and are compatible with Windows, macOS, and Linux. No platform-specific code is used.
106+
107+
## 📝 Notes
108+
- Make sure `win-results.key` and `win-results.json` are in the same directory as the scripts.
109+
- For Linux/macOS, use the same commands in your terminal.
110+
111+
---
112+
Made with ❤️ by the BubblesTheDev!
113+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
import json
3+
from cryptography.fernet import Fernet, InvalidToken
4+
5+
import sys
6+
key_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "win-results.key")
7+
results_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "win-results.json")
8+
9+
def error(msg):
10+
print(f"[ERROR] {msg}")
11+
exit(1)
12+
13+
# Check file existence
14+
if not os.path.exists(key_path):
15+
error("Key file does not exist.")
16+
if not os.path.exists(results_path):
17+
error("Results file does not exist.")
18+
19+
with open(key_path, "rb") as kf:
20+
key = kf.read()
21+
if len(key) != 44:
22+
error("Key file is not a valid Fernet key (44 bytes).")
23+
try:
24+
fernet = Fernet(key)
25+
except Exception:
26+
error("Key is not a valid Fernet key.")
27+
28+
with open(results_path, "rb") as rf:
29+
encrypted = rf.read()
30+
if not encrypted:
31+
error("Results file is empty.")
32+
try:
33+
decrypted = fernet.decrypt(encrypted)
34+
except InvalidToken:
35+
error("Failed to decrypt results: Invalid key or corrupted file.")
36+
except Exception as e:
37+
error(f"Failed to decrypt results: {e}")
38+
try:
39+
data = json.loads(decrypted)
40+
except Exception:
41+
error("Decrypted data is not valid JSON.")
42+
if not isinstance(data, list):
43+
error("Decrypted results is not a list.")
44+
print(json.dumps(data, indent=2))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
import os
3+
import sys
4+
from cryptography.fernet import Fernet
5+
6+
key_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "win-results.key")
7+
8+
def error(msg):
9+
print(f"[ERROR] {msg}")
10+
exit(1)
11+
12+
# Security: refuse to write to symlink or non-regular file
13+
if os.path.exists(key_path):
14+
if os.path.islink(key_path):
15+
error(f"Refusing to overwrite symlink: {key_path}")
16+
if not os.path.isfile(key_path):
17+
error(f"Refusing to overwrite non-regular file: {key_path}")
18+
# Confirm before overwriting
19+
try:
20+
resp = input(f"Key file already exists at {key_path}. Overwrite? (y/N): ").strip().lower()
21+
except EOFError:
22+
resp = 'n'
23+
if resp != 'y':
24+
print("Aborted. Key not overwritten.")
25+
exit(0)
26+
27+
key = Fernet.generate_key()
28+
with open(key_path, "wb") as f:
29+
f.write(key)
30+
print(f"New Fernet key generated and saved to {key_path}.")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
customtkinter==5.2.2
2+
cryptography==46.0.1
3+
pyarmor==9.1.9

War-Card-Game-Linux+MacOs/war.py

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)