Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding > Coding Tutorials
You last visited: Today at 13:33

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Guide] Assignments to help learn C#

Discussion on [Guide] Assignments to help learn C# within the Coding Tutorials forum part of the General Coding category.

Reply
 
Old   #1
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
[Guide] Assignments to help learn C#

Ok so due to a request in the Co2 programing section, I decided to post some really simple programs people can try to code as ways to teach themselves C# and test out new concepts. Note: I'll try to rank them by difficulty but A: it's been forever since I saw the writeup for these programs and B: I everyone finds different things more/less complicated. I'll also link off to some good resources for people to look at.

C# Resources!

GREAT video tutorials in C# that hybrid made a while back


Some ones I wrote up explaining how to relate basic programing principles to Conquer pserver development. Not as useful to most people as it's not as generic.


Some really nice C# tuts (Note: I haven't read most of them but I saw a few and they looked very useful)


C# For dummies PDF file.



Ok so now you know some basics of C# and are thinking "what now!". Chances are you aren't at a level where you can code something super difficult but it's always good to have some goals set for yourself. Here's some simple ideas for programs you can make to test out your new skills.

Sample Program Suggestions:

Make a program to ask the user some questions. Store these variables and return them later

EG: Ask the user for their first name, last name, then return a string along the lines of "Hi: First Name, Last Name. How are you today?"


Make a program that asks the users to enter one number at a time. Take these numbers and store them and when the user is finished entering numbers, take the average of them.

Hint: I'd suggest an array to store numbers. For added complexity, check user input for validity, handle any exceptions with nice user friendly comments and such.


Make a program that accepts user input and then saves it to a file (name of their choosing)

For added challenge, check if the file name is already existing, then ask if the user wants to overwrite it, add to it or use a different file name.


Make a program that asks the user to enter a username and password. Check to see if it already exists in a text file. If so check if the user/pass match and print out a msg. If not ask if they wish to create the new account (if so, add to the accounts text file)


Make a program that does a similar thing using sql databases!


Mini Projects:

Game of Nim:
Simple marble game where you can take up to half the current stack of marbles and no more. You play vs a computer and the person who leaves 1 marble left loses.

Rules for program:


User enters number of marbles for round (between 10-100) (check for validity)
50/50 chance that computer will play "smart" or dumb.
50/50 chance that player goes first
Player and computer will alternate between turns (player entering a number of marbles to take. Check for validity and that it is < 1/2 current marbles). Check win conditions.

If computer is playing smart then you will want to follow a few rules (I think it was something like square root of current marbles -1 or something like that... look it up on google). If computer is not playing smart then have it chose a random valid number of marbles to take. Printing out the choice it made and the remaining marbles obviously.

On round end, print out who won and ask if the user wishes to play another round. If not, close the program.


Population simulator

Ok... I'm very forgetful on the details for this program... it was the first thing I ever had to code for some damn class (which I dropped after seeing the second assignment lol!) so bear with me..


On program start, the user will be prompted for a number of things.

Initial population:
Maximum population:
Years to simulate:
Death rate (0-100):
Birth Rate (0-100):

You will now run a simulation through the number of years entered printing out the result for every year.

Note: All initial population is considered to be Adults.

Each year the following things should happen in your program.

Adults give birth (to babies) X the birth rate
Adults die X the death rate

Babies grow into youth
Youth grow into adults

Population is checked VS max population. If this happens, the population is cut in half (no decimals) and a msg is printed out during the yearly report.

Population is checked to ensure that it is > 0.

Deaths are rounded UP (you can't have a partial death)
Births are truncated DOWN (you can't have a partial birth)


When the years are up you should print out the final results and ask the user if they wish to start a new simulation at which point the program starts from the beginning.

(yes... this was the first program they ever tried to get me to write when I'd never even used the language before... I was less than impressed)


Image Manipulator

Ok so this is the point where I switched classes so I'm again, rough on the details...

Basically you want to write a program that will manipulate a png photograph to find outlines of objects.

To do this you will want to load in the data from the photograph using a binary reader and examine each pixel (they are stored as values in the photo, try opening a png with notepad and you will see what I mean).

You want to use the header information to grab the width/height of the photograph and then the remaining information to create a proper database storing information in your program. You then want to compare each pixel in the photograph to each one around it (checking for edges of course). You will then round each pixel either to 0 or 255 (full black or full white) [note... this was intended to be run on black and white photographs...]. Once finished, save the new file to a new .png and examine results.

This is a basic version of the program, there was alot more needing to be done in the actual version but you can use this type of thing for all sorts of image manipulation/checking *cough* Dmaps in conquer converted to png are a great way to run checks to see if the target coords are valid.



So yah... I'll try to think of some more sample projects people may want to try to teach themselves coding and I'll also try to add in a few more helpful links to fill this out some. If anyone can think of any, just lemme know and I'll add them to the list (credit given of course). Hopefully this will help a few people who are actually trying to learn some coding but if not, try to enjoy ^^

Pro4Never
pro4never is offline  
Thanks
15 Users
Old 06/23/2010, 06:00   #2
 
Arcо's Avatar
 
elite*gold: 0
Join Date: Oct 2009
Posts: 8,783
Received Thanks: 5,304
Very nice little thing you got going here chris.
Blunt and right to the point.
Arcо is offline  
Old 06/24/2010, 01:38   #3
 
hunterman01's Avatar
 
elite*gold: 20
Join Date: Dec 2006
Posts: 945
Received Thanks: 175
Thanks buddy this is really nice. Gives me something to do.
hunterman01 is offline  
Old 06/26/2010, 20:53   #4
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,226
Received Thanks: 868
The first ex I made in 10 minutes...

Make 2 labels
- First name
- Last name
2 buttons
- Submit
- Exit
2 textboxes

add this code
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        // vars
        public string FirstName = "";
        public string LastName = "";


        private void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("Please fill out the form", "TestProg");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != (""))
            {
                if (textBox2.Text != (""))
                {
                    FirstName = (textBox1.Text);
                    LastName = (textBox2.Text);
                    MessageBox.Show("Hello " + FirstName + ". Your last name is " + LastName + ". What a lovley day it is!", "Hello " + FirstName);
                    Reset();
                }
                else
                {
                    MessageBox.Show("Error: You cannot leave your last name empty", "Error!");
                }
            }
            else
            {
                MessageBox.Show("Error: You cannot leave your first name empty", "Error!");
            }
        }
        public void Reset()
        {
            FirstName = "";
            LastName = "";
            textBox1.Text = ("");
            textBox2.Text = ("");
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
so **** simple you could also do
MessageBox.Show("Hello {0} Your last name is {1}",FirstName,LastName); <-- along those lines
_DreadNought_ is offline  
Old 06/27/2010, 04:43   #5
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Oohhh windows forms.


I'm a huge fan of consoles personally but nice example for people.
pro4never is offline  
Old 06/27/2010, 18:27   #6
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,226
Received Thanks: 868
Not to keen on console's but I made this is under 5 minutes without reciving an error once ( type or mistake ) so I think I did pretty good
Code:
//vars
            string Firstname = "";
            string Lastname = "";

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Hello sir, what is your first name ?");
            Console.ForegroundColor = ConsoleColor.Blue;
            Firstname = Console.ReadLine();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("What is your last name then {0}?", Firstname);
            Console.ForegroundColor = ConsoleColor.Blue;
            Lastname = Console.ReadLine();
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Nice to meet you {0} {1} what a nice day it is", Firstname, Lastname);
            Console.ReadLine();
edit: spend another 10 minutes made it more better / advanced here the script
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        //vars
        public static string Firstname = "";
        public static string Lastname = "";
        public static string ConsoleFName = "";
        public static string ConsoleLName = "";
        public static string NwhyR = "";

        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Hello sir, what is your first name ?");
            Console.ForegroundColor = ConsoleColor.Blue;
            Firstname = Console.ReadLine();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("What is your last name then {0}?", Firstname);
            Console.ForegroundColor = ConsoleColor.Blue;
            Lastname = Console.ReadLine();
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Nice to meet you {0} {1} would you like to know my name?", Firstname, Lastname);
            Console.WriteLine("************ Y = Yes, N = No ************");
            Commands(Console.ReadLine());
        }
        public static void Commands(string command)
        {
            try
            {
                string[] data = command.Split(' ');
                switch (data[0])
                {
                    case "Y":
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("Well, Guess what!, your going to name");
                            Console.WriteLine("Please type in my first name {0}", Firstname);
                            Console.ForegroundColor = ConsoleColor.Blue;
                            ConsoleFName = Console.ReadLine();
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("Please type in my last name {0}", Firstname);
                            Console.ForegroundColor = ConsoleColor.Blue;
                            ConsoleLName = Console.ReadLine();
                            Console.ForegroundColor = ConsoleColor.Magenta;
                            Console.WriteLine("My name is now {0} {1} thanks for the awesome name {2}", ConsoleFName, ConsoleLName, Firstname);
                            Console.WriteLine("Press enter to exit.");
                            Console.ReadLine();
                        }
                        break;

                    case "N":
                        {
                            Console.WriteLine("Please tell my why ?");
                            NwhyR = Console.ReadLine();
                            Console.ForegroundColor = ConsoleColor.Magenta;
                            Console.WriteLine("What! and you thing *{0}* is a good enough reason??, Screw you {1} {2}", NwhyR, Firstname, Lastname);
                            Console.WriteLine("Press enter to exit.");
                            Console.ReadLine();
                        }
                        break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}
Thanks would be nice -_-
_DreadNought_ is offline  
Thanks
1 User
Old 07/04/2010, 23:12   #7
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,338
Received Thanks: 490
why ?
~Yuki~ is offline  
Old 07/10/2010, 08:01   #8
 
Jay Niize's Avatar
 
elite*gold: 0
Join Date: Oct 2009
Posts: 4,851
Received Thanks: 3,417
#Added to List

Very nice tut!!!
Jay Niize is offline  
Old 08/03/2010, 16:39   #9
 
_Emme_'s Avatar
 
elite*gold: 1142
Join Date: Aug 2006
Posts: 2,464
Received Thanks: 1,162
@Elim


Quote:
class Program
{
static void Main(string[] args)
{
Console.Clear();
SetColor(ConsoleColor.White);
Console.WriteLine("Hello, can I please have your full name?");
Console.Write("Name: ");
string[] fullname = Console.ReadLine().Split(' ');
if (fullname.Length < 2)
Main(new string[2]);
goto AskForName;
AskForName:
Console.WriteLine("Mr/Mrs. {0}, would you like to know my name? Y/N", fullname[fullname.Length - 1]);

ConsoleKeyInfo keyInfo = Console.ReadKey();
Console.WriteLine();
if (keyInfo.Key == ConsoleKey.Y)
Console.WriteLine("My name is 'test'. Goodbye {0}", fullname[0]);
else if (keyInfo.Key == ConsoleKey.N)
Console.WriteLine("Alright {0}, see ya later!", fullname[0]);
else
goto AskForName;

Console.ReadLine();


}
static void SetColor(ConsoleColor color)
{ Console.ForegroundColor = color; }
}
_Emme_ is offline  
Thanks
1 User
Old 09/01/2010, 16:48   #10
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,226
Received Thanks: 868
Didn't think of that ^ +k
_DreadNought_ is offline  
Old 09/04/2010, 01:26   #11




 
ShapyShape's Avatar
 
elite*gold: 192
The Black Market: 394/0/0
Join Date: Aug 2010
Posts: 3,677
Received Thanks: 513
Fine.. - very nice tutorial..
ShapyShape is offline  
Old 09/21/2010, 06:36   #12
 
rhinostopper's Avatar
 
elite*gold: 0
Join Date: Jul 2007
Posts: 51
Received Thanks: 1
thanks, helped alot and will be my main guide to this for now. =)
rhinostopper is offline  
Reply


Similar Threads Similar Threads
[GUIDE]To all who want learn about edit shop dat and item dat using hexedit
11/30/2009 - EO PServer Guides & Releases - 3 Replies
So i got some pm from peoples that need guides on how to use hexedit to edit shop dat and itemtype dat.. so i will give some link that you all can use http://www.elitepvpers.com/forum/eo-pserver-hostin g/189204-guide-hexedit-shopping-mall-replace-items -equipment-eggs.html http://www.elitepvpers.com/forum/eo-pserver-hostin g/345275-release-itemtype-editor.html http://www.elitepvpers.com/forum/eo-pserver-hostin g/352209-release-shop-dat-editor.html...
[request]guide how to learn to code
10/03/2008 - CO2 Private Server - 6 Replies
hey all does anyone has a guide to learn how to code cause i'm sick of waiting till someone releases a good source or some new releases + i wanna release new things to and make unique things for pservers if someone has a guide to learn how to code stuff for conquer only pls post it that would be awesome greetz jochemke
What do YOU want to learn?
10/02/2008 - Conquer Online 2 - 19 Replies
Hey guys, Im just wondering what you guys are wanting to learn about programming. Im wanting to write a tutorial on something, I just dont know what people are interested in. Some questions in which I would like you to answer if you are interested are: What language would you like to learn?
TO LEARN!!!!!!
05/09/2008 - GunZ - 14 Replies
Heya everyone as you can tell im new to these forums, but i am willing and wanting to learn how to hack gunz (ijji). There are a few things i need to be cleared up, why is that in all these "how to" guides, once you finish editing the system.mrs it either gets updated through your gunz launcher or when you inject a "".dll you get error messages, booted from the game or the game just doesnt load after the gameguard screen? Id also like to know how i can go about fixing this problem and wether or...
i want to learn
04/16/2007 - General Coding - 23 Replies
hi allz,i want to start making trainers,hacks,ect...... but irst i want to know how to do it,what i need and like this,please give me some advice,no flaming sonybaci



All times are GMT +1. The time now is 13:34.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.