Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class Game : MonoBehaviour {
- // TODO the last answer doesn't disappear
- // TODO countries with long names are don't have the right appearance
- // Lists of countries
- string[] countriesBeginner = { "France", "Italy", "The United Kingdom", "Germany", "United States", "Spain", "Russia", "Japan", "China", "Brazil", "Mexico", "Portugal", "India", "Argentina", "Canada", "Australia", "South Korea"};
- string[] countriesEasy = { "Ireland", "Norway", "Greece" , "Austria", "Belgium", "Netherlands", "Vatican", "Denmark", "Finland", "Hungary", "Czech Republic", "Egypt", "Poland", "Sweden", "Monaco", "Peru", "Switzerland", "Luxembourg", "Ukraine", "Israel", "Iceland"};
- string[] countriesMedium = { "Iraq", "Bulgaria", "Cuba", "Chile", "Thailand", "Singapore", "Afganistan", "Iran", "San Marino", "Turkey", "New Zealand", "Jamaica", "South Africa", "Panama", "Belarus", "Colombia", "Croatia", "Indonesia", "Romania", "Estonia", "Venezuela", "Latvia", "Philippines", "Bolivia", "North Korea", "Uruguay", "Bosnia and Herzegovina" };
- string[] countriesHard = { "Malaysia", "Pakistan", "Albania", "Ecuador", "United Arab Emirates", "Vietnam", "Kuwait", "Syria", "El Salvador", "Serbia", "Taiwan", "Algeria", "Kenya", "Nepal", "Haiti", "Lebanon", "Slovakia", "Tunisia", "Andorra", "Lithuania", "Malta", "Bangladesh", "Jordan", "Mongolia", "Saudi Arabia", "Azerbaijan", "Cyprus", "Guatemala", "Qatar", "Macedonia", "Libya", "Paraguay", "Slovenia", "Cambodia", "Ethiopia", "Guyana", "Liechtenstein", "Morocco", "Costa Rica", "Georgia", "Kosovo", "Bahamas", "Kazakhstan", "Yemen", "Armenia", "Dominican Republic", "Nicaragua", "Oman", "Senegal", "Sierra Leone", "Maldives", "Moldova", "Ghana" };
- string[] countriesExpert = { "Saint Vincent and the Grenadines", "Djibouti", "Montenegro", "Suriname", "East Timor", "Somalia", "Trinidad and Tobago", "Zimbabwe", "Bahrain", "Democratic Republic of Congo", "Laos", "Angola", "Barbados", "Belize", "Fiji", "Honduras", "Uzbekistan", "Antigua and Barbuda", "Bhutan", "Republic of the Congo", "Guinea-Bissau", "Sao Tome and Principe", "Sudan", "Nigeria", "Papua New Guinea", "Seychelles", "Grenada", "Kyrgyztan", "Liberia" };
- string[] countriesExtreme = { "Madagascar", "Namibia", "Brunei", "Burkina Faso", "Uganda", "Gabon", "Rwanda", "South Sudan", "Turkmenistan", "Botswana", "Cameroon", "Dominica", "Eritrea", "Mozambique", "Tajikistan", "Togo", "Zambia", "Benin", "Mali", "Mauritius", "Samoa", "Sri Lanka", "Saint Lucia", "Myanmar", "Cape Verde", "Central African Republic", "Chad", "Guinea", "Vanuatu", "Burundi", "Comoros", "Gambia", "Malawi", "Niger", "Saint Kitts and Nevis", "Tanzania", "Lesotho", "Swaziland", "Tuvalu", "Cote d'lvoire", "Equatorial Guinea", "Mauritania", "Nauru", "Kiribati", "Marshall Islands", "Federated States of Micronesia", "Solomon Islands", "Tonga", "Palau" };
- // Lists of capitals
- string[] capitalsBeginner = { "paris", "rome", "london", "berlin", "washington dc", "madrid", "moscow", "tokyo", "beijing", "brasilia", "mexico city", "lisbon", "new delhi", "buenos aires", "ottawa", "canberra", "seoul" };
- string[] capitalsEasy = { "dublin", "oslo", "athens", "vienna", "brussels", "amsterdam", "vatican city", "copenhagen", "helsinki", "budapest", "prague", "cairo", "warsaw", "stockholm", "monaco", "lima", "bern", "luxembourg", "kiev", "jerusalem", "reykjavik" };
- string[] capitalsMedium = { "baghdad", "sofia", "havana", "santiago", "bangkok", "singapore", "kabul", "tehran", "san marino", "ankara", "wellington", "kingston", "cape town", "panama city", "minsk", "bogota", "zagreb", "jakarta", "bucharest", "tallinn", "caracas", "riga", "manila", "la paz", "pyongyang", "montevideo", "sarajevo"};
- string[] capitalsHard = { "kuala lumpur", "islamabad", "tirana", "quito", "abu dhabi", "hanoi", "kuwait city", "damascus", "san salvador", "belgrade", "taipei", "algiers", "nairobi", "kathmandu", "port-au-prince", "beirut", "bratislava", "tunis", "andorra la vella", "vilnius", "valletta", "dhaka", "amman", "ulaanbaatar", "riyadh", "baku", "nicosia", "guatemala city", "doha", "skopje", "tripoli", "asuncion", "ljubljana", "phnom penh", "addis ababa", "georgetown", "vaduz", "rabat", "san jose", "tbilisi", "pristina", "nassau", "astana", "sana'a", "yerevan", "santo domingo", "managua", "muscat", "dakar", "freetown", "male", "chisinau", "accra" };
- string[] capitalsExpert = { "kingstown", "djibouti", "podgorica", "paramaribo", "dili", "mogadishu", "port of spain", "harare", "manama", "kinshasa", "vientiane", "luanda", "bridgetown", "belmopan", "suva", "tegucigalpa", "tashkent", "saint john's", "thimphu", "brazzaville", "bissau", "sao tome", "khartoum", "abuja", "port moresby", "victoria", "saint georges", "bishkek", "monrovia" };
- string[] capitalsExtreme = { "antananarivo", "windhoek", "bandar seri begawan", "ouagadougou", "kampala", "libreville", "kigali", "juba", "ashgabat", "gaborone", "yaounde", "roseau", "asmara", "maputo", "dushanbe", "lome", "lusaka", "porto novo", "bamako", "port louis", "apia", "sri jayawardenera pura kotte", "castries", "naypyidaw", "praia", "bangui", "n'djamena", "conakry", "port vila", "bujumbura", "moroni", "banjul", "lilongwe", "niamey", "basseterre", "dodoma", "maseru", "mbabane", "funafuti", "yamoussoukro", "malabo", "nouakchott", "yaren", "south tarawa", "majuro", "palikir", "honiara", "nuku'alofa", "ngerulmud" };
- // Game state
- int level;
- enum Screen { Start, Help, MainMenu, Capital, Win, Records};
- Screen currentScreen;
- string currentCountry;
- string currentCapital;
- // For counting input and answers
- int item = 0;
- int remaining = 0;
- int right = 0;
- int wrong = 0;
- int hints = 5;
- // Resets the variables above
- void resetVariables()
- {
- right = 0;
- wrong = 0;
- item = 0;
- remaining = 0;
- hints = 5;
- }
- // For keeping track of high scores
- int scoreBeginner;
- int scoreEasy;
- int scoreMedium;
- int scoreHard;
- int scoreExpert;
- int scoreExtreme;
- // Other
- const string menuHint = "Type menu to get back to the start";
- int currentLevel;
- void Start ()
- {
- showStartMenu();
- }
- // Used to check player's input
- // Programs response depends on the current screen
- // Typing menu will alwasy bring the player to the start menu
- void OnUserInput(string input)
- {
- if (input == "menu") // we can always go to the main menu
- {
- showStartMenu();
- resetVariables();
- }
- else if (currentScreen == Screen.Start)
- {
- runStartMenu(input);
- }
- else if (currentScreen == Screen.MainMenu)
- {
- runMainMenu(input);
- }
- else if (currentScreen == Screen.Capital)
- {
- runGame(input);
- }
- else if (currentScreen == Screen.Win)
- {
- playAgain(input);
- }
- else if (currentScreen == Screen.Records)
- {
- runRecords(input);
- }
- else if (currentScreen == Screen.Help)
- {
- runHelp(input);
- }
- }
- // Used to run the start screen
- // If the player inputs 1-3 the program goes to the corresponding screen
- // If the player inputs anything else the program resets the screen
- void runStartMenu(string input)
- {
- if (input == "1")
- {
- showMainMenu();
- }
- else if (input == "2")
- {
- showHelp();
- }
- else if (input == "3")
- {
- showRecords();
- }
- else
- {
- showStartMenu();
- }
- }
- // Clears the screen and displays the start menu
- void showStartMenu()
- {
- currentScreen = Screen.Start;
- Terminal.ClearScreen();
- Terminal.WriteLine("WELCOME TO THE CAPITAL QUIZ");
- Terminal.WriteLine("");
- Terminal.WriteLine("1 - Select difficulty");
- Terminal.WriteLine("2 - See instructions");
- Terminal.WriteLine("3 - High Scores");
- Terminal.WriteLine("");
- Terminal.WriteLine("Choose your selection by entering the");
- Terminal.WriteLine("number");
- Terminal.WriteLine("");
- }
- // Used to run the main menu
- // Converts player's input to an Int and checks if corresponding difficulty level exists
- // If the level exists program starts the game
- void runMainMenu(string input)
- {
- bool isValidLevelNumber = (input == "1" || input == "2" || input == "3" || input == "4" || input == "5" || input == "6");
- if (isValidLevelNumber)
- {
- level = int.Parse(input);
- currentLevel = level;
- setRemaining();
- askForCapital();
- print(item);
- print(countriesBeginner[item]);
- }
- else
- {
- showMainMenu();
- }
- }
- // Clears the screen and displays the menu
- void showMainMenu()
- {
- currentScreen = Screen.MainMenu;
- Terminal.ClearScreen();
- Terminal.WriteLine("CHOOSE DIFFICULTY");
- Terminal.WriteLine("");
- Terminal.WriteLine("1 - Beginner");
- Terminal.WriteLine("2 - Easy");
- Terminal.WriteLine("3 - Medium");
- Terminal.WriteLine("4 - Hard");
- Terminal.WriteLine("5 - Expert");
- Terminal.WriteLine("6 - Extreme");
- Terminal.WriteLine("");
- Terminal.WriteLine("Please enter your selection:");
- Terminal.WriteLine("");
- }
- // Used for running the game
- // Checks the player's input and manages the hints
- // Checks if the player's answer is correct or false
- void runGame(string input)
- {
- if (input == "hint" && hints > 0)
- {
- hints--;
- askForCapital();
- Terminal.WriteLine("HINT: " + currentCapital.Anagram());
- }
- else if (input == "hint" && hints <= 0)
- {
- askForCapital();
- Terminal.WriteLine("You are out hints");
- }
- else if (currentCapital == input)
- {
- right++;
- item++;
- askForCapital();
- }
- else
- {
- wrong++;
- item++;
- askForCapital();
- }
- }
- // Used to run the Records screen
- void runRecords(string input)
- {
- if (input == "menu")
- {
- showStartMenu();
- resetVariables();
- }
- else
- {
- showRecords();
- }
- }
- void runHelp(string input)
- {
- if (input == "menu")
- {
- showStartMenu();
- resetVariables();
- }
- else
- {
- showHelp();
- }
- }
- // If player types play after answering all the questions the program starts the game again
- void playAgain(string input)
- {
- if (input == "play")
- {
- level = currentLevel;
- resetVariables();
- setRemaining();
- askForCapital();
- print(item);
- print(countriesBeginner[item]);
- }
- else
- {
- displayWinScreen();
- }
- }
- // Displays insturctions
- void showHelp()
- {
- currentScreen = Screen.Help;
- Terminal.ClearScreen();
- Terminal.WriteLine("INSTRUCTIONS");
- Terminal.WriteLine("");
- Terminal.WriteLine("You may type menu at any point to get");
- Terminal.WriteLine("back to the start");
- Terminal.WriteLine("");
- Terminal.WriteLine("All capital names exclude all capital");
- Terminal.WriteLine("letters, dots, dashes and letters not");
- Terminal.WriteLine("in the English alphabet");
- Terminal.WriteLine("");
- Terminal.WriteLine("Typing hint turns the correct capital");
- Terminal.WriteLine("name into an anagram");
- }
- // Calculates player's records and clear rates and displays them
- void showRecords()
- {
- currentScreen = Screen.Records;
- Terminal.ClearScreen();
- string rateBeginner = Math.Round(((double)scoreBeginner / countriesBeginner.Length) * 100, 1).ToString();
- string rateEasy = Math.Round(((double)scoreEasy / countriesEasy.Length) * 100, 1).ToString();
- string rateMedium = Math.Round(((double)scoreMedium / countriesMedium.Length) * 100, 1).ToString();
- string rateHard = Math.Round(((double)scoreHard / countriesHard.Length) * 100, 1).ToString();
- string rateExpert = Math.Round(((double)scoreExpert / countriesExpert.Length) * 100, 1).ToString();
- string rateExtreme = Math.Round(((double)scoreExtreme / countriesExtreme.Length) * 100, 1).ToString();
- Terminal.WriteLine("YOUR HIGH SCORES");
- Terminal.WriteLine("");
- Terminal.WriteLine("Beginner: [" + scoreBeginner + "/" + countriesBeginner.Length + "] " + rateBeginner + "%");
- Terminal.WriteLine("Easy: [" + scoreEasy + "/" + countriesEasy.Length + "] " + rateEasy + "%");
- Terminal.WriteLine("Medium: [" + scoreMedium + "/" + countriesMedium.Length + "] " + rateMedium + "%");
- Terminal.WriteLine("Hard: [" + scoreHard + "/" + countriesHard.Length + "] " + rateHard + "%");
- Terminal.WriteLine("Expert: [" + scoreExpert + "/" + countriesExpert.Length + "] " + rateExpert + "%");
- Terminal.WriteLine("Extreme: [" + scoreExtreme + "/" + countriesExtreme.Length + "] " + rateExtreme + "%");
- Terminal.WriteLine("");
- Terminal.WriteLine(menuHint);
- Terminal.WriteLine("");
- }
- // Sets remaining variable's value depending on how many items the corresponding list has
- private void setRemaining()
- {
- switch (level)
- {
- case 1:
- remaining = countriesBeginner.Length;
- break;
- case 2:
- remaining = countriesEasy.Length;
- break;
- case 3:
- remaining = countriesMedium.Length;
- break;
- case 4:
- remaining = countriesHard.Length;
- break;
- case 5:
- remaining = countriesExpert.Length;
- break;
- case 6:
- remaining = countriesExtreme.Length;
- break;
- }
- }
- // Asks the player for an answer
- // If the player has answered all the questions the program dislplays the win screen
- void askForCapital()
- {
- currentScreen = Screen.Capital;
- Terminal.ClearScreen();
- countAnswers();
- setCountry();
- setCapital();
- Terminal.WriteLine("");
- Terminal.WriteLine("HINTS: " + hints + "/5");
- Terminal.WriteLine("======================================");
- Terminal.WriteLine("What is the capital of " + currentCountry);
- Terminal.WriteLine("Type hint for help");
- Terminal.WriteLine("");
- if (right + wrong == remaining)
- {
- displayWinScreen();
- }
- }
- // Counts answers and hints and returns a string value including them
- void countAnswers()
- {
- string answers = "RIGHT: " + right + " WRONG: " + wrong + " Answered: " + item + "/" + remaining;
- Terminal.WriteLine(answers);
- if (right + wrong == remaining)
- {
- displayWinScreen();
- }
- }
- // Sets a value currentCountry
- void setCountry()
- {
- switch (level)
- {
- case 1:
- currentCountry = countriesBeginner[item];
- break;
- case 2:
- currentCountry = countriesEasy[item];
- break;
- case 3:
- currentCountry = countriesMedium[item];
- break;
- case 4:
- currentCountry = countriesHard[item];
- break;
- case 5:
- currentCountry = countriesExpert[item];
- break;
- case 6:
- currentCountry = countriesExtreme[item];
- break;
- }
- }
- // Sets a value for currentCapital
- void setCapital()
- {
- switch (level)
- {
- case 1:
- currentCapital = capitalsBeginner[item];
- break;
- case 2:
- currentCapital = capitalsEasy[item];
- break;
- case 3:
- currentCapital = capitalsMedium[item];
- break;
- case 4:
- currentCapital = capitalsHard[item];
- break;
- case 5:
- currentCapital = capitalsExpert[item];
- break;
- case 6:
- currentCapital = capitalsExtreme[item];
- break;
- default:
- Debug.LogError("Invalid level number");
- break;
- }
- }
- // Displays the win screen including the player's score
- void displayWinScreen()
- {
- currentScreen = Screen.Win;
- Terminal.ClearScreen();
- compareScores();
- Terminal.WriteLine("RIGHT: " + right + " WRONG: " + wrong);
- Terminal.WriteLine("");
- Terminal.WriteLine("type play to play again or type menu toget back to the start");
- Terminal.WriteLine("");
- }
- // If the new score is higher than the high score the program sets a new value for the corresponding level's high score
- private void compareScores()
- {
- switch (level)
- {
- case 1:
- if (right > scoreBeginner)
- {
- scoreBeginner = right;
- Terminal.WriteLine("NEW HIGH SCORE!");
- Terminal.WriteLine("");
- }
- break;
- case 2:
- if (right > scoreEasy)
- {
- scoreEasy = right;
- Terminal.WriteLine("NEW HIGH SCORE!");
- Terminal.WriteLine("");
- }
- break;
- case 3:
- if (right > scoreMedium)
- {
- scoreMedium = right;
- Terminal.WriteLine("NEW HIGH SCORE!");
- Terminal.WriteLine("");
- }
- break;
- case 4:
- if (right > scoreHard)
- {
- scoreHard = right;
- Terminal.WriteLine("NEW HIGH SCORE!");
- Terminal.WriteLine("");
- }
- break;
- case 5:
- if (right > scoreExpert)
- {
- scoreExpert = right;
- Terminal.WriteLine("NEW HIGH SCORE!");
- Terminal.WriteLine("");
- }
- break;
- case 6:
- if (right > scoreExtreme)
- {
- scoreExtreme = right;
- Terminal.WriteLine("NEW HIGH SCORE!");
- Terminal.WriteLine("");
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement