Showing posts with label Visual C# Express. Show all posts
Showing posts with label Visual C# Express. Show all posts

Wednesday, April 23, 2008

Project 2: Swarm and Gravitate

In this program, I started learning the basic flow of the Windows Forms program. I did some event handling and some graphics, learned some more stuff that C# makes retarded easy (the List container, primarily), and did some really simple math (that took a little too long to figure out--it's been too long since I've taken math. Or physics.)

Swarm() calculates the center position of the collection of bodies and everybody accelerates towards that position. Gravitate() attracts the bodies to one another by (something resembling) gravity. This is all, of course, 2D.

Things I'd like to add:

  • Hitting tab to center on a body doesn't properly work. I need to fix that.
  • Once that works, I'd like to be able to double click on a position to center on that point.
  • There is no consequence of collisons--gravity simply turns off when the bodies are about to touch (to keep them both from rocketing off into space).
  • It'd be nice to put in a menu to add / delete planetary bodies.
  • It'd be nice to put in controls to drive around one of the planets.
If I can think of anything else to add, I'll add it. I'm planning on moving on to a simple game next. Don't think I'm going to mess with DirectX yet, think I'll do something hands-on and 2D before I start messing around with the XNA toolkit.

Here's the source file.

Friday, April 18, 2008

Project 1: Time Sheet Calculator

Okay, so this whole thing started the other day when I got sick of doing payroll. At my workplace, the staff members clock in and clock out with and old-fashioned time card system, once which prints the time on a piece of card stock. Every other Thursday, I have to go through every single card, calculate the shift times in my head, and then add them all up on my own. It's a tedious and pointless process. I could spend a couple hundred bucks to buy an electronic system that would make it automatic. That, OR--!!!

I downloaded Visual C# Express, since I heard every retard on the planet is using C# these days. I learned what I needed to know from the in-program documentation, and start to finish spent about 30 or 40 minutes. Here's what I ended up with:


It's ugly, right? But it gets the job done. I spend about 2 hours per payroll adding all that up--with this, I'll probably spend 15 minutes.

Here's the 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 PayrollMcGee
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void TotalLabel_Update()
{
TotalLabel.Text = ((dateTimePicker2.Value - dateTimePicker1.Value) +
(dateTimePicker4.Value - dateTimePicker3.Value) +
(dateTimePicker6.Value - dateTimePicker5.Value) +
(dateTimePicker8.Value - dateTimePicker7.Value) +
(dateTimePicker10.Value - dateTimePicker9.Value) +
(dateTimePicker12.Value - dateTimePicker11.Value) +
(dateTimePicker14.Value - dateTimePicker13.Value) +
(dateTimePicker16.Value - dateTimePicker15.Value) +
(dateTimePicker18.Value - dateTimePicker17.Value) +
(dateTimePicker20.Value - dateTimePicker19.Value) +
(dateTimePicker22.Value - dateTimePicker21.Value) +
(dateTimePicker24.Value - dateTimePicker23.Value) +
(dateTimePicker26.Value - dateTimePicker25.Value) +
(dateTimePicker28.Value - dateTimePicker27.Value)).ToString();
}

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
TotalLabel_Update();
}

private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
{
TotalLabel_Update();
}

...

private void dateTimePicker28_ValueChanged(object sender, EventArgs e)
{
TotalLabel_Update();
}
}
}

Tedious, right? Just like always. It's super ghett0, completely taped together, and probably looks like something somebody would do if they'd just discovered visual programming interfaces.

So, um, yeah. That's me.