diff --git a/Python/DrawAlongMaps/gen_data.py b/Python/DrawAlongMaps/gen_data.py new file mode 100644 index 0000000..02524ed --- /dev/null +++ b/Python/DrawAlongMaps/gen_data.py @@ -0,0 +1,77 @@ +import sys +import os +from os import listdir +from os.path import isfile, join +import csv + +DBG = not True + +class Country: + Name = "" + Capital = "" + MapFile = "" + LocationFile = "" + Continent = "" + + def AssignMapFile(self, path): + self.MapFile = path + + def AssignLocationFile(self, path): + self.LocationFile = path + + def Print(self): + print("COUNTRY\t[{0}\n\t\t{1}\n\t\t{2}\n\t\t{3}\n\t\t{4}]".format( + self.Continent, + self.Name, + self.Capital, + self.MapFile, + self.LocationFile)) + +def dbg(x): + if not DBG: + return + if type(x) is Country: + x.Print() + else: + print(x) + +def CountryInfoFromCsv(): + with open("list-of-countries-in-the-world.csv") as csvfile: + reader = csv.reader(csvfile, delimiter=',', quotechar='"') + for row in reader: + country = Country() + country.Continent = row[0].strip() + country.Name = row[1].strip() + country.Capital = row[2].strip() + yield country + +def MapsFilesFromDirectory(directory, keyfunc): + files = [join(directory, f) for f in listdir(directory) if isfile(join(directory, f))] + filepaths = {} + for i in files: + key = keyfunc(os.path.basename(i)) + filepaths[key] = i + return filepaths + +def CheckAndAssociateMapFiles(maps, country, associatefunc): + normalizedname = country.Name.lower().replace(' ', '-') + if normalizedname in maps: + associatefunc(maps[normalizedname]) + else: + dbg("{0} not found.".format(normalizedname)) + +def GenData(): + countries = [] + countryinfo = CountryInfoFromCsv() + countrymaps = MapsFilesFromDirectory( + "C:\\Users\\Rovin\\maps\\CountryMaps", + lambda s : s[:-8]) + locationmaps = MapsFilesFromDirectory( + "C:\\Users\\Rovin\\maps\\CountryLocationMaps", + lambda s : s[7:-4]) + for i in countryinfo: + dbg(i) + CheckAndAssociateMapFiles(countrymaps, i, i.AssignMapFile) + CheckAndAssociateMapFiles(locationmaps, i, i.AssignLocationFile) + countries.append(i) + return countries diff --git a/Python/DrawAlongMaps/list-of-countries-in-the-world.csv b/Python/DrawAlongMaps/list-of-countries-in-the-world.csv new file mode 100644 index 0000000..42803b9 --- /dev/null +++ b/Python/DrawAlongMaps/list-of-countries-in-the-world.csv @@ -0,0 +1,236 @@ +Africa,Algeria,Algiers +Africa,Angola,Luanda +Africa,Benin,Porto-Novo +Africa,Botswana,Gaborone +Africa,Burkina Faso,Ouagadougou +Africa,Burundi,Bujumbura +Africa,Cape Verde,Praia +Africa,Central African Republic,Bangui +Africa,Chad,N'Djamena +Africa,Comoros,Moroni +Africa,Democratic Republic of the Congo,Kinshasa +Africa,Djibouti,Djibouti-city +Africa,Egypt,Cairo +Africa,Equatorial Guinea,Malabo +Africa,Eritrea,Asmara +Africa,Ethiopia,Addis Ababa +Africa,Gabon,Libreville +Africa,The Gambia,Banjul +Africa,Ghana,Accra +Africa,Guinea,Conakry +Africa,Guinea-Bissau,Bissau +Africa,Ivory Coast,Yamoussoukro +Africa,Kenya,Nairobi +Africa,Lesotho,Maseru +Africa,Liberia,Monrovia +Africa,Libya,Tripoli +Africa,Madagascar,Antananarivo +Africa,Malawi,Lilongwe +Africa,Mali,Bamako +Africa,Mauritania,Nouakchott +Africa,Mauritius,Port Louis +Africa,Mozambique,Maputo +Africa,Namibia,Windhoek +Africa,Niger,Niamey +Africa,Nigeria,Abuja +Africa,Qatar,Doha +Africa,Republic of the Congo,Brazzaville +Africa,Rwanda,Kigali +Africa,Sao Tome and Principe,Sao Tome +Africa,Senegal,Dakar +Africa,Seychelles,Victoria +Africa,Sierra Leone,Freetown +Africa,Somalia,Mogadishu +Africa,South Africa,Cape Town +Africa,South Sudan,Juba +Africa,Sudan,Khartoum +Africa,Swaziland,Mata-utu +Africa,Tanzania,Dodoma +Africa,Togo,Lome +Africa,Tonga,Nuku?alofa +Africa,Tunisia,Tunis +Africa,Uganda,Kampala +Africa,Western Sahara,El Aaiun +Africa,Zambia,Lusaka +Africa,Zimbabwe,Harare +Asia,Afghanistan,Kabul +Asia,Bahrain,Manama +Asia,Bangladesh,Dhaka +Asia,Bhutan,Thimphu +Asia,Brunei,Bandar Seri Begawan +Asia,Cambodia,Phnom Penh +Asia,Cameroon,Yaoundé +Asia,China,Beijing +Asia,Christmas Island (Australia),Flying Fish Cove +Asia,Cocos (Keeling) Islands (Australia),"West Island, Cocos Islands " +Asia,East Timor,Dili +Asia,Hong Kong,Hong Kong City +Asia,India,New Delhi +Asia,Indonesia,Jakarta +Asia,Iran,Tehran +Asia,Iraq,Baghdad +Asia,Israel,Jerusalem +Asia,Japan,Tokyo +Asia,Jordan,Amman +Asia,Kazakhstan,Astana +Asia,Kiribati,Tarawa +Asia,Kosovo,Pristina +Asia,Kuwait,Kuwait City +Asia,Kyrgyzstan,Bishkek +Asia,Laos,Vientiane +Asia,Lebanon,Beirut +Asia,Malaysia,Kuala Lumpur +Asia,Maldives,Male +Asia,Mongolia,Ulan Bator +Asia,Burma,Naypyidaw +Asia,Nepal,Kathmandu +Asia,North Korea,Pyongyang +Asia,Oman,Muscat +Asia,Pakistan,Islamabad +Asia,Palestine,Ramallah and Gaza +Asia,Philippines,Manila +Asia,Saudi Arabia,Riyadh +Asia,Singapore,Singapore +Asia,South Korea,Seoul +Asia,Sri Lanka,Sri Jayawardenapura-kotte +Asia,Syria,Damascus +Asia,Taiwan,Taipei +Asia,Tajikistan,Dushanbe +Asia,Thailand,Bangkok +Asia,Turkey,Ankara +Asia,Turkmenistan,Ashgabat +Asia,United Arab Emirates,Abu Dhabi +Asia,Uzbekistan,Tashkent +Asia,Vietnam,Hanoi +Asia,Yemen,Sana'a +Europe,Albania,Tirana +Europe,Andorra,Andorra La Vella +Europe,Armenia,Yerevan +Europe,Austria,Vienna +Europe,Azerbaijan,Baku +Europe,Belarus,Minsk +Europe,Belgium,Brussels +Europe,Bosnia and Herzegovina,Sarajevo +Europe,Bulgaria,Sofia +Europe,Croatia,Zagreb +Europe,Cyprus,Nicosia +Europe,Czech Republic,Prague +Europe,Denmark,Copenhagen +Europe,Estonia,Tallinn +Europe,Faroe Islands (Denmark),Torshavn +Europe,Finland,Helsinki +Europe,France,Paris +Europe,Georgia,Tbilisi +Europe,Germany,Berlin +Europe,Gibraltar,Gibraltar +Europe,Greece,Athens +Europe,Guernsey (UK),Saint Peter Port +Europe,Hungary,Budapest +Europe,Iceland,Reykjavík +Europe,Ireland,Dublin +Europe,Isle of Man (UK),Douglas +Europe,Italy,Rome +Europe,Jersey (UK),Saint Helier +Europe,Latvia,Riga +Europe,Liechtenstein,Vaduz +Europe,Lithuania,Vilnius +Europe,Luxembourg,Luxembourg +Europe,Macedonia,Skopje +Europe,Malta,Valletta +Europe,Moldova,Chisinau +Europe,Monaco,Monaco +Europe,Montenegro,Podgorica +Europe,Morocco,Rabat +Europe,Netherlands,Amsterdam +Europe,Norway,Oslo +Europe,Poland,Warsaw +Europe,Portugal,Lisbon +Europe,Romania,Bucharest +Europe,Russia,Moscow +Europe,San Marino,San Marino +Europe,Serbia,Belgrade +Europe,Slovakia,Bratislava +Europe,Slovenia,Ljubljana +Europe,Spain,Madrid +Europe,Sweden,Stockholm +Europe,Switzerland,Bern +Europe,Transnistria,Tiraspol +Europe,Ukraine,Kiev +Europe,United Kingdom,London +Europe,Vatican City,Vatican City +North America,Anguilla (UK),The Valley +North America,Antigua and Barbuda,Saint Johns +North America,Aruba (Netherlands),Oranjestad +North America,Bahamas,Nassau +North America,Barbados,Bridgetown +North America,Belize,Belmopan +North America,Bermuda (UK),Hamilton +North America,British Virgin Islands (UK),Road Town +North America,Canada,Ottawa +North America,Cayman Islands (UK),George Town +North America,Costa Rica,San Jose +North America,Cuba,Havana +North America,Curacao (Netherlands),Willemstad +North America,Dominica,Roseau +North America,Dominican Republic,Santo Domingo +North America,El Salvador,San Salvador +North America,Greenland (Denmark),Nuuk +North America,Grenada,St. George's +North America,Guam (USA),Hagatna +North America,Guatemala,Guatemala City +North America,Haiti,Port-au-prince +North America,Honduras,Tegucigalpa +North America,Jamaica,Kingston +North America,Mexico,Mexico City +North America,Montserrat (UK),"Brades, Plymouth" +North America,Nicaragua,Managua +North America,Panama,Panama City +North America,Puerto Rico,San Juan +North America,Saint Kitts and Nevis,Basseterre +North America,Saint Lucia,Castries +North America,Saint Martin,Philipsburg +North America,Saint Pierre and Miquelon (France),Saint-Pierre +North America,Saint Vincent and the Grenadines,Kingstown +North America,Sint Maarten (Netherlands),Philipsburg +North America,Trinidad and Tobago,Port Of Spain +North America,Turks and Caicos Islands (UK),Cockburn Town +North America,The United States of America,Washington D.C. +North America,United States Virgin Islands (USA),Charlotte Amalie +North America,Saint Barthelemy,"Gustavia, Saint Barthélemy" +Oceania,American Samoa (USA),Pago Pago +Oceania,Australia,Canberra +Oceania,Cook Islands (New Zealand),Avarua +Oceania,Fiji,Suva +Oceania,French Polynesia (France),Papeete +Oceania,Marshall Islands,Majuro +Oceania,Micronesia,Palikir +Oceania,Nauru,Yaren +Oceania,New Caledonia (France),Noumea +Oceania,New Zealand,Wellington +Oceania,Niue (New Zealand),Alofi +Oceania,Norfolk Island (Australia),Kingston +Oceania,Northern Mariana Islands (USA),Saipan +Oceania,Palau,Ngerulmud +Oceania,Papua New Guinea,Port Moresby +Oceania,Pitcairn Islands (UK),Adamstown +Oceania,Samoa,Apia +Oceania,Solomon Islands,Honiara +Oceania,Tokelau (New Zealand),"Nukunonu, Atafu,Tokelau" +Oceania,Tuvalu,Funafuti +Oceania,Vanuatu,Port Vila +Oceania,Wallis and Futuna (France),Mata-Utu +South America,Argentina,Buenos Aires +South America,Bolivia,Sucre +South America,Brazil,Brasília +South America,Chile,Santiago +South America,Colombia,Bogotá +South America,Ecuador,Quito +South America,Falkland Islands (UK),Stanley +South America,French Guiana (France),Cayenne +South America,Guyana,Georgetown +South America,Paraguay,Asuncion +South America,Peru,Lima +South America,"Saint Helena, Ascension, and Tristan da Cunha (UK)",Jamestown +South America,Suriname,Paramaribo +South America,Uruguay,Montevideo +South America,Venezuela,Caracas diff --git a/Python/DrawAlongMaps/quiz.py b/Python/DrawAlongMaps/quiz.py new file mode 100644 index 0000000..706de71 --- /dev/null +++ b/Python/DrawAlongMaps/quiz.py @@ -0,0 +1,111 @@ +from gen_data import Country, GenData +import random +import time +import os +import colorama + +AllContinents = ["Africa", + "Asia", + "Europe", + "North America", + "Oceania", + "South America"] +PlayFor = AllContinents +Score = {"m": 0, "r": 0} +ExitGame = False + +data = GenData() +data = [x for x in data if not x.MapFile == "" and x.Continent in PlayFor] +datasize = len(data) +playedindices = [-1] + +def ShowScore(): + print("Score: Mimi={0}, Rainy={1}".format(Score["m"], Score["r"])) + +def ClearScreen(): + print(chr(27) + "[2J") + +def Play(): + global data + global datasize + global playedindices + global ExitGame + index = -1 + if len(playedindices) == datasize + 1: + ExitGame = True + print("No more unique countries left!") + ShowWinner() + return + while index in playedindices: + index = random.randint(0, datasize - 1) + playedindices.append(index) + choice = data[index] + ClearScreen() + print("3..") + time.sleep(1) + print("2..") + time.sleep(1) + print("1..") + time.sleep(1) + print("Draw... ", end = " ") + print(colorama.Fore.LIGHTYELLOW_EX + choice.Name) + print(colorama.Style.RESET_ALL) + return InputHandler(choice) + +def InputHandler(state): + global Score + global ExitGame + command = "" + while True: + command = input("si/sm/sl/m/r/t/x > "); + if command in ["si", "sm", "sl", "m", "r", "t", "x"]: + break + if command == "si": + print("Capital: {0}\nContinent: {1}".format(state.Capital, state.Continent)) + return InputHandler(state) + elif command == "sm": + os.system(state.MapFile); + return InputHandler(state) + elif command == "sl": + os.system(state.LocationFile); + return InputHandler(state) + elif command == "x": + ClearScreen() + ShowWinner() + ExitGame = True + return + elif command == "m": + Score["m"] += 1 + elif command == "r": + Score["r"] += 1 + elif command == "t": + Score["m"] += 1 + Score["r"] += 1 + return + +def ShowWinner(): + ShowScore() + winner = "" + if Score["m"] > Score["r"]: + winner = "Mimi" + elif Score["m"] < Score["r"]: + winner = "Rainy" + else: + winner = "BOTH" + winner = "\n\n{0} WON! :)\n\n".format(winner) + print(colorama.Fore.LIGHTGREEN_EX + winner) + print(colorama.Style.RESET_ALL) + +print("A country name will appear on the screen. Draw it's map, it's location in the world, and mark it's capital correctly. 1 mark for getting it more correct than other players. Commands: \n" + + "\tsi for Show Info\n" + + "\tsm for Show Map\n" + + "\tsl for Show Location\n" + + "\tm for +1 Mimi\n" + + "\tr for +1 Rainy\n" + + "\tt for tie\n" + + "\tx for exit and show score") +input("Press Enter key to start the game...") +colorama.init() +while not ExitGame: + Play() +colorama.deinit() diff --git a/Python/colorama_try.py b/Python/colorama_try.py new file mode 100644 index 0000000..3136c7a --- /dev/null +++ b/Python/colorama_try.py @@ -0,0 +1,9 @@ +import colorama +colorama.init() +from colorama import Fore, Back, Style +print(Fore.RED + 'some red text') +print(Back.GREEN + 'and with a green background') +print(Style.DIM + 'and in dim text') +print(Style.RESET_ALL) +print('back to normal now') +colorama.deinit()