예제 #1
0
    def test_hypnen_at_the_end(self):
        words = [
            TextPunctuation('сло-', [None, None, None, constants.HYPHEN]),
            End()
        ]
        result = run_through_module(words)

        self.assertEqual(result, [End()])
예제 #2
0
    def test_union_with_foll_upper(self):
        words = [
            TextPunctuation('З', [None]),
            TextPunctuation('собою', [None, None, None, None, None]),
            End()
        ]
        result = run_through_module(words)

        self.assertEqual(result, [Text('зсобою'), End()])
예제 #3
0
    def test_non_alphabet(self):
        words = [
            TextPunctuation('foreign',
                            [None, None, None, None, None, None, None]),
            End()
        ]
        result = run_through_module(words)

        self.assertEqual(result, [End()])
예제 #4
0
    def test_punctuation_within(self):
        words = [
            TextPunctuation('сло!во',
                            [None, None, None, constants.PUNCT, None, None]),
            End()
        ]
        result = run_through_module(words)

        self.assertEqual(result, [End()])
예제 #5
0
    def test_hyphen(self):
        words = [
            TextPunctuation('сло-во',
                            [None, None, None, constants.HYPHEN, None, None]),
            End()
        ]
        result = run_through_module(words)

        self.assertEqual(result, [Text('слово'), End()])
예제 #6
0
    def test_quotation(self):
        words = [
            TextPunctuation('«слово»', [
                constants.PUNCT, None, None, None, None, None, constants.PUNCT
            ]),
            End()
        ]
        result = run_through_module(words)

        self.assertEqual(result, [Text('слово'), End()])
예제 #7
0
    def test_union_with_prec_upper(self):
        words = [
            TextPunctuation('українського', [
                None, None, None, None, None, None, None, None, None, None,
                None, None
            ]),
            TextPunctuation('Ж', [None]),
            End()
        ]
        result = run_through_module(words)

        self.assertEqual(result, [Text('українськогож'), End()])
예제 #8
0
    def run(self):
        pipe_out = self._pipes[0]

        words = self.read()

        for word in words:
            send_word(word, pipe_out)

        send_word(End(), pipe_out)
예제 #9
0
파일: game.py 프로젝트: GHLoeng/Tank
    def start(self):
        self.music.play_game_start()
        self.score, self.scoreP1, self.scoreP2 = 0, 0, 0
        while self.game_state == State.Ok:
            self.clock.tick(Clock_frequency)

            self.tank_factory.create()

            gf.check_events(self.tank_factory, self.music)
            self.turnScore = gf.update_screen(self.screen, self.game_map,
                                              self.tank_factory, self.music,
                                              self.board)
            self.score += self.turnScore
            gf.draw_screen(self.screen, self.game_map, self.tank_factory,
                           self.board)

            self.game_state = gf.check_win(self.game_map, self.tank_factory)
            if self.game_state == State.Success:
                self.game_level += 1
                if self.game_level > Max_level:
                    self.game_level = 1
                    break
                else:
                    if self.game_level >= 2:
                        if self.is_2p: self.draw_score_p2()
                        else: self.draw_score_p1()
                    self.initialize()
                    self.game_state = State.Ok

        self.game_level = 1
        self.music.play_game_over()
        score1, score2, count = 0, 0, 0
        while count <= 3:
            score1 += self.tank_factory.tot_tank_type1[
                count] * self.enemy_score[count]
            score2 += self.tank_factory.tot_tank_type2[
                count] * self.enemy_score[count]
            count += 1
        self.scoreP1 += score1
        self.scoreP2 += score2
        self.end_menu = End(self.screen, self.tank_factory)
        if self.is_2p: self.end_menu.draw2p(self.scoreP1, self.scoreP2)
        else: self.end_menu.draw(self.score)
예제 #10
0
def end(status):
    """
    End Scene
    :param status: (bool) Ready to capture User Event
    :return: Updated Status Param
    """
    current = End()
    if current.status:
        status = current.status
    return status
예제 #11
0
def main():
	choose_word = Word()
	word = choose_word.getWord()
	words_without_spaces = list(word)
	for i in word:
		if i == 'space':
			words_without_spaces.remove(i)

	win = GraphWin('Hangman', 600, 300)

	hang = Hang(win)
	slots_display = Format(word, win)
	letters_slots = slots_display.position_letters(150)

	end = hang.end_game()

	letters_class = Letters(win, letters_slots, words_without_spaces)

	all_letters = []

	while end:
		letter = win.getKey().lower()
		if len(letter) != 1 or letter.isalpha() == False:
			continue
		elif letter in all_letters:
			print('You already tried that letter')
			continue
		all_letters.append(letter)
		errors = hang.draw_hangman(letter, words_without_spaces)

		letters_class.display_letter(letter)

		complete = all(i in all_letters for i in words_without_spaces)

		end = hang.end_game(errors, complete)

	if complete == True:
		Text(Point(325, 40), 'You got it! Amazing!').draw(win)
	elif complete == False:
		lost = Lost(win, letters_slots, words_without_spaces)
		lost.display_result()
		Text(Point(325, 40), 'You lost...try again').draw(win)

	quit_button = End(win, 570, 280, 40, 20, 'Quit')
	restart_button = End(win, 515, 280, 60, 20, 'Restart')

	while True:
		click = win.getMouse()
		if quit_button.interact(click):
			break
		elif restart_button.interact(click):
			win.close()
			main()
			break

	win.close()
예제 #12
0
파일: game.py 프로젝트: GHLoeng/Tank
class Game:
    def __init__(self):
        pygame.init()
        pygame.mixer.init()
        self.screen = pygame.display.set_mode((Screen_width, Screen_height))
        pygame.display.set_caption(Game_name)

        self.clock = None
        self.music = None
        self.game_state = None
        self.is_2p = None
        self.score = None
        self.scoreP1 = None
        self.scoreP2 = None
        self.turnScore = None
        self.game_map = None
        self.tank_factory = None
        self.board = None
        self.game_level = 1
        self.white = (255, 255, 255)
        self.red = (255, 0, 0)
        self.font = pygame.font.SysFont(None, 36)
        self.full_image = pygame.image.load(Full_path)
        self.tank_image = []
        self.enemy_num = [0, 0, 0, 0]
        self.enemy_score = [100, 200, 300, 400]
        tank_Ypos = 6
        while tank_Ypos <= 9:
            self.tank_image.append(
                self.full_image.subsurface(
                    pygame.Rect((1 * 32, tank_Ypos * 32), (32, 32))))
            tank_Ypos = tank_Ypos + 1

    def Start_menu(self):
        self.start_menu = Start(self.screen)
        self.game_level = 1
        self.is_2p = self.start_menu.draw()

    def prefstr(self, text, pos, color):
        self.text_image = self.font.render(text, True, color, Bg_color)
        self.screen.blit(self.text_image, pos)

    def prefnum(self, num, pos, color):
        self.text = "{:,}".format(num)
        self.text_image = self.font.render(self.text, True, color, Bg_color)
        self.screen.blit(self.text_image, pos)

    def draw_score_p1(self):
        while True:
            self.screen.fill(Bg_color)
            self.prefstr("Total Score : ", [50, 40], self.white)
            self.prefnum(self.score, [300, 40], self.red)
            self.prefstr("Score : ", [50, 80], self.white)
            self.prefnum(self.score, [300, 80], self.white)
            tank_num = 0
            while tank_num <= 3:
                self.screen.blit(self.tank_image[tank_num],
                                 [50, 120 + tank_num * 50])
                self.prefnum(self.tank_factory.tot_tank_type1[tank_num],
                             [180, 130 + tank_num * 50], self.white)
                self.prefnum(
                    self.tank_factory.tot_tank_type1[tank_num] *
                    self.enemy_score[tank_num], [300, 130 + tank_num * 50],
                    self.white)
                tank_num = tank_num + 1
            self.prefstr("Press space to continue", [100, 350], self.white)
            pygame.display.update()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE: return

    def draw_score_p2(self):
        score1, score2, count = 0, 0, 0
        while count <= 3:
            score1 += self.tank_factory.tot_tank_type1[
                count] * self.enemy_score[count]
            score2 += self.tank_factory.tot_tank_type2[
                count] * self.enemy_score[count]
            count += 1
        self.scoreP1 += score1
        self.scoreP2 += score2
        while True:
            self.screen.fill(Bg_color)
            self.prefstr("Player 1", [200, 5], self.white)
            self.prefstr("Player 2", [300, 5], self.white)
            self.prefstr("Total Score : ", [50, 40], self.white)
            self.prefnum(self.scoreP1, [250, 40], self.red)
            self.prefnum(self.scoreP2, [350, 40], self.red)
            self.prefstr("Score : ", [50, 80], self.white)
            self.prefnum(score1, [250, 80], self.white)
            self.prefnum(score2, [350, 80], self.white)
            tank_num = 0
            while tank_num <= 3:
                self.screen.blit(self.tank_image[tank_num],
                                 [220, 120 + tank_num * 50])
                self.prefnum(self.tank_factory.tot_tank_type1[tank_num], \
                             [150, 130 + tank_num * 50], self.white)
                self.prefnum(self.tank_factory.tot_tank_type1[tank_num]*\
                             self.enemy_score[tank_num], [50, 130 + tank_num * 50], self.white)
                self.prefnum(self.tank_factory.tot_tank_type2[tank_num], \
                             [310, 130 + tank_num * 50], self.white)
                self.prefnum(self.tank_factory.tot_tank_type2[tank_num]*\
                             self.enemy_score[tank_num], [390, 130 + tank_num * 50], self.white)
                tank_num = tank_num + 1
            self.prefstr("Press space to continue", [100, 350], self.white)
            pygame.display.update()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE: return

    def initialize(self):
        self.clock = pygame.time.Clock()
        self.music = GameMusic()
        self.game_state = State.Ok
        self.game_map = Map(self.screen, self.game_level)
        self.tank_factory = TankFactory(self.screen, Enemy_number, self.is_2p)
        self.board = Board(self.screen, self.tank_factory, self.is_2p,
                           self.game_level)

    def start(self):
        self.music.play_game_start()
        self.score, self.scoreP1, self.scoreP2 = 0, 0, 0
        while self.game_state == State.Ok:
            self.clock.tick(Clock_frequency)

            self.tank_factory.create()

            gf.check_events(self.tank_factory, self.music)
            self.turnScore = gf.update_screen(self.screen, self.game_map,
                                              self.tank_factory, self.music,
                                              self.board)
            self.score += self.turnScore
            gf.draw_screen(self.screen, self.game_map, self.tank_factory,
                           self.board)

            self.game_state = gf.check_win(self.game_map, self.tank_factory)
            if self.game_state == State.Success:
                self.game_level += 1
                if self.game_level > Max_level:
                    self.game_level = 1
                    break
                else:
                    if self.game_level >= 2:
                        if self.is_2p: self.draw_score_p2()
                        else: self.draw_score_p1()
                    self.initialize()
                    self.game_state = State.Ok

        self.game_level = 1
        self.music.play_game_over()
        score1, score2, count = 0, 0, 0
        while count <= 3:
            score1 += self.tank_factory.tot_tank_type1[
                count] * self.enemy_score[count]
            score2 += self.tank_factory.tot_tank_type2[
                count] * self.enemy_score[count]
            count += 1
        self.scoreP1 += score1
        self.scoreP2 += score2
        self.end_menu = End(self.screen, self.tank_factory)
        if self.is_2p: self.end_menu.draw2p(self.scoreP1, self.scoreP2)
        else: self.end_menu.draw(self.score)
예제 #13
0
    def test_punctuation_only(self):
        words = [TextPunctuation('—', [constants.PUNCT]), End()]
        result = run_through_module(words)

        self.assertEqual(result, [End()])
예제 #14
0
from clean_module import CleanModule
from config_data import ConfigData
from end import End
from pipe import Pipe
from read_module import ReadModule
from word import Text

file_path = '../test_files/belarusian/test_belarusian.txt'
encoding = 'utf-8'
data = ConfigData('../../configs/conf_be_cyr.json')

read_clean_pipe = Pipe(queue.Queue(), threading.Condition())
clean_out_pipe = Pipe(queue.Queue(), threading.Condition())

expected_result = [Text('у'), Text('беларускай'), Text('мове'), Text('зычныя'), Text('могуць'), Text('адрознівацца'), Text('даўжынёй'), Text('гучання'), Text('якая'), Text('паказвае'), Text('на'), Text('стык'), Text('марфем'), Text('пераважная'), Text('колькасць'), Text('гукаў'), Text('утвараюццаў'), Text('цэнтры'), Text('ротавай'), Text('поласці'), Text('пры'), Text('высокім'), Text('агульным'), Text('пад’ёме'), Text('языка'), Text('вялікае'), Text('знаходзіласяў'), Text('дынастычнай'), Text('уніі'), Text('зпольскім'), Text('каралеўствам'), End()]


def get_from_module(pipe_out):
    read_module = ReadModule([read_clean_pipe], file_path, encoding, data)
    read_module.run()
    result = []

    while True:
        pipe_out.acquire()
        if pipe_out.empty():
            pipe_out.wait()
        cleaned_word = pipe_out.get()
        result.append(cleaned_word)
        pipe_out.release()
예제 #15
0
    def test_capital(self):
        words = [TextPunctuation('Київ', [None, None, None, None]), End()]
        result = run_through_module(words)

        self.assertEqual(result, [Text('київ'), End()])
예제 #16
0
    def test_end(self):
        words = [End()]

        result = run_through_module(words)

        self.assertEqual(result, [End()])
예제 #17
0
import constants
from config_data import ConfigData
from end import End
from pipe import *
from read_module import ReadModule
from word import TextPunctuation


file_path = '../test_files/belarusian/test_belarusian.txt'
encoding = 'utf-8-sig'
data = ConfigData('../../../py_scripts/configs/conf_be_cyr.json')

pipe_out = Pipe(queue.Queue(), threading.Condition())
module = ReadModule([pipe_out], file_path, encoding, data)

expected_result = [TextPunctuation('У', [None]), TextPunctuation('беларускай', [None, None, None, None, None, None, None, None, None, None]), TextPunctuation('мове', [None, None, None, None]), TextPunctuation('зычныя', [None, None, None, None, None, None]), TextPunctuation('могуць', [None, None, None, None, None, None]), TextPunctuation('адрознівацца', [None, None, None, None, None, None, None, None, None, None, None, None]), TextPunctuation('даўжынёй', [None, None, None, None, None, None, None, None]), TextPunctuation('гучання,', [None, None, None, None, None, None, None, constants.PUNCT]), TextPunctuation('якая', [None, None, None, None]), TextPunctuation('пака-звае', [None, None, None, None, constants.HYPHEN, None, None, None, None]), TextPunctuation('на', [None, None]), TextPunctuation('стык', [None, None, None, None]), TextPunctuation('марфем...', [None, None, None, None, None, None, constants.PUNCT, constants.PUNCT, constants.PUNCT]), TextPunctuation('Пераважная', [None, None, None, None, None, None, None, None, None, None]), TextPunctuation('‚колькасць‘', [constants.PUNCT, None, None, None, None, None, None, None, None, None, constants.PUNCT]), TextPunctuation('гукаў', [None, None, None, None, None]), TextPunctuation('утвараюцца', [None, None, None, None, None, None, None, None, None, None]), TextPunctuation('ў', [None]), TextPunctuation('цэнтры', [None, None, None, None, None, None]), TextPunctuation('ротавай', [None, None, None, None, None, None, None]), TextPunctuation('поласці', [None, None, None, None, None, None, None]), TextPunctuation('пры', [None, None, None]), TextPunctuation('высокім', [None, None, None, None, None, None, None]), TextPunctuation('агульным', [None, None, None, None, None, None, None, None]), TextPunctuation('пад’ёме', [None, None, None, None, None, None, None]), TextPunctuation('языка.', [None, None, None, None, None, constants.PUNCT]), TextPunctuation('Вялікае', [None, None, None, None, None, None, None]), TextPunctuation('Ducatus', [None, None, None, None, None, None, None]), TextPunctuation('Lithuaniae', [None, None, None, None, None, None, None, None, None, None]), TextPunctuation('знаходзілася', [None, None, None, None, None, None, None, None, None, None, None, None]), TextPunctuation('ў', [None]), TextPunctuation('дынастычнай', [None, None, None, None, None, None, None, None, None, None, None]), TextPunctuation('уніі', [None, None, None, None]), TextPunctuation('—', [constants.PUNCT]), TextPunctuation('з', [None]), TextPunctuation('Польскім', [None, None, None, None, None, None, None, None]), TextPunctuation('кара-леўствам!', [None, None, None, None, constants.HYPHEN, None, None, None, None, None, None, None, None, constants.PUNCT]), End()]


def get_from_module():

    module.run()
    result = []

    while True:
        pipe_out.acquire()
        if pipe_out.empty():
            pipe_out.wait()
        cleaned_word = pipe_out.get()
        result.append(cleaned_word)
        pipe_out.release()
예제 #18
0
    ins4p2 = Instruction.Instruction(False, "resultado ins4p2", 5)
    instructionsP2 = [ins1p2, ins2p2, ins3p2, ins4p2]
    p2 = Process.Process(2, instructionsP2)

    memory = Memory.Memory()
    memory.putProcess(p1)
    memory.putProcess(p2)

    pcbP1 = PCB.PCB(1, len(p1.getInstructions()))
    pcbP2 = PCB.PCB(2, len(p2.getInstructions()))

    #pcbP1 = PCBPriority.PCBPriority(pcbP1, 10)
    #pcbP2 = PCBPriority.PCBPriority(pcbP2, 3)

    cpu = Cpu.Cpu(memory)
    policy = Simple.Simple()
    #policy = RoundRobin.RoundRobin(1)
    scheduler = ReadyFIFO.ReadyFIFO(cpu, policy)
    #scheduler = ReadyPriority.ReadyPriority(cpu, policy)
    scheduler.put(pcbP1)
    scheduler.put(pcbP2)
    io = IO.IO(memory)
    end = End.End()

    clock = Clock.Clock()
    clock.addObserver(cpu)
    clock.addObserver(scheduler)

    kernel = Kernel.Kernel(scheduler, cpu, memory, io, end, clock)

    kernel.turnOn()
예제 #19
0
    def test_union_with_foll_last(self):
        words = [TextPunctuation('з', [None]), End()]
        result = run_through_module(words)

        self.assertEqual(result, [Text('з'), End()])
예제 #20
0
from clean_module import CleanModule
from config_data import ConfigData
from end import End
from pipe import Pipe
from read_module import ReadModule
from word import Text

file_path = '../test_files/serbian/test_serbian.txt'
encoding = 'utf-8-sig'
data = ConfigData('../../configs/conf_sr_cyr.json')

read_clean_pipe = Pipe(queue.Queue(), threading.Condition())
clean_out_pipe = Pipe(queue.Queue(), threading.Condition())


expected_result = [Text('просторе'), Text('данашњег'), Text('панонског'), Text('басена'), Text('некада'), Text('је'), Text('прекривао'), Text('праокеан'), Text('тетис'), Text('чијим'), Text('повлачењем'), Text('је'), Text('и'), Text('настао'), Text('панонски'), Text('басен'), Text('повлачењем'), Text('тетис'), Text('је'), Text('иза'), Text('себе'), Text('оставио'), Text('веома'), Text('плодно'), Text('тло'), Text('па'), Text('се'), Text('због'), Text('тога'), Text('панонски'), Text('басен'), Text('назива'), Text('још'), Text('и'), Text('житницом'), Text('србије'), Text('за'), Text('просторе'), Text('ове'), Text('регије'), Text('особена'), Text('је'), Text('црница'), Text('или'), Text('чернозем'), Text('као'), Text('врста'), Text('земљишта'), Text('међутим'), Text('јавља'), Text('се'), Text('и'), Text('деградирани'), Text('чернозем'), Text('као'), Text('и'), Text('плодно'), Text('алувијално'), Text('тло'), Text('и'), Text('гајњаче'), End()]


def get_from_module(pipe_out):
    read_module = ReadModule([read_clean_pipe], file_path, encoding, data)
    read_module.run()
    result = []

    while True:
        pipe_out.acquire()
        if pipe_out.empty():
            pipe_out.wait()
        cleaned_word = pipe_out.get()
        result.append(cleaned_word)
        pipe_out.release()
예제 #21
0
clean_out_pipe = Pipe(queue.Queue(), threading.Condition())

expected_result = [
    Text('toto'),
    Text('je'),
    Text('prvá'),
    Text('veta'),
    Text('#tomobil'),
    Text('ide'),
    Text('posledné'),
    Text('slovo'),
    Text('má'),
    Text('byť'),
    Text('vyhodené'),
    Text('slovo'),
    End()
]


def get_from_module(pipe_out):
    read_module = ReadModule([read_clean_pipe], file_path, encoding, data)
    read_module.run()
    result = []

    while True:
        pipe_out.acquire()
        if pipe_out.empty():
            pipe_out.wait()
        cleaned_word = pipe_out.get()
        result.append(cleaned_word)
        pipe_out.release()
예제 #22
0
from pipe import Pipe
from queue import Queue
from threading import Condition
from write_module import WriteModule
from word import SyllablesLengths
from end import End
import unittest
import time
import os.path

words_to_do = [[End()],
               [
                   SyllablesLengths(["pou", "ze"], [2, 2]),
                   SyllablesLengths(["fa", "rma", "ceu", "ti", "cký"],
                                    [2, 3, 2, 2, 3]),
                   End()
               ], [SyllablesLengths(["sněh"], [3])] * 1000]

syllables = ["pou-ze fa-rma-ceu-ti-cký", "sněh " * 999 + "sněh"]

lengths = ["2-2 2-3-2-2-3", "3 " * 999 + "3"]

file_path = "blabla/"

file_syllables = file_path + "syllable_text.txt"

file_lengths = file_path + "syllable_lengths_text.txt"


class TestStringMethods(unittest.TestCase):
    @classmethod
예제 #23
0
    def test_apostrophe_U02BC(self):
        words = [TextPunctuation('вʼю', [None, None, None]), End()]
        result = run_through_module(words)

        self.assertEqual(result, [Text('вʼю'), End()])
예제 #24
0
    if play == 1:
        play = rules(0)

        # if rules scene returns true => game : level 1
        if play == 1:

            #  Play with  music preferences ( "on" by default, only for the first time )
            play, music_status = levels(0, 1, "on")

            # Level one returns true => Check for the others
            if play == 1:
                for level_id in range(2, 4):

                    # Current level returns true : Play another one
                    if play == 1:
                        play, music_status = levels(0, level_id, music_status)

                        # Quit
                        if play == 0:
                            state_id = End()
                            run = False

            else:
                run = False
        else:
            run = False
    else:
        run = False

pygame.quit()
예제 #25
0
import pygame
import sys

from head import Head
from end import End
from body import Body

pygame.init()
FPS = 60

screen = pygame.display.set_mode((1200, 600))
pygame.display.set_caption('贪吃蛇')

body = Body(screen)
head = Head(screen, body)
end = End(screen, body)

while True:
    for event in pygame.event.get():
        # 判断事件是否为退出事件
        if event.type == pygame.QUIT:
            # 退出pygame
            pygame.quit()
            # 退出系统
            sys.exit()
        #写控制蛇移动的一些标记
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                head.moving_left = True
                body.moving_left = True
                end.moving_left = True
예제 #26
0
 def tearDownClass(cls):
     run_through_module(End())
예제 #27
0
open_door = pygame.image.load("images/open_door.png")
closed_door = pygame.image.load("images/closed_door.png")

dynamite_sound = pygame.mixer.Sound("sounds/bomb.wav")
key_sound = pygame.mixer.Sound("sounds/key.ogg")
door_sound = pygame.mixer.Sound("sounds/door_creak_closing.wav")

pygame.mixer.music.load("sounds/zombie_theme.wav")
pygame.mixer.music.play(-1)

level = Level1()

surface = Surface(SURFACE_SIZE, TILE_SIZE, level)

end_tile = Surface.get_tile_by_number(173)
level.end = End(end_tile.x, end_tile.y)

player_position = Surface.get_tile_by_number(level.player_position)

player = Player(player_position.x, player_position.y, TILE_SIZE)

bg = pygame.image.load("images/bg.png")

game_screen = pygame.display.set_mode(SURFACE_SIZE)

pygame.display.set_caption("Zombie")

clock = pygame.time.Clock()

total_frames = 0