diff --git a/PROJECT.py b/PROJECT.py new file mode 100644 index 0000000..3946d4d --- /dev/null +++ b/PROJECT.py @@ -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() \ No newline at end of file diff --git a/google/db.sqlite3 b/google/db.sqlite3 new file mode 100644 index 0000000..499e81c Binary files /dev/null and b/google/db.sqlite3 differ diff --git a/google/google/__pycache__/__init__.cpython-36.pyc b/google/google/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..a54d80c Binary files /dev/null and b/google/google/__pycache__/__init__.cpython-36.pyc differ diff --git a/google/google/__pycache__/settings.cpython-36.pyc b/google/google/__pycache__/settings.cpython-36.pyc new file mode 100644 index 0000000..1dcf3fe Binary files /dev/null and b/google/google/__pycache__/settings.cpython-36.pyc differ diff --git a/google/google/__pycache__/urls.cpython-36.pyc b/google/google/__pycache__/urls.cpython-36.pyc new file mode 100644 index 0000000..9216f3a Binary files /dev/null and b/google/google/__pycache__/urls.cpython-36.pyc differ diff --git a/google/google/__pycache__/views.cpython-36.pyc b/google/google/__pycache__/views.cpython-36.pyc new file mode 100644 index 0000000..3abcdbe Binary files /dev/null and b/google/google/__pycache__/views.cpython-36.pyc differ diff --git a/google/google/home.html b/google/google/home.html new file mode 100644 index 0000000..19fb2c6 --- /dev/null +++ b/google/google/home.html @@ -0,0 +1,9 @@ +{% extends "layout.html" %} + +{% block content %} + {% if user.is_authenticated %} +

Hello, {{ user.username }}

+ {% else %} + Log in + {% endif %} +{% endblock content %} \ No newline at end of file diff --git a/google/google/login.html b/google/google/login.html new file mode 100644 index 0000000..26b0d7f --- /dev/null +++ b/google/google/login.html @@ -0,0 +1,14 @@ +{% extends "layout.html" %} + + +{% block content %} +

Login

+
+ {% csrf_token %} + {{ form.as_p }} + +
+
+

-- OR --

+ Login with Google
+{% endblock %} \ No newline at end of file diff --git a/google/google/settings.py b/google/google/settings.py new file mode 100644 index 0000000..5a97362 --- /dev/null +++ b/google/google/settings.py @@ -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' diff --git a/google/google/urls.py b/google/google/urls.py new file mode 100644 index 0000000..ca49269 --- /dev/null +++ b/google/google/urls.py @@ -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'), +] diff --git a/google/google/views.py b/google/google/views.py new file mode 100644 index 0000000..22055d5 --- /dev/null +++ b/google/google/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render + + +def home(request): + return render(request, 'home.html') diff --git a/google/google/wsgi.py b/google/google/wsgi.py new file mode 100644 index 0000000..ef37710 --- /dev/null +++ b/google/google/wsgi.py @@ -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() diff --git a/google/manage.py b/google/manage.py new file mode 100644 index 0000000..04ce98f --- /dev/null +++ b/google/manage.py @@ -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)