Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ __pycache__/
local_settings.py
db.sqlite3

tmp
tmp

node_modules/
my_note.md
package-lock.json
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Users\\User\\.virtualenvs\\CS-Build-Week-1-45dnoyNn\\Scripts\\python.exe"
}
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ django-cors-headers = "*"
gunicorn = "*"
django-heroku = "*"
django-rest-api = "*"
dj-database-url = "*"
whitenoise = "*"


[dev-packages]

Expand Down
339 changes: 339 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions adv_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', cast=bool)

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['text-adv-game.herokuapp.com']


# Application definition
Expand Down Expand Up @@ -55,6 +55,7 @@

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand All @@ -63,8 +64,9 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
]

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
ROOT_URLCONF = 'adv_project.urls'

TEMPLATES = [
Expand Down Expand Up @@ -147,7 +149,21 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)


# compression and caching support
# source http://whitenoise.evans.io/en/stable/django.html
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Make sure staticfiles is configured correctly
# source http://whitenoise.evans.io/en/stable/django.html
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')


import django_heroku
django_heroku.settings(locals())
Empty file added adventure/.vscode/settings.json
Empty file.
47 changes: 41 additions & 6 deletions adventure/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,28 @@ def initialize(request):
uuid = player.uuid
room = player.room()
players = room.playerNames(player_id)
return JsonResponse({'uuid': uuid, 'name':player.user.username, 'title':room.title, 'description':room.description, 'players':players}, safe=True)
return JsonResponse({
'uuid': uuid,
'name':player.user.username,
'title':room.title,
'description':room.description,
'players':players},
safe = True)

# GET all rooms
@api_view(["GET"])
def rooms(request):
rooms = Room.objects.all()
result = []
for room in rooms.values():
result.append(room)
return JsonResponse({
'rooms': result}, safe = True)

# @csrf_exempt
@api_view(["POST"])
def move(request):
dirs={"n": "north", "s": "south", "e": "east", "w": "west"}
dirs = {"n": "north", "s": "south", "e": "east", "w": "west"}
reverse_dirs = {"n": "south", "s": "north", "e": "west", "w": "east"}
player = request.user.player
player_id = player.id
Expand All @@ -44,8 +59,8 @@ def move(request):
elif direction == "w":
nextRoomID = room.w_to
if nextRoomID is not None and nextRoomID > 0:
nextRoom = Room.objects.get(id=nextRoomID)
player.currentRoom=nextRoomID
nextRoom = Room.objects.get(id = nextRoomID)
player.currentRoom = nextRoomID
player.save()
players = nextRoom.playerNames(player_id)
currentPlayerUUIDs = room.playerUUIDs(player_id)
Expand All @@ -54,14 +69,34 @@ def move(request):
# pusher.trigger(f'p-channel-{p_uuid}', u'broadcast', {'message':f'{player.user.username} has walked {dirs[direction]}.'})
# for p_uuid in nextPlayerUUIDs:
# pusher.trigger(f'p-channel-{p_uuid}', u'broadcast', {'message':f'{player.user.username} has entered from the {reverse_dirs[direction]}.'})
return JsonResponse({'name':player.user.username, 'title':nextRoom.title, 'description':nextRoom.description, 'players':players, 'error_msg':""}, safe=True)
return JsonResponse({
'name':player.user.username,
'title':nextRoom.title,
'description':nextRoom.description,
'players':players,
'error_msg':""},
safe = True)
else:
players = room.playerNames(player_id)
return JsonResponse({'name':player.user.username, 'title':room.title, 'description':room.description, 'players':players, 'error_msg':"You cannot move that way."}, safe=True)
return JsonResponse({
'name':player.user.username,
'title':room.title,
'description':room.description,
'players':players,
'error_msg':"You cannot move that way."},
safe = True)


# STRETCH GOAL
@csrf_exempt
@api_view(["POST"])
def say(request):
# IMPLEMENT
return JsonResponse({'error':"Not yet implemented"}, safe=True, status=500)


@csrf_exempt
@api_view(["GET"])
def rooms(request):
room = Room.objects.all().values()
return JsonResponse({'rooms': list(room) }, safe=True)
3 changes: 3 additions & 0 deletions adventure/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def playerNames(self, currentPlayerID):
def playerUUIDs(self, currentPlayerID):
return [p.uuid for p in Player.objects.filter(currentRoom=self.id) if p.id != int(currentPlayerID)]

# def __str__(self):
# return self.title


class Player(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
Expand Down
1 change: 1 addition & 0 deletions adventure/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
url('init', api.initialize),
url('move', api.move),
url('say', api.say),
url('rooms', api.rooms)
]
1 change: 0 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

urlpatterns = [
path('', include('rest_auth.urls')),
# path('', views.home, name='blog-home'),
path('registration/', include('rest_auth.registration.urls')),
]
17 changes: 16 additions & 1 deletion my_note.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@
- pip install django-heroku
- pip install django-cors-headers
- pip install django-rest-auth
- pip install django-allauth
- pip install django-allauth


## Deploy on Heroko
Ann's path for Heroku
- `./node_modules/heroku/bin/run`
- run `pip freeze` and coppy everything
- create `reauirements.txt` and paste
- `git init` create gitignore
-

- `herohu addons` check if we have heroku database
- `heroku run python manage.py migrate` migrate to posgres
- `heroku run bash`
- `python manage.py createsuperuser`
- `python manage.py shell` do the magic
24 changes: 24 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
asgiref==3.2.3
astroid==2.3.3
autopep8==1.4.4
certifi==2019.11.28
colorama==0.4.1
decouple==0.0.7
Django==3.0.1
django-crispy-forms==1.8.1
isort==4.3.21
lazy-object-proxy==1.4.3
mccabe==0.6.1
Pillow==7.0.0
pipenv==2018.11.26
pycodestyle==2.5.0
pylint==2.4.4
pylint-django==2.0.13
pylint-plugin-utils==0.6
python-decouple==3.3
pytz==2019.3
six==1.13.0
sqlparse==0.3.0
virtualenv==16.7.8
virtualenv-clone==0.5.3
wrapt==1.11.2
6 changes: 3 additions & 3 deletions util/sample_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ def print_rooms(self):


w = World()
num_rooms = 44
width = 8
height = 7
num_rooms = 100
width = 10
height = 10
w.generate_rooms(width, height, num_rooms)
w.print_rooms()

Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1