yaleft.blogg.se

Codereview stack exchange
Codereview stack exchange




codereview stack exchange

Randgen tells me that I'm doing some random generation.

codereview stack exchange

However, would that work and is it the most efficient method? If not, give me an idea.

#Codereview stack exchange code#

I've tried to add a do-while function for scanfs, but it seems I can't have more than one condition (I tried adding multiple checks if input is != to the letter).Īlso, 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? I know I can check for 1's and then add code to put a 1 in (i+n) which would make a vertical ship spanning 2 tiles and for horizontal (i+1, i-1), but I would need some checks (I'm thinking of adding a few ifs to check if I'm on n tile) to see if the 1 is by the 'edge'. Could have I done anything in a different, easier, or more convenient way?Īlso, what would be the most optimal way of solving wrong input when it comes to size and difficulty? 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).This what I've made so far but i'm in doubt if my code is: Printf("\nNumber of misses(out of %d): %d\n\n",difficulty,x_count) Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Printf("Number of ships to be sunk:%d",shipcount) While(shipcount!=0 & x_count!=difficulty)īattle(ships,pseudo_gui,n,coords,&shipcount,&x_count) Printf("\nNumber of misses allowed: %d\n\n",difficulty) Printf("\n\nNumber of ships to be sunk:%d",shipcount) Pseudo_gui=(char*)malloc((n+1)*sizeof(char)) Printf("\nYou've already uncovered this field!\n\n") ĭefault:printf("\nYou've choosen poorly!") Printf("\nYou've already uncovered this field!\n") Void battle(int **ships_ptr, char **pseudo_gui_ptr,int n, struct coord x,int* count,int* miss) Void draw_gui(char **pseudo_gui_ptr,int n) Goal: Create a simple battleship game to test what I've learned so far.






Codereview stack exchange