示例#1
0
    public void InstShotCell(int x, int y, int field, char mode)
    {
        Jobster jb = GameObject.Find("jobster").GetComponent <Jobster>();

        y = 9 - y;
        float      resultX       = fieldResize.leftMargin + jb.startedGame.Human.currentField.singleCellSize * x;
        float      resultY       = fieldResize.topMargin + jb.startedGame.Human.currentField.singleCellSize * y;
        GameObject resultingPref = (mode == 's') ? this.ShotCell : this.MissCell;
        GameObject go            = new GameObject();

        if (field == 1) // player
        {
            go = (GameObject)Instantiate(resultingPref, new Vector3(0, 0, 1.5f), Quaternion.identity);
        }
        else // enemy
        {
            resultX = jb.startedGame.AI.currentField.realObjectReference.GetComponent <GUITexture>().pixelInset.xMin + x * jb.startedGame.Human.currentField.singleCellSize;
            go      = (GameObject)Instantiate(resultingPref, new Vector3(0, 0, 0), Quaternion.identity);
        }

        Rect rt = new Rect();

        rt.yMin = resultY;
        rt.yMax = resultY + jb.startedGame.Human.currentField.singleCellSize;
        rt.xMax = resultX + jb.startedGame.Human.currentField.singleCellSize;
        rt.xMin = resultX;

        go.GetComponent <GUITexture>().pixelInset = rt;
    }
示例#2
0
    public override void PlaceEnemyShips()
    {
        Jobster jb = GameObject.Find("jobster").GetComponent <Jobster>();

        while (this.currentShip < 10)
        {
            if (this.currentShip == 0)
            {
                this.ships[this.currentShip] = new QuadDeck();
                jb.ShipCorInit(4);
            }
            else if (this.currentShip > 0 && this.currentShip < 3)
            {
                this.ships[this.currentShip] = new TriDeck();
                jb.ShipCorInit(3);
            }
            else if (this.currentShip > 2 && this.currentShip < 6)
            {
                this.ships[this.currentShip] = new DoubleDeck();
                jb.ShipCorInit(2);
            }
            else if (this.currentShip > 5 && this.currentShip < 10)
            {
                this.ships[this.currentShip] = new SingleDeck();
                jb.ShipCorInit(1);
            }
        }
    }
示例#3
0
    public void ChangeOrientation()
    {
        this.Orientation *= -1;
        Jobster jb = GameObject.Find("jobster").GetComponent <Jobster>();

        this.PreparationsForChange(this.Orientation, this.X, this.Y, jb.startedGame.Human.currentField.singleCellSize);
    }
示例#4
0
    public Field()
    {
        CustomError ce = new CustomError("Field", "constructor");

        this.cells = new Cell[this.byX, this.byY];
        GUITexture gt = new GUITexture();
        Jobster    jb = GameObject.Find("jobster").GetComponent <Jobster>();
    }
示例#5
0
    public int EnemyShot(int x, int y)
    {
        x = Mathf.Abs(x);
        y = Mathf.Abs(y);
        Jobster jb  = GameObject.Find("jobster").GetComponent <Jobster>();
        Morpher mph = GameObject.Find("Morpher").GetComponent <Morpher>();

        Debug.Log("Enemy shot int, int");
        if (!jb.startedGame.Human.currentField.cells[x, y].IsShot)
        {
            jb.startedGame.Human.currentField.cells[x, y].IsShot = true;
            if (jb.startedGame.Human.currentField.cells[x, y].HasShip)
            {
                jb.startedGame.WhosTurn = 2;
                for (int i = 0; i < jb.startedGame.Human.ships.Length; i++)
                {
                    for (int j = 0; j < jb.startedGame.Human.ships[i].Size; j++)
                    {
                        Cell c = jb.startedGame.Human.ships[i].GetCell(j);
                        if (x == c.X && y == c.Y)
                        {
                            jb.startedGame.Human.ships[i].ShotIncrease();
                            mph.InstShotCell(x, y, 1, 's');
                            jb.PlayExplosion();
                            return(0);
                        }
                    }
                }
            }
            else
            {
                //jb.startedGame.WhosTurn = 1;
                mph.InstShotCell(x, y, 1, 'm');
                jb.PlayMiss();
                this.turnInProcess = false;

                /*if (this.currentCycle >= 3)
                 * {
                 *  this.justHit = false;
                 * }*/
                return(1);
            }
        }
        else
        {
            //jb.startedGame.WhosTurn = 2;

            /*if (this.currentCycle >= 3)
             * {
             *  this.justHit = false;
             * }*/
            this.turnInProcess = false;
            return(2);
        }

        return(3);
    }
示例#6
0
    public static void FireBindShip()
    {
        Jobster jb = GameObject.Find("jobster").GetComponent <Jobster>();

        if (jb.startedGame.Human.ships[jb.startedGame.Human.currentShip].AllowedToBind)
        {
            if (EventManager.OnBindShip != null)
            {
                EventManager.OnBindShip();
            }
        }
    }
示例#7
0
    // Update is called once per frame
    void Update()
    {
        Jobster job = GameObject.Find("jobster").GetComponent <Jobster>();

        if (job.changeSizeFlag != 0)
        {
            EventManager.FireResize();
        }

        if (Input.GetKeyUp(KeyCode.Escape))
        {
            EventManager.FireGamePause();
        }
    }
示例#8
0
    public override void CheckBindSpace()
    {
        Jobster jb = GameObject.Find("jobster").GetComponent <Jobster>();

        int plusX = (this.Orientation > 0) ? 1 : 0;
        int plusY = (this.Orientation < 0) ? 1 : 0;

        for (int i = 0; i < this.size; i++)
        {
            if (jb.startedGame.Human.currentField.cells[this.X + (plusX * i), this.Y + (plusY * i)].IsOccupied)
            {
                this.AllowedToBind = false;
                return;
            }
        }

        this.AllowedToBind = true;
    }
示例#9
0
    public override void ShootTheBitch(int x, int y)
    {
        Jobster jb  = GameObject.Find("jobster").GetComponent <Jobster>();
        Morpher mph = GameObject.Find("Morpher").GetComponent <Morpher>();

        if (!jb.startedGame.AI.currentField.cells[x, y].IsShot)
        {
            jb.startedGame.AI.currentField.cells[x, y].IsShot = true;
            if (jb.startedGame.AI.currentField.cells[x, y].HasShip)
            {
                jb.startedGame.WhosTurn = 1;
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < jb.startedGame.AI.ships[i].Size; j++)
                    {
                        Cell c = jb.startedGame.AI.ships[i].GetCell(j);
                        if (x == c.X && y == c.Y)
                        {
                            jb.startedGame.AI.ships[i].ShotIncrease();
                            mph.InstShotCell(x, y, 2, 's');
                            jb.PlayExplosion();
                        }
                    }
                }
            }
            else
            {
                jb.startedGame.WhosTurn = 2;
                mph.InstShotCell(x, y, 2, 'm');
                jb.PlayMiss();
            }
        }
        else
        {
            jb.startedGame.WhosTurn = 1;
        }
    }
示例#10
0
    public override int EnemyShot()
    {
        /*if (this.justHit)
         * {
         *  Debug.Log("Shooting after hit");
         *  this.ShootAfterHit();
         *  this.turnInProcess = false;
         *  return;
         * }
         *
         * if (this.jbRef.startedGame.WhosTurn == 1)
         *  return;*/

        int     x   = Random.Range(0, 10);
        int     y   = Random.Range(0, 10);
        Jobster jb  = GameObject.Find("jobster").GetComponent <Jobster>();
        Morpher mph = GameObject.Find("Morpher").GetComponent <Morpher>();

        //Debug.Log("enemy shot void");
        if (!jb.startedGame.Human.currentField.cells[x, y].IsShot)
        {
            jb.startedGame.Human.currentField.cells[x, y].IsShot = true;
            if (jb.startedGame.Human.currentField.cells[x, y].HasShip)
            {
                jb.startedGame.WhosTurn = 2;
                for (int i = 0; i < jb.startedGame.Human.ships.Length; i++)
                {
                    for (int j = 0; j < jb.startedGame.Human.ships[i].Size; j++)
                    {
                        Cell c = jb.startedGame.Human.ships[i].GetCell(j);
                        if (x == c.X && y == c.Y)
                        {
                            this.hp.x    = x;
                            this.hp.y    = y;
                            this.justHit = true;
                            jb.startedGame.Human.ships[i].ShotIncrease();
                            mph.InstShotCell(x, y, 1, 's');
                            this.hitShipSize  = jb.startedGame.Human.ships[i].Size;
                            this.hitShipIndex = i;
                            jb.PlayExplosion();
                            this.turnInProcess = false;
                            //this.ShootAfterHit();
                            return(0);
                        }
                    }
                }
            }
            else
            {
                //jb.startedGame.WhosTurn = 1;
                mph.InstShotCell(x, y, 1, 'm');
                jb.PlayMiss();
                this.turnInProcess = false;
                return(1);
            }
        }
        else
        {
            //jb.startedGame.WhosTurn = 2;
            this.turnInProcess = false;
            return(2);
        }

        return(3);
    }
示例#11
0
 // Use this for initialization
 void Start()
 {
     this.jbRef = GameObject.Find("jobster").GetComponent<Jobster>();
 }
示例#12
0
    public override void Bind()
    {
        this.CheckBindSpace();
        Morpher mph     = GameObject.Find("Morpher").GetComponent <Morpher>();
        Jobster jb      = GameObject.Find("jobster").GetComponent <Jobster>();
        int     i       = 0;
        int     barrier = this.size;

        if (this.Orientation > 0)
        {
            if (this.X > 0)
            {
                i = -1;
            }
            else
            {
                i = 0;
            }

            if (this.X + this.size < 10)
            {
                barrier += 1;
            }
        }
        else
        {
            if (this.Y > 0)
            {
                i = -1;
            }
            else
            {
                i = 0;
            }

            if (this.Y + this.size < 10)
            {
                barrier += 1;
            }
        }

        for (; i < barrier; i++)
        {
            if (this.Orientation > 0)
            {
                jb.startedGame.Human.currentField.cells[this.X + i, this.Y].IsOccupied = true;
                if (i > -1 && i < size + 1)
                {
                    jb.startedGame.Human.currentField.cells[this.X + i, this.Y].HasShip = true;
                }

                if (this.Y > 0)
                {
                    jb.startedGame.Human.currentField.cells[this.X + i, this.Y - 1].IsOccupied = true;
                }
                if (this.Y < 9)
                {
                    jb.startedGame.Human.currentField.cells[this.X + i, this.Y + 1].IsOccupied = true;
                }
            }
            else
            {
                jb.startedGame.Human.currentField.cells[this.X, this.Y + i].IsOccupied = true;
                if (i > -1 && i < size + 1)
                {
                    jb.startedGame.Human.currentField.cells[this.X, this.Y + i].HasShip = true;
                }

                if (this.X > 0)
                {
                    jb.startedGame.Human.currentField.cells[this.X - 1, this.Y + i].IsOccupied = true;
                }
                if (this.X < 9)
                {
                    jb.startedGame.Human.currentField.cells[this.X + 1, this.Y + i].IsOccupied = true;
                }
            }
        }

        for (int k = 0; k < this.size; k++)
        {
            if (this.Orientation > 0)
            {
                this.cells[k] = jb.startedGame.Human.currentField.cells[this.X + k, this.Y];
            }
            else
            {
                this.cells[k] = jb.startedGame.Human.currentField.cells[this.X, this.Y + k];
            }
        }

        mph.InstAShip(this.Orientation);
        EventManager.OnBindShip -= this.Bind;
    }
示例#13
0
 // Use this for initialization
 void Start()
 {
     this.jbRef = GameObject.Find("jobster").GetComponent <Jobster>();
 }
示例#14
0
    public void Resize()
    {
        Rect fieldSizes = gameObject.GetComponent <GUITexture>().GetScreenRect();

        float halfOfScreen = Screen.width / 2;

        float aimWidth     = halfOfScreen - fieldResize.leftMargin * 2;
        float aimHeight    = Screen.height - fieldResize.topMargin * 2;
        int   fixDimension = 0;
        float fixValue     = 0.0f;

        if (aimHeight != aimWidth)
        {
            if (aimHeight > aimWidth)
            {
                fixDimension = 1;//fix height;
                fixValue     = aimHeight - aimWidth;
            }
            else
            if (aimHeight < aimWidth)
            {
                fixDimension = 2;    //fix width
                fixValue     = aimWidth - aimHeight;
            }
        }

        float dimension = Mathf.Min(aimHeight, aimWidth);

        if (gameObject.name == "player_field")
        {
            gameObject.GetComponent <GUITexture>().pixelInset = new Rect(fieldResize.leftMargin, fieldResize.topMargin, dimension, dimension);
        }
        else
        {
            gameObject.GetComponent <GUITexture>().pixelInset = new Rect(halfOfScreen + fieldResize.leftMargin, fieldResize.topMargin, dimension, dimension);
        }
        Jobster jb       = GameObject.Find("jobster").GetComponent <Jobster>();
        float   cellSize = Mathf.Ceil(jb.startedGame.Human.currentField.realObjectReference.GetComponent <GUITexture>().pixelInset.width / 10);

        jb.startedGame.Human.currentField.singleCellSize = cellSize;
        GameObject crosshair = GameObject.Find("crosshair");

        if (fixDimension == 1)
        {
            crosshair.GetComponent <GUITexture>().pixelInset = new Rect(halfOfScreen + fieldResize.leftMargin, Mathf.Floor(Screen.height - fieldResize.topMargin - cellSize - fixValue), cellSize, cellSize);
        }
        else if (fixDimension == 2)
        {
            crosshair.GetComponent <GUITexture>().pixelInset = new Rect(halfOfScreen + fieldResize.leftMargin, Mathf.Floor(Screen.height - fieldResize.topMargin - cellSize), cellSize, cellSize);
        }

        GameObject blueBor = GameObject.Find("blueBorder");

        if (blueBor != null)
        {
            if (fixDimension == 1)
            {
                blueBor.GetComponent <GUITexture>().pixelInset = new Rect(fieldResize.leftMargin, Mathf.Floor(Screen.height - fieldResize.topMargin - fixValue), cellSize, cellSize);
            }
            else if (fixDimension == 2)
            {
                blueBor.GetComponent <GUITexture>().pixelInset = new Rect(fieldResize.leftMargin, Mathf.Floor(Screen.height - fieldResize.topMargin), cellSize, cellSize);
            }

            blueBor.transform.position = new Vector3(0, 0, 0.4f);
        }

        jb.LastHeight = Screen.height;
        jb.LastWidth  = Screen.width;
    }
示例#15
0
    private void ShipDestroyed()
    {
        Jobster jb  = GameObject.Find("jobster").GetComponent <Jobster>();
        Morpher mph = GameObject.Find("Morpher").GetComponent <Morpher>();

        if (this.shotCellNum == this.size)
        {
            //int i = 0;
            int barrier = this.size;

            int   x              = this.cells[0].X;
            int   y              = this.cells[0].Y;
            int   field          = (jb.startedGame.WhosTurn == 1) ? 2 : 1;
            Field fieldReference = (jb.startedGame.WhosTurn == 1) ? jb.startedGame.AI.currentField : jb.startedGame.Human.currentField;

            if (this.Orientation > 0) //width
            {
                if (x > 0)
                {
                    if (y > 0)
                    {
                        if (!fieldReference.cells[x - 1, y - 1].IsShot)
                        {
                            fieldReference.cells[x - 1, y - 1].IsShot = true;
                            mph.InstShotCell(x - 1, y - 1, field, 'm');
                        }
                    }

                    if (!fieldReference.cells[x - 1, y].IsShot)
                    {
                        fieldReference.cells[x - 1, y].IsShot = true;
                        mph.InstShotCell(x - 1, y, field, 'm');
                    }

                    if (y < 9)
                    {
                        if (!fieldReference.cells[x - 1, y + 1].IsShot)
                        {
                            fieldReference.cells[x - 1, y + 1].IsShot = true;
                            mph.InstShotCell(x - 1, y + 1, field, 'm');
                        }
                    }
                }

                for (int i = 0; i < this.size; i++)
                {
                    if (y > 0)
                    {
                        if (!fieldReference.cells[x + i, y - 1].IsShot)
                        {
                            mph.InstShotCell(x + i, y - 1, field, 'm');
                        }
                    }

                    if (y < 9)
                    {
                        if (!fieldReference.cells[x + i, y + 1].IsShot)
                        {
                            mph.InstShotCell(x + i, y + 1, field, 'm');
                        }
                    }
                }

                if (x < 9)
                {
                    x = this.cells[this.cells.Length - 1].X;
                    y = this.cells[this.cells.Length - 1].Y;

                    if (y > 0)
                    {
                        if (!fieldReference.cells[x + 1, y - 1].IsShot)
                        {
                            fieldReference.cells[x + 1, y - 1].IsShot = true;
                            mph.InstShotCell(x + 1, y - 1, field, 'm');
                        }
                    }

                    if (!fieldReference.cells[x + 1, y].IsShot)
                    {
                        fieldReference.cells[x + 1, y].IsShot = true;
                        mph.InstShotCell(x + 1, y, field, 'm');
                    }

                    if (y < 9)
                    {
                        if (!fieldReference.cells[x + 1, y + 1].IsShot)
                        {
                            fieldReference.cells[x + 1, y + 1].IsShot = true;
                            mph.InstShotCell(x + 1, y + 1, field, 'm');
                        }
                    }
                }
            }
            else // height
            {
                if (y > 0)
                {
                    if (x > 0)
                    {
                        if (!fieldReference.cells[x - 1, y - 1].IsShot)
                        {
                            fieldReference.cells[x - 1, y - 1].IsShot = true;
                            mph.InstShotCell(x - 1, y - 1, field, 'm');
                        }
                    }

                    if (!fieldReference.cells[x, y - 1].IsShot)
                    {
                        fieldReference.cells[x, y - 1].IsShot = true;
                        mph.InstShotCell(x, y - 1, field, 'm');
                    }

                    if (x < 9)
                    {
                        if (!fieldReference.cells[x + 1, y - 1].IsShot)
                        {
                            fieldReference.cells[x + 1, y - 1].IsShot = true;
                            mph.InstShotCell(x + 1, y - 1, field, 'm');
                        }
                    }
                }

                for (int i = 0; i < this.size; i++)
                {
                    if (x > 0)
                    {
                        if (!fieldReference.cells[x - 1, y + i].IsShot)
                        {
                            mph.InstShotCell(x - 1, y + i, field, 'm');
                        }
                    }

                    if (x < 9)
                    {
                        if (!fieldReference.cells[x + 1, y + i].IsShot)
                        {
                            mph.InstShotCell(x + 1, y + i, field, 'm');
                        }
                    }
                }

                if (y < 9)
                {
                    x = this.cells[this.cells.Length - 1].X;
                    y = this.cells[this.cells.Length - 1].Y;

                    if (x > 0)
                    {
                        if (!fieldReference.cells[x - 1, y + 1].IsShot)
                        {
                            fieldReference.cells[x - 1, y + 1].IsShot = true;
                            mph.InstShotCell(x - 1, y + 1, field, 'm');
                        }
                    }

                    if (!fieldReference.cells[x, y + 1].IsShot)
                    {
                        fieldReference.cells[x, y + 1].IsShot = true;
                        mph.InstShotCell(x, y + 1, field, 'm');
                    }

                    if (x < 9)
                    {
                        if (!fieldReference.cells[x + 1, y + 1].IsShot)
                        {
                            fieldReference.cells[x + 1, y + 1].IsShot = true;
                            mph.InstShotCell(x + 1, y + 1, field, 'm');
                        }
                    }
                }
            }

            if (jb.startedGame.WhosTurn == 1)
            {
                jb.startedGame.AI.DecShips();
            }
            else
            {
                jb.startedGame.Human.DecShips();
            }
        }
    }
示例#16
0
 public AIPlayer()
 {
     this.jobsterReference = GameObject.Find("jobster").GetComponent <Jobster>();
     this.currentField     = new Field("enemy_field", 2);
     this.jbRef            = GameObject.Find("jobster").GetComponent <Jobster>();
 }
示例#17
0
 public AIPlayer()
 {
     this.jobsterReference = GameObject.Find("jobster").GetComponent<Jobster>();
     this.currentField = new Field("enemy_field", 2);
     this.jbRef = GameObject.Find("jobster").GetComponent<Jobster>();
 }