Battleship game, concept and ideas!

Form based game lets discuss ideas!

Page 1 of 1

5 Replies - 10216 Views - Last Post: 24 June 2009 - 05:15 PM Rate Topic: -----

#1 frostyraver   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 195
  • Joined: 21-April 09

Battleship game, concept and ideas!

Post icon  Posted 19 June 2009 - 05:56 AM

Right I'm getting the need to start a new project soon, seeing as I don't feel like adding on to battle arena, and I'll be finished my monopoly game VERY soon, I had a small version done now i'm making a much larger version.

Anywho, I don't think it would be incredibly hard to, make said battleship game I imagine you would have:

Start Game > 2 player > Show main screen > Player 1 puts on their ships (1) and hits ok > Player 2 then does the same > then the games starts >(start) (2) player 1 goes, If selected square has any boat piece do the HIT code and uncover square, else do miss, finish go > Do the ship checker make sure players have thier ships up > player 2's turn does the same type of code > Do the ship checker make sure players have thier ships up if so then loop back to (start) if not then display victory for play that doesn't have the ships > return to menu.

The only problem I can see is how would you go about placing down the ships at (1)? Any ideas? or at (2) how would you display the board? lots of image boxes?

I'm very interested in this as I might find a new technique.

Is This A Good Question/Topic? 0
  • +

Replies To: Battleship game, concept and ideas!

#2 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,617
  • Joined: 25-December 08

Re: Battleship game, concept and ideas!

Posted 19 June 2009 - 06:00 AM

While this is more for the "Game Programming" forum. Placing ships isnt that hard. Couple of options. If you make a Ship object. You can store its start location, size, and orientation. Then whenever someone fires on a location, you just have to loop through the ships checking to see if that location matches any part of the ship, if it is increment a kill counter and update the map with a X, otherwise update map with an O at the location.

Another option is to modify the map's location with a letter for each ship
(i.e.:
- - - A - -
- - - A - B
- - - A - B
C C C C - -
- - - - - -
)
Granted this is the back end view that the other player can't see. Then when you strike a location, if == '-' change to O otherwise change to X

if your doing this this through Console, the -, x, o look good normally. but if you want to you to use a gui like Windows.Forms, you can make a Button[,], and when you click on the button, you fire, and then set said Button.Enabled = false, and change Button.Text = (hit or miss)

This post has been edited by SwiftStriker00: 19 June 2009 - 06:08 AM

Was This Post Helpful? 0
  • +
  • -

#3 frostyraver   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 195
  • Joined: 21-April 09

Re: Battleship game, concept and ideas!

Posted 19 June 2009 - 06:06 AM

Maybe I need to look into drag and cropping for c#, or I could stick in to use the arrow keys to move then you can rotate, this is for form based c# gaming btw.

I stated earlier i'll have the co ordinates mapped for when you place a ship down to an array, ship part 1 for array 0, ship part 2 array 1 and so on. and if the selected hit matches any part of the array, then turn that part of the array into a hit.

Would remove the use for a random searcher, since we're dealing with values that don't change.
Was This Post Helpful? 0
  • +
  • -

#4 frostyraver   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 195
  • Joined: 21-April 09

Re: Battleship game, concept and ideas!

Posted 24 June 2009 - 02:58 PM

Righteo I have SOME type of console code going down:

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

namespace BattleShip
{
	class Program
	{
		// Set up the map
		static string a1 = "*";
		static string a2 = "*";
		static string a3 = "*";
		static string a4 = "*";
		static string a5 = "*";
		static string a6 = "*";
		static string b1 = "*";
		static string b2 = "*";
		static string b3 = "*";
		static string b4 = "*";
		static string b5 = "*";
		static string b6 = "*";
		static string c1 = "*";
		static string c2 = "*";
		static string c3 = "*";
		static string c4 = "*";
		static string c5 = "*";
		static string c6 = "*";
		static string d1 = "*";
		static string d2 = "*";
		static string d3 = "*";
		static string d4 = "*";
		static string d5 = "*";
		static string d6 = "*";
		static string e1 = "*";
		static string e2 = "*";
		static string e3 = "*";
		static string e4 = "*";
		static string e5 = "*";
		static string e6 = "*";

		// Few varibles here for the setup
		int ship;
		int choiceship;
		string dir;
		string loc;

		static void Main(string[] args)
		{
			// Declair the choice
			int choice;

			// Display the welcome start up message loop untill user enters 4 or higher for a selection
			do
			{
				Console.WriteLine("***********************");
				Console.WriteLine("|	 Battle Ship	 |");
				Console.WriteLine("***********************");
				Console.WriteLine("1. Place Ship");
				Console.WriteLine("2.");
				Console.WriteLine("3. View Map");
				Console.WriteLine("4. Exits");
				Console.Write("Choice: ");
				choice = Convert.ToInt16(Console.ReadLine());
				Console.Clear();
				if (choice == 0)
				{

				}
				else if (choice == 1)
				{
					do
					{
						// Ship placement message
						Console.WriteLine("************************");
						Console.WriteLine("|	 Place Ship	   |");
						Console.WriteLine("************************");
						Console.WriteLine("| Pick a ship to place |");
						Console.WriteLine("| 1 Spaced Ship		|");
						Console.WriteLine("| 2 Spaced Ship		|");
						Console.WriteLine("| 3 Spaced Ship		|");
						Console.WriteLine("************************");
						Console.Write("Choice: ");
						choiceship = Convert.ToInt16(Console.ReadLine());

						// Direction Error code not done yet
						Console.WriteLine("******************************************************");
						Console.WriteLine("Type in a direction (L) for length ways, (W) for width");
						Console.Write("Choice: ");
						dir = Convert.ToInt16(Console.ReadLine());

						// Location, Error code not done yet
						Console.WriteLine("******************************************************");
						Console.WriteLine("Type in the starting location (a1, a2, b1, b2 .etc)");
						Console.Write("Choice: ");
						
						// if the ship choice is 1 apply that to the varible, we don't want to set up with a detection for what was pressed this will give us non hardcoded varible errors if we want to skip some boats for 1 3 and 5
						if (choiceship == 1)
						{
							ship = 1;
							// Grabs the location start
							loc = Convert.ToInt16(Console.ReadLine());
							// Run the ship placer code since we have what we need
							ShipPlace();
						}
						if (choiceship == 2)
						{
							ship = 2;
							dir = Convert.ToInt16(Console.ReadLine());
							ShipPlace();
						}
						if (choiceship == 3)
						{
							ship = 3;
							dir = Convert.ToInt16(Console.ReadLine());
							ShipPlace();
						}
					} while (choice < 4);
				}
				else if (choice == 2)
				{

				}
				else if (choice == 3)
				{
					Map();
				}
			} while (choice < 4);
		}
		// Displays the map output
		public static void Map()
		{
			Console.WriteLine("  A B C D E");
			Console.WriteLine("1 " + a1 + " " + b1 + " " + c1 + " " + d1 + " " + e1 + "");
			Console.WriteLine("2 " + a2 + " " + b2 + " " + c2 + " " + d2 + " " + e2 + "");
			Console.WriteLine("3 " + a3 + " " + b3 + " " + c3 + " " + d3 + " " + e3 + "");
			Console.WriteLine("4 " + a4 + " " + b4 + " " + c4 + " " + d4 + " " + e4 + "");
			Console.WriteLine("5 " + a5 + " " + b5 + " " + c5 + " " + d5 + " " + e5 + "");
			Console.WriteLine("6 " + a6 + " " + b6 + " " + c6 + " " + d6 + " " + e6 + "");
			Console.ReadLine();
			Console.Clear();
		}
		// This applies the ship to the board
		public static void ShipPlace()
		{
			Console.WriteLine("******************************************************");
			Console.WriteLine("");
			Console.Write("Choice: ");
			dir = Convert.ToInt16(Console.ReadLine());
		}
	}
}




I think i'm teaching myself correctly, i'm not sure how to go about placing does the ships, I was thinking of doing a 1 - 25 grid system, but I want a1 and a2, maybe do if user puts in a1 it's actually value is place ment 1 on the board and then I can do the sums better to place, so if a user select DOWN and a1 I can just do if use selects a1 and down spit out the co ords for it, same as for b2 and down, if a6 and down and ship = 3 then display the error that you can't have a ship placed there.

This is too much if statements, Is there some other expression I can use for this? Maybe an multi dimensional array? I might end up with the same thing tho.
Was This Post Helpful? 0
  • +
  • -

#5 lesPaul456   User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Battleship game, concept and ideas!

Posted 24 June 2009 - 03:37 PM

Just a few questions...

Have you thought of using XNA or DirectX?
Is your game going to be tile based?
Was This Post Helpful? 0
  • +
  • -

#6 frostyraver   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 195
  • Joined: 21-April 09

Re: Battleship game, concept and ideas!

Posted 24 June 2009 - 05:15 PM

View PostlesPaul456, on 24 Jun, 2009 - 02:37 PM, said:

Just a few questions...

Have you thought of using XNA or DirectX?
Is your game going to be tile based?


I could yeah, but i'm learning console/form based operations, Then maybe move onto it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1