Skip to content

Commit

Permalink
Merge pull request #107 from fleizean/mpa
Browse files Browse the repository at this point in the history
MPA'dan sevgilerle w/@fleizean
  • Loading branch information
yeaktas committed Feb 17, 2024
2 parents 255b4a3 + b6ed738 commit 2cf3482
Show file tree
Hide file tree
Showing 18 changed files with 197 additions and 137 deletions.
10 changes: 5 additions & 5 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<li>✅ Users can update their information. </li>
<li>✅ Users can upload an avatar, with a default option if none is provided. </li>
<li>⌛ Users can add others as friends and view their online status. </li>
<li> User profiles display stats, such as wins and losses. </li>
<li> Each user has a <b>Match History</b> including 1v1 games, dates, and relevant
<li> User profiles display stats, such as wins and losses. </li>
<li> Each user has a <b>Match History</b> including 1v1 games, dates, and relevant
details, accessible to logged-in users.</li>
</ul>
</details>
Expand Down Expand Up @@ -58,16 +58,16 @@
<summary> <b> Live Chat. ⌛</b></summary>
You have to create a chat for your users in this module:
<ul>
<li> The user should be able to send <b>direct messages</b> to other users. </li>
<li> The user should be able to send <b>direct messages</b> to other users. </li>
<li>⌛ The user should be able to block other users. This way, they will see no more messages from the account they blocked. </li>
<li>⌛ The user should be able to invite other users to play a Pong game through the chat interface. </li>
<li>⌛ The tournament system should be able to warn users expected for the next game. </li>
<li> The user should be able to access other players profiles through the chat interface. </li>
<li> The user should be able to access other players profiles through the chat interface. </li>
</ul>
</details>

<details>
<summary> <b> Introduce an AI Opponent. </b></summary>
<summary> <b> Introduce an AI Opponent. </b></summary>
In this major module, the objective is to incorporate an AI player into the game. Notably, the use of the <b>A* algorithm</b> is not permitted for this task. Key features and goals include:
<ul>
<li>✅ Develop an AI opponent that provides a challenging and engaging gameplay experience for users. </li>
Expand Down
4 changes: 2 additions & 2 deletions indianpong/pong/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UserProfileAdmin(admin.ModelAdmin):
fieldsets = (
('User Information', {'fields': ('username', 'password', 'displayname', 'email', 'avatar', 'friends', 'elo_point', 'indian_wallet')}),
('Dates', {'fields': ('date_joined', 'last_login')}),
('Roles', {'fields': ('is_staff', 'is_active', 'is_superuser', 'is_verified', 'is_42student')}),
('Roles', {'fields': ('is_staff', 'is_active', 'is_superuser', 'is_verified', 'is_42student', 'is_indianai')}),
('Permissions', {'fields': ('groups', 'user_permissions')}),
)

Expand Down Expand Up @@ -60,7 +60,7 @@ def get_item_name(self, obj):

@admin.register(UserGameStat)
class UserGameStatAdmin(admin.ModelAdmin):
list_display = ('get_user', 'total_games_pong', 'total_win_pong', 'total_lose_pong', 'total_win_streak_pong', 'total_win_rate_pong', 'total_lose_streak_pong', 'total_avg_game_duration', 'total_avg_points_won', 'total_avg_points_lost')
list_display = ('get_user', 'total_games_pong', 'total_win_pong', 'total_lose_pong', 'total_win_streak_pong', 'total_win_rate_pong', 'total_lose_streak_pong', 'total_avg_game_duration_pong', 'total_avg_points_won_pong', 'total_avg_points_lost_pong')
search_fields = ('userprofile__username', 'total_win_pong',)

def get_user(self, obj):
Expand Down
1 change: 1 addition & 0 deletions indianpong/pong/management/commands/initdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def handle(self, *args, **options):
file.close()
user.is_verified = True
user.indian_wallet = 1000
user.is_indianai = True
user.elo_point = 1000
user.save()
self.stdout.write(self.style.SUCCESS('IndianAI created successfully.'))
Expand Down
9 changes: 5 additions & 4 deletions indianpong/pong/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0 on 2024-02-16 23:15
# Generated by Django 5.0 on 2024-02-17 19:50

import datetime
import django.contrib.auth.models
Expand Down Expand Up @@ -53,9 +53,9 @@ class Migration(migrations.Migration):
('total_win_streak_pong', models.IntegerField(default=0)),
('total_lose_streak_pong', models.IntegerField(default=0)),
('total_win_rate_pong', models.FloatField(default=0.0)),
('total_avg_game_duration', models.DurationField(blank=True, default=datetime.timedelta(0), null=True)),
('total_avg_points_won', models.FloatField(default=0.0)),
('total_avg_points_lost', models.FloatField(default=0.0)),
('total_avg_game_duration_pong', models.DurationField(blank=True, default=datetime.timedelta(0), null=True)),
('total_avg_points_won_pong', models.FloatField(default=0.0)),
('total_avg_points_lost_pong', models.FloatField(default=0.0)),
],
),
migrations.CreateModel(
Expand All @@ -76,6 +76,7 @@ class Migration(migrations.Migration):
('avatar', models.ImageField(blank=True, null=True, upload_to=pong.utils.get_upload_to)),
('is_verified', models.BooleanField(default=False)),
('is_42student', models.BooleanField(default=False)),
('is_indianai', models.BooleanField(default=False)),
('indian_wallet', models.IntegerField(blank=True, default=0, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(9999)])),
('elo_point', models.IntegerField(blank=True, default=0, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(99999)])),
('friends', models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL)),
Expand Down
17 changes: 12 additions & 5 deletions indianpong/pong/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class UserProfile(AbstractUser):
#channel_name = models.CharField(max_length=100, blank=True, null=True)
is_verified = models.BooleanField(default=False)
is_42student = models.BooleanField(default=False)
is_indianai = models.BooleanField(default=False)
store_items = models.ManyToManyField(StoreItem, through='UserItem', blank=True)
game_stats = models.OneToOneField('UserGameStat', on_delete=models.SET_NULL, null=True, blank=True)
indian_wallet = models.IntegerField(blank=True, null=True, default=0, validators=[MinValueValidator(0), MaxValueValidator(9999)])
Expand Down Expand Up @@ -67,15 +68,15 @@ class UserGameStat(models.Model):
total_win_streak_pong = models.IntegerField(default=0)
total_lose_streak_pong = models.IntegerField(default=0)
total_win_rate_pong = models.FloatField(default=0.0)
total_avg_game_duration = models.DurationField(default=timedelta(0), null=True, blank=True)
total_avg_points_won = models.FloatField(default=0.0)
total_avg_points_lost = models.FloatField(default=0.0)
total_avg_game_duration_pong = models.DurationField(default=timedelta(0), null=True, blank=True)
total_avg_points_won_pong = models.FloatField(default=0.0)
total_avg_points_lost_pong = models.FloatField(default=0.0)

def formatted_game_duration(self):
if self.total_avg_game_duration is None:
if self.total_avg_game_duration_pong is None:
return None

total_seconds = int(self.total_avg_game_duration.total_seconds())
total_seconds = int(self.total_avg_game_duration_pong.total_seconds())
hours, remainder = divmod(total_seconds, 3600)
minutes, seconds = divmod(remainder, 60)

Expand All @@ -94,6 +95,12 @@ def formatted_win_rate(self):
# Win rate'i string olarak formatla
return f"%{win_rate_percentage:.1f}"

def formatted_avg_points_lost(self):
return "{:.2f}".format(self.total_avg_points_lost_pong)

def formatted_avg_points_won(self):
return "{:.2f}".format(self.total_avg_points_won_pong)

class VerifyToken(models.Model):
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
token = models.CharField(max_length=255)
Expand Down
17 changes: 9 additions & 8 deletions indianpong/pong/templates/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
<div class="chat-container">
<!-- start: Sidebar -->
<aside class="chat-sidebar">
<a href="#" class="chat-sidebar-logo"><i class="bi bi-discord"></i></a>
{% comment %} <a href="#" class="chat-sidebar-logo"><i class="bi bi-discord"></i></a> {% endcomment %}
<ul class="chat-sidebar-menu">
<li class="active">
<a href="#" data-title="DM"><i class="bi bi-chat-square-fill"></i></a>
</li>
<li>
<a href="#" data-title="Room"><i class="bi bi-chat-square-quote-fill"></i></a>
</li>
<li>
{% comment %} <li>
<a href="#" data-title="Settings"><i class="bi bi-gear-fill"></i></a>
</li>
</li> {% endcomment %}
<li class="chat-sidebar-profile">
<button type="button" class="chat-sidebar-profile-toggle"><i class="bi bi-person-circle" style="font-size: 24px; color: #059669;"></i></button>
{% comment %} <button type="button" class="chat-sidebar-profile-toggle"><i class="bi bi-person-circle" style="font-size: 24px; color: #059669;"></i></button> {% endcomment %}
<ul class="chat-sidebar-profile-dropdown">
<li>
<a href="#"><i class="bi bi-person-fill"></i> Profile</a>
Expand All @@ -44,19 +44,20 @@
<!-- start: Content side -->
<div class="content-sidebar">
<div class="content-sidebar-title">Chats</div>
<form action="" class="content-sidebar-form">
{% comment %} <form action="" class="content-sidebar-form">
<input type="search" class="content-sidebar-input" placeholder="Search..." />
<button type="submit" class="content-sidebar-submit"><i class="bi bi-search"></i></button>
</form>
</form> {% endcomment %}
<div class="content-messages">
<ul class="content-messages-list">
<li class="content-message-title">
<span>Recently</span>
</li>
{% for user in users %}
{% for user in users %}
<li>
<a href="{% url 'start_chat' user %}" data-link>
<img class="content-message-image" src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OXx8cGVvcGxlfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60" alt="" />
<img class="content-message-image" src="{% if user.avatar %}{{ user.avatar.url }}{% else %}/static/assets/profile/profilephoto.jpeg{% endif %}" alt="" />

<span class="content-message-info">
<span class="content-message-name">{{ user }}</span>
</span>
Expand Down
4 changes: 2 additions & 2 deletions indianpong/pong/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h2 class="text-right">
<div class="card-block">
<h6 class="m-b-20">Average Points Won</h6>
<h2 class="text-right">
<i class="bi bi-star-fill"></i><span>{% if profile.game_stats.total_avg_points_won %} {{ profile.game_stats.total_avg_points_won }} {% else %} 0 {% endif %}</span>
<i class="bi bi-star-fill"></i><span>{% if profile.game_stats.formatted_avg_points_won %} {{ profile.game_stats.formatted_avg_points_won }} {% else %} 0 {% endif %}</span>
</h2>
</div>
</div>
Expand All @@ -105,7 +105,7 @@ <h2 class="text-right">
<div class="card-block">
<h6 class="m-b-20">Average Points Lost</h6>
<h2 class="text-right">
<i class="bi bi-bucket-fill"></i><span> {% if profile.game_stats.total_avg_points_lost %} {{ profile.game_stats.total_avg_points_lost }} {% else %} 0 {% endif %}</span>
<i class="bi bi-bucket-fill"></i><span> {% if profile.game_stats.formatted_avg_points_lost %} {{ profile.game_stats.formatted_avg_points_lost }} {% else %} 0 {% endif %}</span>
</h2>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions indianpong/pong/templates/friends.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<div class="profile-card">
<div class="image">
{% if friend.avatar %}
<a href="profile/{{friend.username}}"><img src="{{friend.avatar.url}}" alt="" class="profile-img" /></a>
<a href="/profile/{{friend.username}}"><img src="{{friend.avatar.url}}" alt="" class="profile-img" /></a>
{% else %}
<a href="profile/{{friend.username}}"><img src="/static/assets/profile/profilephoto.jpeg" alt="" class="profile-img" /></a>
<a href="/profile/{{friend.username}}"><img src="/static/assets/profile/profilephoto.jpeg" alt="" class="profile-img" /></a>
{% endif %}
</div>
<div class="text-data">
Expand All @@ -43,7 +43,7 @@
</div>
{% if not friend.social.stackoverflow and not friend.social.twitter and not friend.social.github and not friend.social.instagram %}
<div class="buttons" style="margin-top: 60px !important;">
<button class="button-message">Message</button>
<button class="button-message">Message</button>
</div>
{% else %}
<div class="buttons">
Expand Down
4 changes: 2 additions & 2 deletions indianpong/pong/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<link rel="stylesheet" href="../../../static/css/profile.css">
<link rel="stylesheet" href="../../../static/css/register.css">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" integrity="sha384-T5tECSTsKEQtE6K1qePvHLLOv3MAF/8ZxU9tmQF5PFRpD02iPK8M3UAVU5/sd12G" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.2/font/bootstrap-icons.min.css">

</head>
Expand All @@ -30,7 +30,7 @@
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-SmV1dWObC8dTRSZpO6P5C5aNv6aBAKp3r+UrN5vZHE3agHTtSZQuqUmmFYYEgx4J" crossorigin="anonymous"></script>
<script src="{% static "js/index.js" %}"></script>
{% comment %} <script src="{% static "js/router.js" %}"></script> {% endcomment %}
</body>
Expand Down
Loading

0 comments on commit 2cf3482

Please sign in to comment.