Author Topic: Programming help (part 2)  (Read 926 times)

0 Members and 1 Guest are viewing this topic.

Offline Gai Daigoji

  • Gekigangar!
  • 28
    • http://www.freewebs.com/neo-terra
Programming help (part 2)
Ok so as a few of you know from Game Warden, I'm starting to learn the coding known as C#. My friend at work is giving me little tutorials to do to build my skills up and I've tried this one since 9am (BST) this morning and cant get my head around it. So here is the tutorial question:

Ask the user for the triangle size they wish to display.  Display a triangle created out of asterisks based on the size entered. .

For example, for a request of 6 the triangle should be:

*
**
***
****
*****
******

======

Ok so here is my coding so far:

int userInput;
         


         Console.Write("Please enter a number to be converted in to a triangle");
         userInput = Console.Read();
         Convert.ToInt32(Console.Read());
         
         

         while (userInput > 1)

         {
            Console.WriteLine("*", userInput);
            userInput++;
            
         }

   
      }
   }
}

=====

Any ideas on what to add or how I should do it? I hate having a problem I cant solve, it makes me want to pull my hair out lol >.<

Any help would be great, thanks :)
Freespace 2: Neo-Terra - My Freespace 2 website that holds my completed FS2 campaigns.

Darkness Rising - Current campaign I'm working on.

Mission Designer for the Wing Commander Saga.

CURRENT PROJECT: Darkness Rising, WCS
COMPLETED PROJECTS: Neo-Terra, Unification Prequel, Solar Wars Chapter 1, Deep Blood, Return to Neo-Terra (Part 1).

 

Offline aldo_14

  • Gunnery Control
  • 213
Re: Programming help (part 2)
//(pseudocode, becuase I don't know C#)

int depth = somethign; //triangle depth, i.e. 6; this is where we do the read / conversion stuff to get an input val

for(int i=1; i<= depth; i++)  {
//i.e. go from 1 to 6; top to bottom

   for(int j=1; j<=i; j++)  {
//print 'i' *s; so we go from *, to **, to *** etc as i goes from 1,2,3 etc

       print("*");
   }
   newLine();
}
« Last Edit: November 21, 2005, 09:56:07 am by aldo_14 »

 

Offline kode

  • The Swedish Chef
  • 28
  • The Swede
    • http://theswe.de
Re: Programming help (part 2)
ruby-code, since this stuff's super easy in ruby ;)
Code: [Select]
puts "Please enter a number to be converted in to a triangle"
number = (gets.to_i+1) #don't wanna deal with the fence-post error
number.times do |x|
  x.times { print "*" }
  puts
end

well, I guess that didn't help you that much. however, the way I'd go about it in (basically) any other programming language would be to nest two for-loops, much like aldo in the post above.

oh, and aren't you asking for input two times now? (I don't know C#, but that what it looks like to me):

         userInput = Console.Read();
         Convert.ToInt32(Console.Read());

to:

        userInput = Convert.ToInt32(Console.Read());


you are then, from the looks of it, entering an infinite loop (unless the input was less than 1)

« Last Edit: November 21, 2005, 09:46:15 am by kode »
Pray, v. To ask that the laws of the universe be annulled in behalf of a single petitioner confessedly unworthy.
- Ambrose Bierce
<Redfang> You're almost like Stryke 9 or an0n
"Facts do not cease to exist because they are ignored."
- Aldous Huxley
WAR IS PEACE
FREEDOM IS SLAVERY
IGNORANCE IS STRENGTH

 

Offline Gai Daigoji

  • Gekigangar!
  • 28
    • http://www.freewebs.com/neo-terra
Re: Programming help (part 2)
Ok then I've sorted that. So I have a different one to do thats alot more harder then anything I've had to do, it's like a console game. (Based on that Pass the Pigs game)

Program has to ask for a number of players, and based on that number play a 10 round game of Pass the Pigs. For example:

How many people would like to play? 2
Thank you. Let's starting playing Pass the Pigs

Round 1
--------

  Player 1
  --------
  Pink  Razorback  --->  Razorback  Current score this round = 5
  Do you want to roll the pigs again (Y/n) n

  Player 2
  --------
  Pink  Dot  --->  Pig Out!  No score for this round

  Current Scores after round 1
  ------------------------------
  Player 1 = 5
  Player 2 = 0

Round 2
--------

  Player 1
  --------
  Leaning Jowler  Pink  --->  Leaning Jowler  Current score this round = 15
  Do you want to roll the pigs again (Y/n) n

  Player 2
  --------
  Pink  Pink  --->  Sider  Current score this round = 1
  Do you want to roll the pigs again (Y/n) y
  Razorback  Pink  --->  Razorback  Current score this round = 6
  Do you want to roll the pigs again (Y/n) y
  Pink  Razorback  --->  Razorback  Current score this round = 11
  Do you want to roll the pigs again (Y/n) y
  Dot  Leaning Jowler  --->  Leaning Jowler  Current score this round = 26
  Do you want to roll the pigs again (Y/n) n

  Current Scores after round 2
  ------------------------------
  Player 1 = 20
  Player 2 = 26

======

There's different points awarded for the random moves:

Razorback = 5 points
Trooter = 5 points
Snouter = 10 points
Leaning Jouwler = 15 points

etc


I'm going to start work on this now to learn it, but any help you can give me would be great :).
Freespace 2: Neo-Terra - My Freespace 2 website that holds my completed FS2 campaigns.

Darkness Rising - Current campaign I'm working on.

Mission Designer for the Wing Commander Saga.

CURRENT PROJECT: Darkness Rising, WCS
COMPLETED PROJECTS: Neo-Terra, Unification Prequel, Solar Wars Chapter 1, Deep Blood, Return to Neo-Terra (Part 1).

 

Offline FireCrack

  • 210
  • meh...
Re: Programming help (part 2)
^i dont raly understand this game...
actualy, mabye not.
"When ink and pen in hands of men Inscribe your form, bipedal P They draw an altar on which God has slaughtered all stability, no eyes could ever soak in all the places you anoint, and yet to see you all at once we only need the point. Flirting with infinity, your geometric progeny that fit inside you oh so tight with triangles that feel so right."
3.141592653589793238462643383279502884197169399375105820974944 59230781640628620899862803482534211706...
"Your ever-constant homily says flaw is discipline, the patron saint of imperfection frees us from our sin. And if our transcendental lift shall find a final floor, then Man will know the death of God where wonder was before."

 

Offline Gai Daigoji

  • Gekigangar!
  • 28
    • http://www.freewebs.com/neo-terra
Re: Programming help (part 2)
There's a GUI version here: http://www.fontface.com/games/pigs

Thats the sort of thing am trying to create, only not a GUI version just a console version. But am not sure how to go about it =/
Freespace 2: Neo-Terra - My Freespace 2 website that holds my completed FS2 campaigns.

Darkness Rising - Current campaign I'm working on.

Mission Designer for the Wing Commander Saga.

CURRENT PROJECT: Darkness Rising, WCS
COMPLETED PROJECTS: Neo-Terra, Unification Prequel, Solar Wars Chapter 1, Deep Blood, Return to Neo-Terra (Part 1).

 

Offline FireCrack

  • 210
  • meh...
Re: Programming help (part 2)
Lemme see...

to start wiht you may wnat to impose a max amount of players, much easier

basicly, start with determining the number of players, you want to store that in a variable

Use a for loop to restrict the whole game to 10 rounds, and another to restrict each round to the number of players

generate random numbers for points the players get and store this info.
actualy, mabye not.
"When ink and pen in hands of men Inscribe your form, bipedal P They draw an altar on which God has slaughtered all stability, no eyes could ever soak in all the places you anoint, and yet to see you all at once we only need the point. Flirting with infinity, your geometric progeny that fit inside you oh so tight with triangles that feel so right."
3.141592653589793238462643383279502884197169399375105820974944 59230781640628620899862803482534211706...
"Your ever-constant homily says flaw is discipline, the patron saint of imperfection frees us from our sin. And if our transcendental lift shall find a final floor, then Man will know the death of God where wonder was before."

 

Offline Gai Daigoji

  • Gekigangar!
  • 28
    • http://www.freewebs.com/neo-terra
Re: Programming help (part 2)
That sounds about right, but I'm not sure how to do that. Like I said am only learning this stuff and been with it for less than two weeks >.<.
Freespace 2: Neo-Terra - My Freespace 2 website that holds my completed FS2 campaigns.

Darkness Rising - Current campaign I'm working on.

Mission Designer for the Wing Commander Saga.

CURRENT PROJECT: Darkness Rising, WCS
COMPLETED PROJECTS: Neo-Terra, Unification Prequel, Solar Wars Chapter 1, Deep Blood, Return to Neo-Terra (Part 1).

 

Offline FireCrack

  • 210
  • meh...
Re: Programming help (part 2)
Okay, just didnt want to throw evereything at you too fast...

I dont know C# so i cant help you with the syntax but you basicly want (pseudo-code)
Code: [Select]
var int numplayers
var int scores[16]  //This is for an array with 16 int variables in it, dont know how C# does it...

input(numplayers);

for(r=0;r<10;r++) //keep doing this 10 times for 10 rounds
{
    for(p=0;p<numplayers; p++) // go once for each player...
    {
        //prompt for roll or pass here
        if(roll)
        {
            //generate random number, 0-1 here
            If ( number < 0.5 ) // if our number is less than .5, so 50% of the time
            {
                //Do text "pig out" here
            }
            else if( number < 0.75) //if our numner isn't less than 0.5 but is less than .25 (25% of the time)
            {
                  score[p]+=5 //give the current player 5 points
                  //do text for "score 5 points whatever here"
            }
            else if( number <.9) // 15% of the time
            {
                 score[p]+=10 // 10 points, say stuff too
            }
             //...

        }
    }
}
that's everything but the "winning" or it should be providing i didnt muff somthing...

And also that's only for one pig, you should be able to figure out the second youself
« Last Edit: November 23, 2005, 04:08:25 pm by FireCrack »
actualy, mabye not.
"When ink and pen in hands of men Inscribe your form, bipedal P They draw an altar on which God has slaughtered all stability, no eyes could ever soak in all the places you anoint, and yet to see you all at once we only need the point. Flirting with infinity, your geometric progeny that fit inside you oh so tight with triangles that feel so right."
3.141592653589793238462643383279502884197169399375105820974944 59230781640628620899862803482534211706...
"Your ever-constant homily says flaw is discipline, the patron saint of imperfection frees us from our sin. And if our transcendental lift shall find a final floor, then Man will know the death of God where wonder was before."

 

Offline Gai Daigoji

  • Gekigangar!
  • 28
    • http://www.freewebs.com/neo-terra
Re: Programming help (part 2)
Thanks. I'll have a go at this tomorrow. Also the variables are pretty much the same, things like int, double, string etc.
Freespace 2: Neo-Terra - My Freespace 2 website that holds my completed FS2 campaigns.

Darkness Rising - Current campaign I'm working on.

Mission Designer for the Wing Commander Saga.

CURRENT PROJECT: Darkness Rising, WCS
COMPLETED PROJECTS: Neo-Terra, Unification Prequel, Solar Wars Chapter 1, Deep Blood, Return to Neo-Terra (Part 1).