Hard Light Productions Forums
Off-Topic Discussion => General Discussion => Topic started by: Gai Daigoji on November 21, 2005, 06:08:47 am
-
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 :)
-
//(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();
}
-
ruby-code, since this stuff's super easy in ruby ;)
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)
-
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 :).
-
^i dont raly understand this game...
-
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 =/
-
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.
-
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 >.<.
-
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)
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
-
Thanks. I'll have a go at this tomorrow. Also the variables are pretty much the same, things like int, double, string etc.