Merge pull request 'Polishing' (#11) from kyler/polishing into master
Reviewed-on: #11
This commit is contained in:
commit
d456aefe8b
|
@ -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.
|
38
README.md
38
README.md
|
@ -1,7 +1,43 @@
|
||||||
# CS 2450 Final Project
|
# CS 2450 Final Project
|
||||||
*Kyler Olsen* - *Spring 2025*
|
*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)
|
- 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)
|
- 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 to install the required python modules.
|
||||||
|
|
||||||
|
```$ pip install -r requirements.txt```
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
The following command to run the server.
|
||||||
|
|
||||||
|
```$ python3 main.py -s```
|
||||||
|
|
||||||
|
The following command to 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] [-b]
|
||||||
|
|
||||||
|
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)
|
||||||
|
-b, --bible-only Run in bible-only mode (for server)
|
||||||
|
```
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Library:
|
||||||
def serve_forever(self):
|
def serve_forever(self):
|
||||||
try:
|
try:
|
||||||
print(f"Starting server at {self.__host}:{self.__port}")
|
print(f"Starting server at {self.__host}:{self.__port}")
|
||||||
|
if self.__bible_only: print("Bible-only mode active.")
|
||||||
with self.__socket as s:
|
with self.__socket as s:
|
||||||
s.bind((self.__host, self.__port))
|
s.bind((self.__host, self.__port))
|
||||||
s.listen(1)
|
s.listen(1)
|
||||||
|
|
39
main.py
39
main.py
|
@ -1,4 +1,8 @@
|
||||||
|
# Kyler Olsen
|
||||||
|
# CS 2450 Final Project
|
||||||
|
# Apr 2025
|
||||||
|
|
||||||
|
import argparse
|
||||||
import random
|
import random
|
||||||
|
|
||||||
def name_gen():
|
def name_gen():
|
||||||
|
@ -43,18 +47,41 @@ def name_gen():
|
||||||
|
|
||||||
return random.choice(adjectives).capitalize() + random.choice(animals).capitalize()
|
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
|
from library import Library
|
||||||
lib = Library(host, port)
|
lib = Library(host, port, bible_only=bible_only)
|
||||||
lib.serve_forever()
|
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
|
from ui import UI
|
||||||
|
if not playername: playername = name_gen()
|
||||||
ui = UI(playername, host, port)
|
ui = UI(playername, host, port)
|
||||||
ui.loop()
|
ui.loop()
|
||||||
|
|
||||||
def main():
|
def main(argv):
|
||||||
client(name_gen())
|
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)"
|
||||||
|
)
|
||||||
|
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, bible_only=args.bible_only)
|
||||||
|
else:
|
||||||
|
client(playername=args.playername, host=args.host or 'localhost', port=args.port)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
from sys import argv
|
||||||
|
main(argv)
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
# Kyler Olsen
|
# Kyler Olsen
|
||||||
# Mar 2024
|
# Mar 2024
|
||||||
|
|
||||||
|
# CS 2450 Final Project
|
||||||
|
# Apr 2025
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
__LINKS = {
|
__LINKS = {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
blessed==1.21.0
|
Loading…
Reference in New Issue