Ejemplo n.º 1
0
    public int GetLevelScore(int levelNum = -1)
    {
        if (levelNum < 0)
        {
            levelNum = this.currentLevel;
        }

        int result = 0;

        try
        {
            result = this.scorePerLevel[levelNum];
        }
        catch (KeyNotFoundException e)
        {
#if UNITY_EDITOR
            Debug.LogError("No such index.");
            Debug.LogError(e.Message);
            return(-1);
#else
            GameObject.Find("MainHelper").GetComponent <MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "No such index.", e);
            EventSystem.FireInterfaceUpdate(this, ev);
#endif
        }

        return(result);
    }
Ejemplo n.º 2
0
 public static void FireInterfaceUpdate(object sender, InterfaceUpdateEventArgs e)
 {
     if (EventSystem.OnInterfaceUpdate != null)
     {
         EventSystem.OnInterfaceUpdate(sender, e);
     }
 }
Ejemplo n.º 3
0
 public static void FireInterfaceUpdate(object sender, InterfaceUpdateEventArgs e)
 {
     if (EventSystem.OnInterfaceUpdate != null)
     {
         EventSystem.OnInterfaceUpdate(sender, e);
     }
 }
Ejemplo n.º 4
0
    protected void BgAudioLoader()
    {
        try
        {
            UnityEngine.Object[] objs = Resources.LoadAll(@"bg_audio/");

            foreach (UnityEngine.Object obj in objs)
            {
                this.clips.Add((AudioClip)obj);
            }
            this.totalClips = clips.Count;
            AudioClip clip = clips[0];

            this.mainAudioSource.clip = clip;
            this.mainAudioSource.Play();
        }
        catch (UnityException e)
        {
        #if UNITY_EDITOR
            Debug.Log("Can't load audio clips");
            Debug.Log(e.Message);
            return;
        #else
            this.currentGame.PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "Can't load audio clips", e);
            EventSystem.FireInterfaceUpdate(this, ev);
        #endif
        }
    }
Ejemplo n.º 5
0
    protected void BgLoader()
    {
        try
        {
            UnityEngine.Object[] objs     = Resources.LoadAll(@"bg_textures/");
            List <Texture2D>     textures = new List <Texture2D>();
            foreach (UnityEngine.Object obj in objs)
            {
                textures.Add((Texture2D)obj);
            }
            Texture2D tex = textures[UnityEngine.Random.Range(0, textures.Count)];

            if (tex != null)
            {
                GameObject.Find("Plane").GetComponent <Renderer>().material.mainTexture = tex;
            }
            else
            {
                throw new UnityException("Texture is null object");
            }
        }
        catch (UnityException e)
        {
#if UNITY_EDITOR
            Debug.Log("Can't load bg textures");
            Debug.Log(e.Message);
            return;
#else
            this.currentGame.PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "Can't load bg textures", e);
            EventSystem.FireInterfaceUpdate(this, ev);
#endif
        }
    }
Ejemplo n.º 6
0
    protected void BgAudioLoader()
    {
        try
        {
            UnityEngine.Object[] objs = Resources.LoadAll(@"bg_audio/");

            foreach (UnityEngine.Object obj in objs)
            {
                this.clips.Add((AudioClip)obj);
            }
            this.totalClips = clips.Count;
            AudioClip clip = clips[0];

            this.mainAudioSource.clip = clip;
            this.mainAudioSource.Play();
        }
        catch (UnityException e)
        {
#if UNITY_EDITOR
            Debug.Log("Can't load audio clips");
            Debug.Log(e.Message);
            return;
#else
            this.currentGame.PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "Can't load audio clips", e);
            EventSystem.FireInterfaceUpdate(this, ev);
#endif
        }
    }
Ejemplo n.º 7
0
    protected void UpdateInterface(object sender, InterfaceUpdateEventArgs e)
    {
        switch (e.UpdateReason)
        {
        case InterfaceUpdateReasons.BallLost:
            Player ballLostSender = (Player)sender;

            if (ballLostSender.PlayerScoreGUI.Equals(this.firstPlayerScore))
            {
                int        index  = ballLostSender.CurrentBall;
                GameObject target = this.firstPlayerBalls.objectReferences[index - 2];
                if (target != null)    // balls start at one [1]
                {
                    GameObject.Find("Morpher").GetComponent <Morpher>().KillBallIndicator(target);
                    target = null;
                }
            }
            else
            {
                /* enemy ball remove handling*/
            }

            break;

        case InterfaceUpdateReasons.LevelChanged:
            if (this.firstPlayerScore != null)
            {
                this.firstPlayerScore.GetComponent <Text>().text = (0).ToString();
            }
            if (this.secondPlayerScore != null)
            {
                this.secondPlayerScore.GetComponent <Text>().text = (0).ToString();
            }
            break;

        case InterfaceUpdateReasons.ScoreIncreased:
            Player scoreIncreasedSender = (Player)sender;

            if (scoreIncreasedSender.PlayerScoreGUI.Equals(this.firstPlayerScore))
            {
                this.firstPlayerScore.GetComponent <Text>().text = e.UpdatedValue;
            }
            else
            {
                /*second player score handling*/
            }
            break;

        case InterfaceUpdateReasons.GameOver: break;

        case InterfaceUpdateReasons.ExceptionThrown:
            if (e.ExceptionUpdate)
            {
                this.ShowException(e);
            }
            break;

        case InterfaceUpdateReasons.UnknownReason: break;
        }
    }
Ejemplo n.º 8
0
 public static void FireChangeLevel(object sender, ChangeLevelEventArgs e)
 {
     if (EventSystem.OnEndLevel != null)
     {
         EventSystem.OnEndLevel(sender, e);
         InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.LevelChanged, "");
         EventSystem.FireInterfaceUpdate(sender, ev);
     }
 }
Ejemplo n.º 9
0
 public static void FireChangeLevel(object sender, ChangeLevelEventArgs e)
 {
     if (EventSystem.OnEndLevel != null)
     {
         EventSystem.OnEndLevel(sender, e);
         InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.LevelChanged, "");
         EventSystem.FireInterfaceUpdate(sender, ev);
     }
 }
Ejemplo n.º 10
0
 // Update is called once per frame
 void Update()
 {
     if (this.hitsTookPlace == this.hitsToKill)
     {
         Destroy(gameObject);
         this.mhReference.GetCurrentGame().GetCurrentField().BrickDestroyed(this.coordinates);
         this.mhReference.GetCurrentGame().GetHumanPlayer().IncreaseLevelScore(this.hitsToKill * this.pointsPerHit);
         InterfaceUpdateEventArgs e = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ScoreIncreased, this.mhReference.GetCurrentGame().GetHumanPlayer().GetLevelScore().ToString());
         EventSystem.FireInterfaceUpdate(this.mhReference.GetCurrentGame().GetHumanPlayer(), e);
     }
 }
Ejemplo n.º 11
0
 // Update is called once per frame
 void Update()
 {
     if (this.hitsTookPlace == this.hitsToKill)
     {
         Destroy(gameObject);
         this.mhReference.GetCurrentGame().GetCurrentField().BrickDestroyed(this.coordinates);
         this.mhReference.GetCurrentGame().GetHumanPlayer().IncreaseLevelScore(this.hitsToKill * this.pointsPerHit);
         InterfaceUpdateEventArgs e = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ScoreIncreased, this.mhReference.GetCurrentGame().GetHumanPlayer().GetLevelScore().ToString());
         EventSystem.FireInterfaceUpdate(this.mhReference.GetCurrentGame().GetHumanPlayer(), e);
     }
 }
Ejemplo n.º 12
0
    protected void UpdateInterface(object sender, InterfaceUpdateEventArgs e)
    {
        switch (e.UpdateReason)
        {
            case InterfaceUpdateReasons.BallLost:
                Player ballLostSender = (Player)sender;

                if (ballLostSender.PlayerScoreGUI.Equals(this.firstPlayerScore))
                {
                    int index = ballLostSender.CurrentBall;
                    GameObject target = this.firstPlayerBalls.objectReferences[index - 2];
                    if(target != null) // balls start at one [1]
                    {
                        GameObject.Find("Morpher").GetComponent<Morpher>().KillBallIndicator(target);
                        target = null;
                    }
                }
                else
                {
                    /* enemy ball remove handling*/
                }

                break;
            case InterfaceUpdateReasons.LevelChanged:
                if (this.firstPlayerScore != null)
                    this.firstPlayerScore.GetComponent<Text>().text = (0).ToString();
                if (this.secondPlayerScore != null)
                    this.secondPlayerScore.GetComponent<Text>().text = (0).ToString();
                break;
            case InterfaceUpdateReasons.ScoreIncreased:
                Player scoreIncreasedSender = (Player)sender;

                if (scoreIncreasedSender.PlayerScoreGUI.Equals(this.firstPlayerScore))
                {
                    this.firstPlayerScore.GetComponent<Text>().text = e.UpdatedValue;
                }
                else
                {
                    /*second player score handling*/
                }
                break;
            case InterfaceUpdateReasons.GameOver: break;
            case InterfaceUpdateReasons.ExceptionThrown:
                if(e.ExceptionUpdate)
                    this.ShowException(e);
                break;
            case InterfaceUpdateReasons.UnknownReason: break;
        }
    }
Ejemplo n.º 13
0
 protected void IncBallNum(object sender, BallCrushedEventArgs e)
 {
     if (this.currentBall <= this.totalBalls)
     {
         ++this.currentBall;
         InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.BallLost, string.Empty);
         EventSystem.FireInterfaceUpdate(this, ev);
     }
     else
     {
         object           snd = new object();
         EndGameEventArgs ev  = new EndGameEventArgs(this.highScore, this.playerName, this.currentLevel, EndGameReasons.WastedAllBalls);
         EventSystem.FireEndGame(snd, ev); // TODO: eventsystem game end event
     }
 }
Ejemplo n.º 14
0
    public void NextLevel(object sender, ChangeLevelEventArgs ea)
    {
        if ((this.currentLevel + 1) >= this.totalLevels)
        {
            return;
        }

        try
        {
            this.AddToHighScore(this.scorePerLevel[this.currentLevel]);
        }
        catch (KeyNotFoundException e)
        {
#if UNITY_EDITOR
            Debug.LogError("No such index.");
            Debug.LogError(e.Message);
            return;
#else
            GameObject.Find("MainHelper").GetComponent <MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "No such index.", e);
            EventSystem.FireInterfaceUpdate(this, ev);
#endif
        }
        finally
        {
            this.CurrentLevel += 1;
        }

        try
        {
            if (!this.scorePerLevel.Exists(x => x == this.CurrentLevel))
            {
                this.scorePerLevel.Add(0);
            }
        }
        catch (KeyNotFoundException e)
        {
#if UNITY_EDITOR
            Debug.LogError("No such index.");
            Debug.LogError(e.Message);
            return;
#else
            GameObject.Find("MainHelper").GetComponent <MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "No such index.", e);
            EventSystem.FireInterfaceUpdate(this, ev);
#endif
        }
    }
Ejemplo n.º 15
0
    private bool ReadFieldFromFile(int levelNum = 0)
    {
#if UNITY_EDITOR
        string path = @"Assets\Standard Assets\Resources\";
#else
        string path = @"Data\Levels\";
#endif

        try
        {
            this.charTmpgrid = new char[this.sizeX, this.sizeY];
            int i = 0;
            using (StreamReader sr = new StreamReader(path + @"Level" + levelNum.ToString() + ".txt"))
            {
                while (sr.Peek() >= 0)
                {
                    string line = sr.ReadLine();
                    int    k    = 0;
                    for (int j = 0; j < line.Length; j++)
                    {
                        if (line[j] == '_' || line[j] == 'x')
                        {
                            this.charTmpgrid[i, k] = line[j];
                            k++;
                        }
                    }
                    i++;
                }
            }

            return(true);
        }
        catch (IOException e)
        {
#if UNITY_EDITOR
            Debug.LogError("Can't read from file!");
            Debug.LogError(e.Message);
            return(false);
#else
            GameObject.Find("MainHelper").GetComponent <MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "Can't read from file!", e);
            EventSystem.FireInterfaceUpdate(this, ev);
#endif
        }
    }
Ejemplo n.º 16
0
 public void BrickDestroyed(GridCellCoords c)
 {
     try
     {
         this.grid[c.x, c.y].HasBrick = false;
     }
     catch (KeyNotFoundException e)
     {
     #if UNITY_EDITOR
         Debug.LogError("No such index.");
         Debug.LogError(e.Message);
         return;
     #else
         GameObject.Find("MainHelper").GetComponent<MainHelper>().GetCurrentGame().PauseGame();
         InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "No such index.", e);
         EventSystem.FireInterfaceUpdate(this, ev);
     #endif
     }
     finally
     {
         --this.totalBricks;
     }
 }
Ejemplo n.º 17
0
    public void BrickDestroyed(GridCellCoords c)
    {
        try
        {
            this.grid[c.x, c.y].HasBrick = false;
        }
        catch (KeyNotFoundException e)
        {
#if UNITY_EDITOR
            Debug.LogError("No such index.");
            Debug.LogError(e.Message);
            return;
#else
            GameObject.Find("MainHelper").GetComponent <MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "No such index.", e);
            EventSystem.FireInterfaceUpdate(this, ev);
#endif
        }
        finally
        {
            --this.totalBricks;
        }
    }
Ejemplo n.º 18
0
    private bool ConstructGrid(int forLevel = 0)
    {
        try
        {
            this.grid = new GridCell[this.sizeX, this.sizeY];
            this.ReadFieldFromFile(forLevel);
            for (int i = 0; i < this.sizeX; i++)
            {
                for (int j = 0; j < this.sizeY; j++)
                {
                    if (this.charTmpgrid[i, j] == 'x')
                    {
                        this.grid[i, j] = new GridCell(i, j, true, this.charTmpgrid[i, j]);
                        this.totalBricks++;
                    }
                    else
                    {
                        this.grid[i, j] = new GridCell(i, j, false);
                    }
                }
            }

            return(true);
        }
        catch (UnityException e)
        {
#if UNITY_EDITOR
            Debug.LogError("Error Constructing Field");
            Debug.LogError(e.Message);
            return(false);
#else
            GameObject.Find("MainHelper").GetComponent <MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "Error Constructing Field", e);
            EventSystem.FireInterfaceUpdate(this, ev);
#endif
        }
    }
Ejemplo n.º 19
0
 protected void ShowException(InterfaceUpdateEventArgs e)
 {
     Time.timeScale = 0;
     this.exceptionCanvasReference.GetComponent<Canvas>().enabled = true;
     this.exceptionTextReference.GetComponent<Text>().text += " " + e.UpdatedValue;
 }
Ejemplo n.º 20
0
    public void IncreaseLevelScore(int score, int levelNum = -1)
    {
        if (levelNum < 0)
            levelNum = this.currentLevel;

        try
        {
            this.scorePerLevel[levelNum] += score;
        }
        catch (KeyNotFoundException e)
        {
        #if UNITY_EDITOR
            Debug.LogError("No such index.");
            Debug.LogError(e.Message);
            return;
        #else
            GameObject.Find("MainHelper").GetComponent<MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "No such index.", e);
            EventSystem.FireInterfaceUpdate(this, ev);
        #endif
        }
    }
Ejemplo n.º 21
0
    public void NextLevel(object sender, ChangeLevelEventArgs ea)
    {
        if ((this.currentLevel + 1) >= this.totalLevels) return;

        try
        {
            this.AddToHighScore(this.scorePerLevel[this.currentLevel]);
        }
        catch (KeyNotFoundException e)
        {
        #if UNITY_EDITOR
            Debug.LogError("No such index.");
            Debug.LogError(e.Message);
            return;
        #else
            GameObject.Find("MainHelper").GetComponent<MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "No such index.", e);
            EventSystem.FireInterfaceUpdate(this, ev);
        #endif
        }
        finally
        {
            this.CurrentLevel += 1;
        }

        try
        {
            if (!this.scorePerLevel.Exists(x => x == this.CurrentLevel))
                this.scorePerLevel.Add(0);
        }
        catch (KeyNotFoundException e)
        {
        #if UNITY_EDITOR
            Debug.LogError("No such index.");
            Debug.LogError(e.Message);
            return;
        #else
            GameObject.Find("MainHelper").GetComponent<MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "No such index.", e);
            EventSystem.FireInterfaceUpdate(this, ev);
        #endif
        }
    }
Ejemplo n.º 22
0
    private bool ReadFieldFromFile(int levelNum = 0)
    {
        #if UNITY_EDITOR
        string path = @"Assets\Standard Assets\Resources\";
        #else
        string path = @"Data\Levels\";
        #endif

        try
        {
            this.charTmpgrid = new char[this.sizeX, this.sizeY];
            int i = 0;
            using (StreamReader sr = new StreamReader(path + @"Level" + levelNum.ToString() + ".txt"))
            {
                while (sr.Peek() >= 0)
                {
                    string line = sr.ReadLine();
                    int k = 0;
                    for (int j = 0; j < line.Length; j++)
                    {
                        if (line[j] == '_' || line[j] == 'x')
                        {
                            this.charTmpgrid[i, k] = line[j];
                            k++;
                        }
                    }
                    i++;
                }
            }

            return true;
        }
        catch (IOException e)
        {
        #if UNITY_EDITOR
            Debug.LogError("Can't read from file!");
            Debug.LogError(e.Message);
            return false;
        #else
            GameObject.Find("MainHelper").GetComponent<MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "Can't read from file!", e);
            EventSystem.FireInterfaceUpdate(this, ev);
        #endif
        }
    }
Ejemplo n.º 23
0
    private bool ConstructGrid(int forLevel = 0)
    {
        try
        {
            this.grid = new GridCell[this.sizeX, this.sizeY];
            this.ReadFieldFromFile(forLevel);
            for (int i = 0; i < this.sizeX; i++)
            {
                for (int j = 0; j < this.sizeY; j++)
                {
                    if (this.charTmpgrid[i, j] == 'x')
                    {
                        this.grid[i, j] = new GridCell(i, j, true, this.charTmpgrid[i, j]);
                        this.totalBricks++;
                    }
                    else
                    {
                        this.grid[i, j] = new GridCell(i, j, false);
                    }
                }
            }

            return true;
        }
        catch (UnityException e)
        {
        #if UNITY_EDITOR
            Debug.LogError("Error Constructing Field");
            Debug.LogError(e.Message);
            return false;
        #else
            GameObject.Find("MainHelper").GetComponent<MainHelper>().GetCurrentGame().PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "Error Constructing Field", e);
            EventSystem.FireInterfaceUpdate(this, ev);
        #endif
        }
    }
Ejemplo n.º 24
0
 protected void IncBallNum(object sender, BallCrushedEventArgs e)
 {
     if (this.currentBall <= this.totalBalls)
     {
         ++this.currentBall;
         InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.BallLost, string.Empty);
         EventSystem.FireInterfaceUpdate(this, ev);
     }
     else
     {
         object snd = new object();
         EndGameEventArgs ev = new EndGameEventArgs(this.highScore, this.playerName, this.currentLevel, EndGameReasons.WastedAllBalls);
         EventSystem.FireEndGame(snd, ev); // TODO: eventsystem game end event
     }
 }
Ejemplo n.º 25
0
    protected void BgLoader()
    {
        try
        {
            UnityEngine.Object[] objs = Resources.LoadAll(@"bg_textures/");
            List<Texture2D> textures = new List<Texture2D>();
            foreach (UnityEngine.Object obj in objs)
            {
                textures.Add((Texture2D)obj);
            }
            Texture2D tex = textures[UnityEngine.Random.Range(0, textures.Count)];

            if (tex != null)
            {
                GameObject.Find("Plane").GetComponent<Renderer>().material.mainTexture = tex;
            }
            else
            {
                throw new UnityException("Texture is null object");
            }
        }
        catch (UnityException e)
        {
        #if UNITY_EDITOR
            Debug.Log("Can't load bg textures");
            Debug.Log(e.Message);
            return;
        #else
            this.currentGame.PauseGame();
            InterfaceUpdateEventArgs ev = new InterfaceUpdateEventArgs(InterfaceUpdateReasons.ExceptionThrown, "Can't load bg textures", e);
            EventSystem.FireInterfaceUpdate(this, ev);
        #endif
        }
    }
Ejemplo n.º 26
0
 protected void ShowException(InterfaceUpdateEventArgs e)
 {
     Time.timeScale = 0;
     this.exceptionCanvasReference.GetComponent <Canvas>().enabled = true;
     this.exceptionTextReference.GetComponent <Text>().text       += " " + e.UpdatedValue;
 }