This commit is contained in:
Deni Putra 2018-10-14 13:58:26 +00:00 committed by GitHub
commit 319f8ce546
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 51 additions and 13 deletions

3
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
"python.linting.enabled": false
}

View file

@ -107,24 +107,31 @@ def do_play_card(bot, player, result_id):
send_async(bot, chat.id,
text=__("{name} won!", multi=game.translate)
.format(name=user.first_name))
send_async(bot, chat.id,
text=__("Game ended! Flawless Victory!"))
if us.stats:
us.games_played += 1
# us.games_played += 1
if game.players_won is 0:
us.first_places += 1
game.players_won += 1
if game.mode == 'one':
gm.end_game(chat, user)
else:
game.players_won += 1
try:
gm.leave_game(user, chat)
if game.mode != 'one':
gm.leave_game(user, chat)
except NotEnoughPlayersError:
send_async(bot, chat.id,
text=__("Game ended!", multi=game.translate))
us2 = UserSetting.get(id=game.current_player.user.id)
if us2 and us2.stats:
us2.games_played += 1
# us2.games_played += 1
us2.last_places += 1
gm.end_game(chat, user)

3
bot.py
View file

@ -36,7 +36,7 @@ from errors import (NoGameInChatError, LobbyClosedError, AlreadyJoinedError,
from internationalization import _, __, user_locale, game_locales
from results import (add_call_bluff, add_choose_color, add_draw, add_gameinfo,
add_no_game, add_not_started, add_other_cards, add_pass,
add_card, add_mode_classic, add_mode_fast, add_mode_wild)
add_card, add_mode_classic, add_mode_fast, add_mode_wild, add_mode_one)
from shared_vars import gm, updater, dispatcher
from simple_commands import help_handler
from start_bot import start_bot
@ -594,6 +594,7 @@ def reply_to_query(bot, update):
add_mode_classic(results)
add_mode_fast(results)
add_mode_wild(results)
add_mode_one(results)
else:
add_not_started(results)

View file

@ -78,9 +78,9 @@ class Deck(object):
self.cards.clear()
for color in c.COLORS:
for value in c.WILD_VALUES:
for _ in range(4):
for _ in range(2):
self.cards.append(Card(color, value))
for special in c.SPECIALS:
for _ in range(6):
for _ in range(8):
self.cards.append(Card(None, None, special=special))
self.shuffle()

View file

@ -64,7 +64,7 @@ class Game(object):
return players
def start(self):
if self.mode == None or self.mode != "wild":
if self.mode == None or self.mode == "wild":
self.deck._fill_classic_()
else:
self.deck._fill_wild_()

View file

@ -22,6 +22,7 @@ import logging
from game import Game
from player import Player
from user_setting import UserSetting
from errors import (AlreadyJoinedError, LobbyClosedError, NoGameInChatError,
NotEnoughPlayersError)
@ -62,6 +63,11 @@ class GameManager(object):
self.logger.info("Joining game with id " + str(chat.id))
try:
us = UserSetting.get(id=user.id)
if not us:
us = UserSetting(id=user.id)
us.games_played += 1
game = self.chatid_games[chat.id][-1]
except (KeyError, IndexError):
raise NoGameInChatError()

View file

@ -129,6 +129,17 @@ def add_mode_wild(results):
)
)
def add_mode_one(results):
"""Change mode to classic"""
results.append(
InlineQueryResultArticle(
"mode_one",
title=_("😐 Saitama mode"),
input_message_content=
InputTextMessageContent(_('One hit Kill? 😐'))
)
)
def add_draw(player, results):
"""Add option to draw"""

View file

@ -79,6 +79,7 @@ def kb_select(bot, update, groups):
us.first_places = 0
us.games_played = 0
us.cards_played = 0
us.last_places = 0
send_async(bot, chat.id, text=_("Deleted and disabled statistics!"))

View file

@ -31,8 +31,8 @@ help_text = ("Follow these steps:\n\n"
" running game with /join\n"
"3. After at least two players have joined, start the game with"
" /start\n"
"4. Type <code>@unobot</code> into your chat box and hit "
"<b>space</b>, or click the <code>via @unobot</code> text "
"4. Type <code>@xultanbot</code> into your chat box and hit "
"<b>space</b>, or click the <code>via @xultanbot</code> text "
"next to messages. You will see your cards (some greyed out), "
"any extra options like drawing, and a <b>?</b> to see the "
"current game state. The <b>greyed out cards</b> are those you "
@ -72,10 +72,11 @@ attributions = ("Attributions:\n"
"Originals available on http://game-icons.net\n"
"Icons edited by ɳick")
modes_explanation = ("This UNO bot has three game modes: Classic, Sanic and Wild.\n\n"
modes_explanation = ("This UNO bot has four game modes: One, Classic, Sanic and Wild.\n\n"
" 🎻 The Classic mode uses the conventional UNO deck and there is no auto skip.\n"
" 🚀 The Sanic mode uses the conventional UNO deck and the bot automatically skips a player if he/she takes too long to play its turn\n"
" 🐉 The Wild mode uses a deck with more special cards, less number variety and no auto skip.\n\n"
" 🐉 The Wild mode uses a deck with more special cards, less number variety and no auto skip.\n"
" 😐 The Saitama mode uses a deck with more special cards, less number variety and no auto skip, but ended with one win.\n\n"
"To change the game mode, the GAME CREATOR has to type the bot nickname and a space, just like when playing a card, and all gamemode options should appear.")
@ -134,6 +135,13 @@ def stats(bot, update):
n).format(number=n)
)
n = us.last_places
stats_text.append(
_("{number} last place",
"{number} last places",
n).format(number=n)
)
n = us.cards_played
stats_text.append(
_("{number} card played",

View file

@ -28,6 +28,7 @@ class UserSetting(db.Entity):
lang = Optional(str, default='') # The language setting for this user
stats = Optional(bool, default=False) # Opt-in to keep game statistics
first_places = Optional(int, default=0) # Nr. of games won in first place
last_places = Optional(int, default=0) # Nr. of games last place
games_played = Optional(int, default=0) # Nr. of games completed
cards_played = Optional(int, default=0) # Nr. of cards played total
use_keyboards = Optional(bool, default=False) # Use keyboards (unused)