|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
|||||
|
|||||
|
Re: Teach Genia How to Program and Win a Prize
Quote:
![]() |
|
#17
|
|||||
|
|||||
|
Re: Teach Genia How to Program and Win a Prize
Yeah, so I'm not a comp sci major anymore, but indeed I was once, many moons ago. I thought I liked technology... I later realized I just loved language in general. However...
I bought this book when I was a senior in high school. It never left my desk at home during that year, and early into college. For just beginning, especially with if/then statements and such, this is an excellent reference. That, or go to a local college's bookstore (in Genia's case, Purdue) and look for the CS courses. Look for low numbered classes, like 101, 102, etc., and look at the books that are required for the class. These are often really good books to look at (and, instead of buying it, you may be able to get some for really cheap on Amazon or from the local library). |
|
#18
|
|||||
|
|||||
|
Re: Teach Genia How to Program and Win a Prize
Quote:
Some of the words I've created Wrecktangle, Wreckedtangle, Advntrr, Xplrr, Byse, UhHuh, UhUh .... and that is just for my greeter. |
|
#19
|
|||||
|
|||||
|
Re: Teach Genia How to Program and Win a Prize
Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace First_Project
{
public class WinForm : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
public System.Windows.Forms.Label lblChalkboard;
public System.Windows.Forms.Button btnLearn;
public System.Windows.Forms.Button btnDontLearn;
public WinForm()
{
InitializeComponent();
}
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.lblChalkboard = new System.Windows.Forms.Label();
this.btnLearn = new System.Windows.Forms.Button();
this.btnDontLearn = new System.Windows.Forms.Button();
this.SuspendLayout();
this.lblChalkboard.Location = new System.Drawing.Point(32, 88);
this.lblChalkboard.Name = "lblChalkboard";
this.lblChalkboard.Size = new System.Drawing.Size(240, 48);
this.lblChalkboard.TabIndex = 0;
this.lblChalkboard.Text = "Do you want to learn?";
this.btnLearn.Location = new System.Drawing.Point(32, 176);
this.btnLearn.Name = "btnLearn";
this.btnLearn.Size = new System.Drawing.Size(72, 24);
this.btnLearn.TabIndex = 1;
this.btnLearn.Text = "Learn";
this.btnLearn.Click += new System.EventHandler(this.btnLearn_Click);
this.btnDontLearn.Location = new System.Drawing.Point(128, 176);
this.btnDontLearn.Name = "btnDontLearn";
this.btnDontLearn.Size = new System.Drawing.Size(80, 24);
this.btnDontLearn.TabIndex = 2;
this.btnDontLearn.Text = "Dont Learn";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.btnDontLearn);
this.Controls.Add(this.btnLearn);
this.Controls.Add(this.lblChalkboard);
this.Name = "WinForm";
this.Text = "Teach Genia OOP C#";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new WinForm());
}
private void btnLearn_Click(object sender, System.EventArgs e)
{
lblChalkboard.Text = "I'm not a good teacher, go search on google :P";
}
private void btnDontLearn_Click(object sender, System.EventArgs e)
{
lblChalkboard.Text = "Yeah... that was probably a safe bet, huh.";
}
}
}
EDIT: It's .Text not .text, like I said, I started today. EDIT 2: This wasn't meant to be taken serious, I highly don't recommend learning C# as your beginning language, however I just found my old PHP tutorials so I'll post those. Last edited by Mike : 23-02-2005 at 17:40. |
|
#20
|
||||
|
||||
|
Re: Teach Genia How to Program and Win a Prize
Quote:
Code:
#define true 1
#define false 0
#define Genia 461
unsigned char passesLegendOfMaxOnHeavy(int person) {
if (person==Genia) {
return true;
} else {
return false;
}
}
if(passesLegendOfMaxOnHeavy(Genia)) {
awesome=1;
} else {
triesAgain=1;
}
Code:
#define dlavery 116 #define JVN 229 *removes nerd hat* I'm such a dork... Nonetheless, awesome, Genia. You might just be a CS major in training, if you're willing to trade in your social life. ![]() |
|
#21
|
|||||
|
|||||
|
Re: Teach Genia How to Program and Win a Prize
What is this, social life you speak of?
I'm pretty sure you define it in a different way, you crazy programmer >_< |
|
#22
|
|||||
|
|||||
|
Re: Teach Genia How to Program and Win a Prize
Here's some old PHP tutorials I wrote a while back, finally found them.
PHP Tutorials PHP Tutorial Lesson 1 Introduction: Hopefully by the end of these tutorials you will have enough knowledge to make your own web-based games. However there are alot of things you'll need to cover by yourself. I have also made this tutorial so that you won't need any fancy "Make a website in 24 hour" software. Dreamweaver is not needed. I recommend Crimson Editor. I will be making reference to it throughout the tutorials. Lesson 1 will be about Proper Coding. Proper Coding Of all the most annoying things I could single out easily one MAJOR problem among beginning and expert coders alike. The code layout, the code may work fine but it is hell on the eyes and if/when you come back to it in a while it will be very hard to understand. You should always write your code so that it is easily readable in case you get it wrong the first try, also if you were ever to hire a new coder this will make their job ALOT easier. Here are the basic principle elements * User Friendlyness * Legibility * Finding Errors User Friendlyness: The way your scripts operate should be easy to understand without any confusing functions. A user may try to make a username such as Mike's Account, your program should be able to catch the ' and tell the user that it is an illegal character (because of the security risk it poses, you will learn about this later on). Now instead of automatically replacing the ' with say, a space, your script should notify the user that a ' is an illegal character. Following these guidlines will also help you keep down the need for support. Error messages should also be user friendly, you can get some pretty gruesome error messages that will confuse your users, with some simple error handling you can display a user friendly error and possibly give some links to notify your technical staff. Legibility: Your code should be readable, heres an example of some bad code Code:
<?php
$the_password_that_the_guy_used = $_POST['password'];
if($the_password_that_the_guy_used == "password"){
$afdafdsaf = "welcome";
}else{
$afdafdsaf = "your not him!";
}
echo $afdafdsaf;
?>
Code:
<?php
$password = $_POST['password'];
if($password == "password"){
$message = "welcome";
}else{
$message = "your not him!";
}
echo $message;
?>
99.9% of your errors will come in this form What I usually do in this situation is copy the problem part, google it, and read some answers to other peoples problems. If it is relevant to my problem then usually it fixes it, however if that doesn't work then I will open up my code in Crimson Editor and find the error line. One thing to remember about PHP is that it doesn't say what line the error is on but what line the page crashed on. For example if my bike got a flat tire at yard 10 and I hit a tree at yard 30 PHP would say that the error was on yard 30. Get it? Good. Conclusion: To wrap up the first part of my tutorial, i'd like to give some good php sites. Help Sites PHPFreaks Site PHPFreaks Forums PHP Enabled Free Hosting Hostultra Spunge *Recommended!* Next Tutorial: My next tutorial will cover variables and if/then statements. We will write some basic code to allow very simple user login. Note: If you have anything to contribute feel free to PM or email me |
|
#23
|
|||||
|
|||||
|
Re: Teach Genia How to Program and Win a Prize
PHP Tutorial Lesson 2
Introduction: During this tutorial I will teach you: 1. Using Variables 2. Comparing 3. If / Thens 4. POST / GET By the end you should be able to make a simple user login form. Some Stuff You Need To Know (Basic) * <?php -Starts the php * ?> -Ends the php * Anything after a // is a comment and will not be shown on runtime * All lines should end in a semi-colon ( Except for If/Thens and Comments* Echo outputs text to the browser * Brackets ({ and }) let the code know that the if/then has started/finished Using Variables: Variables are objects that hold a chunk of information for you to use later on. Variables are always started with a dollar sign ($) and can have anything after that ($name, $password, etc.) One important thing to remember is that variables ARE case sensitive! A variable such as $name is different then a variable called $Name. An important thing to remember is that variables must start with either a letter or underscore (_). A variable name such as $1stGuy is invalid, however $_1stGuy is able to be used. Displaying variables with other strings is something unique to php, lets see this code for example. Code:
<?php
$name = "Mike";
echo $name; //puts out Mike
echo "My name is $name"; //puts out My name is Mike
echo 'My name is $name'; //puts out My name is $name
?>
One important thing to remember about PHP is it's way of comparing and setting variables. If you look in the code above you'll see that I used Code:
$name = "Mike"; Code:
<?php
$name = "Mike";
if($name == "Mike"){
echo "Your name is Mike!";
}
?>
If / Then As you have seen before i've been using many if(... statements. These are fairly easy to comprehend and are in this format This is very usefull for creating a hard coded login and is essential if you ever plan on coding anything. POST / GET NOTE: Some HTML knowledge is required for this section. POST and GET are two different ways of transfering information from one page to another. Here is our HTML form for POST on a page that I will call login.html Code:
<HTML> <BODY> <FORM ACTION = "login.php" METHOD = "POST"> <INPUT TYPE = "text" NAME = "name"> <BR> <INPUT TYPE = "password" NAME = "password"> <BR> <INPUT TYPE = "submit" VALUE = "Login!"> </FORM> </BODY> </HTML> Code:
<?php
$name = $_POST['name'];
$password = $_POST['password'];
if($name == "Mike" && $password = "Password"){
echo "Welcome!";
}else{
echo "Invalid Login!";
}
?>
Code:
<HTML> <BODY> <FORM ACTION = "login.php" METHOD = "GET"> <INPUT TYPE = "text" NAME = "name"> <BR> <INPUT TYPE = "password" NAME = "password"> <BR> <INPUT TYPE = "submit" VALUE = "Login!"> </FORM> </BODY> </HTML> Code:
<?php
$name = $_GET['name'];
$password = $_GET['password'];
if($name == "Mike" && $password = "Password"){
echo "Welcome!";
}else{
echo "Invalid Login!";
}
?>
http://www.server.com/login.php?nam...ssword=Password However if I was using POST it would just show http://www.server.com/login.php GET is good if you want something that can be bookmarked, etc. Conclusion: Hopefully you understand what this code does and how it does it. Copying and pasting will get you no where. You must understand what it is doing, try experimenting. See what you can do with this simple snippet, the possibilities are endless. Next Tutorial: Possibly writing to a file, and opening from a file. Maybe a multiple user login via txt files, possibly a quotes system? |
|
#24
|
|||||
|
|||||
|
Re: Teach Genia How to Program and Win a Prize
PHP Tutorials Lesson 3
Introduction: In this tutorial you will learn 1. Arrays 2. File Functions 3. Randomizing 4. Putting It Together By the end you should be able to display random quotes, combine this with the previous tutorials and you should be able to make a form which adds a quote to a text file which then displays a random quote from that file. Arrays: An array is basically a list of something, that is numbered. This would be an array called dogs. Dogs: 0. Golden Retriever 1. Rottweiler 2. Labrador Retriever Notice that it starts at zero? In pretty much all languages arrays start at zero. In php this would be Code:
$dog = array("Golden Retriever", "Rottweiler", "Labrador Retriever");
//Now to display it we would use $dog[index] like so
echo $dog[0]; //shows Golden Retriever
echo $dog[1]; //shows Rottweiler
echo $dog[2]; //shows Labrador Retriever
There is also another kind of array, say you don't want to remember what number it is, instead remember a keyword. This will also come in useful when you start in mysql. Code:
$dog = array(
"Golden Retriever" => "Sammy",
"Rottweiler" => "Spot",
"Labrador Retriever" => "Snickers",
);
echo "My Golden Retrievers name is $dog['Golden Retriever'], my Rottweilers name is $dog['Rottweiler'], and my Labrador Retrievers name is $dog['Labrador Retriever']";
//that will show My Golden Retrievers name is Sammy, my Rottweilers name is Spot, and my Labrador Retrievers name is Snickers.
Code:
$dog = array(
"Golden Retriever" => array("Sammy", "Fast"),
"Rottweiler" => array("Spot", "Lazy"),
"Labrador Retriever" => array("Snickers", "Slow"),
);
echo "My Golden Retriever's name is $dog['Golden Retriever'][0] and is $dog['Golden Retriever'][1], my Rottweiler's name is $dog['Rottweiler'][0] and is $dog['Rottweiler'][1], my Labrador Retriever's name is $dog['Labrador Retriever'][0] and is $dog['Labrador Retriever'][1].;
//That will show My Golden Retriever's name is Sammy and is Fast, my Rottweiler's name is Spot and is Lazy, my Labrador Retriever's name is Snickers and is Slow.
File Functions: For this part we will use the following functions * File * Fopen * Fwrite * Fclose File: What file does is open up a file and put the info into an array seperated by each line. Lets take a look at this code Code:
$quotes = file("quotes.txt");
File is automatically doing this Code:
$file = array("This is a quote", "This is another quote", "Quote 3");
file(page); NOTE: You do not need to use fopen when using file Fopen: As you may guess, this function opens a file for appending, writing, etc. The format is $variable = fopen(page, mode); $variable is because when you use other functions to write to it, etc, you have to reference back to the fopen. $variable is your reference point. Page is just what it says, the page you want to open. Mode is what you want to do with it, here are the modes that you need to know right now Fwrite: This writes to the file, obviously :. The syntax isfwrite(variable, "what_you_want_to_write"); Remember I said you needed a variable in Fopen? That will be used here to tell the server what file to write too. Depending on your mode in Fopen it will either append, read, read/write, etc. Fclose: Fclose does just that, close the file to prevent corruption. Syntax is fclose(variable); Yet again using that reference point that I told you about when using fopen. Randomizing: For this part we will use the following functions * Count * Rand Count: Count counts the amount of things in a variable, if you want it to count the number of items in an array you could use a code like this Code:
$dogs = array("Golden Retriever", "Rottweiler", "Labrador Retriever");
$count = count($dogs);
echo $count;
//will display 3
count(item); Rand: Produces a random number between a given maximum and minimum integer, or a completely random number. Sample code: Code:
echo rand() . "\n"; //Could display something like 2042 echo echo rand(1, 10); //Could display something like 5 Putting It All Together To create our quotes system you first have to take your quotes and put them in an array Code:
$quotes = file("quotes.txt");
Code:
$quote = $quotes[rand(0, count($quotes) - 1)]; Code:
rand(0, count($quotes) - 1; So now your code is saying $quote = $quotes[random_number], just have it echo it and your done! Our full code is Code:
<?php
$quotes = file("quotes.txt");
$quote = $quotes[rand(0, count($quotes) - 1)];
echo $quote;
?>
Hopefully you understand everything i've said so far. Using the fwrite function you should be able to write to quotes.txt, however remember that after each one you have to have a line break. Happy coding ![]() |
|
#25
|
|||||
|
|||||
|
Re: Teach Genia How to Program and Win a Prize
PHP Tutorials Lesson 4
Note: The links to images have long since stopped working. Introduction: In this tutorial you will learn 1. Introduction to MySQL & phpMyAdmin 2. Connecting To Your Database 3. SQL Queries 4. Putting Information Into A Database 5. Extracting Information From A Database Introduction to MySQL & phpMyAdmin: MySQL: What is MySQL? Simply put, MySQL is a database system. SQL stands for Structured Query Language, which is exactly what it is: a language that queries information out of a database. MySQL is the most popular open source database because of it's speed and reliability. Most free hosts do NOT give you a MySQL database with their hosting package. Below is a list of the few that do. 1. Spunge 2. FreeSQL* 3. HomepageHost 4. HostRave * Is only a database host, does not host sites phpMyAdmin: What is phpMyAdmin? phpMyAdmin is a frontend to the MySQL server. It allows you to create, drop, and alter databases, run any line of SQL code, delete, edit, and add fields, and manage field keys. NOTE: I censored my pics since they are vital to a site I am making now... you can never be too safe Here is the welcome screen to phpMyAdmin Over on the left under "Home" it shows you Database Name Table 1 Table 2 Now you click on a table and you are immediately brought to the Structure page of it At the bottom you can see a textbox, this is where you can run your SQL statements. Above you can see the fields their type and their other info. The other pages that you can navigate to are shown at the top. For this tutorial I will be giving the most info on Browse and Structure pages. These are the most commonly used pages. Click on the browse tab and you are brought here Here you are shown the current contents of the table and you are given options to Edit it or Delete it. Although you cannot see it in this picture there is also a SQL textbox on the bottom. SQL: Just an SQL textbox. Select: Fancy options to extract data. Insert: Fancy options to insert data. Export: Back up your database. Operations: Move table, alter table, rename table, etc. Empty: Delete all info from the table Drop: Delete table. Connecting To Your Database: Includes: Before you begin with this you must learn about the include() function. What the include does is INCLUDE a file within your file, for example if I had a site where on every page at the top it said "abcdedfghijklmnopqrstuvwxyz012345679" now I don't want to keep typing that over and over again so what I would do is I would make a file called alphabet.php that echo'ed the text. Then at the top of every page I would put Code:
include("alphabet.php");
Connecting: To connect to your database you need 4 things. A username, password, host, and database name. With most sites you need to connect to your database on every page so you make an include file called connect.php, in that file you have the following code. Code:
<?php
mysql_connect("server", "username", "password") or die("Could not connect to server");
mysql_select_db("database_name") or die("Could not open database");
?>
SQL Queries: *: * in SQL means everything, so instead of using SELECT `field`, `field2`, `field3` FROM `table` WHERE `condition` = 'constraint'; You would do SELECT * FROM `table` WHERE `condition` = 'constraint'; %: % in SQL is a wildcard, say you wanted to find a user with a bad word in their profile, you would use SELECT `name` FROM `users` WHERE `profile` LIKE '%badword%'; Delete: This statement will delete that row of fields. The syntax is DELETE FROM `table` WHERE `field` = 'value'; So if you wanted to delete a user with id #1 the code would be DELETE FROM `users` WHERE `id` = '1'; Where: Say you wanted to make a users clicks go up by one, but you don't want everyones clicks to go up by one. You would use WHERE. First you would get some data that is unique to the user (id, name, etc) and use the code UPDATE `table` SET `clicks` = $clicks WHERE `id` = 1; Where $clicks is the amount of clicks the user currently has and 1 is the users ID. Don't worry about the UPDATE... that will be explained soon. Like: Like is somewhat like the WHERE query in the fact that it's a constraint. The syntax is SELECT * FROM `table` WHERE `field` LIKE '%constraint%'; For example, if you wanted to find all users with "mike" in their name you would use SELECT * FROM `users` WHERE `name` LIKE '%mike%'; Putting Info Into Your Database: Insert: The first method of doing this is the INSERT statement, the syntax of this is INSERT INTO `table` (field1, field2) VALUES ('data', 'data2'); Take notice that the order of field names corresponds with the order of info to be inserted. Update: UPDATE is used when you want to update existing data. The syntax is UPDATE `table` SET `field` = 'new data' WHERE `id` = 1; Now to use these you would have to find a way to run them, once connected to your server you would have the following code Code:
<?php
include("connect.php");
mysql_query("Your Query");
?>
Select: This is the only method of getting information out of the database, the syntax is like so SELECT `field` FROM `table` WHERE `condition` = 'constraint'; To put this to use you would have Code:
<?php
include("connect.php");
$name = mysql_query("SELECT `name` FROM `users` WHERE `id` = '1'");
echo $name;
?>
Code:
<?php
include("connect.php"); // connect to your server
$sql = mysql_query("SELECT * FROM `users` WHERE `id` = '1'"); // put our query in a variable
$user = mysql_fetch_array($sql); // get the info and put it in an array
/*
Lets assume for a minute that in the user table you have the fields name, id, and email
The name is Mike, the ID is 1, and the email is email@domain.com
*/
echo $user['name']; // will echo name
echo $user['id']; // will echo 1
echo $user['email']; // will echo email
?>
|
|
#26
|
|||||
|
|||||
|
Re: Teach Genia How to Program and Win a Prize
Hmm, some stuff got removed by the forums.
I'm going to start work on a C Tutorial Whitepaper, and a PHP Tutorial Whitepaper (Both based off these tutorials) |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|