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: