Skip to content

Instantly share code, notes, and snippets.

@pikachu0310
Created May 18, 2019 16:46
Show Gist options
  • Save pikachu0310/0d6086562656ddd38f998047f7b3a821 to your computer and use it in GitHub Desktop.
Save pikachu0310/0d6086562656ddd38f998047f7b3a821 to your computer and use it in GitHub Desktop.
うーん...
# <editor-fold desc="序盤まとめ">
import discord
import random
from googletrans import Translator
from asyncio import sleep
from datetime import datetime
import sys
import time
import math
kousin = datetime.now().strftime("%m/%d %H:%M:%S")
client = discord.Client() # せつぞく
# 起動時に実行するお
@client.event
async def on_ready():
print('Pikachu BOT TEST 起動')
print("テスト")
await client.change_presence(game=discord.Game(name="最終更新時間" + str(kousin)))
# </editor-fold>
max_x = 15
max_y = 15
x = 1
y = max_x
center = int(((max_x - (max_x % 2)) / 2 + 1) * x) + int(((max_y - (max_y % 2)) / 2) * y)
location = center
print(location)
# 地形作成
print('実行開始')
map = {} # x,y座標 マップ
action = True
num = None
air = '・'
map_wall = []
print('map生成中')
for i in range(0, max_x * max_y):
map[i] = air
for i in range(max_y):
map_wall.append(max_y * i)
map_wall.append((i + 1) * max_y - 1)
print(map_wall)
for i in range(0, max_x * max_y):
if i < y or i >= max_x * max_y - y or i in map_wall:
map[i] = "壁"
'''
for i in range(0, max_x * max_y):
map[i] = air
map_str = '壁壁・・・・・・・・・・壁壁壁'
for i in range(len(map_str)):
map[i] = map_str[i]
map[i]
'''
# 表示 display
display_a = {}
display_b = {}
display_num = 15 # 表示する一辺の長さ(奇数)(視界)
display_num2 = int((display_num - 1) / 2) # /2-1
for i in range(0, display_num):
display_y = (display_num2 - i) * y
for j in range(0, display_num):
display_x = j - display_num2 - x
display_b[j] = display_x + display_y
if len(display_b) == display_num:
display_a[i] = display_b
display_b = {}
print(display_a)
def display():
global display_str
display_str = ''
for i in range(0, display_num):
for j in range(0, display_num):
display_str += map[location + (display_a[i][j])]
if j == display_num - 1:
display_str += '\n'
print(display_str)
# 生き物 動作定義
creatures = {}
creatures['あ'] = center
creatures['い'] = center
creatures['う'] = center
creatures['え'] = center
creatures['お'] = center
creatures['敵'] = center
player = {}
player['ピ'] = location
player['し'] = location
god = {}
god['自'] = location
def move(name):
global move_mode, mx, my,move_to
move_mode = None
mx = 0
my = 0
try:
if creatures[name] != None:
move_mode = 'creatures'
except:
try:
if player[name] != None:
move_mode = 'player'
except:
try:
if god[name] != None:
move_mode = 'god'
except:
pass
if move_mode == 'creatures':
position = creatures[name]
before_position = creatures[name]
before_map = map[position]
while True:
if random.randrange(0, 1 + 1) == 0:
mx = random.randrange(-1, 1 + 1) * x
my = 0
else:
mx = 0
my = random.randrange(-1, 1 + 1) * y
if map[position + mx + my] != '壁':
if mx != 0 or my != 0:
break
creatures[name] = position + mx + my
map[before_position] = air
map[creatures[name]] = name
elif move_mode == 'player':
position = player[name]
before_position = player[name]
before_map = map[position]
while True:
if random.randrange(0, 0 + 1) == 0:
mx = random.randrange(-1, 1 + 1) * x
my = random.randrange(-1, 1 + 1) * y
if map[position + mx + my] != '壁':
if mx != 0 or my != 0:
break
player[name] = position + mx + my
map[before_position] = air
map[player[name]] = name
elif move_mode == 'god':
position = god[name]
before_position = god[name]
before_map = map[position]
if move_to == "stop":
move_to = None
if move_to == "w":
my = y
elif move_to == "a":
mx = -x
elif move_to == "s":
my = -y
elif move_to == "d":
mx = x
if map[position + mx + my] != '壁':
god[name] = position + mx + my
else:
move_to = None
map[before_position] = air
map[god[name]] = name
ikkai = True
move_to = None
# ほ ん へ
@client.event # ----------------------------------------------------------------------------------------------------
async def on_message(message):
global ikkai,move_to
# 動かす
if ikkai:
ikkai = False
times = 0
global action
while True:
times += 1
if action:
time.sleep(1)
# print('\n'*0)
display()
await client.send_message(client.get_channel("579326998724214804"), str(display_str + "\n使えるコマンド: /move (移動方向)   移動方向は、(w,a,s,d,stop)の5種類あるよ(例:/move w)"))
# print('x:',str(location%y),'y:',str(int((location-location%y)/y)))
action = False
action = True
for i in range(0, 0+1):
move("敵")
move('あ')
move('い')
move('う')
move('え')
move('お')
for j in range(0, 2 + 1):
move('ピ')
move('し')
if move_to == "w" or move_to == "a" or move_to == "s" or move_to == "d" or move_to == "stop":
move("自")
"""
move('あ')
move('い')
move('う')
move('え')
move('お')
move('ピ')
move('し')
"""
try:
if client.user != message.author:
if message.channel.id == "579326998724214804":
if message.content.split()[0] == "/move":
move_to = str(message.content.split()[1])
except:
pass
# ------------------------------------------------------------------------------------------------------------------
# bot起動構文
client.run("教えないぜ?")
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment