Kurohige Posted May 22, 2010 Posted May 22, 2010 It is the first time I try to participate in a forum cause I am in great need...! I have to deliver an exercise till Tuesday and I don't think I am going to make it...so I need your help. We have been given a task to create the game "Battleship" using DevC++,without creating or downloading any great libraries. (The game will be played in one computer for each team but vs players that run the same programm in their own computer). This is how it should be: *The programma should read a notepad(where there should be the ships that we use in form of a table with 10 columns and 10 lines-->file "Navy"). *Then it should ask the developer if he is taking the shot or firing. -If he takes the shot then he should alter this table-notepad.If the enemy suceeds the shots must continue with the same way,if not it would be our turn to shoot. -If we are shooting we should save the shooting co-ordinates somehow so if we suceed we will avoid hitting the same target again. *The game ends if all ships are destroyed. (Forgive my English,I need your help) I will try to add here what my team and I have created... Navy.txt written.txt
timo Posted May 23, 2010 Posted May 23, 2010 You are probably not asking for someone to do your homework. You probably do not want comments on the style of your code snippet (because if you are worried about getting something finished at all then style is not your main problem). You did not say what exactly you need help with.
Kurohige Posted May 23, 2010 Author Posted May 23, 2010 No I don't want someone to do my homework..! I am working with it..!I am just not so good at using C and I would like some help.(if it was in python I would have achieved it...) I have problems in facing this: *When I hit a target I want to alter this table-text but in the same time save the coordinates that I hit(so if next time I try to hit the same target,a message would appear telling me to change the cooridnates)...there are many checks I have to do..and when I try one another one pops up...it is like endless.Since I am not very familiar with C knowledge I cannot overpass this problem by using some commands few know. If you can show me an example in C commands,I might be able to modify it and use it... Even If I find solution in this I have many things I have to do...and time runs out...if you have any questions about the project I gave you written please ask me...I have still 2 more days to end this... Merged post follows: Consecutive posts mergedI forgot to say...: *I propably should have created to texts... -One for the shots I am taking. -and one for the shots I am firing... Navy.txt is for the shots I am taking it...
timo Posted May 23, 2010 Posted May 23, 2010 When I hit a target I want to alter this table-text but in the same time save the coordinates that I hit(so if next time I try to hit the same target,a message would appear telling me to change the cooridnates)...there are many checks I have to do..and when I try one another one pops up...it is like endless.Since I am not very familiar with C knowledge I cannot overpass this problem by using some commands few know. If you can show me an example in C commands,I might be able to modify it and use it... By default, Dev-C++ is C++, not C. You can write C in C++ but in this case, I'll assume you also have the extended possibilities of C++, for example vectors which you can consider arrays of variable size. I cannot really estimate the exact problem you have but maybe this helps: // add support for C++ vector. #include <vector> ... // define vectors for stored previous coordinates. std::vector<int> i_coordinates(0), j_coordinates(0); ... // test if the coordinates (i,j) have already been stored as being used. for (size_t idx=0; idx<i_coordinates.size(); ++idx) if (i==i_coordinates[idx] && j==j_coordinates[idx]) { // do whatever you want to do if the coordinates have already been used. } ... // if a target is hit at coordinates (i,j) change some table text and store coordinates. if ( whatever_your_condition_for_hitting_a_ship) { this_table_text[i][j] = new_entry; // store coordinates and mark as already-used. i_coordinates.push_back(i); j_coordinates.push_back(j); }
Kurohige Posted May 25, 2010 Author Posted May 25, 2010 Thank you for your help...but these are too difficult for me to use and modify..! Luckily another member of my team has succeded with another way..! I will finish it with another way myself since I started it...I wil suceed. I do not know If i am allowed to post it here after...if not,if anyone will want help with a similar matter you can write me...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now