Esempio n. 1
0
 void Start()
 {
     loadingSplashScreen         = GameObject.Find(LOADING_SPLASH_SCREEN_NAME);
     loadingIcon                 = GameObject.Find(LOADING_ICON_NAME);
     splashMessage               = GameObject.Find(SPLASH_MESSAGE_NAME);
     splashMessageHomePosition   = splashMessage.transform.localPosition;
     splashMessageStartYPosition = splashMessageHomePosition.y - (Math.Abs(splashMessageHomePosition.y) - (loadingIcon.GetComponent <RectTransform>().sizeDelta.y / 2 - loadingIcon.transform.localPosition.y) - splashMessage.GetComponent <RectTransform>().sizeDelta.y / 2);
     splashMessage.GetComponent <TextMeshProUGUI>().color = new Color(splashMessage.GetComponent <TextMeshProUGUI>().color.r, splashMessage.GetComponent <TextMeshProUGUI>().color.g, splashMessage.GetComponent <TextMeshProUGUI>().color.b, 0);
     musicSound                  = GameObject.Find(MUSIC_SOUND_NAME);
     battleButtonSound           = GameObject.Find(BATTLE_BUTTON_SOUND);
     splashMessageHomeStartTime  = 0;
     splashMessageColorDirection = true;
     splashMessageGenerator      = new SplashMessageGenerator();
     screenType                  = typeof(Field);
     splashScreenStartTime       = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
     for (int sceneIndex = 0; sceneIndex < SceneManager.sceneCount; ++sceneIndex)
     {
         Scene scene = SceneManager.GetSceneAt(sceneIndex);
         if (GetType().ToString() != scene.name)
         {
             foreach (GameObject gameObject in scene.GetRootGameObjects())
             {
                 RobotGame robotGame = gameObject.GetComponent <RobotGame>();
                 if (robotGame != null)
                 {
                     screenType = robotGame.getScreenTypeToChangeTo();
                     if (screenType == default)
                     {
                         screenType = GameObject.Find("BuildHubCanvas") != null ? typeof(BuildHub) : typeof(Field);
                     }
                     SettingsManager settingsManager = new SettingsManager();
                     SettingPairs    settingPairs    = settingsManager.getSettingPairs(robotGame.getCurrentSettings());
                     enableSplashScreenAnimation = settingPairs.splash_screen_animation;
                     splashMessage.SetActive(enableSplashScreenAnimation);
                     colorScheme = ImageTools.getColorFromString(settingPairs.color_scheme);
                     musicVolume = (float)(settingPairs.music_volume / 100 * settingPairs.master_volume / 100);
                     musicSound.GetComponent <AudioSource>().volume = musicVolume;
                     battleButtionVolume = (float)(settingPairs.action_performed_volume / 100 * settingPairs.master_volume / 100);
                     battleButtonSound.GetComponent <AudioSource>().volume = battleButtionVolume;
                     if (screenType.ToString() == "Field")
                     {
                         battleButtonSound.GetComponent <AudioSource>().Play();
                     }
                     loadingIcon.GetComponent <UnityEngine.UI.Image>().color = colorScheme;
                     splashMessage.GetComponent <TextMeshProUGUI>().color    = colorScheme;
                     splashMessage.GetComponent <TextMeshProUGUI>().color    = new Color(splashMessage.GetComponent <TextMeshProUGUI>().color.r, splashMessage.GetComponent <TextMeshProUGUI>().color.g, splashMessage.GetComponent <TextMeshProUGUI>().color.b, 0);
                 }
                 if (SceneManager.GetActiveScene().name == "SplashScreen")
                 {
                     gameObject.SetActive(false);
                 }
             }
         }
     }
     if (GetComponent <RobotGame>() == null)
     {
         switchScene();
     }
 }
Esempio n. 2
0
 public void Init(RobotGame robotGame)
 {
     this.robotGame = robotGame;
     foreach (Area area in areas)
     {
         area.logic_mgr.bindRobotGame(robotGame);
     }
 }
Esempio n. 3
0
    byte[] BigRecivebuffer = new byte[MaxRecive]; // 4m

    public Robot(int robotID, string ip, int aren, int size, bool bSYNC = false)
    {
        this.robotID = robotID;
        clientSocket = new ClientSocket(ip);
        robotGame    = new RobotGame(robotID, aren, size);
        bCheckSync   = bSYNC;

        robotGame.bSYN = bSYNC;
    }
Esempio n. 4
0
        public void WhenRobotMoves_RobotIsAtCorrectPosition(DirectionEnum initalDirection, int x, int y, int newX, int newY)
        {
            var mdMock           = new Mock <IMessageDisplayer>();
            var messageDisplayer = mdMock.Object;
            var board            = new Board(5, 5);
            var robot            = new RobotProject.Robot();
            var game             = new RobotGame(board, robot, messageDisplayer);


            game.ProcessCommand($"PLACE {x} {y} {DirectionEnum.North.ToString().ToUpper()}");
            game.ProcessCommand($"MOVE");
            game.ProcessCommand($"REPORT");

            mdMock.Verify(m => m.DisplayMessage($"Output: {newX}, {newY}, { initalDirection.ToString()}"), Times.AtMostOnce());
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start the game...");
            var robot = new Robot();
            var board = new Board(5, 5);

            var robotGame = new RobotGame(board, robot, new ConsolMessageDisplayer());

            do
            {
                var command      = Console.ReadLine();
                var commandLines = command.Split(" ");

                if (commandLines[0].ToUpper().Equals("QUIT"))
                {
                    break;
                }
                robotGame.ProcessCommand(command);
            } while (true);
        }
Esempio n. 6
0
 private void loadScene(CancellationToken token, string sceneName)
 {
     for (int sceneIndex = 0; sceneIndex < SceneManager.sceneCount; ++sceneIndex)
     {
         Scene scene = SceneManager.GetSceneAt(sceneIndex);
         if (sceneName != scene.name)
         {
             foreach (GameObject gameObject in scene.GetRootGameObjects())
             {
                 RobotGame robotGame = gameObject.GetComponent <RobotGame>();
                 if (robotGame != null)
                 {
                     experience      = robotGame.getExperience();
                     credits         = robotGame.getCredits();
                     humanRobot      = robotGame.getHumanRobot();
                     humanRobotParts = robotGame.getHumanRobotParts();
                     obstaclesData   = robotGame.getObstaclesData();
                     currentSettings = robotGame.getCurrentSettings();
                     previousRoundDamageDifference    = robotGame.getPreviousRoundDamageDifference();
                     previousRoundMaxDamageDifference = robotGame.getPreviousRoundMaxDamageDifference();
                     previousRoundTimeElapsed         = robotGame.getPreviousRoundTimeElapsed();
                     buildHubStatesData = robotGame.getBuildHubStatesData();
                     fieldStatesData    = robotGame.getFieldStatesData();
                     trainingMode       = robotGame.getTrainingMode();
                     if (trainingMode)
                     {
                         currentTest = TESTS.AI_AGENT_TRAINING;
                     }
                     foreach (Part part in humanRobotParts)
                     {
                         currentHumanRobotParts.Add(part.clone(true));
                     }
                     foreach (Robot robot in myRobots)
                     {
                         currentMyRobots.Add(robot.clone(true));
                     }
                     foreach (Setting setting in settingList)
                     {
                         currentSettingValueList.Add(setting.currentValue);
                     }
                 }
                 SplashScreen splashScreen = gameObject.GetComponent <SplashScreen>();
                 if (splashScreen != null)
                 {
                     List <GameObject> gameObjectsInOldScene = new List <GameObject>(scene.GetRootGameObjects());
                     GameObject        splashScreenCanvas    = gameObjectsInOldScene.Find(g => g.name == "SplashScreenCanvas");
                     SceneManager.MoveGameObjectToScene(splashScreenCanvas, SceneManager.GetActiveScene());
                     GameObject        loadingSplashScreen       = splashScreenCanvas.transform.Find("LoadingSplashScreen").gameObject;
                     List <GameObject> gameObjectsInCurrentScene = new List <GameObject>(FindObjectsOfType <GameObject>());
                     GameObject        currentSplashScreenCanvas = gameObjectsInCurrentScene.Find(g => g.name.Contains("SplashScreenCanvas"));
                     loadingSplashScreen.transform.SetParent(currentSplashScreenCanvas.transform);
                     splashScreen.transform.SetParent(GameObject.Find("Directional Light").transform);
                 }
             }
             SceneManager.UnloadSceneAsync(scene);
         }
     }
     splashScreenLoader = SceneManager.LoadSceneAsync(SPLASH_SCREEN_SCENE_NAME, LoadSceneMode.Additive);
     splashScreenLoader.allowSceneActivation = false;
     initializeScene(sceneName);
 }
Esempio n. 7
0
 public GameController()
 {
     Board = new Board(5, 5);
     Game  = new RobotGame(Board);
 }
Esempio n. 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadRobot1TextBox.Text = "C:\\BjarkesStuff\\lessons\\week2_c#\\day4_robotgame\\robotspil\\RobotSpil_Data\\TestRobot1.xml";
                LoadRobot2TextBox.Text = "C:\\BjarkesStuff\\lessons\\week2_c#\\day4_robotgame\\robotspil\\RobotSpil_Data\\TestRobot1.xml";
            }

            try // <- laziness inc. (R) (C)
            {
                String filenameRobot1 = LoadRobot1TextBox.Text; // "C:\\BjarkesStuff\\lessons\\week2_c#\\day4_robotgame\\robotspil\\RobotSpil_Data\\TestRobot1.xml";
                String filenameRobot2 = LoadRobot2TextBox.Text; // "C:\\BjarkesStuff\\lessons\\week2_c#\\day4_robotgame\\robotspil\\RobotSpil_Data\\TestRobot1.xml";

                RobotLoadSave loadSave = new RobotLoadSave();
                Robot robot1 = loadSave.Load(filenameRobot1); // exception if error
                Robot robot2 = loadSave.Load(filenameRobot2); // exception if error

                int NUM_ROUNDS = 10;

                RobotGame game = new RobotGame(robot1, robot2, NUM_ROUNDS);
                RobotGame.GameResult result = game.runGame();

                String output = "";
                foreach (RoundResult roundResult in result.results)
                {

                    output += "\n";
                    output += "New round\n";
                    output += "---------\n";
                    output += "\n";
                    output += robot1.getName() + " has " + roundResult.getRobot1LivesBefore() + " lives left.\n";
                    output += robot2.getName() + " has " + roundResult.getRobot2LivesBefore() + " lives left.\n";
                    output += "\n";

                    output += robot1.getName() + " attacks with " + roundResult.getRobot1Attack() + ", " + robot2.getName() + " defends with " + roundResult.getRobot2Defense() + "\n";
                    output += roundResult.getRobot2LoosesALife() ? "Attack was successful\n" : "Attack was averted\n";

                    output += robot2.getName() + " attacks with " + roundResult.getRobot2Attack() + ", " + robot1.getName() + " defends with " + roundResult.getRobot1Defense() + "\n";
                    output += roundResult.getRobot1LoosesALife() ? "Attack was successful\n" : "Attack was averted\n";
                }

                output += "\n";

                switch (result.outcome)
                {
                    case RobotGame.Outcome.ROBOT1WINS:
                        output += "<h3>" + robot1.getName() + "wins!</h3>\n";
                        break;
                    case RobotGame.Outcome.ROBOT2WINS:
                        output += "<h3>" + robot2.getName() + "wins!</h3>\n";
                        break;
                    case RobotGame.Outcome.DRAW:
                        output += "<h3>Nobody wins! Draw between " + robot1.getName() + " and " + robot2.getName() + "</h3>\n";
                        break;
                }

                output = output.Replace("\n", "<br>");
                output = "<pre><code>" + output + "</code></pre>";

                GameWindow.Text = output;

                // TEMP: DOESN'T OVERWRITE OLD ROBOT FOR NOW
                loadSave.Save(robot1, filenameRobot1 + ".new.xml");
                loadSave.Save(robot2, filenameRobot2 + ".new.xml");
            }
            catch (Exception ex)
            {
                GameWindow.Text = "Helpful error message: Can't read robots";
            }
        }
 public void bindRobotGame(RobotGame robotGame)
 {
     this.game = robotGame;
 }