fr0stn1k

rock-paper-scissors_vk

Nov 26th, 2020 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. import vk_api, json
  2. import random
  3. from vk_api.longpoll import VkLongPoll, VkEventType
  4.  
  5. vk_session = vk_api.VkApi(token = '4618438e9a144cb8df60e0ab89571ec7b4a1b3fd6b088267c949de581d9879c46fdcb23daba64602bb9d5')
  6. vk = vk_session.get_api() #Было session_api
  7.  
  8. longpoll = VkLongPoll(vk_session)
  9.  
  10. list = ['Камень', 'Ножницы', 'Бумага']
  11. scoreboard = {}
  12. scoreboard['score'] = 0
  13.  
  14. def sender(id, text):
  15. vk.messages.send(user_id = id, message = text, random_id = 0)#Отправка сообщений
  16.  
  17. def send_stick(id, number):
  18. vk.messages.send(user_id = id, sticker_id = number, random_id = 0) #Отправка стикеров
  19.  
  20. def send_photo(id, url):
  21. vk.messages.send(user_id = id, attachment = url, random_id = 0) #Отправка фото
  22.  
  23. def rock_paper_scissors(id, element)
  24. b = random.choice(list)
  25. if (mes =='камень' and b =='Камень') or (mes == 'ножницы' and b =='Ножницы') or (mes == 'бумага' and b == 'Бумага'):
  26. sender(id, b)
  27. sender(id, 'Ничья!')
  28. elif (mes == 'камень' and b =='Бумага') or (mes == 'бумага' and b == 'Ножницы') or (mes == 'ножницы' and b == 'Камень'):
  29. scoreboard['score'] = scoreboard['score'] - 1
  30. sender(id, b)
  31. sender(id, 'Компьютер победил! Попробуй еще раз')
  32. elif (mes == 'камень' and b == 'Ножницы') or (mes == 'ножницы' and b == 'Бумага') or (mes == 'бумага' and b== 'Камень'):
  33. scoreboard['score'] = scoreboard['score'] + 1
  34. sender(id, b)
  35. ender(id, 'Ты победил! Но получится ли в следующий раз?')
  36. elif mes == 'конец игры':
  37.  
  38. for event in longpoll.listen():
  39. if event.type == VkEventType.MESSAGE_NEW:
  40. if event.to_me:
  41.  
  42. mes = event.text.lower() #mes - сообщение
  43. id = event.user_id
  44.  
  45. #задаем переменную игрока
  46. player = False
  47.  
  48. if mes == 'привет':
  49. sender(id, 'И тебе привет 😷. Чтобы узнать мои комнды напиши: "помощь"')
  50. elif mes == 'помощь':
  51. sender(id, '1.Скинь стикер\n2.Скинь пикчу\n3.Игры')
  52. elif mes == 'пока':
  53. sender(id, 'До свидания')
  54. elif mes == 'скинь стикер':
  55. send_stick(id, 8651)
  56. elif mes == 'скинь пикчу':
  57. send_photo(id, 'photo-200079360_457239018')
  58. elif mes == 'игры':
  59. sender(id, '1.Камень, ножницы✂, бумага📃')
  60. elif mes == 'камень ножницы бумага' or mes == 'камень, ножницы, бумага':
  61. sender(id, 'Чтобы играть введите "играть", а после выберите камень, ножницы или бумагу\nЕсли хотите закончить игру напишите "конец игры"')
  62. elif mes == 'играть камень':
  63. rock_paper_scissors(id, 'камень')
  64. elif mes == 'играть ножницы':
  65. rock_paper_scissors(id, 'ножницы')
  66. elif mes == 'играть бумага':
  67. rock_paper_scissors(id, 'бумага')
  68. else:
  69. sender(id, 'Непонел')
  70.  
Advertisement
Add Comment
Please, Sign In to add comment