Battleship | program simulates the game of Battleship | Game Engine library
kandi X-RAY | Battleship Summary
kandi X-RAY | Battleship Summary
This program simulates the game of Battleship. The game was created with C. Since it’s a two player game between a user vs the computer, there is some implementation of AI. Will be focusing more on revising the AI on this.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Battleship
Battleship Key Features
Battleship Examples and Code Snippets
Community Discussions
Trending Discussions on Battleship
QUESTION
I am trying to make a battleship type of game where there is a 3 by 3 board with one random point on the board that you are trying to guess. You should have 2 tries to guess the point, with an incorrect guess leaving an x in place of the o on the board.
The error is for this line:
...ANSWER
Answered 2022-Apr-04 at 01:35You can't list that index since it doesn't exist. If you want to reference a specific 'o' for each index, you need to turn each 'o' per string into its own list of o's.
QUESTION
The grids div sample.
...ANSWER
Answered 2022-Mar-14 at 15:12You can use the index and get the next elements in the array
QUESTION
I'm creating a battleship game in Ruby. Currently, players have 2 boats (size 3 and size 4) and I arbitrarily placed the boats by myself in the code.
Each player has its own board (array1/array2): I put a 0 when the spot is empty and 1 when there's a boat.
My question is, how can I make the players to place their ships on their board by themselves? My idea was to ask them to enter the first point of each boat and then ask them the side (north, east, south and west) to set the orientation. Obviously, a ship can't be placed out of bounds nor on the same space as another ship.
How can I make sure of that with my code? I have no idea where to start...
Thanks!
...ANSWER
Answered 2022-Feb-23 at 18:37Going with your idea.
- Get user input (x,y) for start of ship
- Make sure that space is free (0)
- Create a function that checks if a ship of size N (3 or 4) would fit in each orientation. For example in pseudocode (and this can be generalized with a direction parameter):
QUESTION
I'm making a battleship game implementation with HTML/JavaScript. This function is supposed to add the positions of the ships on an HTML table by copying the elements from a 2d array(p1Board) with the positions of the ships.
...ANSWER
Answered 2022-Feb-14 at 05:56The problem is that you are not specifying the row from which you want to get the cells. Also, once you get the cells, you need to access their .length property.
Change this line
QUESTION
I am trying to show only the first two rows of a CSS GRID.
The width of the container is unknown therefore it should be responsive.
Also the content of each box is unknown.
My current hacky solution is to define the following two rules:
- use an automatic height for the first two rows
- set the height of the next 277 rows to 0 height
grid-auto-rows: auto auto 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
I tried repeat() like this: grid-auto-rows: auto auto repeat(277, 0px)
but unfortunately it didn't set the height to 0.
Is there any clean way to repeat height 0?
...ANSWER
Answered 2022-Feb-07 at 21:16Define a template for the two rows and then use grid-auto-rows
with 0
QUESTION
Trying to get a little practice in decoding JSON data, and I am having a problem. I know the URL is valid, but for some reason my decoder keeps throwing an error. Below is my model struct, the JSON object I'm trying to decode, and my decoder.
Model Struct:
...ANSWER
Answered 2022-Jan-20 at 20:58The EventResponse
suggests that the JSON will be of the form:
QUESTION
Im am building a game of battleship and im using the following code to edit a 6 by 6 figure to represent ships being placed in it.
...ANSWER
Answered 2021-Dec-31 at 16:51You can use a "flag" to achieve this sort of try-until-success logic, for example
QUESTION
I am using subplot() and pcolor(zeros(7,7)); to produce the following figure for a battleship game (please see link below). Im trying to change the color of specific grids to represent ships, but I can't figure it out, so can I please get help with this, I need to for example change grids 22 and 23 in "your board" to red and have the existing figure updated, not get a new figure.
...ANSWER
Answered 2021-Dec-29 at 14:36It's easiest if you set up a function to create/colour a specific square, then this is trivial, and can be recycled throughout your game. Below I've made the local function drawSquare(bs,N,player,color)
which accepts a board size (bs
), square number (N
), a player ('top'
or 'bottom'
), and a colour, which can be any valid MATLAB colorspec
.
Then I've made another function setup(bs)
which calls this a bunch of times to create the "board" for each player.
Then you can see it's as simple as calling drawSquare( bs, 3, 'top', 'r' );
to turn the top player's square number 3 red.
Equally it's easy to call drawSquare( bs, 4, 'top', [0.6,0.5,0.5] );
to colour square 4 for that player a grey-ish tone to show something like a "hit" square in the battleships game.
QUESTION
I am trying to create a basic Battleship game in Python using Tkinter.
Below is a very simplified version of my code. Essentially I am creating a 10*10 grid of buttons and positioning them using .grid
. What I'd like to do is click one of those buttons and pass that buttons grid values (x, y) from the GameBoard
class to the Battleship
class to position the ship.
I have tried using self.row = row
and self.column = column
, however when I do this I immediately receive an attribute error, 'GameBoard' object has no attribute 'row'
.
ANSWER
Answered 2021-Dec-16 at 12:56As @acw1668 pointed out in a comment, the problem is the gboard
attributes row
and column
haven't been created yet when you call bt.position_ship()
in the main()
function.
I don't know your overall game design, but a very simple way to fix that would be to assign a random board position to them in the GameBoard.__init__()
method.
I've also modified the code to show how to call bt.position_ship()
when a button is clicked. This is done by passing the BattleShip
instance bt
to the build_grid()
function so it can be included in calls to the clicked()
method, which can now call it when its called.
QUESTION
I honestly couldn't come up with a better title since it's a scenario-based question:
We have a Battleships game, and we want to ask the player for a pair of coordinates to set one of their ships on the grid (more specifically, the starting point and the ending point of the ship). Assuming that the coordinates were properly given and that the ship is in bounds of the grid plane, we only need to check if the ship collides with any other ship currently on the grid plane.
Context: A Grid has a Content property, and it's either ShipContent or EmptyContent.
The CollisionChecker() method loops through the space between the pair of coordinates that were previously given (mind that these can't be diagonal, this is also assumed to be checked prior).
The player wants to put their battleship between A1 and A4. Since the letters are equal, we loop through 1 to 4, simple enough. However, the player could've entered A4 and A1 respective to their order. Both of these scenarios are expected to work as they are logically sound, but they can cause OutOfBound exceptions and/or improper loops if they are not handled accordingly.
Last bit of context, CoordinateLetter is an enum that has the entire English alphabet in it.
...ANSWER
Answered 2021-Nov-26 at 20:44You could make the code easier to follow and maintain, maybe a little more logical in the naming.
But sometimes you do what you have to.
This is just me messing around with it...
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Battleship
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page