import tkinter as tk
from tkinter import font
import random

hlavni = tk.Tk()

hlavni.geometry("1200x750")

label_font = font.Font(size=15, weight = 'bold')

def start():
    maze = create_maze()
    display_maze(maze)

def easy():
    canvas.delete('all')
    krok = 40
    krok2 = 0

    pravdepodobnost = 0.4
    pocet_car = 6

    for x in range(pocet_car):
        for y in range(pocet_car):
            if random.random() <= pravdepodobnost:
                canvas.create_line(y*krok,krok2,y*krok, krok2+40,width=3)
        krok2 += 40

    krok = 40
    krok2 = 0

    for x in range(pocet_car):
        for y in range(pocet_car):
            if random.random() <= pravdepodobnost:
                canvas.create_line(krok2, y*krok, krok2+40, y*krok,width=3)
        krok2 += 40

    canvas.create_rectangle(3,3,pocet_car*krok,pocet_car*krok,width=3)
    canvas.create_line(krok*(pocet_car/2), pocet_car*krok, krok*(pocet_car/2)+krok, pocet_car*krok, fill="red", width=3)

def medium():
    canvas.delete('all')
    krok = 40
    krok2 = 0

    pravdepodobnost = 0.4
    pocet_car = 8

    for x in range(pocet_car):
        for y in range(pocet_car):
            if random.random() <= pravdepodobnost:
                canvas.create_line(y*krok,krok2,y*krok, krok2+40,width=3)
        krok2 += 40

    krok = 40
    krok2 = 0

    for x in range(pocet_car):
        for y in range(pocet_car):
            if random.random() <= pravdepodobnost:
                canvas.create_line(krok2, y*krok, krok2+40, y*krok,width=3)
        krok2 += 40

    canvas.create_rectangle(3,3,pocet_car*krok,pocet_car*krok,width=3)
    canvas.create_line(krok*(pocet_car/2), pocet_car*krok, krok*(pocet_car/2)+krok, pocet_car*krok, fill="red", width=3)

def hard():
    canvas.delete('all')
    krok = 40
    krok2 = 0

    pravdepodobnost = 0.4
    pocet_car = 10

    for x in range(pocet_car):
        for y in range(pocet_car):
            if random.random() <= pravdepodobnost:
                canvas.create_line(y*krok,krok2,y*krok, krok2+40,width=3)
        krok2 += 40

    krok = 40
    krok2 = 0

    for x in range(pocet_car):
        for y in range(pocet_car):
            if random.random() <= pravdepodobnost:
                canvas.create_line(krok2, y*krok, krok2+40, y*krok,width=3)
        krok2 += 40

    canvas.create_rectangle(3,3,pocet_car*krok,pocet_car*krok,width=3)
    canvas.create_line(krok*(pocet_car/2), pocet_car*krok, krok*(pocet_car/2)+krok, pocet_car*krok, fill="red", width=3)

menu_frame = tk.Frame(hlavni)
menu_frame.pack(side=tk.LEFT, padx=10, pady=10)

button_frame = tk.Frame(menu_frame)
button_frame.pack(padx=10, pady=20)

position_frame = tk.Frame(menu_frame)
position_frame.pack(padx=10, pady=30)

option_label = tk.Label(button_frame, text="Výběr bludiště", font = label_font)
option_label.pack(pady=10, padx=10)

a = tk.Button(button_frame,text="EASY", background="green", height=2, width=10, command=easy)
a.pack(padx=10, pady=5)

b = tk.Button(button_frame,text="MEDIUM", background="orange", height=2, width=10, command=medium)
b.pack(padx=10, pady=5)

c = tk.Button(button_frame,text="HARD", background="red", height=2, width=10, command=hard)
c.pack(padx=10, pady=5)

position_label = tk.Label(position_frame, text="Umístění robota", font = label_font)
position_label.pack(pady=10, padx=10)

startbtn = tk.Button(menu_frame, text=u"START", activebackground="red", background="light green", font= (None, 20), height=2, width=10,command=easy)
startbtn.pack(side="left",pady=20, padx=20)

xposition_label = tk.Label(position_frame, text="x:", font = label_font)
xposition_label.pack(pady=10, padx=10)

xposition_entry = tk.Entry(position_frame, font = label_font)
xposition_entry.pack(pady=10, padx=35)

yposition_label = tk.Label(position_frame, text="y:", font = label_font)
yposition_label.pack(pady=10, padx=10)

yposition_entry = tk.Entry(position_frame, font = label_font)
yposition_entry.pack(pady=10, padx=35)

cara = tk.Canvas(hlavni, width=2, height=1080, bg="black")
cara.pack(side=tk.LEFT)

canvas = tk.Canvas(hlavni, width=400, height=400, bg="white")
canvas.pack(pady=100)
#####

#####
hlavni.mainloop()


import random
import linecache
import PlayerClass

class Hangman:

    def __init__(self):
        self.a = random.randint(1, 214)
        self.specLine = linecache.getline("HangmanWords.txt", self.a)
        self.charList = []
        self.player = PlayerClass.Player()
        self.name = "Player"
        self.num_guesses = 10
        self.guess_control = 10

    def welcome_message(self):
        print()
        print("\u001b[34mWelcome, \u001b[30m", self.player.get_name(),  ",\u001b[34m to Hangman!")
        print("A random word has been selected, "
              "and each letter is represented by a \"_\".")
        print("Keep guessing letters until you find the right word,"
              " or until you run out of guesses.")
        print("By default, you only get 10 wrong guesses before the game ends.")
        print("Choose your letters wisely. \u001b[0m")
        print()

    def get_word(self):
        self.a = random.randint(1, 214)
        self.specLine = linecache.getline("HangmanWords.txt", self.a)
        print("THE WORD: ")
        self.charList = []
        for i in range(1, len(self.specLine)):
            self.charList.append("_")

        for i in range(len(self.charList)):
            print(self.charList[i], end=" ")

        print("   (", len(self.charList), "letters)")
        print()

    def play_hangman(self):
        self.get_word()
        letter = "_"
        print("You have", self.num_guesses, "guesses left!")

        guess_list = []
        while (letter in self.charList) and (self.num_guesses <= self.guess_control):
            guess = input("Guess a letter: ")
            while guess in guess_list:
                print("You already guessed that one.")
                guess = input("Guess something else: ")
            guess_list.append(guess)

            if guess in self.specLine:
                for index in range(len(self.charList)):
                    if self.specLine[index] == guess:
                        self.charList[index] = guess

            else:
                self.num_guesses -= 1
                if self.num_guesses == 0:
                    print("Sorry, you ran out of guesses.")
                    print("The word was\u001b[31m", self.specLine, "\u001b[0m")
                    self.player.add_loss()
                    break

            for i in range(len(self.charList)):
                print(self.charList[i], end=" ")
            print()

            if letter not in self.charList:
                print()
                print("Congratulations! You guessed the word\u001b[33m", end=" ")
                for i in range(len(self.charList)):
                    print(self.charList[i], end="")
                print("\u001b[0m!! ")
                self.player.add_win()
                break

            else:
                print("You have", self.num_guesses, "guesses left!")
                print()

        self.num_guesses = self.guess_control

    def change_guesses(self):
        print("There are currently ", self.num_guesses, "guesses.")
        self.num_guesses = int(input("Enter the new number of guesses (number must not be less than 5): "))
        while self.num_guesses < 5:
            self.num_guesses = int(input("Enter a valid number of guesses (number must not be less than 5): "))
        self.guess_control = self.num_guesses
        print("There are now ", self.num_guesses, "guesses.")

    def set_player(self, name):
        self.player.set_name(name)

    def get_player(self):
        if self.name == "Player":
            self.name = input("Please enter your name: ")
            self.set_player(self.name)
            return self.player.get_name()

    def menu_choice(self):
        print()
        print("----------------------------------")
        print("|             Menu               |")
        print("|--------------------------------|")
        print("| 0.        End game             |")
        print("| 1. Display welcome message     |")
        print("| 2.       Play game             |")
        print("| 3.     Display stats           |")
        print("| 4.      Reset stats            |")
        print("| 5. Change number of guesses    |")
        print("----------------------------------")
        print()
        choice = int(input("Enter your choice from the menu: "))
        while choice < 0 or choice > 5:
            choice = int(input("Please enter a valid choice: "))
        return choice

    def run(self):
        self.get_player()
        choice = -1
        while choice != 0:
            choice = self.menu_choice()
            if choice == 1:
                print()
                self.welcome_message()
            elif choice == 2:
                print()
                self.play_hangman()
                print()
            elif choice == 3:
                print()
                print(self.player)
                print()
            elif choice == 4:
                print()
                self.player.reset()
                print(self.player)
                print()
            elif choice == 5:
                print()
                self.change_guesses()
                print()
        if choice == 0:
            print("wins percent: ", self.player.get_wins_percent(), "%")
            print("Good game, ", self.player.get_name(), end="")
            print("!")


from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse
from django_loci.tests.base.test_admin import BaseTestAdmin
from swapper import load_model

from ...tests.utils import TestAdminMixin
from .utils import TestGeoMixin

Device = load_model('config', 'Device')
Location = load_model('geo', 'Location')
FloorPlan = load_model('geo', 'FloorPlan')
DeviceLocation = load_model('geo', 'DeviceLocation')

class TestAdmin(TestAdminMixin, TestGeoMixin, BaseTestAdmin, TestCase):
    app_label = 'geo'
    object_model = Device
    location_model = Location
    floorplan_model = FloorPlan
    object_location_model = DeviceLocation
    user_model = get_user_model()

    def setUp(self):
        """override TestAdminMixin.setUp"""
        pass

    def _create_multitenancy_test_env(self, vpn=False):
        org1 = self._create_organization(name='test1org')
        org2 = self._create_organization(name='test2org')
        inactive = self._create_organization(name='inactive-org', is_active=False)
        operator = self._create_operator(organizations=[org1, inactive])
        l1 = self._create_location(
            name='location1org', type='indoor', organization=org1
        )
        l2 = self._create_location(
            name='location2org', type='indoor', organization=org2
        )
        l3 = self._create_location(
            name='location-inactive', type='indoor', organization=inactive
        )
        fl1 = self._create_floorplan(location=l1, organization=org1)
        fl2 = self._create_floorplan(location=l2, organization=org2)
        fl3 = self._create_floorplan(location=l3, organization=inactive)
        d1 = self._create_object(
            name='org1-dev',
            organization=org1,
            key='key1',
            mac_address='00:11:22:33:44:56',
        )
        d2 = self._create_object(
            name='org2-dev',
            organization=org2,
            key='key2',
            mac_address='00:12:22:33:44:56',
        )
        d3 = self._create_object(
            name='org3-dev',
            organization=inactive,
            key='key3',
            mac_address='00:13:22:33:44:56',
        )
        self._create_object_location(location=l1, floorplan=fl1, content_object=d1)
        self._create_object_location(location=l2, floorplan=fl2, content_object=d2)
        self._create_object_location(location=l3, floorplan=fl3, content_object=d3)
        data = dict(
            l1=l1,
            l2=l2,
            l3_inactive=l3,
            fl1=fl1,
            fl2=fl2,
            fl3_inactive=fl3,
            org1=org1,
            org2=org2,
            inactive=inactive,
            operator=operator,
        )
        return data

    def test_location_queryset(self):
        self._create_admin()
        data = self._create_multitenancy_test_env()
        self._test_multitenant_admin(
            url=reverse(f'admin:{self.app_label}_location_changelist'),
            visible=[data['l1'].name, data['org1'].name],
            hidden=[
                data['l2'].name,
                data['org2'].name,
                data['inactive'].name,
                data['l3_inactive'].name,
            ],
        )

    def test_location_organization_fk_autocomplete_view(self):
        self._create_admin()
        data = self._create_multitenancy_test_env()
        self._test_multitenant_admin(
            url=self._get_autocomplete_view_path(
                self.app_label, 'location', 'organization'
            ),
            visible=[data['org1'].name],
            hidden=[data['org2'].name, data['inactive']],
        )

    def test_floorplan_queryset(self):
        self._create_admin()
        data = self._create_multitenancy_test_env()
        self._test_multitenant_admin(
            url=reverse(f'admin:{self.app_label}_floorplan_changelist'),
            visible=[data['fl1'], data['org1'].name],
            hidden=[
                data['fl2'],
                data['org2'].name,
                data['inactive'].name,
                data['fl3_inactive'],
            ],
        )

    def test_admin_menu_groups(self):
        # Test menu group (openwisp-utils menu group) for Location , FloorPlan

        self.client.force_login(self._create_admin())
        models = ['location', 'floorplan']
        response = self.client.get(reverse('admin:index'))
        for model in models:
            with self.subTest(f'test menu group link for {model} model'):
                url = reverse(f'admin:{self.app_label}_{model}_changelist')
                self.assertContains(response, f' class="mg-link" href="{url}"')
        with self.subTest('test "Geographic Info" group is registered'):
            self.assertContains(
                response,
                '<div class="mg-dropdown-label">Geographic Info </div>',
                html=True,
            )