Naval battle program C # [closed]

-1

I have to do a naval battle game for college using windows forms in visual studio, the problem and I could not understand the logic to generate naval battle maps, I can not think of a way to do that.

What should be done is to place custom boats, other than the ones you already have, which are: An aircraft carrier (five squares each), Two tanks (four squares each), Three torpedo boats (three squares each), Four submarines (two squares each).

The player also enters the size of the map, which generates 2 maps, one for player 1 and one for player 2. When player 1 enters with all the ships, they hide and there are disabled , then player 2 can put his ships and they hide and then change the maps to start the game.

I was told to use picturebox[,] but how does this work? Has anyone done anything like this?

I have to save the ranking on file but I have no idea how to do this. I made a code here for menu I'll leave it here.

Player Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BatalhaNaval
{
    class Jogador
    {
        private string nome;
        private int pontos;
        public Jogador()
        {

        }
        public int Pontos
        {
            get
            {
                return pontos;
            }
            set
            {
                pontos = value;
            }
        }
        public string Nome
        {
            get
            {
                return nome;
            }
            set
            {
                nome = value;
            }
        }
    }
}

Menu Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BatalhaNaval
{
    public partial class menu : Form
    {
        public menu()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Formulario janelanome = new Formulario();
            janelanome.Show();
            Hide();
        }
    }
}

Player name and map size form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BatalhaNaval
{
    public partial class Formulario : Form
    {
        public Formulario()
        {
            InitializeComponent();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            jogo janelajogo = new BatalhaNaval.jogo();
            janelajogo.Show();
            Hide();
        }
    }
}

Print from the menu:

Printtheform:

    
asked by anonymous 30.10.2017 / 12:11

1 answer

1

So, you can do this in N different ways ... There may be way easier, but I would do it in a DataGridView , using Rows and Columns to make the map.

To fill the map with the right ships, you can create buttons that define how many squares you can occupy. For example, when you click on the TORPEDER button, you define that only 3 clicks can be done (via a counter).

You should also check that the DataGridView cell has already been populated, to check the players' hits (to sink the ships or count how many are missing). You will also need to link the respective cells to each ship added to warn you if it has been hit or has been sunk, for example:

COLUNA/LINHA       NAVIO 
     A2         DESTROIER_1
     A3         DESTROIER_1
     A4         DESTROIER_1
     C4         DESTROIER_2
     D4         DESTROIER_2
     E4         DESTROIER_2

Again, there are N ways you can do this.

edit1: answering the @Arthur question

If you clicked here (1), you have to check if the clicks can be on the red items, and for that you can use math as an ally to perform the checks. Again, maybe this is not the best way to do this, but it's an approach I would probably make.

    
01.11.2017 / 14:15