-1
I have to make a naval battle game for college using windows Forms in visual studio, the problem is that I could not understand the logic to generate naval battle maps, I can not think of a way to do this.
What must be done is to put custom boats, in addition to the ones that already have, which are: One 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 with the size of the map, with this is generated 2 maps, one for player 1 and one for player 2. When player 1 enters with all ships, they hide and there are disabled
, so player 2 can put their ships and they hide and then swap the maps to start the game.
Told me to use picturebox[,]
but how does it work? Someone has done something like this before?
I have to save the ranking on file but I have an idea how to do that. I made a code here for menu.
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();
}
}
}
Menu print:
Form print:
I managed to make a picture box custom but as I will work with him to store the ships, and as I will put the ships in the 2 trays?
– Arthur Henrique
You’ve already made progress on your project?
– Márcio Cristian
Life tip: separate game logic from your screen representation. Make the whole game without thinking about screen, then you think about which screen components will use.
– Oralista de Sistemas
i am doing by picture box the problem is that are 7x7 to 15x15 the size of the board that can be chosen, and to put the ships is being difficult because I am doing if by if I do not know if there is a more efficient way to do this
– Arthur Henrique