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

im having a few loop problems in C#

Options
2»

Comments

  • 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 Posts: 27,163 ✭✭✭✭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 Posts: 27,163 ✭✭✭✭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 Posts: 27,163 ✭✭✭✭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 Posts: 27,163 ✭✭✭✭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 Posts: 27,163 ✭✭✭✭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
  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    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...
    why does the int.Parse(xcoordString); not catch letters?


    Let us know how you get on grade-wise...


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    it should

    and it does
    but like i said, only for the first loop of attack, then it...doesnt

    so if they make me demonstrate it..im gonna test the errors only on the first attack and say i missed it :p


  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    should the guard not be:
    while ((x > 0) && (x < 9))?
    I know this should be the same as
    while((x < 0) || (x> 9)) but right now my brain will not accept that...
    can someone give me an example to set my mind at ease...Im sure Im overlooking something...

    x = 5

    ((5 > 0 ) && (5 < 9)) = true && true = true

    ((5 < 0) || (5 > 9)) = false && false = false..

    :confused:


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    aw man..you lost me already im just not thinking straight either now..i think i need to wind down a bit on NFSU2..if you cant program..race fast cars :D

    thanks again for both your help..ill let you know wot mark i get for it..however i dunno how long that will take, they havent even marked the last piece we did yet, probably wont be till after chrissstmmaasss


Advertisement