コード例 #1
0
ファイル: AIPlayer.cs プロジェクト: Sckorn/battleships
    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);
    }
コード例 #2
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;
        }
    }
コード例 #3
0
ファイル: AIPlayer.cs プロジェクト: Sckorn/battleships
    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);
    }
コード例 #4
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();
            }
        }
    }