From 567d1d39cd62cf202ca260c029a8c5432de9c60f Mon Sep 17 00:00:00 2001 From: hmc-yak-s18 Date: Sun, 4 Mar 2018 00:58:27 -0800 Subject: [PATCH 1/2] outputs player list within x miles --- venv/Main.py | 32 ++++++++++++++++++++++---------- venv/templates/index.html | 11 +++++++++-- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/venv/Main.py b/venv/Main.py index 18857c23..37c96968 100644 --- a/venv/Main.py +++ b/venv/Main.py @@ -248,10 +248,10 @@ def gpsdata(): data = request.data playerID = getID() DATA.playerList[playerID] = {data} - print(playerID) session['playerID'] = playerID - #newDistEntry = updatePlayerMatrix(playerID) - #DATA.distanceMatrix.append(newDistEntry) + newDistEntry = updatePlayerMatrix(playerID) + DATA.distanceMatrix.append(newDistEntry) + players = findUsersWithinXMiles(playerID,500) return "Player is in the database" def getID(): @@ -268,22 +268,35 @@ def updateNumPlayers(): DATA.numPlayers = len(DATA.playerList.keys()) return -''' def updatePlayerMatrix(playerID): +def updatePlayerMatrix(playerID): keyList = list(DATA.playerList.keys()) - print(keyList) if len(keyList) == 1: keyList = [] else: keyList.remove(playerID) - print(keyList) if len(keyList) <= 0: return newPlayerMatrix = [] for i in range (DATA.numPlayers): - print(i) - newPlayerMatrix[i] = calculateDist(playerID,keyList[i]) + newPlayerMatrix.append(calculateDist(playerID,keyList[i])) return newPlayerMatrix - ''' + +def findUsersWithinXMiles(playerID, x): + keyList = list(DATA.playerList.keys()) + playerIndexinMatrix = keyList.index(playerID) + outputPlayers = [] + for i in range (DATA.numPlayers): + if iEnter the Game ID
-
@@ -157,6 +157,12 @@
+

Latitude: ???
+ Longitude: ??? +

+

+ This is a placeholder for the badass goddamn map that will appear here +

@@ -262,6 +268,7 @@ } + \ No newline at end of file From d1170eb5d45862aab800d01c08ed3aedbcc208dc Mon Sep 17 00:00:00 2001 From: hmc-yak-s18 Date: Sun, 4 Mar 2018 05:33:14 -0800 Subject: [PATCH 2/2] finished GPS integreation --- venv/Main.py | 40 ++++++++++++++---- venv/Templates/gameList.html | 80 ++++++++++++++++++++++++++++++++++++ venv/templates/game.html | 7 ---- venv/templates/index.html | 19 ++++----- 4 files changed, 122 insertions(+), 24 deletions(-) create mode 100644 venv/Templates/gameList.html diff --git a/venv/Main.py b/venv/Main.py index 37c96968..b0664470 100644 --- a/venv/Main.py +++ b/venv/Main.py @@ -14,6 +14,10 @@ def index_page(): return render_template('index.html', default_people=DATA.DEFAULT_SIZE) +@app.route('/gameList') +def gameList_page(): + return render_template('gameList.html', filteredGames =DATA.filteredGames) + @app.route('/checkGameOver', methods=["POST"]) def check_game_over(): ''' Given a game ID, checks if the spy was discovered or not based on @@ -27,10 +31,11 @@ def check_game_over(): def new_game(): ''' Creates a new game ''' # make new game - + print('test1') # L[0] = numPlayers # L[1] = isFancy L = request.get_json() + print(L) isFancy = L[1] try: num_players = int(L[0]) @@ -73,7 +78,6 @@ def new_game(): @app.route('/game/') def join_game(id_num): ''' Connects user to existing game - if possible ''' - print(id_num) try: id_num = int(id_num) except: @@ -121,7 +125,7 @@ def __init__(self): self.GAME_CAP = 10 self.DEFAULT_SIZE = 5 self.MAX_SIZE = 100 - + self.activePlayers = {} self.adjectives_list = [] self.colors_list = [] self.locations_dict = {} @@ -131,6 +135,7 @@ def __init__(self): self.playerList = {} self.playerID = 0 self.MAX_PLAYER_ID = 10000 + self.filteredGames = [] def load_json_adjectives(self): ''' Loads all of the adjectives and colors from the external info.JSON @@ -157,8 +162,7 @@ def next_game_id(self): class Game: ''' Each game will be an instance of this object ''' - def __init__(self, num_people, fancy=True, - location_type="random", time_limit=0, location=None): + def __init__(self, num_people, fancy=True, location_type="random", time_limit=0, location=None): ''' Initializer for a new game ''' self.num_people = num_people self.current_players = 0 @@ -192,6 +196,9 @@ def join_game(self, gameid): session['gameid'] = gameid session['userid'] = self.current_players + if 'playerID' in session: + activePlayers[session['playerID']] = {session['gameid']} + # When a new person joins a game, we need to increment the number of # people in the game, and then give them a role that is available @@ -252,7 +259,26 @@ def gpsdata(): newDistEntry = updatePlayerMatrix(playerID) DATA.distanceMatrix.append(newDistEntry) players = findUsersWithinXMiles(playerID,500) - return "Player is in the database" + activeUsers = filterIDs(players) + activeGames = findGames(activeUsers) + return "Player Database Updated" + +def findGames(users): + gameIDs = [] + DATA.filteredGames = [] + for i in range(len(users)): + tempGame = DATA.activePlayers[users[i]] + gameIDs.append(tempGame) + DATA.filteredGames.append(gameIDs[i]) + return gameIDs + + +def filterIDs(users): + activeUsers = [] + for i in range(len(users)): + if users[i] in list(DATA.activePlayers.keys()): + activeUsers.append(users[i]) + return activeUsers def getID(): '''Takes the data variable playerID, assigns it to a user, and @@ -373,4 +399,4 @@ def testing(): DATA.load_json_roles() DATA.debugging = debugging - app.run(host='0.0.0.0') \ No newline at end of file + app.run(host='127.0.0.1') \ No newline at end of file diff --git a/venv/Templates/gameList.html b/venv/Templates/gameList.html new file mode 100644 index 00000000..4768304c --- /dev/null +++ b/venv/Templates/gameList.html @@ -0,0 +1,80 @@ + + + SAD + + + + +

+ Below are the list of games people around you are active in! +

+

Game 1 +

Game 2 +

Game 3 +

Game 4 +

Game 5 +

Game 6 +

Game 7 +

Game 8 +

Game 9 +

Game 10 +

+ + + \ No newline at end of file diff --git a/venv/templates/game.html b/venv/templates/game.html index 9604e01a..78ead6f4 100644 --- a/venv/templates/game.html +++ b/venv/templates/game.html @@ -62,13 +62,6 @@

Enter Your Guess

-

Latitude: ???
- Longitude: ??? -

- -

- This is a placeholder for the badass goddamn map that will appear here -

- \ No newline at end of file