Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

im having a few loop problems in C#

  • 23-11-2004 8:40pm
    #1
    Closed Accounts Posts: 807 ✭✭✭


    ok this is doing my head in now we have to make a battleship program for uni

    we had the assignment for a few weeks and i pretty much did it it has to be handed in well thursday before 9:30am (its done online from home thank god) but i wont be up at that time..day off.. so really any time tomorrow

    the problem is i came round to writing the testing up on monday to find i have..lets say 3 problems, all of which i know can be solved with a loop but ive tried practically every way of doing it i can think of (which isnt admittingly much )

    but ive tried and tried and i keep getting ..not so much errors but they dont do what i tell them

    its getting beyond a joke now im on the verge of handing it in as it is i just dont know how many marks i will lose tho :(

    is anybody pretty ..good with c# that can help me out, ill pm you the codes as there a bit long to be posting here, i really dont think there hard its just a case of a bool or a do while statement i presume but NOTHING works :eek:

    if anyone could help me out tonight id be really grateful ive done all the write ups as such i just want to polish off the program and will submit it but i really want to finish off some other work tomorrow

    pleaseee you c# guys you dont know many times ive been on the verge of putting my fist though the monitor :rolleyes:


«1

Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Can't you just post up what you want to do here, as well as telling us what ideas you've already had to solve each one? We might be able to help you find the flaw in your methods...


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    fair enough but there a bit big, ill do the important 1 first, the other 2 if i dont figure them out the program can still work quite easily, this 1 if i enter the coordinates of the ship in the same place repeatedly it will count as 1 ship 1 hit will blow them all up and the ship counter wont work and the game will nevvverr end so thats a no no..ok:

    you have to place 8 ships on your own grid ive done 1 here as follows:

    int Battleship1x = -1;
    int Battleship1y = -1;


    bool Battleship1xbool = false;


    while (!Battleship1xbool)
    {
    Console.Write("\nEnter the X Coordinates of Your First Battleship:");
    string Battleship1xText = Console.ReadLine();
    try
    {
    Battleship1x = int.Parse(Battleship1xText);
    }
    catch
    {
    Console.WriteLine("\nThis is an incorrect coordinate, please re enter" );
    }
    if ((Battleship1x > lowestSeaValue) && (Battleship1x < highestSeaValue))
    Battleship1xbool = true;
    }


    bool Battleship1ybool = false;
    while (!Battleship1ybool)
    {
    Console.Write("\nEnter the Y Coordinates of Your First Battleship:");
    string Battleship1yText = Console.ReadLine();
    try
    {
    Battleship1y = int.Parse(Battleship1yText);
    }
    catch
    {
    Console.WriteLine("\nThis is an incorrect coordinate, please re enter" );
    }
    if ((Battleship1y > lowestSeaValue) && (Battleship1y < highestSeaValue))
    Battleship1ybool = true;
    }


    Console.WriteLine(Battleship1x + "," + Battleship1y);
    MySea[Battleship1y, Battleship1x] = MySeaState.Battleship;
    PrintMySea();

    you cannot enter a grid cood out out of range which is great battleship1x stands for battleship 1 x coords theres 2 battleships then some cruisers etc etc

    ok!...i do that and i thought, i need to validate it so when it comes to battleship2x and you cant put it in the same place and write over it, so far ive tried a do while loop round the whole thing (ive deleted it now but) something like

    do
    {
    above
    } while (mysea[battleship1y,battleship1x == myseastate.emptysea

    but apart from this not working, i also want to display a thing saying you have already choose this spot please try again
    as it is its quite happy to overwrite them all in 1 place, if there was a way i could then do for the next 1...ALL parts of the grid, except the one ive just picked, this could work, but i didnt know how to approach this, i tried to make each of these a method but i got too many errors

    any help is gonna have to be prettty basic as im not very good at c# yet as you can see...still a learner :(


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    So you're using individual variables for the X and Y of each ship? It would be a lot more efficient if you were to use just 2 eight element arrays instead. This would make it a lot easier to validate whether they are over lapping as well, as after you parse the integer value,you can loop through the length of each array and make sure it doesn't equal any current value.


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    hmm, how would i go about doing this because ...well tomorrow is the deadline and i dont want to have to change a big bulk of my code if i cant even do it :confused:

    -edit-

    just to clear that up i mean how can i make 2 ints like x,y into 1 so try catch would work and everything?


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Declare two 8-element int arrays (int[] name = new int[8]) and use them to put the co-ordinates into.

    Then, when you parse the int value from the console, start a loop that iterates x-1 times, where x is the number of the current boat you're putting down, and checks the parsed value against the x and y positions of of the boats already in the water. If the value doesn't match, then you can put the boat there, but if it does ask for the value again.


  • Advertisement
  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    oh crrrap them

    i think we are banned from using arrays apart from drawing the grid, he wants us to focus on methods this time

    however ive sort of cheated it where i had:

    if ((Battleship1y > lowestSeaValue) && (Battleship1y < highestSeaValue))

    all ive done , its really daft/easy/doesnt look great but works is go:

    if ((Battleship1y > lowestSeaValue) && (Battleship1y < highestSeaValue) && (MySea[Battleship2y, Battleship1y] == (MySeaState.EmptySea)))

    now when y would clash with another ship it just askes for the coordinate again..its not great but tbh ive spent about...10-15hrs trying to sort these tiny problems out and i just give in now

    thanks for the arrays idea, even though i think its slightly complicated for me

    my dodgy way above solves my second problem however im having a slight problem resetting a bool with my final error this 1 ...well if you look:

    bool xvalid = false;
    bool yvalid = false;

    while (!xvalid)
    {
    Console.Write("\nEnter Your X Coordinate to Attack: ");
    string xcoordString = Console.ReadLine();

    try
    {
    xcoordinates = int.Parse(xcoordString);
    }
    catch
    {
    Console.WriteLine("\nYou must enter a correct grid reference");
    }

    if ((xcoordinates > -1) && (xcoordinates < 10))
    xvalid = true;
    continue;



    }

    while (!yvalid)
    {
    Console.Write("\nEnter Your Y Coordinate to Attack: ");
    string ycoordString = Console.ReadLine();

    try
    {
    ycoordinates = int.Parse(ycoordString);
    }
    catch
    {
    Console.WriteLine("\nYou must enter a correct grid reference");
    }

    if ((ycoordinates > -1) && (ycoordinates < 10))
    yvalid = true;
    continue;
    }

    this asks for the coords for you to attack, for your first loop its completely validated you cant enter anything out of bounds, however after your first go it must leave the bool as true as then anything can pass, is there a simple way or place to put something to reset the bool for each go..if you see what i mean?

    i really appreciate the help man! just 1 last problem..and were there

    :D !!


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    The only thing I can think of here is to set the coordinate outside the bounds by default before entering the loop, and then running the loop while it is outside the bounds. Once it is inside the bounds, the loop should pass over to the next one, and you won't need any funny stuff with booleans at all.


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    well this is in its own methods..so will what your saying work...or would calling the method again at the end work? ( your way...makes sense but ...hmm i dunno if i could do it)


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Its a literal two line switch, remove all references of xvalid and yvalid, and move the bounds check into the while statement.

    I could have said that before, but one of the traits of being a good programmer is never explaining in few words what can be described in many... ;)


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    now you see , your a good programmer..im a n00b programmer..you have to tell it to me realllllyyyy basic

    ..switch...i havent done switch before :eek:

    my god if i could get this to work id be done...argh..im just a bit dubious of hacking up my code :rolleyes:

    -edit-

    do
    {
    Console.Write("\nEnter Your X Coordinate to Attack: ");
    string xcoordString = Console.ReadLine();

    try
    {
    xcoordinates = int.Parse(xcoordString);
    }
    catch
    {
    Console.WriteLine("\nYou must enter a correct grid reference");
    continue;
    }

    } while ((xcoordinates < 0) || (xcoordinates > 9));






    do
    {
    Console.Write("\nEnter Your Y Coordinate to Attack: ");
    string ycoordString = Console.ReadLine();

    try
    {
    ycoordinates = int.Parse(ycoordString);
    }
    catch
    {
    Console.WriteLine("\nYou must enter a correct grid reference");
    continue;
    }

    }while ((ycoordinates < 0) || (ycoordinates > 9)
    && (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.Attacked)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedBattleship)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedCruiser)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedRowingBoat)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedRowingBoat)));

    bools are gone...how do i change this in..english terms then not c# as i cant keep up :(


  • Advertisement
  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Heh, sorry, didn't mean literal switch, perhaps swap would have been better... lol... If that works, it should do fine... Butt ugly, but as long as it works... :D If it doesn't, and since you've proven to me that you're trying, I'll give you some source...


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    no that doesnt work :(

    all that WILL do when it works is stop someone entering the same grid ref twice

    i just need to ..do it every go instead of just the first :(

    trying...trying..lol i dont think ive ever put so much effort into a piece of work in my life :eek:


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Ok, let me get this straight, this is working in stopping the user enter the same grid coordinates twice, but your problem now is that it only runs once to begin with?

    Just trying to see if I understand what you're saying...


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    ok that is part of a "MyGame" method, thats the top of the method, the bottom of the method that i havent posted in...er if you need it to make sense is:

    Console.WriteLine("\n" + xcoordinates + "," + ycoordinates);


    if ((TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Battleship) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Cruiser) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Submarine) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.RowingBoat))
    {
    TheEnemySea[xcoordinates, ycoordinates]++;
    EnemyShipCounter++;


    Console.WriteLine("You Hit My Ship!");

    }

    if (EnemyShipCounter == 6)
    Console.WriteLine("You have destroyed all my ships");


    if ((TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.EmptySea))
    {
    TheEnemySea[xcoordinates, ycoordinates]++;
    Console.WriteLine(" You Missed!!");
    }



    }


    basically that..so if it equals a ship it adds 1 to the counter (each ship has a value and each attacked version of that ship is worth 1 more..so it changes the grid image)

    well basically the whole thing loops till someone has lost all there ships now after ive placed my ships (the first error i showed you) the game begins, i attack by using the above code and its fully validated i cant enter anything out of bounds..then the enemy automatically has a go (random)..then when it comes back to my go its no longer validated i can enter what i want and it will accept it and carry on to the bots next go :confused:

    (if that makes sense at all)


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    I've highlihted a sction below in bold that I don't think you need, since all you want to do is validate the y coordinate the same way you did the x.

    Why are you changing the coordinates on the EnemySea with each shot? I don't see why you need to do that...
    do
    {
    Console.Write("\nEnter Your X Coordinate to Attack: ");
    string xcoordString = Console.ReadLine();
    
    try
    {
    xcoordinates = int.Parse(xcoordString);
    }
    catch
    {
    Console.WriteLine("\nYou must enter a correct grid reference");
    continue;
    }
    
    } while ((xcoordinates < 0) || (xcoordinates > 9));
    
    do
    {
    Console.Write("\nEnter Your Y Coordinate to Attack: ");
    string ycoordString = Console.ReadLine();
    
    try
    {
    ycoordinates = int.Parse(ycoordString);
    }
    catch
    {
    Console.WriteLine("\nYou must enter a correct grid reference");
    continue;
    }
    
    }while ((ycoordinates < 0) || (ycoordinates > 9)
    [b]&& (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.Attacked)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedBattleship)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedCruiser)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedRowingBoat)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedRowingBoat))[/b]);
    
    Console.WriteLine("\n" + xcoordinates + "," + ycoordinates);
    
    
    if ((TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Battleship) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Cruiser) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Submarine) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.RowingBoat))
    {
    TheEnemySea[xcoordinates, ycoordinates]++;
    EnemyShipCounter++;
    
    
    Console.WriteLine("You Hit My Ship!");
    
    }
    
    if (EnemyShipCounter == 6)
    Console.WriteLine("You have destroyed all my ships");
    
    
    if ((TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.EmptySea))
    {
    TheEnemySea[xcoordinates, ycoordinates]++;
    Console.WriteLine(" You Missed!!");
    }
    
    }
    


  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    ok, bearing in that Im wading in here and its been years since Ive done C and Im possibly a bit confused by the problem, it looks to me like you need to stick this

    Snippet #1
    do
    {
    Console.Write("\nEnter Your X Coordinate to Attack: ");
    string xcoordString = Console.ReadLine();
    
    try
    {
    xcoordinates = int.Parse(xcoordString);
    }
    catch
    {
    Console.WriteLine("\nYou must enter a correct grid reference");
    continue;
    }
    XXXXXXXX
    } while ((xcoordinates < 0) || (xcoordinates > 9));
    
    around all of this
    Snippet #2
    Console.WriteLine("\n" + xcoordinates + "," + ycoordinates);
    
    
    if ((TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Battleship) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Cruiser) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Submarine) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.RowingBoat))
    {
    TheEnemySea[xcoordinates, ycoordinates]++;
    EnemyShipCounter++;
    
    
    Console.WriteLine("You Hit My Ship!");
    
    }
    
    if (EnemyShipCounter == 6)
    Console.WriteLine("You have destroyed all my ships");
    
    
    if ((TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.EmptySea))
    {
    TheEnemySea[xcoordinates, ycoordinates]++;
    Console.WriteLine(" You Missed!!");
    }
    
    }
    
    So put Snippet #2 in where the XXXXXX is in Snippet 1....


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    GreeBo, That first loop is only used to validate the x position. Doing what you day will put the rest of the method code before the validation, or even entry of the y coordinate, causing no end of trouble with Symbol Not Found errors...


  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    GreeBo, That first loop is only used to validate the x position. Doing what you day will put the rest of the method code before the validation, or even entry of the y coordinate, causing no end of trouble with Symbol Not Found errors...
    I was only pasting the code, the Y co-ord input/validation was implied.
    What do you mean when you say "Doing what you day will put the rest of the method code before the validation"? <edit> Duh, that we use the values before we validate them... :rolleyes: </edit>

    Also, what is
    TheEnemySea[xcoordinates, ycoordinates]++;
    
    for?

    <edit>
    are we reading in all the "hit" co-ords in one go or one at a time?
    </edit>


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Sorry, meant "say"... Damn me and my bad but fast typing... ;)

    Been wondering about that second one myself...


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    I've highlihted a sction below in bold that I don't think you need, since all you want to do is validate the y coordinate the same way you did the x.

    Why are you changing the coordinates on the EnemySea with each shot? I don't see why you need to do that...
    do
    {
    Console.Write("\nEnter Your X Coordinate to Attack: ");
    string xcoordString = Console.ReadLine();
    
    try
    {
    xcoordinates = int.Parse(xcoordString);
    }
    catch
    {
    Console.WriteLine("\nYou must enter a correct grid reference");
    continue;
    }
    
    } while ((xcoordinates < 0) || (xcoordinates > 9));
    
    do
    {
    Console.Write("\nEnter Your Y Coordinate to Attack: ");
    string ycoordString = Console.ReadLine();
    
    try
    {
    ycoordinates = int.Parse(ycoordString);
    }
    catch
    {
    Console.WriteLine("\nYou must enter a correct grid reference");
    continue;
    }
    
    }while ((ycoordinates < 0) || (ycoordinates > 9)
    [b]&& (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.Attacked)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedBattleship)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedCruiser)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedRowingBoat)) ||
    (TheEnemySea[xcoordinates, ycoordinates] == (EnemySeaState.AttackedRowingBoat))[/b]);
    
    Console.WriteLine("\n" + xcoordinates + "," + ycoordinates);
    
    
    if ((TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Battleship) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Cruiser) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.Submarine) ||
    (TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.RowingBoat))
    {
    TheEnemySea[xcoordinates, ycoordinates]++;
    EnemyShipCounter++;
    
    
    Console.WriteLine("You Hit My Ship!");
    
    }
    
    if (EnemyShipCounter == 6)
    Console.WriteLine("You have destroyed all my ships");
    
    
    if ((TheEnemySea[xcoordinates, ycoordinates] == EnemySeaState.EmptySea))
    {
    TheEnemySea[xcoordinates, ycoordinates]++;
    Console.WriteLine(" You Missed!!");
    }
    
    }
    


    the bit you hightlighted ..i hope what it meant is

    that nothing after that while statement can be true for it to carry on..i cant place a ship in an already attacked place ..or thats what i hope it does

    i didnt think i was changing the coordinates everything..i thought that added 1 so it would turn into an attacked ship...or thats wot it does elsewhere in my program..if we are talking about the same section

    im seriously losing it now...its been like 3pm till gone 12am for the last 3 nights on the same problems..i cant believe how much hassle its giving me :mad:


  • Advertisement
  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    If you're following the proper rules of Battleship thats going to be a moot point, as all ships will be placed before firing has begun...


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    this is firing..all the ships are already placed...

    placement is done and dusted!

    all i want this section to do is ask for X..ask for Y..check it hasnt already been hit then firrreeee and change the grid square..and repeat..but WITH validation..which is the pain in the arse :(


  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    Sorry, meant "say"... Damn me and my bad but fast typing... ;)/QUOTE]
    Damn me and my speed reading, I didnt even notice!
    My brain must be set to Auto-Correct.....


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Well then, like I say, you won't need to worry about placing ships where it has already been fired upon then, so you won't need that big chunk that was highlighted.


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    i thought that big bit was checking that the coords id entered didnt equal an attack square...?


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Ah, I guess you're right on that one, my bad... Bit tired myself right now... Though you are checking the rowingboat twice...


  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    ViperVenoM wrote:
    this is firing..all the ships are already placed...

    placement is done and dusted!

    all i want this section to do is ask for X..ask for Y..check it hasnt already been hit then firrreeee and change the grid square..and repeat..but WITH validation..which is the pain in the arse :(
    If you're following the proper rules of Battleship thats going to be a moot point, as all ships will be placed before firing has begun...
    ok, I think we (well I do!) need a bit of a walk thorough about how the game is gonna be played and what the rules are....
    Do you enter all your positions in one go (in one line?) and likewise for the firing?

    What do you mean by "change the grid square"?
    Surely the position depends on what the user inputs as their firing target co-ords?


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    yep thats a mistake..changed it to submarine in my real program

    aw dude..please dont go to sleep, sort this tinnnyyy error out and ..and..you can sleep in tomorrow! :p

    i noticed you give me reputation..how the hell do i do that :confused:


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    you can sleep in tomorrow!
    I wish, I have to be up at 7.30 to go to college :(

    Why do you want to change the grid square, thats what I don't understand right now, the rest looks to be fine...


  • Advertisement
  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    GreeBo wrote:
    ok, I think we (well I do!) need a bit of a walk thorough about how the game is gonna be played and what the rules are....
    Do you enter all your positions in one go (in one line?) and likewise for the firing?

    What do you mean by "change the grid square"?
    Surely the position depends on what the user inputs as their firing target co-ords?


    ok its basically in methods...first the comp draws 2 grids out then it goes onto placing ships, the enemys are stored in the source...mine i am asked to enter where i want to put them (see page 1 error) when all mine are in the grid shows the enemys grid all hidden and it shows my little grid with B's and S's and C's for the various ship names...the next methods are both our goes

    my go involves having a pop at his grid..if i miss the grid changes to a * and if i hit a ship the grid changes to a X the way ive done this is named emptysea and all the ships..they have been given a value..an attacked version of the ship is give then next value up..so battleship = 1 and attacked battleship = 2..when i hit his sea it adds 1 to the counter and changes whats displayed in the grid, i have my go then he has his go randomly attacking my sea and updating whats shown in my grid we each take it in turns to have goes till someone has no ships left...everytime i ship is hit this adds 1 to the counter and when it equals the counter end game method fires and says game over you won/lost

    just the validation with my current problem doesnt want to loop for each of my goes..

    (im trying to hurry up incase you go to bed..eek go go go me)


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    I wish, I have to be up at 7.30 to go to college :(

    Why do you want to change the grid square, thats what I don't understand right now, the rest looks to be fine...


    my grid is
    ~~~~~~~~~~
    ~~~~~~~~~~
    ~~~~~~~~~~
    ~~~~~~~~~~
    ~~~~~~~~~~
    ~~~~~~~~~~
    ~~~~~~~~~~

    etc etc 10x10

    my grid will look like:

    ~~~~~~~~~
    ~~~~~~~~~
    ~B~~~~~~~
    ~~~~~~~~~
    ~~~~~S

    etc etc...

    enemys will just be plain

    when 1 is attacked i want it to change to

    ~~~~~*~~
    ~~~~~~~~
    ~~~~~~~~
    ~~~X~~~~

    etc

    the X changes from a ship and the * changes from a shot fired at the empty sea

    would sending you the .exe help..its 24kb or so?


  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    ViperVenoM wrote:
    would sending you the .exe help..its 24kb or so?
    Yeah, Im sure no one would mind if you rename the extension (.zip or something) and attach it to a msg...
    attach the src too, zip it up, its probably easier to look at the src code...


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    I presume that all the enemy stuff is taken care of in another method? In that case what you'll be doing is running this one, then the next, then back to this...

    If there is another loop required, it'll be outside this method. You'll want to keep it looping until either all your ships or all his ships are destroyed, so something like
    while(EnemyShipCounter > 6 && PlayerShipCounter > 6)
    

    As long as both of you still have ships, this will keep calling the methods in turn...


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    yes i have an EndGame method along them lines:

    static void EndGame()
    {
    do
    {
    MyGame ();
    PrintMySea ();
    PrintEnemySea ();
    HisGame ();
    }
    while((MyShipCounter <6) && (EnemyShipCounter <6));

    if (EnemyShipCounter == 6)
    {
    Console.WriteLine("\nAll Enemy Ships Destroyed");
    Console.WriteLine("\n Congratulations You have Won the game");
    Console.ReadLine();


    }
    if (MyShipCounter == 6)
    {
    Console.WriteLine("\nYou have Lost The Game!");
    Console.ReadLine();

    }

    im wondering if its my do while round them methods thats causing me this error as i have a few others declared at the top too :confused:

    ok my program:

    -edit- remember to come back! i know my game my be damn addictive and all :p

    ha i dont believe it ive just found another error...if i win the game the computer has 1 more go before the game ends..if thats a lot of hard work im tempted to just leave that 1 ..it will still "work" and ive seriously seen enough of c# to last me a lifetime already :mad:


  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    while(EnemyShipCounter < 6 && PlayerShipCounter < 6)
    

    :D


  • Advertisement
  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    well mine count up..so im taking thats right..however it starts at 0..adds 1 7 times..and works correctly if i stop it at 6...ill never get programming :rolleyes:


  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    Hey, so whats the problem with the program at the moment, its running fine for me......
    <edit>
    you seem to have mixed up your X and Y co-ords for the firing, if I enter 0, 9 ir shoots at 9,0 :)
    </edit>


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    GreeBo wrote:
    while(EnemyShipCounter < 6 && PlayerShipCounter < 6)
    

    :D
    Like I said... Tired... lol


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Me too... I say hand it in as is... Its pretty good, you should get a decent grade for it.

    Leave it as is, and get some sleep...


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    but

    have u tried to break it?

    after your first go at attacking enter daft things..they get really bitchy over validation at uni

    and thats my problem!

    and i dont need sleep im not in till friday :D

    (/me shuts up if he wants help)


  • Advertisement
  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    GreeBo wrote:
    Hey, so whats the problem with the program at the moment, its running fine for me......
    <edit>
    you seem to have mixed up your X and Y co-ords for the firing, if I enter 0, 9 ir shoots at 9,0 :)
    </edit>



    ****TT ive sent you the wrong 1

    no no no wait pleaseee

    ok its a little more validation proof..and i thought id enter them the right way round..it goes across first then down?..youve got me looking now :confused:


  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    ok still, here
    but it validated fine (well, it didnt throw an error, but it just re-prompts me)


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Well, either way, it seems to be ok... I ran it, attacked one, then hit both x and y with a barrage of numbers in multiples of 9, and it worked, validated each time. You might want ot give a message stating that you can only go as far as 9, by the way, looks better presentation wise...


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    no you see the attack

    after you entered X and Y once...(that time you cant break it)

    after the enemys had his go then you get Another go

    then try entering letters and things

    it says you must enter a correct grid ref..then goes on and asks for y anyway! :confused:

    i know its validation proof wise on entering your own ships..but attacking...thanks btw..we had an option to make a GUI..heh no thanks :rolleyes:

    -edit- yep your right i did a whoooopsy with x and changed them round now thanks..didnt see that :rolleyes:


  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    couple of small things but otherwise it looks ok
    1) if I enter an invalid number I dont get an error but I get reprompted
    2) if I leave it blank I do get an error, just use the same logic for 1 & 2
    3) if you enter an invalid Y co-ord when you are firing it appears to core dump :eek:

    fix these little bits and then get some sleep, it looks pretty good.
    Well done.


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    omg core dump...wot the hell! i cant fix that i dont even know what ive done to make it do that..i really think im gonna leave it as it is soon is getting me all stressed :(

    thanks for spotting more errors :p

    only problem is on friday morning they are being presented..i just hopes mine not the only 1 that crashes :rolleyes:


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Damn it, I knew there was an IsNumeric function in there, but its VB.NET only... Unless I can find a way to get the ASCII\Unicode values of the string and comapre them to the values for 0-9, I can't think of a way to cleanly make sure you aren't using letters...

    On second thoughts, anything too advanced could show you getting help, which could get you in trouble...


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    i think im just gonna submit

    even if i get half marks for the whole thing thats still 50%..i only need 40%..it seems they dont care what grade you get in the first year..just get over 40%..and i dont think this counts to the WHOLE year..maybe 10 or 20%..all this and i think its worth 10% of getting me through to my next year..so 40% = 4%!!!!!!!!!! all this hassle for 4%...

    you know what..it doesnt matter mate thanks for all the help, both of you but im just gonna submit it right now before i find anything wrong it WORKS as long as you dont try and bust it..the specification asks for a working program..which it does...making it idiot proof is a different spec and not worth as much...

    yep it can go now before i find another error :rolleyes:


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Well, congrats on a job well done.


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    thanks :D

    now the webpage creator thingy is being a bitch..heh it wont update..oh i love programming...and evveryything that goes with it...i will get this to work though!!!

    nope that was my fault..im getting tired too lol :rolleyes:


  • Advertisement
Advertisement