Ejemplo n.º 1
0
        public bool Play(string msg)
        {
            string[] values = msg.Split('_');

            int i = int.Parse(values[0]);
            int j = int.Parse(values[1]);

            Point p = new Point(i, j);

            bool isShooted = false;

            if (IsStriked(p))
            {
                MarkCell(p, CellState.striked);
                isShooted = true;
                CheckDestroyedShip(p);
            }
            else
            {
                MarkCell(p, CellState.missed);
            }

            draw.Invoke(map);

            if (alives == 0)
            {
                over.Invoke();
                isWinner = true;
            }

            return(isShooted);
        }
Ejemplo n.º 2
0
        private void PlaceShip(Point p)
        {
            if (index + 1 < st.Length)
            {
                index++;
                alives++;

                Ship ship = new Ship(st[index], p, direction);

                if (IsValidLocation(ship))
                {
                    ships.Add(ship);
                    MarkLocation(ship, CellState.busy);
                    draw.Invoke(map);
                }

                else
                {
                    index--;
                    alives--;
                }

                if (index + 1 == st.Length)
                {
                    state = State.ready;
                    check.Invoke();

                    if (playerType == PlayerType.bot)
                    {
                        MaskCells();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void Btn_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            if (btn.Name == "switcher")
            {
                brain.Switch(btn.Name);

                if (Controls[100].Text == "LeftToRight")
                {
                    Controls[100].Text = "UpToDown";
                }

                else
                {
                    Controls[100].Text = "LeftToRight";
                }
            }

            else if (brain.state == State.construction)
            {
                brain.Process(btn.Name);

                if (brain.alives == 10 && playerType == PlayerType.human)
                {
                    Controls[100].Visible = false;
                }
            }

            else if (brain.state == State.game)
            {
                if (!brain.Play(btn.Name))
                {
                    //Thread.Sleep(500);
                    turn.Invoke();
                }
            }
        }
Ejemplo n.º 4
0
        private void Btn_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            if (btn.Name == "switcher")
            {
                brain.Switch(btn.Name);

                if (Controls[100].Text == "Horyzontal")
                {
                    Controls[100].Text = "Vertical";
                }

                else
                {
                    Controls[100].Text = "Horyzontal";
                }
            }

            else if (brain.state == State.construction)
            {
                brain.Process(btn.Name);

                if (brain.alives == 10 && playerType == PlayerType.human)
                {
                    Controls[100].Visible = false;
                }
            }

            else if (brain.state == State.game)
            {
                if (!brain.Play(btn.Name))
                {
                    turn.Invoke();
                }
            }
        }