Remember Me? Hi all, I had intended to post this the other day, as I'm stuck, but my computer crashed via some problem with TrueCrypt and I am now using my GFs cpu to do this. Anyway I have been writing trying to write this battleship game as homework. Any help or guidance would be appreciated, I'm really stuck on the semantics of how to complete this as of this point.
The instructions are as follows: The objective is to implement, utilizing functions and arrays, the battleship game on an 8x8 board.
The computer generates 4 random linear ships of size 1, 2, 3, and 4 one of each each aligned horizontally or vertically disjoint and not touching each other directly but can touch by corners.Mahwari ka blood rokne ka sabar mantra
The user then tries to sink the ships - a ship must be hit on all its squares to sink. The user's score is the number of hits needed to sink all boats. At each step, the user should be given a choice of trying a hit or giving up. If given up, the board should be displayed using for ship squares not hit yet. If trying to hit, the user should specify row and column on the board for the hit - for this purpose, rows and columns of the display should use numbers starting with 1, which will be used by the user.
Menu should be displayed using function int readMenu void ; which should display menu options, read user's input, verify until correct, and return. The main program will look like this: Code:. Last edited by LightYear; at PM. Last edited by Adak; at PM.
Oh yea I'm cooking now. I think I understand, here's what i have so far, just as an update. Don't need any help yet. Okay finally ran into a little snag What type does proces I've placed comments to help locate that. The calling function will know and handle whether it's a row being returned, or a column. It should return an int 1 for hit, or 0 for a miss, and make the needed changes on the board array, if needed.
I'm not sure I get it.
Am I reading that right? Yeah that makes sense. Thanks adak. OK, I think this makes more sense.Skip to content. Instantly share code, notes, and snippets. Code Revisions 1 Stars 2 Forks 3. Embed What would you like to do?Mahila var kavita
Embed Embed this gist in your website. Share Copy sharable link for this gist. Learn more about clone URLs. Download ZIP. You have wasted a guess!Nes development tutorial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment. You signed in with another tab or window. Reload to refresh your session.
battleship-like C Program
You signed out in another tab or window. You cannot see the boats. Boat carrierBoat ' h '5r1, c1, 0" Aircraft Carrier ". Boat carrierBoat ' v '5r1, c1, 0" Aircraft Carrier ". Boat battleship1Boat ' h '4r1, c1, 0" Battleship 1 ". Boat battleship1Boat ' v '4r1, c1, 0" Battleship 1 ". Boat battleship2Boat ' h '4r1, c1, 0" Battleship 2 ". Boat battleship2Boat ' v '4r1, c1, 0" Battleship 2 ". Boat destroyer1Boat ' h '3r1, c1, 0" Destroyer 1 ".
Boat destroyer1Boat ' v '3r1, c1, 0" Destroyer 1 " .For this project we're going to play a game, Battleship.C++ Tutorial 10 - Making a simple ship battle (sinking) game
Welcome back. So we're not exactly going to be playing like that. This will be a 1 sided game where you are trying to sink someone else's ships. You won't have any. The focus of the project is on a 2D array and so we'll be focusing mostly on that aspect.
You'll be reading information from files and playing the game in that way. With Regards, Koustav. Hello My name is Ahmed, i'm a top rated freelancer. Over the last 7 years, I have worked for several clients. Python and Scrapping expert More. The email address is already associated with a Freelancer account. Enter your password below to link accounts:. I'll wait for you to come back and keep reading. Looking to make some money?
Your email address. Apply for similar jobs. Set your budget and timeframe. Outline your proposal. Get paid for your work. It's free to sign up and bid on jobs. Awarded to:. AhmedLabib93 Hello My name is Ahmed, i'm a top rated freelancer. Link Accounts. I am a new user I am a returning user. Email address. Username Valid username. I am looking to Hire Work. Username or Email. Password I forgot my password.Forum Beginners Battleship game. Nov 19, at pm UTC. I'm looking to make a two player battleship game.
I'm not going to worry about playing the game with a computer, that would be even more work. Basically, I need to make the game using functions no longer than 15 lines not including comments or blank linesincluding main. The game will be on a 10x10 board, using the following pieces: 1 Aircraft Carrier, 5 spots 1 Battleship, 4 spots 1 Destroyer, 3 spots 1 Submarine, 3 spots 1 Patrol Boat, 2 spots The players will each place their ships, and then begin to guess. I realize this potentially a pretty hefty program.
BATTLESHIP SOURCE CODE
But before I start, does anyone have any tips or algorithms I can use to get going? Thank you for any help. Last edited on Nov 30, at am UTC. Take it one step at a time. I'd start with the board which would just be represented as a 2D array. After that, work on a placement function that places ships on the board where a player wants. I'd do it as ask the player for a single point, then ask horizontal or vertical. Pass this info to the placement function, check if it collides with another already present ship or goes out of bounds, if not, update your board array.
Then just build a shoot function. Nov 30, at am UTC. I took a bit of a break from this program, but I am back into it. I am only as far as printing my board although it isn't quite what I want yet. Last edited on Dec 1, at am UTC. Do you have pseudo code for this project worked up? That might help you focus if you don't. Off the top my head. I'm thinking something like That's actually a really helpful idea. The way I've been doing this is so unorganized that I don't really know what is going to go where.
And your code may not be quite the same, but is valuable as far as how to place symbols on the board and use two players. Thank you! Dec 1, at am UTC. I'm having a lot of trouble figuring out how to place ships on the board. It seems like it would take a lot of code to create ships with a certain number of spots, then choose if they are horizontal or vertical, where to place them, and to check if they are on the board. And I need to do that for both players.
Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I have been coding the battleship game in C but I have a few problems. First of all, I would like to have a counter for the "hit and sunk" ships it is coded, but it doesn't seem to work, after you hit a ship, it always prints 1and therefore, this doesn't end the program when all ships are sunk.
Here is my code for the main and "shoot" functions:. To fix this, pass a copy of the memory location of valueand then increment the number stored at that location. It needs to be passed by reference. Send the pointer to sunkand receive sunk as a pointer in the shoot function.
Alternatively, make sunk a global variable and increment it, although I'd not suggest this for bigger programs! Read more about passing by value and passing by reference to prevent such things from happening in the future! Learn more. Battleship game in C Ask Question. Asked 2 years, 4 months ago. Active 2 years, 4 months ago. Viewed 2k times. Not a single comment in the entire program.
You are a very naughty boy. SO is not a debugging service, you need to debug the code yourself first. Active Oldest Votes. When using a function call in C, the value is passed by copy. Edwin Buck Edwin Buck Thanks, I'll try! Harsh Harsh 2 2 silver badges 17 17 bronze badges. Sign up or log in Sign up using Google.
I first made the default in switch request the input again, but the problem is that it only requests twice once for the initial request and 2nd time in the default. I've tried to add a do-while function for scanf s, but it seems I can't have more than one condition I tried adding multiple checks if input is!
Also, could you help me pitch some ideas how I could add longer ships which would span over 2 tiles since I'm using a random generator? However, would that work and is it the most efficient method? If not, give me an idea. I'd include something about map in the title. I wouldn't put this here. You should call this once per program, and you might generate multiple maps per program. That's getting to be a rather lot of parameters. I'd put everything inside a Game or Map struct. That way you just pass one pointer, and the everything else comes as part of that.
What are you doing?
You don't want to do anything multiple times, so you shouldn't be using a loop. You know exactly what i and j will be so just calculate those values. Reading back the GUI is generally not helpful. What if the GUI changes?The basic program idea is to make repeated "guesses" as to where in an "ocean" of "quadrants", as represented by a 10x10 array, the enemy has ships.
The goal of the game is to sink all the "enemy's" ships with as few guesses as possible. An aircraft carrier, which fills 5 consecutive ocean "cells" in either a vertical column or horizontal row direction. A battleship, which fills 4 consecutive ocean "cells" in either a vertical column or horizontal row direction. A frigate, which fills 3 consecutive ocean "cells" in either a vertical column or horizontal row direction.
A submarine, which fills 3 consecutive ocean "cells" in either a vertical column or horizontal row direction. A mine sweeper, which fills 2 consecutive ocean "cells" in either a vertical column or horizontal row direction.
Then the teacher's program will repeatedly call my makeNextGuess function to both tell me the result of my last guess and receive information from me well, my makeNextGuess function what my next guess is.
The prototype for makeNextGuess is:. The first time that my teacher program calls my function, to start the game, the Status passed will be NONE. This is a one sided game of battleship. My teacher writes code to place ships.
I come up with a program to sink the ships. I guess that would be useful, I need some help writing my makeNextGuess function.Plotly click event r
I'm not sure where to start. I need to use pointers in this but I'm not real clear on how they work or how to implement them in this. I guess I need a couple more functions but I just can't think straight to get the right loops together.Dahej gidc company list pdf
I hadn't even taken the array into consideration that probably why I am so confused I don't know what anything points to You have to use static variables or global variables I'd stay away from these if you can avoid itfor this exercise. The reason for using static variables is so that they stay set after the function exits, but as long as the function is part of the running program. What have you tried so far and what problems are you having with the program.
The only advice I will give now is the very basic advice of "use a 2 dimensional array". EDIT: your pointers need to be to the 2D array with the ship positions so that you can edit the array based on whether the shot is a hit or a miss. Let us know if you need any more help after you try that for a while.
EDIT2: Arrays are always pointers, whenever you change a value in an array it changes the value in the array outside of the function as well. Keep in mind that after you hit a target in a specific location, you want another shot to the same spot to result in a miss. This is what I need help with. Update: To clarify Update 2: I guess that would be useful, I need some help writing my makeNextGuess function. Update 4: thanks you Matthew I should have know that Answer Save.
- Gotv cheat 2020
- Google translate audio to text
- Cafc grants amicus request in lexmark v. impression products
- I2s microphone
- Numpy fillna
- Precognition esp
- Julien chabbott wedding
- Courses mega links
- Bgyqn canada envios a cuba
- Ffmpeg hls multiple bitrates
- Bal disp ratio
- Vauxhall zafira p0171 fault code
- Outlaws mc oklahoma
- Nalu lemon in the woods
- Redmi note 4 screen broken but working
- Diskstation login password