Exemple #1
0
class Main:
    clock = pygame.time.Clock()
    game_exit = False
    white = (255, 255, 255)

    def __init__(self):
        pygame.init()
        pygame.display.set_caption("Gravity")
        self.screen = pygame.display.set_mode(C.size)

        self.entities = Entities(self.screen)
        self.main_loop()

    def main_loop(self):
        self.screen.fill(C.background_color)

        while not self.game_exit:
            self.handle_keys()
            self.screen.set_alpha(75)
            self.screen.set_colorkey(self.white)

            self.draw()
            pygame.display.update()
            self.clock.tick(60)

        quit()
        pygame.quit()

    def handle_keys(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.game_exit = True

    def draw(self):
        self.entities.update()
Exemple #2
0
    def __init__(self):
        pygame.init()
        pygame.display.set_caption("Gravity")
        self.screen = pygame.display.set_mode(C.size)

        self.entities = Entities(self.screen)
        self.main_loop()
Exemple #3
0
 def createEntities(self, collection):
     [
         document.createEntities() for document in collection
         if document.entities.isEmpty()
     ]
     self.entities = Entities('')
     self._addDocumentEntities(collection)
    def Create(self, e):

        id = e.GetId()
        index = self.__ids.index(id)

        o = Entities.CreateString(Entities(index).string)
        o.age = self.__world.age
        o.world = self.__world

        self.__world.AddToWorld(o, self.__index)
Exemple #5
0
 def return_all_posts_for_a_forum(self, forumid):
     connection = mysql.connector.connect(user='******',
                                          password='******',
                                          host='127.0.0.1',
                                          database='smarthealthdb')
     cursor = connection.cursor()
     try:
         cursor.execute("select * from smarthealthdb.post")
         results = cursor.fetchall()
         all_posts = []
         if cursor.rowcount >= 1:
             for row in results:
                 username = row[0]
                 timecreated = row[1]
                 got_forumid = row[2]
                 textentry = row[3]
                 photolocation = row[4]
                 linklocation = row[5]
                 videolocation = row[6]
                 if got_forumid == forumid:
                     post_row = Entities.Post(username, timecreated,
                                              forumid, textentry,
                                              photolocation, linklocation,
                                              videolocation)
                     all_posts.append(post_row)
         connection.commit()
         return all_posts
     except Exception as e:
         raise
     finally:
         cursor.close()
Exemple #6
0
 def read(self, username, timecreated):
     connection = mysql.connector.connect(user='******',
                                          password='******',
                                          host='127.0.0.1',
                                          database='smarthealthdb')
     cursor = connection.cursor()
     try:
         cursor.execute("select * from smarthealthdb.post")
         results = cursor.fetchall()
         forum_row = None
         if cursor.rowcount >= 1:
             for row in results:
                 got_username = row[0]
                 got_timecreated = row[1]
                 forumid = row[2]
                 textentry = row[3]
                 photolocation = row[4]
                 linklocation = row[5]
                 videolocation = row[6]
                 if got_username == username and got_timecreated == timecreated:
                     post_row = Entities.Post(username, timecreated,
                                              forumid, textentry,
                                              photolocation, linklocation,
                                              videolocation)
         connection.commit()
         return post_row
     except Exception as e:
         raise
     finally:
         cursor.close()
Exemple #7
0
def view_post():
    if session.get('logged_in') is None:
        return redirect(url_for('PetCare.login'))
    postDao = PostDao()
    post = postDao.get_post(request.args['postId'])
    postInfo = Entities.make_post_output(dict(post))
    return render_template('view_post.html', post=postInfo)
Exemple #8
0
 def read_datum(self, username):
     myflag = 0
     mydatumlist = []
     con = mysql.connector.connect(user='******',
                                   password='******',
                                   host='127.0.0.1',
                                   database='smarthealthdb')
     cursor = con.cursor(buffered=True)
     try:
         query = ("select * from smarthealthdb.datum")
         cursor.execute(query)
         if cursor.rowcount > 0:
             result = cursor.fetchall()
             for row in result:
                 if row[1] == username:
                     myflag = 1
                     myboj = Entities.Datum(row[0], row[1], row[2], row[3],
                                            row[4])
                     mydatumlist.append(myboj)
             if myflag == 0:
                 return None
             else:
                 return mydatumlist
         else:
             return None
     except Exception as e:
         raise
     finally:
         cursor.close()
Exemple #9
0
 def return_all_forums(self):
     connection = mysql.connector.connect(user='******', password='******', host='127.0.0.1', database='smarthealthdb')
     cursor = connection.cursor()
     try:
         cursor.execute("select * from smarthealthdb.forum")
         results = cursor.fetchall()
         all_forums = []
         if cursor.rowcount >= 1:
             for row in results:
                 forumid = row[0]
                 topic = row[1]
                 url = row[2]
                 summary = row[3]
                 whencreated = row[4]
                 whenclosed = row[5]
                 createdbymoderator_username = row[6]
                 deletedbymoderator_username = row[7]
                 forum_row = Entities.Forum(forumid, topic, url, summary, whencreated, whenclosed,
                                                createdbymoderator_username, deletedbymoderator_username)
                 all_forums.append(forum_row)
         connection.commit()
         return all_forums
     except Exception as e:
         raise
     finally:
         cursor.close()
 def return_all_my_friend_requests(self, my_username):
     connection = mysql.connector.connect(user='******',
                                          password='******',
                                          host='127.0.0.1',
                                          database='smarthealthdb')
     cursor = connection.cursor()
     try:
         cursor.execute("select * from smarthealthdb.friendship")
         my_friendship_requests = []
         results = cursor.fetchall()
         if cursor.rowcount >= 1:
             for row in results:
                 requester_username = row[0]
                 requested_username = row[1]
                 when_requested = row[2]
                 when_withdrawn = row[3]
                 when_rejected = row[4]
                 when_confirmed = row[5]
                 when_unfriended = row[6]
                 if requested_username == my_username and when_confirmed == None and when_unfriended == None and when_rejected == None:
                     friendship_row = Entities.Friendship(
                         requester_username, requested_username,
                         when_requested, when_withdrawn, when_rejected,
                         when_confirmed, when_unfriended)
                     my_friendship_requests.append(friendship_row)
         connection.commit()
         return my_friendship_requests
     except Exception as e:
         raise
     finally:
         cursor.close()
Exemple #11
0
 def return_ratings_for_a_post(self, post_username, post_timecreated):
     connection = mysql.connector.connect(user='******',
                                          password='******',
                                          host='127.0.0.1',
                                          database='smarthealthdb')
     cursor = connection.cursor()
     try:
         cursor.execute(
             "select * from smarthealthdb.rating where post_username = %s "
             "and post_timecreated = %s", (post_username, post_timecreated))
         results = cursor.fetchall()
         ratings = []
         row_count = cursor.rowcount
         if row_count > 0:
             for row in results:
                 post_username = row[0]
                 post_timecreated = row[1]
                 rater_username = row[2]
                 stars = row[3]
                 rating_row = Entities.Rating(post_username,
                                              post_timecreated,
                                              rater_username, stars)
                 ratings.append(rating_row)
         connection.commit()
         return ratings
     except Exception as e:
         raise
     finally:
         cursor.close()
Exemple #12
0
def filter_posts():
	if session.get('logged_in') is None:
		return redirect(url_for('PetCare.login'))

	gender_filter = request.form['gender']
	species_filter = request.form['species']
	age_filter = request.form['age']

	start_date = request.form['start_date']
	end_date = request.form['end_date']
	start_date_value = int(time.mktime(time.strptime(start_date, '%Y-%m-%d'))) if len(start_date) > 0 else 0
	end_date_value = int(time.mktime(time.strptime(end_date, '%Y-%m-%d'))) if len(end_date) > 0 else 0

	accountDao = AccountDao()
	reputation = accountDao.get_account_reputation(session['logged_in'])
	postDao = PostDao()
	all_posts = postDao.list_all_posts(reputation=reputation)

	filtered_posts = []
	for post in all_posts:
		if gender_filter != '-1' and int(gender_filter) != post['gender']:
			continue
		if len(species_filter) > 0 and species_filter != post['species']:
			continue
		if age_filter != '-1' and int(age_filter) != post['age']:
			continue
		if len(start_date) > 0 and post['start_date'] < start_date_value:
			continue
		if len(end_date) > 0 and post['end_date'] > end_date_value:
			continue			
		filtered_posts.append(post)

	postInfos = [Entities.make_post_output(dict(post)) for post in filtered_posts]
	return render_template('list_posts.html', posts=postInfos, fromFilter=True)
 def read_comments_of_post(self, post_username, post_timecreated):
     connection = mysql.connector.connect(user='******',
                                          password='******',
                                          host='127.0.0.1',
                                          database='smarthealthdb')
     cursor = connection.cursor()
     comments = []
     try:
         cursor.execute("select * from smarthealthdb.comment")
         results = cursor.fetchall()
         if cursor.rowcount >= 1:
             for row in results:
                 got_post_username = row[0]
                 got_post_timeCreated = row[1]
                 commenter_username = row[2]
                 commenttime = row[3]
                 commenttext = row[4]
                 photolocation = row[5]
                 linklocation = row[6]
                 videolocation = row[7]
                 if post_username == got_post_username and post_timecreated == got_post_timeCreated:
                     comment_object = Entities.Comment(
                         post_username, post_timecreated,
                         commenter_username, commenttime, commenttext,
                         photolocation, linklocation, videolocation)
                     comments.append(comment_object)
         return comments
     except Exception as e:
         raise
     finally:
         cursor.close()
Exemple #14
0
    def post(self):
        bussiness = (json.loads(self.request.body))
        email = bussiness["email"]
        taxId = bussiness["taxId"]
        name = bussiness["name"]
        address = bussiness["address"]
        city = bussiness["city"]
        state = bussiness["state"]
        postalCode = bussiness["postalCode"]
        amount = int(bussiness["amount"])

        exist = any(b for b in bussinesss if b.ownerEmail == email)
        if exist == 0:
            bussinessEntity = Entities.Bussiness(email, taxId, name, address,
                                                 city, state, postalCode,
                                                 amount)
            bussinesss.append(bussinessEntity)

        message = ""
        if amount > 50000:
            message = "Declined"
        elif amount == 50000:
            message = "Undecided"
        else:
            message = "Approved"

        self.write({'message': message})
Exemple #15
0
 def handle_keys(self, event):
     if event.type == pygame.QUIT:
         self.game_exit = True
     if event.type == pygame.KEYDOWN:
         if event.key == pygame.K_a:
             Constants.A = True
         if event.key == pygame.K_d:
             Constants.D = True
         if event.key == pygame.K_SPACE and len(Entities.player_bullet) < 3:
             Entities.player_shoot_bullet(Entities.player)
         if event.key == pygame.K_w and len(Entities.seism_bomb) < 1:
             Entities.player_shoot_seism_bomb(Entities.player)
     if event.type == pygame.KEYUP:
         if event.key == pygame.K_a:
             Constants.A = False
         if event.key == pygame.K_d:
             Constants.D = False
Exemple #16
0
def load_more_posts():
	if session.get('logged_in') is None:
		return redirect(url_for('PetCare.login'))
	accountDao = AccountDao()
	reputation = accountDao.get_account_reputation(session['logged_in'].rstrip())
	postDao = PostDao()
	posts = postDao.list_limited_posts(reputation=reputation, limit=4, offset=request.args.get('offset'))
	postInfos = [Entities.make_post_output(dict(post)) for post in posts]
	return jsonify(postInfos)
Exemple #17
0
def list_posts():
	if session.get('logged_in') is None:
		return redirect(url_for('PetCare.login'))
	accountDao = AccountDao()
	reputation = accountDao.get_account_reputation(session['logged_in'].rstrip())		
	postDao = PostDao()
	posts = postDao.list_limited_posts(reputation=reputation, limit=4, offset=0)
	postInfos = [Entities.make_post_output(dict(post)) for post in posts]
	return render_template('list_posts.html', posts=postInfos, fromFilter=False)
Exemple #18
0
def list_posts():
    if session.get('logged_in') is None:
        return redirect(url_for('PetCare.login'))
    accountDao = AccountDao()
    reputation = accountDao.get_account_reputation(session['logged_in'])
    postDao = PostDao()
    posts = postDao.list_all_posts(reputation)
    postInfos = [Entities.make_post_output(dict(post)) for post in posts]
    return render_template('list_posts.html', posts=postInfos)
Exemple #19
0
 def read(self, username):
     myflag = 0
     con = mysql.connector.connect(user='******',
                                   password='******',
                                   host='127.0.0.1',
                                   database='smarthealthdb')
     cursor = con.cursor(buffered=True)
     try:
         query = (
             "select a.*,b.karma,b.datecreated from smarthealthdb.user a join smarthealthdb.enduser b on a.username=b.username"
         )
         cursor.execute(query)
         if cursor.rowcount > 0:
             result = cursor.fetchall()
             for row in result:
                 if row[0] == username:
                     read_username = row[0]
                     read_password = row[1]
                     read_email1 = row[2]
                     read_email2 = row[3]
                     read_firstname = row[4]
                     read_lastname = row[5]
                     read_aboutme = row[6]
                     read_photourl1 = row[7]
                     read_photourl2 = row[8]
                     read_photourl3 = row[9]
                     read_street_num = row[10]
                     read_street_name = row[11]
                     read_majormunicipality = row[12]
                     read_governing_district = row[13]
                     read_postal_area = row[14]
                     read_user_type_id = row[15]
                     read_status = row[16]
                     read_karma = row[17]
                     read_date_created = row[18]
                     myflag = 1
             if myflag == 1:
                 read_obj = Entities.EndUser(
                     read_karma, read_date_created, read_username,
                     read_password, read_email1, read_email2,
                     read_firstname, read_lastname, read_aboutme,
                     read_photourl1, read_photourl2, read_photourl3,
                     read_street_num, read_street_name,
                     read_majormunicipality, read_governing_district,
                     read_postal_area, read_user_type_id, read_status)
                 return read_obj
             else:
                 return None
         else:
             return None
     except Exception as e:
         raise
     finally:
         cursor.close()
Exemple #20
0
def register():
	if request.method == 'GET':
		return render_template('register.html', error=None)
	accountInfo = Entities.make_account_info(request)
	if not accountInfo:
		return render_template('register.html', error="Required Informaion Missing")
	accountDao = AccountDao()
	isNewAccount = accountDao.add_account(accountInfo)
	if not isNewAccount:
		return render_template('register.html', error="User Account Existed Already")
	EmailHandler.send_authentication(accountInfo['email'], accountInfo['id'], accountInfo['code'])
	return redirect(url_for('PetCare.login'))
 def addqual():
     qual_id = random.randint(1, 1000)
     desc = e3.get()
     if e3.get():
         qo = Entities.Qualification(qual_id, desc)
         if AdministratorBL.AdministratorBL().add_qual(qo) is True:
             Label(master, text="Added").grid(row=8, column=2)
         else:
             Label(master, text="Not Added").grid(row=8, column=2)
     else:
         Label(master,
               text="Qualification description is mandatory!!",
               fg="red").grid(row=8, column=1)
Exemple #22
0
    def __init__(self, title, width, height, background_color=(230, 230, 230)):
        self.title = title
        self.width = width
        self.height = height
        self.background_color = background_color

        Entities()
        Constants()

        self.game_display = pygame.display.set_mode((width, height),
                                                    pygame.SRCALPHA)
        pygame.display.set_caption(title)
        self.main_loop()
Exemple #23
0
def edit_post():
	if session.get('logged_in') is None:
		return redirect(url_for('PetCare.login'))
	accountDao = AccountDao()
	postDao = PostDao()	
	postId = accountDao.get_account_post(session['logged_in'].rstrip())
	
	if postId is None:
		return redirect(url_for('PetCare.create_post'))
	
	prevPost = postDao.get_post(postId)
	prevPostInfo = Entities.make_post_output(dict(prevPost))
	if request.method == 'GET':
		return render_template('edit_post.html', error=None, prevPost=prevPostInfo)

	prevPostDict = dict(prevPost)
	postInfo = Entities.make_post_info(session['logged_in'].rstrip(), request, prevPostDict)
	if not postInfo:
		return render_template('edit_post.html', error="Required Informaion Missing", prevPost=None)
	
	postInfo['id'] = postId
	postDao.update_post(postInfo)
	return redirect(url_for('PetCare.list_posts'))
Exemple #24
0
def register():
    if request.method == 'GET':
        return render_template('register.html', error=None)
    accountInfo = Entities.make_account_info(request)
    if not accountInfo:
        return render_template('register.html',
                               error="Required Informaion Missing")
    accountDao = AccountDao()
    isNewAccount = accountDao.add_account(accountInfo)
    if not isNewAccount:
        return render_template('register.html',
                               error="User Account Existed Already")
    # TODO: send email with authentication url ending with code
    return redirect(url_for('PetCare.login'))
Exemple #25
0
def view_post():
	if session.get('logged_in') is None:
		return redirect(url_for('PetCare.login'))
	postDao = PostDao()
	post = postDao.get_post(request.args['postId'])
	status = 'PENDING'
	if post['match'] is not None and len(post['match']) > 0:
		status = 'MATCHED'
	if time.time() > post['end_date']:
		status = 'FINISHED'
	postInfo = Entities.make_post_output(dict(post))
	isOwner = (session.get('logged_in') == post['owner_id'])
	accountDao = AccountDao()
	ownername =  accountDao.get_name(post['owner_id'])
	return render_template('view_post.html', post=postInfo, status=status, isOwner=isOwner, owner=ownername)
Exemple #26
0
def create_post():
	if session.get('logged_in') is None:
		return redirect(url_for('PetCare.login'))
	accountDao = AccountDao()
	postDao = PostDao()
	postId = accountDao.get_account_post(session['logged_in'].rstrip())
	if postId is not None:
		return redirect(url_for('PetCare.edit_post'))
	if request.method == 'GET':
		return render_template('create_post.html', error=None)
	postInfo = Entities.make_post_info(session['logged_in'].rstrip(), request)
	if not postInfo:
		return render_template('create_post.html', error="Required Informaion Missing")
	postId = postDao.add_post(postInfo)
	accountDao.update_account_post(session['logged_in'].rstrip(), postId)
	return redirect(url_for('PetCare.list_posts'))
 def addprop():
     propid = random.randint(1, 1000)
     name = e4.get()
     desc = e5.get()
     if e4.get() and e5.get():
         po = Entities.Property(propid, name, desc)
         if AdministratorBL.AdministratorBL().add_property(po) is True:
             Label(master, text="Added").grid(row=12, column=2)
         else:
             Label(master, text="Not Added").grid(row=12, column=2)
     else:
         Label(
             master,
             text=
             "Both fields (Property name and Description) are mandatory!!",
             fg="red").grid(row=12, column=1)
Exemple #28
0
def profile():
	if 'login' in request.args and session.get('logged_in') is not None and session.get('logged_in') != request.args['login']:
		session.pop('logged_in', None)
	if session.get('logged_in') is None:
		if 'login' not in request.args:
			return redirect(url_for('PetCare.login')) 
		else:
			return redirect(url_for('PetCare.prompt_login', userId=request.args['login'], targetId=request.args['userId'].rstrip()))
	accountDao = AccountDao()
	postDao = PostDao()
	accountInfo = accountDao.get_account_info(request.args['userId'].rstrip())
	posts = postDao.get_user_posts(request.args['userId'].rstrip())
	postInfos = [Entities.make_post_output(dict(post)) for post in posts]
	myCurrentPostId = accountDao.get_account_post(session['logged_in'].rstrip())
	status = 'UNRELATED' if myCurrentPostId is None else postDao.check_relation(myCurrentPostId, request.args['userId'].rstrip())
	return render_template('profile.html', account=accountInfo, posts=postInfos, status=status)
    def spawnProjectile(self, entity_pos: Tuple[int, int],
                        is_player_projectile: bool) -> None:
        if is_player_projectile:
            offset_y, offset_x = (-1, 0)
        else:
            offset_y, offset_x = (+1, 0)
        entity_y, entity_x = entity_pos
        proj_y, proj_x = entity_y + offset_y, entity_x + offset_x

        projectile = Entities.genNewPlayerProjectile()
        self.setEntityAtPos(proj_y, proj_x, projectile)

        entity_type = (EntityType.PLAYER_PROJECTILE if is_player_projectile
                       else EntityType.ENEMY_PROJECTILE)
        self.instances[entity_type].append(projectile)
        Logger.info(
            f"Spawning projectile: {projectile} - is_player: {is_player_projectile}"
        )
 def create_forum():
     forumid = int(forum_id_create.get())
     topic = topic_create.get()
     url = url_create.get()
     summary = summary_create.get()
     whencreated = datetime.now()
     whenclosed = None
     createdbymoderator_username = username
     deletedbymoderator_username = None
     forum_object = Entities.Forum(forumid, topic, url, summary,
                                   whencreated, whenclosed,
                                   createdbymoderator_username,
                                   deletedbymoderator_username)
     forum_created = business_logic.create_forum(forum_object)
     if forum_created is True:
         Label(master, text="Forum Created!!").grid(row=6, column=4)
     else:
         Label(
             master,
             text="Either moderator does not exis or forum id is not unique!!"
         ).grid(row=6, column=4)