From 47275971de216c8cf45f8b5d67846d8d24436508 Mon Sep 17 00:00:00 2001 From: Kyler Date: Mon, 28 Apr 2025 17:08:44 -0600 Subject: [PATCH 1/3] Add MIT License and update file headers with project details --- LICENSE | 21 +++++++++++++++++++++ main.py | 3 +++ reference.py | 4 ++++ ui.py | 3 +++ 4 files changed, 31 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..60d8a30 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Kyler Olsen + +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. \ No newline at end of file diff --git a/main.py b/main.py index c28dba5..6123154 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,6 @@ +# Kyler Olsen +# CS 2450 Final Project +# Apr 2025 import random diff --git a/reference.py b/reference.py index 7c4d357..c3859c4 100644 --- a/reference.py +++ b/reference.py @@ -1,5 +1,9 @@ # Kyler Olsen # Mar 2024 + +# CS 2450 Final Project +# Apr 2025 + import re __LINKS = { diff --git a/ui.py b/ui.py index 5ef4b6e..7cf5331 100644 --- a/ui.py +++ b/ui.py @@ -1,3 +1,6 @@ +# Kyler Olsen +# CS 2450 Final Project +# Apr 2025 from client import Player from reference import convert_reference, convert_url -- 2.39.5 From b2f4f699375ad89491cb8cb6741020c8baf7058f Mon Sep 17 00:00:00 2001 From: Kyler Date: Mon, 28 Apr 2025 17:28:25 -0600 Subject: [PATCH 2/3] Enhance README and main.py for improved usability and functionality --- README.md | 36 +++++++++++++++++++++++++++++++++++- main.py | 29 +++++++++++++++++++++++++---- requirements.txt | 1 + 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 requirements.txt diff --git a/README.md b/README.md index 0940e8a..e642b45 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,41 @@ # CS 2450 Final Project *Kyler Olsen* - *Spring 2025* -__Scripture Chase Game__ +## Scripture Chase Game - Repo: [git.purplecello.org/KylerOlsen/CS2450-Final-Project](https://git.purplecello.org/KylerOlsen/CS2450-Final-Project.git) - Mirror: [github.com/KylerOlsen/CS2450-Final-Project](https://github.com/KylerOlsen/CS2450-Final-Project.git) + +## Dependencies + +Python 3.10 or greater is recommended. + +In the root of the repo run this command. +```pip install -r requirements.txt``` + +## Running + +The following command with run the server. + +```python3 main.py -s``` + +The following command with run the client. + +```python3 main.py``` + +Here are the options for running. + +``` +$ python3 main.py -h +usage: main.py [-h] [-s] [-H HOST] [-p PORT] [-n PLAYERNAME] + +Run the server or client. + +options: + -h, --help show this help message and exit + -s, --server Run as server + -H HOST, --host HOST Host address (default: '') + -p PORT, --port PORT Port number (default: 7788) + -n PLAYERNAME, --playername PLAYERNAME + Player name (for client) +``` diff --git a/main.py b/main.py index 6123154..920c9ea 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ # CS 2450 Final Project # Apr 2025 +import argparse import random def name_gen(): @@ -51,13 +52,33 @@ def server(host: str='', port: int=7788): lib = Library(host, port) lib.serve_forever() -def client(playername: str, host: str='localhost', port: int=7788): +def client(playername: str = "", host: str='localhost', port: int=7788): from ui import UI + if not playername: playername = name_gen() ui = UI(playername, host, port) ui.loop() -def main(): - client(name_gen()) +def main(argv): + parser = argparse.ArgumentParser(description="Run the server or client.") + parser.add_argument( + "-s", "--server", action="store_true", help="Run as server" + ) + parser.add_argument( + "-H", "--host", type=str, default="", help="Host address (default: '')" + ) + parser.add_argument( + "-p", "--port", type=int, default=7788, help="Port number (default: 7788)" + ) + parser.add_argument( + "-n", "--playername", type=str, default="", help="Player name (for client)" + ) + args = parser.parse_args(argv[1:]) + + if args.server: + server(host=args.host, port=args.port) + else: + client(playername=args.playername, host=args.host or 'localhost', port=args.port) if __name__ == "__main__": - main() + from sys import argv + main(argv) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2240525 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +blessed==1.21.0 -- 2.39.5 From a4d7279c227039b818cfa5b982de9d3840e3b02b Mon Sep 17 00:00:00 2001 From: Kyler Date: Mon, 28 Apr 2025 17:37:40 -0600 Subject: [PATCH 3/3] Update README and main.py to support bible-only mode and improve command formatting --- README.md | 16 +++++++++------- library.py | 1 + main.py | 9 ++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e642b45..27b58e1 100644 --- a/README.md +++ b/README.md @@ -10,24 +10,25 @@ Python 3.10 or greater is recommended. -In the root of the repo run this command. -```pip install -r requirements.txt``` +In the root of the repo run this command to install the required python modules. + +```$ pip install -r requirements.txt``` ## Running -The following command with run the server. +The following command to run the server. -```python3 main.py -s``` +```$ python3 main.py -s``` -The following command with run the client. +The following command to run the client. -```python3 main.py``` +```$ python3 main.py``` Here are the options for running. ``` $ python3 main.py -h -usage: main.py [-h] [-s] [-H HOST] [-p PORT] [-n PLAYERNAME] +usage: main.py [-h] [-s] [-H HOST] [-p PORT] [-n PLAYERNAME] [-b] Run the server or client. @@ -38,4 +39,5 @@ options: -p PORT, --port PORT Port number (default: 7788) -n PLAYERNAME, --playername PLAYERNAME Player name (for client) + -b, --bible-only Run in bible-only mode (for server) ``` diff --git a/library.py b/library.py index ded1329..ddd7e43 100644 --- a/library.py +++ b/library.py @@ -35,6 +35,7 @@ class Library: def serve_forever(self): try: print(f"Starting server at {self.__host}:{self.__port}") + if self.__bible_only: print("Bible-only mode active.") with self.__socket as s: s.bind((self.__host, self.__port)) s.listen(1) diff --git a/main.py b/main.py index 920c9ea..a508f6c 100644 --- a/main.py +++ b/main.py @@ -47,9 +47,9 @@ def name_gen(): return random.choice(adjectives).capitalize() + random.choice(animals).capitalize() -def server(host: str='', port: int=7788): +def server(host: str='', port: int=7788, bible_only: bool=False): from library import Library - lib = Library(host, port) + lib = Library(host, port, bible_only=bible_only) lib.serve_forever() def client(playername: str = "", host: str='localhost', port: int=7788): @@ -72,10 +72,13 @@ def main(argv): parser.add_argument( "-n", "--playername", type=str, default="", help="Player name (for client)" ) + parser.add_argument( + "-b", "--bible-only", action="store_true", help="Run in bible-only mode (for server)" + ) args = parser.parse_args(argv[1:]) if args.server: - server(host=args.host, port=args.port) + server(host=args.host, port=args.port, bible_only=args.bible_only) else: client(playername=args.playername, host=args.host or 'localhost', port=args.port) -- 2.39.5