残り1時間ぐらいあったのでタイマーをセットして地形とユニットの配置に注力してみます
ユニットはクラスで、地形は文字列で
ユニットは漢字で7種類
地形は闇と海と河と草原と森と荒野とラストっぽい所
ユニットの表示は黒い影をいれて見やすくする
一秒ごとに世界を作り直して完成
import time
import pygame
import random
from pygame.locals import *
class Unit:
def __init__(self,x,y,n,c):
self.x=x
self.y=y
self.n=n
self.c=c
def put(self):
x,y=self.x,self.y
text = font.render(self.n, True, (0,0,0))
screen.blit(text, [x*24+24+1, y*24+12+1])
text = font.render(self.n, True, self.c)
screen.blit(text, [x*24+24, y*24+12])
def write_board(bd):
cs=[(0,0,0),(0,0,255),(0,255,255),(0,255,0),(0,100,0),(255,255,0),(255,0,0)]
#font = pygame.font.SysFont("notosansmonocjkjp", 23)
for y in range(32):
for x in range(48):
p=x+y*48
if bd[p]>="1":
pygame.draw.rect(screen, cs[int(bd[p])], Rect(x*24+24,y*24+19,23,23))
def bd_make():
bd=" "*48*32
for n in range(1,7):
n1=[0,30,10,20,10,10,2][n]
for i in range(n1):
x,y=random.randint(0,47-5),random.randint(0,31-5)
for x1 in range(x,x+6):
for y1 in range(y,y+6):
p=x1+y1*48
bd=bd[:p]+str(n)+bd[p+1:]
return bd
def unit_make():
units=[]
for i in range(20):
x,y=random.randint(0,47),random.randint(0,31)
t=random.randint(0,6)
n="竜鬼勇賢僧闘鰐"[t]
units+=[Unit(x,y,n,(255,255,255))]
return units
def gamemain():
while 1:
screen.fill((0,0,0))
bd=bd_make()
units= unit_make()
write_board(bd)
for u in units:
u.put()
pygame.display.update()
pygame.time.wait(1000)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == MOUSEBUTTONUP and event.button == 1:
x, y = event.pos
cx,cy = (x-24)//24,(y-19)//24
print(cx,cy)
screen = pygame.display.set_mode((1200, 800))
pygame.init()
font = pygame.font.SysFont("notosansmonocjkjp", 23)
gamemain()
pygame.quit()