KevTheUseless / DIOXIDE

Dynamic Intelligent OlympiX-in-Informatics-friendly IDE
GNU Affero General Public License v3.0
4 stars 1 forks source link

C H A T #1

Open pythonleo opened 3 years ago

pythonleo commented 3 years ago

yup

pythonleo commented 3 years ago

image

pythonleo commented 3 years ago

![Uploading image.png…]()

KevTheUseless commented 3 years ago
import subprocess

compiler = input()
if compiler == "":
    compiler = "g++"

srcname = input()
if srcname == "":
    srcname = "a.cpp"

outname = input()
if outname == "":
    outname = "a"

log = open("compile.log", "w")
compileLog = subprocess.Popen("%s %s -o %s" % (compiler, srcname, outname), shell=True, stdout=log, stderr=log, encoding="utf-8")
print(compileLog)
KevTheUseless commented 3 years ago
# TextDraw.py
# A place to test

import pygame, sys

def wrap(txtBuffer):
    lines = []
    temp = ""
    for c in txtBuffer:
        if c == '\n':
            lines.append(temp)
            temp = ""
        else:
            temp += c
    lines.append(temp)
    print(lines)
    return lines

def drawTxt(screen, lines, y = 0):
    for line in lines:
        img = raster.render(line, True, (255, 255, 255))
        screen.blit(img, (0, y))
        y += 16

width, height = 800, 600

txtBuffer = []
caps = {
    '`': '~',
    '1': '!',
    '2': '@',
    '3': '#',
    '4': '$',
    '5': '%',
    '6': '^',
    '7': '&',
    '8': '*',
    '9': '(',
    '0': ')',
    '-': '_',
    '=': '+',
    '[': '{',
    ']': '}',
    '\\': '|',
    ';': ':',
    '\'': '"',
    ',': '<',
    '.': '>',
    '/': '?',
    'a': 'A',
    'b': 'B',
    'c': 'C',
    'd': 'D',
    'e': 'E',
    'f': 'F',
    'g': 'G',
    'h': 'H',
    'i': 'I',
    'j': 'J',
    'k': 'K',
    'l': 'L',
    'm': 'M',
    'n': 'N',
    'o': 'O',
    'p': 'P',
    'q': 'Q',
    'r': 'R',
    's': 'S',
    't': 'T',
    'u': 'U',
    'v': 'V',
    'w': 'W',
    'x': 'X',
    'y': 'Y',
    'z': 'Z'
}

pygame.init()
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("TextDraw")
clock = pygame.time.Clock()

raster = pygame.font.Font("Perfect_DOS_VGA_437.ttf", 16)

shift = False
capsLock = False

while True:
    screen.fill((0, 0, 0))
    drawTxt(screen, wrap(txtBuffer))
    pygame.display.update()
    clock.tick(50)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_BACKSPACE:
                try:
                    txtBuffer.pop()
                    for c in txtBuffer:
                        print(txtBuffer)
                except:
                    print(txtBuffer)
            elif event.key == pygame.K_RETURN:
                txtBuffer.append('\n')
                print(txtBuffer)
            elif event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT:
                shift = True
            elif event.key == pygame.K_CAPSLOCK:
                capsLock = 1 - capsLock
            else:
                if 32 <= event.key <= 126 or event.key == pygame.K_TAB:
                    if (44 <= event.key <= 57 or event.key == 59 or event.key == 61 or event.key == 96) and shift:
                        txtBuffer.append(caps[chr(event.key)])
                    elif 97 <= event.key <= 122 and (shift or capsLock):
                        txtBuffer.append(caps[chr(event.key)])
                    else:
                        txtBuffer.append(chr(event.key))
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT:
                shift = False
            elif event.key == pygame.K_CAPSLOCK:
                capsLock = 1 - capsLock
    print(txtBuffer, shift, capsLock)
pythonleo commented 3 years ago

image

pythonleo commented 3 years ago
# kernel.py
# Core of our OS

import pygame, sys, random, time, io, os
from math import *
from contextlib import redirect_stdout
from enum import Enum

width, height = 1024, 768

def pwd(working_dir, args = None):
    print(working_dir, end='\r')

def ls(working_dir, args = None, flag = True):
    files = open("files.img", 'r+', encoding="ISO-8859-1")
    lines = files.read().strip('\0').split('\n')

    result = []
    for i, line in enumerate(lines):
        if line == "!LOC=%s" % working_dir:
            if flag: print(lines[i + 1].strip('!FNAME='), end='\r')
            result.append(lines[i + 1].strip('!FNAME='))
    return result

def cat(working_dir, args = None):
    if not args:
        print("cat: missing argument.\rUsage: cat <filename(s)>", end='\r')
        return
    for target in args:
        files = open("files.img", 'r+', encoding="ISO-8859-1")
        lines = files.read().strip('\0').split('\n')
        contents = []
        for i, line in enumerate(lines):
            if line == '!LOC=%s' % working_dir \
                and lines[i + 1] == '!FNAME=%s' % target:
                    for i in range(i+2, len(lines)):
                        if lines[i] and lines[i][0] == '!': break
                        contents.append(lines[i])
                    break
        else:
            print("cat: %s: no such file." % target, end = '\r')
        print('\r'.join(contents), end='\r')
        files.close()

def rm(working_dir, args = None):
    if not args:
        print("rm: missing argument.\rUsage: rm <filename(s)>", end='\r')
        return
    files = open("files.img", 'r+', encoding="ISO-8859-1")
    to_be_written = []
    target = args[0]
    lines = files.read().strip('\0').split('\n')
    write_or_not = True
    for i, line in enumerate(lines):
        if write_or_not:
            if line == '!FNAME=%s' % target \
           and lines[i-1] == '!LOC=%s' % working_dir:
                write_or_not = False
                to_be_written.pop()
        else:
            if line and line[0] == '!':
                write_or_not = True
        if write_or_not:
            to_be_written.append(line)
    files.close()
    fw = open("files.img", 'w+', encoding="ISO-8859-1")
    fw.write('\n'.join(to_be_written))
    fw.close()

class Pic(object):
    def __init__(self, fileName):
        img = pygame.image.load(fileName)
        self.img = pygame.transform.scale(img, (width, height))
        self.x, self.y = 0, 0
        self.w, self.h = self.img.get_size()
    def draw(self, screen, speed = 5):
        screen.blit(self.img, (self.x, self.y), (0, 0, self.w, self.h))
        pygame.draw.rect(screen, (0, 255, 0), (0, 0, speed * 8, 8), 0)
    def getPixelGrid(self, x0, y0, sideLen, pixelGrid):
        n = sideLen // 2
        for y in range(-n, n + 1):
            for x in range(-n, n + 1):
                pixelGrid[y + n][x + n] = self.img.get_at((x + x0, y + y0))

class Kernel:
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode((width, height))
        pygame.display.set_caption("Winnux 58")
        self.clock = pygame.time.Clock()
        self.raster = pygame.font.Font("res/Perfect_DOS_VGA_437.ttf", 15)
        self.speed = 5
        self.mousePos = (0, 0)
        self.apps = []
        self.appID = 0
        self.dialogs = []
        self.dialogID = 0
    def launch(self):
        for app in self.apps:
            app.draw(self.screen)
        for dialog in self.dialogs:
            try:
                dialog.draw(self.screen)
            except:
                pass
        pygame.display.update()
        self.clock.tick(50)
    def addApp(self, app):
        app.appID = len(self.apps)
        self.apps.append(app)
    def addDialog(self, dialog):
        dialog.dialogID = len(self.dialogs)
        dialog.closeBtn = Secret((dialog.x + 357, dialog.y + 6, 17, 16), dialog.dialogID)
        self.dialogs.append(dialog)
    def keyUp(self, key):
        self.apps[self.appID].keyUp(key)
    def keyDown(self, key):
        self.apps[self.appID].keyDown(key)
    def mouseDown(self, pos, button):
        self.apps[self.appID].mouseDown(pos, button)
        try:
            self.dialogs[self.dialogID].mouseDown(pos, button)
        except:
            pass
    def mouseUp(self, pos, button):
        self.apps[self.appID].mouseUp(pos, button)
    def mouseMotion(self, pos):
        self.apps[self.appID].mouseMotion(pos)

class App:
    def __init__(self, picName):
        self.pic = Pic(picName)
        self.appID = 0
        self.btnList = []
        self.tooltipList = []
        self.txtField = TxtField(0, 0, 0, 0)
        self.txtFieldEnabled = False
        self.canvas = pygame.Surface((width, height - 60))
        self.canvasEnabled = False
        self.secretList = []
    def draw(self, screen):
        if framework.appID != self.appID:
            return
        screen.blit(self.pic.img, (0, 0))
        for button in self.btnList:
            button.draw(screen)
        for tooltip in self.tooltipList:
            tooltip.draw(screen)
        if self.txtFieldEnabled:
            self.txtField.content = self.txtField.wrap(self.txtField.txtBuffer)
            self.txtField.content = self.txtField.content[-self.txtField.h:]
            self.txtField.draw(screen, self.txtField.content, self.txtField.y)
        if self.canvasEnabled:
            if self.appID == snake.appID:
                snakeGame.draw(self.canvas)
                snakeGame.move()
            framework.screen.blit(self.canvas, (0, 60))
    def addButton(self, b):
        self.btnList.append(b)
    def addTooltip(self, txt, font, x, y, c, rect):
        tt = Tooltip(txt, font, x, y, c, rect)
        self.txtList.append(tt)
    def enableTxtField(self, x, y, w, h):
        if self.canvasEnabled:
            print("Only one of either the text field or the canvas can be enabled in an App.")
            return
        self.txtFieldEnabled = True
        self.txtField.x, self.txtField.y = x, y
        self.txtField.w, self.txtField.h = w, h
    def enableCanvas(self):
        if self.txtFieldEnabled:
            print("Only one of either the text field or the canvas can be enabled in an App.")
            return
        self.canvasEnabled = True
    def mouseDown(self, pos, button):
        for btn in self.btnList:
            btn.mouseDown(pos, button)
        for secret in self.secretList:
            secret.mouseDown(pos, button)
    def mouseUp(self, pos, button):
        for button in self.btnList:
            button.mouseUp(pos, button)
    def mouseMotion(self, pos):
        framework.mousePos = pos
        for btn in self.btnList:
            btn.mouseMove(pos)
    def keyUp(self, key):
        if self.txtFieldEnabled:
            self.txtField.keyUp(key)
    def keyDown(self, key):
        if self.txtFieldEnabled:
            self.txtField.keyDown(key)
        if self.canvasEnabled:
            if self.appID == snake.appID:
                snakeGame.keyDown(key)

class Button:
    def __init__(self, picFile, x, y, appID, **txt):
        self.img = pygame.image.load(picFile).convert()
        self.w, self.h = self.img.get_width() // 3, self.img.get_height()
        self.x, self.y = x, y
        self.rect = pygame.Rect(self.x, self.y, self.w, self.h)
        self.status = 0
        self.appID = appID
        self.txt = txt

    def draw(self, screen):
        screen.blit(self.img, (self.x, self.y),
                    (self.status * self.rect.w, 0,
                     self.rect.w, self.rect.h))
        if self.txt:
            screen.blit(self.txt["font"].render(self.txt["content"], True, (0,0,0)), \
                        (self.x + self.w // 2 - 4 * len(self.txt["content"]), self.y + self.h // 2 - 8))
    def mouseDown(self, pos, button):
        if self.rect.collidepoint(pos):
            self.status = 2
    def mouseUp(self, pos, button):
        self.status = 0
        if not self.rect.collidepoint(pos):
            return
        framework.apps[self.appID].pic.draw(framework.screen, framework.speed)
        framework.appID = self.appID
    def mouseMove(self, pos):
        if self.rect.collidepoint(pos):
            self.status = 1
        else:
            self.status = 0

class Tooltip:
    def __init__(self, txt, font, x, y, c, rect):
        self.txt = txt
        self.img = font.render(txt, True, c)
        self.x, self.y = x, y
        self.c = c
        self.rect = pygame.Rect(rect)
    def draw(self, screen):
        if self.rect.collidepoint(framework.mousePos):
            screen.blit(self.img, (self.x, self.y))

class TxtField:
    def __init__(self, x, y, w, h):
        self.isVis = False
        self.x, self.y = x, y
        self.w, self.h = w, h
        self.pwd = '/'
        self.placeholder = ['%s# ' % self.pwd]
        self.txtBuffer = []
        self.content = []
        # MAGIC #
        self.caps = { '`': '~', '1': '!', '2': '@', '3': '#', '4': '$', '5': '%', '6': '^', '7': '&', '8': '*', '9': '(', '0': ')', '-': '_', '=': '+', '[': '{', ']': '}', '\\': '|', ';': ':', '\'': '"', ',': '<', '.': '>', '/': '?', 'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E', 'f': 'F', 'g': 'G', 'h': 'H', 'i': 'I', 'j': 'J', 'k': 'K', 'l': 'L', 'm': 'M', 'n': 'N', 'o': 'O', 'p': 'P', 'q': 'Q', 'r': 'R', 's': 'S', 't': 'T', 'u': 'U', 'v': 'V', 'w': 'W', 'x': 'X', 'y': 'Y', 'z': 'Z' }
        self.shift, self.capsLock = False, False
        self.currentLine, self.loc, self.maxIndex = 0, 0, 0
        self.cLineStr = ""
        self.raster = pygame.font.Font("res/Perfect_DOS_VGA_437.ttf", 16)

        class Cursor(pygame.sprite.Sprite):
            def __init__(self):
                pygame.sprite.Sprite.__init__(self)

                self.image = pygame.Surface((2, 16))
                self.image.fill(pygame.Color(252, 252, 252))

                self.rect = self.image.get_rect()

        self.cursor = Cursor()

        self.frame = 0

    def wrap(self, txtBuffer):
        self.frame += 1
        lines = []
        ptr = 0
        prev_i = 0
        ph = []
        for ch in self.placeholder[ptr]:
            ph.append((ch, (255, 255, 255)))
        if self.loc > self.maxIndex:
            self.loc = self.maxIndex
        if self.loc < 0: self.loc = 0
        if self.maxIndex < 0: self.loc = 0
        for i in range(len(txtBuffer)):
            if txtBuffer[i][0] == '\n':
                self.currentLine = i + 1
                lines.append([])
                for ch, clr in ph:
                    lines[-1].append((ch, clr))
                ptr += 1
                ph = self.placeholder[ptr]
                prev_i = i
            elif txtBuffer[i][0] == '\r' or (i != 0 and (i - prev_i) % self.w == 0):
                ph += txtBuffer[i] if txtBuffer[i][0] not in ('\n', '\r', ' ', '') else ''
                self.currentLine = i + 1
                lines.append(ph)
                ph = ''
                prev_i = i
            elif txtBuffer[i][0] == '\t':
                for _ in range(4): ph.append((' ', (0, 0, 0)))
            else:
                ph.append(txtBuffer[i])
        lines.append(ph)
        return lines
    def draw(self, screen, lines, y = 0):
        for line in lines:
            for i, ch in enumerate(line):
                img = self.raster.render(ch[0], True, ch[1])
                screen.blit(img, (self.x + i * 9, y))
            y += 16

        if self.frame % 50 <= 25: self.cursor.image.fill(pygame.Color(252, 252, 252))
        else: self.cursor.image.fill(pygame.Color(0, 0, 0))

        lines = 0
        for elem in self.txtBuffer:
            if elem[0] in ('\r', '\n'):
                lines += 1
        if lines > 39: lines = 39

        self.cursor.rect.center = (self.x + (self.loc + (len(self.pwd) if not self.isVis else -2) + 1) * 9 + 8,
                                   self.y + lines * 16 + 8)
        screen.blit(self.cursor.image, self.cursor.rect)
    def cd(self, dir_name = None):
        def process_dir(dr: str):
            for d in dr.split('/'):
                if d:
                    if d[0] == '.':
                        if d == '..':
                            self.pwd = ""
                            try: nTemp.pop()
                            except: pass
                            for i in nTemp:
                                if i:
                                    self.pwd += '/' + i
                            self.pwd += '/'
                    elif (d + '/') in ls(self.pwd, [], False):
                        self.pwd += d + '/'
                    else:
                        print("cd: %s: no such directory." % d, end='\r')
                        return
        temp = self.pwd.split('/')
        nTemp = []
        self.pwd = ""
        for i in temp:
            if i:
                self.pwd += '/' + i
                nTemp.append(i)
        self.pwd += '/'
        if dir_name[0] == '/':
            self.pwd = '/'
            dir_name = dir_name[1:]
        process_dir(dir_name)
    def vis(self, args = None):
        self.isVis = True
        if not args:
            print("vis: missing argument.\rUsage: vis <filename>", end='\r')
        if type(args) == type([]):
            print("vis: too many arguments.\rUsage: vis <filename>", end='\r')
        if '/' in args:
            print("No.", end='\r')
            return

        flg = True
        rm(self.pwd, [args])
        files = open("files.img", 'a+', encoding="ISO-8859-1")
        files.write("\n\n!LOC=" + self.pwd + "\n")
        files.write("!FNAME=" + args + "\n")
        self.txtBuffer.append(('\r', (0, 0, 0)))
        self.txtBuffer.append(('\r', (0, 0, 0)))
        while flg:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        self.loc = 0
                        flg = False
                        break
                    self.keyDown(event.key, True)
                    files.write(self.cLineStr)
                elif event.type == pygame.KEYUP:
                    if event.key in (pygame.K_LSHIFT, pygame.K_RSHIFT):
                        self.shift = False
                    elif event.key == pygame.K_CAPSLOCK:
                        self.capsLock = 1 - self.capsLock
                elif event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
            framework.launch()
        files.close()
        self.isVis = False

    def exec_cmd(self, on_scr):
        cmd = on_scr.split()
        try: main = cmd.pop(0)
        except: main = None
        output = io.StringIO()
        with redirect_stdout(output):
            if main:
                if main == "cd":
                    try: self.cd(cmd[0])
                    except: print("cd: missing argument.\rUsage: cd <dirname>", end='\r')
                elif main == "vis":
                    try: self.vis(cmd[0])
                    except: print("vis: missing argument.\rUsage: vis <filename>", end='\r')
                else: 
                    try: exec("%s('%s', %s)" % (main, self.pwd, str(cmd)))
                    except: print("%s: command not found" % on_scr, end='\r')
            else: pass
        self.txtBuffer.append(('\r', (0, 0, 0)))
        self.txtBuffer += list(output.getvalue().rstrip('\n'))
        self.placeholder.append('%s# ' % self.pwd)
    def keyUp(self, key):
        if key == pygame.K_LSHIFT or key == pygame.K_RSHIFT:
            self.shift = False
        elif key == pygame.K_CAPSLOCK:
            self.capsLock = 1 - self.capsLock
    def keyDown(self, key, isVis = False):
        if key == pygame.K_BACKSPACE:
            if (self.txtBuffer and self.txtBuffer[-1][0] != '\n') or not self.txtBuffer:
                try:
                    if self.loc - 1 != -1:
                        self.txtBuffer.pop(self.currentLine + self.loc - 1)
                        self.maxIndex -= 1
                        self.loc -= 1
                except: pass
        elif key == pygame.K_DELETE:
            try:
                if self.loc > self.maxIndex:
                    self.loc = self.maxIndex
                self.txtBuffer.pop(self.currentLine + self.loc)
                self.maxIndex -= 1
            except: pass
        elif key == pygame.K_RETURN:
            cmd = ''
            self.loc = 0
            self.maxIndex = 0
            i = -1
            if isVis:
                while len(self.txtBuffer) > - i - 1 and self.txtBuffer[i][0] != '\r':
                    cmd = self.txtBuffer[i][0] + cmd
                    i -= 1
            else:
                while len(self.txtBuffer) > - i - 1 and self.txtBuffer[i][0] != '\n':
                    cmd = self.txtBuffer[i][0] + cmd
                    i -= 1
            if isVis:
                self.cLineStr = cmd
                self.txtBuffer.append(('\r', (0, 0, 0)))
                return
            else:
                self.exec_cmd(cmd)
                self.txtBuffer.append(('\n'), (0, 0, 0))
        elif key == pygame.K_TAB:
            for _ in range(4):
                self.txtBuffer.append((' ', (0, 0, 0)))
                self.loc += 1
        elif key == pygame.K_LSHIFT or key == pygame.K_RSHIFT:
            self.shift = True
        elif key == pygame.K_CAPSLOCK:
            self.capsLock = 1 - self.capsLock
        elif key == pygame.K_LEFT:
            if self.loc != 0:
                self.loc -= 1
        elif key == pygame.K_RIGHT:
            if self.loc + 1 <= self.maxIndex:
                self.loc += 1
        else:
            if 32 <= key <= 126:
                if (key == 39 or 44 <= key <= 57 or key == 59 or key == 61 or key == 96 or 91 <= key <= 93) and self.shift:
                    self.txtBuffer.insert(self.loc + self.currentLine, (self.caps[chr(key)], (255, 0, 0)))
                elif 97 <= key <= 122 and (self.shift or self.capsLock):
                    self.txtBuffer.insert(self.loc + self.currentLine, (self.caps[chr(key)], (255, 0, 0)))
                else:
                    self.txtBuffer.insert(self.loc + self.currentLine, (chr(key), (255, 255, 255)))
                self.loc += 1
                self.maxIndex += 1

class Secret:
    def __init__(self, rect, dialogID):
        self.rect = pygame.Rect(rect)
        self.dialogID = dialogID
    def mouseDown(self, pos, button):
        if self.rect.collidepoint(pos):
            framework.dialogs.pop()

class DlgStatus(Enum):
    INFO = 0
    WARNING = 1
    ERROR = 2

class Dialog:
    def __init__(self, title, content, status=DlgStatus.INFO):
        self.img = pygame.image.load("res/dialog/dialog.png")
        self.icon = pygame.transform.scale(pygame.image.load("res/dialog/" + str(status) + ".bmp"), (32, 32))
        self.icon.set_colorkey((255, 0, 255))
        self.raster = pygame.font.Font("res/Perfect_DOS_VGA_437.ttf", 16)
        self.title = self.raster.render(title, True, (255, 255, 255))
        self.content = self.wrap(content, 35)
        self.dialogID = 0
        self.w, self.h = self.img.get_size()
        self.x, self.y = 322, 284
        self.closeBtn = None
    def wrap(self, txt, w):
        processed = []
        temp = ""
        for i in range(txt.__len__()):
            if i != 0 and i % w == 0:
                processed.append(self.raster.render(temp, True, (0, 0, 0)))
                temp = ""
            temp += txt[i]
        processed.append(self.raster.render(temp, True, (0, 0, 0)))
        return processed
    def draw(self, screen):
        screen.blit(self.img, (self.x, self.y))
        screen.blit(self.title, (self.x + 10, self.y + 6))
        screen.blit(self.icon, (self.x + 30, self.y + 90))
        for i in range(len(self.content)):
            screen.blit(self.content[i], (self.x + 80, self.y + 35 + i * 16))
    def mouseDown(self, pos, button):
        self.closeBtn.mouseDown(pos, button)

class SnakeGame:
    def __init__(self):
        self.tileWidth = 32
        self.x0, self.y0 = 192, 144
        self.snakeLen = 1
        self.snakePos = []
        self.direction = 0
        self.speedX = (1, 0, -1, 0)
        self.speedY = (0, 1, 0, -1)
        self.sx, self.sy = 0, 0
        self.ix, self.iy = random.randint(0, 19), random.randint(0, 14)
        self.lost = 0
        self.bigFont = pygame.font.Font("res/Perfect_DOS_VGA_437.ttf", 100)
        self.smallFont = pygame.font.Font("res/Perfect_DOS_VGA_437.ttf", 60)
        self.bg = pygame.Surface((640, 480))
        self.bg.fill((255, 255, 255))
        self.gameOver = self.bigFont.render("Game Over!", True, (255, 255, 255))
        self.restart = self.smallFont.render("PRESS R TO RESTART", True, (255, 255, 255))
    def draw(self, canvas):
        canvas.fill((40, 40, 40))
        if self.lost == 1:
            canvas.blit(self.gameOver, (250, 200))
            canvas.blit(self.restart, (230, 300))
            return
        canvas.blit(self.bg, (self.x0, self.y0))
        for pos in self.snakePos[-self.snakeLen:]:
            pygame.draw.rect(canvas, (60, 110, 5), (self.x0 + pos[0] * self.tileWidth, self.y0 + pos[1] * self.tileWidth, self.tileWidth, self.tileWidth))
        pygame.draw.rect(canvas, (190, 30, 50), (self.x0 + self.ix * self.tileWidth, self.y0 + self.iy * self.tileWidth, self.tileWidth, self.tileWidth))
    def move(self):
        if self.lost == 1:
            return
        self.sx = (self.sx + self.speedX[self.direction]) % 20
        self.sy = (self.sy + self.speedY[self.direction]) % 15
        if (self.sx, self.sy) in self.snakePos[-self.snakeLen:]:
            self.lost = 1
        self.snakePos.append((self.sx, self.sy))
        if self.sx == self.ix and self.sy == self.iy:
            self.ix, self.iy = random.randint(0, 19), random.randint(0, 14)
            self.snakeLen += 1
    def keyDown(self, key):
        if key == pygame.K_UP:
            self.direction = 3
        if key == pygame.K_DOWN:
            self.direction = 1
        if key == pygame.K_LEFT:
            self.direction = 2
        if key == pygame.K_RIGHT:
            self.direction = 0
        if key == pygame.K_r and self.lost == 1:
            self.snakeLen = 1
            self.snakePos = []
            self.sx, self.sy = 0, 0
            self.ix, self.iy = random.randint(0, 19), random.randint(0, 14)
            self.lost = 0

framework = Kernel()
bg = App("res/clouds.jpg")
term = App("res/blank.jpg")
snake = App("res/blank.jpg")
snake.enableCanvas()
snakeGame = SnakeGame()
framework.appID = bg.appID
framework.addApp(bg)
framework.addApp(term)
framework.addApp(snake)
framework.addDialog(Dialog("Hey there!", "Welcome to Winnux 58!"))
bg.addButton(Button("res/button/txt_btn.bmp", 20, 20, term.appID, font=framework.raster, content="TERMINAL"))
bg.addButton(Button("res/button/txt_btn.bmp", 20, 60, snake.appID, font=framework.raster, content="SNAKE"))
term.addButton(Button("res/button/txt_btn.bmp", width // 2 - 35, 20, bg.appID, font=framework.raster, content="CLOSE"))
snake.addButton(Button("res/button/txt_btn.bmp", width // 2 - 35, 20, bg.appID, font=framework.raster, content="CLOSE"))
term.enableTxtField(50, 60, 100, 40)

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
            framework.keyDown(event.key)
        elif event.type == pygame.KEYUP:
            framework.keyUp(event.key)
        if event.type == pygame.MOUSEBUTTONDOWN:
            framework.mouseDown(event.pos, event.button)
        elif event.type == pygame.MOUSEBUTTONUP:
            framework.mouseUp(event.pos, event.button)
        elif event.type == pygame.MOUSEMOTION:
            framework.mouseMotion(event.pos)
    framework.launch()
KevTheUseless commented 3 years ago

RTDC 20210117.pptx 1.17 Club活动,ppt讲稿自由发挥,但请至少包含以下内容: 1、我是如何开始学编程的,学习过程; 2、我为什么要做这个软件,心路历程; 3、技术: a)、程序结构 b)、消息传递机制 c)、程序亮点 d)、遇到的最大困难 answer questions 1, 2, 3c, 3d

KevTheUseless commented 3 years ago

woah

pythonleo commented 3 years ago

hi

KevTheUseless commented 3 years ago

nice

KevTheUseless commented 3 years ago

today lets focus on copy paste & editor... stuff

pythonleo commented 3 years ago

actually i wrote a BIT of ctrl-c/v stuff

pythonleo commented 3 years ago

didnt commit yet

KevTheUseless commented 3 years ago

go do that

pythonleo commented 3 years ago

and come in here (ms whiteboard)

KevTheUseless commented 3 years ago

btw i did a windows spt pack & changed the code to be in one file

pythonleo commented 3 years ago

why... i wanted it to be in multiple files nvm though, if it works it's fine

KevTheUseless commented 3 years ago

bc i need the py runtime to be embedded and the embedded runtime doesnt support multi-file modular stuff

KevTheUseless commented 3 years ago

heck it odesnt even have pip

pythonleo commented 3 years ago

holy crap

pythonleo commented 3 years ago

well i'll give u a pull request

KevTheUseless commented 3 years ago

but hey look

KevTheUseless commented 3 years ago

https://cowtransfer.com/s/976ccf9246f048 547147

pythonleo commented 3 years ago

image

pythonleo commented 3 years ago

whiteboard

pythonleo commented 3 years ago

?

KevTheUseless commented 3 years ago

wut

pythonleo commented 3 years ago

oh didnt check sorry

pythonleo commented 3 years ago

image kinda hideous but you get the point, that's gonna be our layout

KevTheUseless commented 3 years ago

x/y for msg area?

pythonleo commented 3 years ago

top-left: (0, 440) btm-right: (340, 710)

KevTheUseless commented 3 years ago

new width/height?

pythonleo commented 3 years ago

ive done the txtfield part already image

KevTheUseless commented 3 years ago

the resize?

KevTheUseless commented 3 years ago

can i have the new width & height

KevTheUseless commented 3 years ago

im done w/ the msg part

KevTheUseless commented 3 years ago

???

KevTheUseless commented 3 years ago

there?

pythonleo commented 3 years ago

? image

pythonleo commented 3 years ago

and push ur stuff

KevTheUseless commented 3 years ago

whiteboard