Skip to content

adding my project #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
136 changes: 136 additions & 0 deletions PROJECT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import random


class game:
dmain = []
name = ""

def __init__(self, name):
self.name = name
def shuffle(self):
random.shuffle(self.dmain)

#block of code to form a deck of 52 cards which will then be distributed
class dmainform:
dmain = []
x=0
def dform(self):
for i in range(4):
for j in range(13):
self.dmain.append(self.x)
self.x+=1
random.shuffle(self.dmain)


class match_a:
nround = 0
nclash = 0
winner = ""
plyrdsub = []
compdsub = []
def __init__(self):
self.distrib()
#code to distribute 26 cards each to player and computer
def distrib(self):
cards = dmainform()
cards.dform()
name = input("Enter Player Name ")
print("\n")
p1 = game(name)
comp = game("Computer")

for i in range(26):
p1.dmain = cards.dmain[: 26]
comp.dmain= cards.dmain[26: 52]


self.plyrdsub = p1.dmain
self.compdsub = comp.dmain
self.playername = p1.name
#actual match takes plae in this code
def startmatch(self):
while self.plyrdsub != [] and self.compdsub != []:
self.nround = self.nround + 1
if self.plyrdsub[0] > self.compdsub[0]:
temp1 = self.plyrdsub[0]
temp2 = self.compdsub[0]
self.plyrdsub = self.plyrdsub[1:]
self.plyrdsub.append(temp1)
self.plyrdsub.append(temp2)
self.compdsub = self.compdsub[1:]

elif self.plyrdsub[0] < self.compdsub[0]:
temp2 = self.plyrdsub[0]
temp1 = self.compdsub[0]
self.compdsub = self.compdsub[1:]
self.compdsub.append(temp1)
self.compdsub.append(temp2)
self.plyrdsub = self.plyrdsub[1:]
else: #code for war
if len(self.plyrdsub) >= 4 and len(self.compdsub) >= 4:
self.nclash = self.nclash + 1
sum1 = self.plyrdsub[1] + self.plyrdsub[2] + self.plyrdsub[3]
sum2 = self.compdsub[1] + self.compdsub[2] + self.compdsub[3]
if sum1 > sum2:
tempa = self.plyrdsub[0]
tempb = self.plyrdsub[1]
tempc = self.plyrdsub[2]
tempd = self.plyrdsub[3]
tempe = self.compdsub[0]
tempf = self.compdsub[1]
tempg = self.compdsub[2]
temph = self.compdsub[3]
self.plyrdsub = self.plyrdsub[4:]
self.plyrdsub.append(tempa)
self.plyrdsub.append(tempb)
self.plyrdsub.append(tempc)
self.plyrdsub.append(tempd)
self.plyrdsub.append(tempe)
self.plyrdsub.append(tempf)
self.plyrdsub.append(tempg)
self.plyrdsub.append(temph)
self.compdsub = self.compdsub[4:]

elif (sum1 < sum2):
tempa = self.plyrdsub[0]
tempb = self.plyrdsub[1]
tempc = self.plyrdsub[2]
tempd = self.plyrdsub[3]
tempe = self.compdsub[0]
tempf = self.compdsub[1]
tempg= self.compdsub[2]
temph = self.compdsub[3]
self.compdsub = self.compdsub[4:]
self.compdsub.append(tempe)
self.compdsub.append(tempf)
self.compdsub.append(tempg)
self.compdsub.append(temph)
self.compdsub.append(tempa)
self.computerdeck.append(tempb)
self.computerdeck.append(tempc)
self.computerdeck.append(tempd)
self.plyrdsub = self.plyrdsub[4:]

else:
self.plyrdsub = self.plyrdsub[4:]
self.compdsub = self.compdsub[4:]

else:
if len(self.plyrdsub) >= 4:
self.winner = "player"
break
elif len(self.compdsub) >= 4:
self.winner = "computer"
break


print("Number of Rounds: " + str(self.nround))
print("Number of Wars: " + str(self.nclash))
if self.plyrdsub == [] or self.winner == "computer":
print("The Computer is the winner")
if self.compdsub == [] or self.winner == "player":
print(str(self.playername) + " is the winner")

#invoking
Game = match_a()
Game.startmatch()
Binary file added google/db.sqlite3
Binary file not shown.
Binary file added google/google/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added google/google/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file added google/google/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file added google/google/__pycache__/views.cpython-36.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions google/google/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "layout.html" %}

{% block content %}
{% if user.is_authenticated %}
<p class="display-4">Hello, {{ user.username }}</p>
{% else %}
<a class="lead" href="{% url 'login' %}">Log in</a>
{% endif %}
{% endblock content %}
14 changes: 14 additions & 0 deletions google/google/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "layout.html" %}


{% block content %}
<h2>Login</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
<br>
<p><strong>-- OR --</strong></p>
<a href="{% url 'social:begin' 'google-oauth2' %}">Login with Google</a><br>
{% endblock %}
134 changes: 134 additions & 0 deletions google/google/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
"""
Django settings for google project.

Generated by 'django-admin startproject' using Django 1.9.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'n#69eg1d740f9@gf274l!455rzl#a5pv7e0q6)$w6qzm&w#6-*'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'social_django'
]

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'google.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
},
]
AUTHENTICATION_BACKENDS = (
'social_core.backends.open_id.OpenIdAuth',
'social_core.backends.google.GoogleOpenId',
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
WSGI_APPLICATION = 'google.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
LOGIN_URL = 'login'
LOGIN_REDIRECT_URL = 'home'

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY ='760967042925-b3k2g3jlf6dqrh8lktjlkvrp1b5i5g8c.apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'EmVZmziKBkmQsgND1SWuMHWx'
28 changes: 28 additions & 0 deletions google/google/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""google URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Import the include() function: from django.conf.urls import url, include
3. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth import views
from .views import home

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^login/$', views.login, name='login'),
url(r'^logout/$', views.logout, name='logout'),
url(r'^auth/', include('social_django.urls', namespace='social')), # <- Here
url(r'^$', home, name='home'),
]
5 changes: 5 additions & 0 deletions google/google/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.shortcuts import render


def home(request):
return render(request, 'home.html')
16 changes: 16 additions & 0 deletions google/google/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for google project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "google.settings")

application = get_wsgi_application()
10 changes: 10 additions & 0 deletions google/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "google.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)