Form1.cs:
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;
using Timer = System.Timers.Timer;
namespace Typer
{
public partial class Form1 : Form
{
const int INTERVAL = 2000;
Timer timer = new Timer();
int index = 0;
int counter = 0;
private Font font = new Font("Arial", 30f);
public int Bodovi = 0;
int indikator = 1;
public Form1()
{
InitializeComponent();
timer.Enabled = true;
timer.Interval = 40;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
}
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
foreach (Znak znak in Znak.Znakovi)
{
znak.Move();
}
counter += (int)timer.Interval;
if (counter >= INTERVAL)
{
Znak.Znakovi[index].Alive = true;
index++;
counter = 0;
index = index % 10;
}
if (Bodovi > indikator * 100)
{
Znak.Speed += 1;
indikator++;
}
Invalidate();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
foreach (Znak znak in Znak.Znakovi)
{
znak.Draw(e.Graphics);
}
e.Graphics.DrawString(Bodovi.ToString(), font, Brushes.Green, Point.Empty);
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
Znak znak = new Znak(this);
}
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
foreach (Znak znak in Znak.Znakovi)
{
if (znak.Character == e.KeyChar)
{
znak.Initialize();
Bodovi += 10;
}
}
}
}
}
Znak.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Typer
{
class Znak
{
private static List<Znak> znakovi;
private Point position;
private static int speed = 1;
private Font font = new Font("Arial", 30f);
private char character;
private bool alive;
private static Random random;
private Form1 forma;
public static int Speed
{
get { return speed; }
set { speed = value; }
}
public static List<Znak> Znakovi
{
get
{
return znakovi;
}
}
public char Character
{
get { return character; }
}
public bool Alive
{
get { return alive; }
set { alive = value; }
}
public void Move()
{
if (alive)
{
position.Y += speed;
if (position.Y > forma.Height)
{
Initialize();
forma.Bodovi -= 20;
}
}
}
public void Initialize()
{
character = OdaberiZnak();
position = new Point(random.Next(0, forma.Width - 40), -50);
}
private char OdaberiZnak()
{
int start = (int)'a';
int end = (int)'z';
int poz = random.Next(start, end + 1);
return (char)poz;
}
public void Draw(Graphics g)
{
g.DrawString(character.ToString(), font, Brushes.White, position);
}
static Znak()
{
znakovi = new List<Znak>();
random = new Random();
}
public Znak(Form1 form)
{
znakovi.Add(this);//dodajemo objekt u listu
forma = form;
Initialize();
}
}
}
[Ovu poruku je menjao negative7 dana 23.05.2010. u 23:56 GMT+1]