diff --git a/games/hello_world/main.exe b/games/hello_world/main.exe new file mode 100644 index 0000000..60af72f Binary files /dev/null and b/games/hello_world/main.exe differ diff --git a/games/hello_world/main.go b/games/hello_world/main.go new file mode 100644 index 0000000..d2c4e91 --- /dev/null +++ b/games/hello_world/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello world") +} diff --git a/games/metadata.json b/games/metadata.json new file mode 100644 index 0000000..56dc642 --- /dev/null +++ b/games/metadata.json @@ -0,0 +1 @@ +{"gameNames": ["hello_world", "rock_paper_scissors", "simon_says"], "numberOfGames": 3} \ No newline at end of file diff --git a/games/rock_paper_scissors/code.exe b/games/rock_paper_scissors/code.exe new file mode 100644 index 0000000..17587ef Binary files /dev/null and b/games/rock_paper_scissors/code.exe differ diff --git a/games/rock_paper_scissors/code.go b/games/rock_paper_scissors/code.go new file mode 100644 index 0000000..57eccc3 --- /dev/null +++ b/games/rock_paper_scissors/code.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Rock paper scissors"); +} \ No newline at end of file diff --git a/games/simon_says/file.exe b/games/simon_says/file.exe new file mode 100644 index 0000000..31c03e5 Binary files /dev/null and b/games/simon_says/file.exe differ diff --git a/games/simon_says/file.go b/games/simon_says/file.go new file mode 100644 index 0000000..e42e138 --- /dev/null +++ b/games/simon_says/file.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Simon says") +} diff --git a/get_game_data_my_version.py b/get_game_data_my_version.py new file mode 100644 index 0000000..e0db312 --- /dev/null +++ b/get_game_data_my_version.py @@ -0,0 +1,79 @@ +import os +import json +import shutil +from subprocess import PIPE, run +import sys + +GAME_DIR_PATTERNS = "game" + + +def find_all_game_paths(source): + game_paths = [] + for root, dirs, files in os.walk(source): + for directory in dirs: + if directory.endswith(GAME_DIR_PATTERNS): + path = os.path.join(source, directory) + game_paths.append(path) + break + return game_paths + + +def get_names_from_paths(paths, to_strip): + new_names = [] + for path in paths: + _, dir_name = os.path.split(path) + new_dir_name = dir_name.replace(to_strip, "") + new_names.append(new_dir_name) + + return new_names + + +def create_directory(path): + if not os.path.exists(path): + os.mkdir(path) + + +def copy_and_overwrite(source, dest): + if os.path.exists(dest): + shutil.rmtree(dest) + shutil.copytree(source, dest) + + +def make_json_metadata_file(path, game_dirs): + data = { + "gameNames": game_dirs, + "numberOfGames": len(game_dirs) + } + + with open(path, "w") as f: + json.dump(data, f) + + +def main(source, target): + cwd = os.getcwd() + source_path = os.path.join(cwd, source) + target_path = os.path.join(cwd, target) + + game_paths = find_all_game_paths(source_path) + print(f"Game Paths: {game_paths}") + new_game_dir = get_names_from_paths(game_paths, "_game") + print(f"New Games Name: {new_game_dir}") + + create_directory(target_path) + + for src, dest in zip(game_paths, new_game_dir): + dest_path = os.path.join(target_path, dest) + copy_and_overwrite(src, dest_path) + + json_path = os.path.join(target_path, "metadata.json") + make_json_metadata_file(json_path, new_game_dir) + + +if __name__ == "__main__": + args = sys.argv + print(args) + if len(args) < 3: + raise Exception( + "You must provide the path to the game and the output file") + source, target = args[1:] + main(source, target)