2006 December 10, Vasárnap 17:18 oda is lehet kattintani :)

Egy "havazás" megvalósítása C#-ben

dátum 2006 December 10, Vasárnap 17:18 írta RoliSoft hozzászólások Nincs hozzászólás kategória Programozás


Google AdSense Reflection

Az előző bejegyzéstől kedvet kaptam hogy én is készítsek el egy hasonló szoftvert. Azonban kicsit bénára sikeredett, ezért csak snippetként raktároztam el.

Fícsörök:
- szállingózás jobbra-balra véletnelszerűen
- zuhanási sebesség változtatható
Ismert csótányok:
- nyomot hagy maga után
- lefagy ha földet ér grimasz

Form1.Designer.cs

namespace WindowsApplication4
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
 
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
 
#region Windows Form Designer generated code
 
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
this.numericUpDown3 = new System.Windows.Forms.NumericUpDown();
this.button2 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(169, 5);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = ""havazás"";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// timer1
//
this.timer1.Interval = 500;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(86, 31);
this.numericUpDown1.Maximum = new decimal(new int[] {
100000000,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(77, 20);
this.numericUpDown1.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 33);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(68, 13);
this.label1.TabIndex = 2;
this.label1.Text = "y koordináta:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 7);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(68, 13);
this.label2.TabIndex = 4;
this.label2.Text = "x koordináta:";
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(86, 5);
this.numericUpDown2.Maximum = new decimal(new int[] {
100000000,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(77, 20);
this.numericUpDown2.TabIndex = 3;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 59);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(55, 13);
this.label3.TabIndex = 6;
this.label3.Text = "sebesség:";
//
// numericUpDown3
//
this.numericUpDown3.Location = new System.Drawing.Point(86, 57);
this.numericUpDown3.Maximum = new decimal(new int[] {
100000000,
0,
0,
0});
this.numericUpDown3.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown3.Name = "numericUpDown3";
this.numericUpDown3.Size = new System.Drawing.Size(77, 20);
this.numericUpDown3.TabIndex = 5;
this.numericUpDown3.Value = new decimal(new int[] {
500,
0,
0,
0});
this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged);
//
// button2
//
this.button2.Location = new System.Drawing.Point(169, 31);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 7;
this.button2.Text = "nullázás";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(252, 82);
this.Controls.Add(this.button2);
this.Controls.Add(this.label3);
this.Controls.Add(this.numericUpDown3);
this.Controls.Add(this.label2);
this.Controls.Add(this.numericUpDown2);
this.Controls.Add(this.label1);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
 
}
 
#endregion
 
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.NumericUpDown numericUpDown3;
private System.Windows.Forms.Button button2;
}
}



Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
 
namespace WindowsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
 
[DllImport("user32")]
internal static extern IntPtr GetDC(IntPtr hwnd);
 
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
button1.Enabled = false;
}
 
private void hohullas(int x, int y)
{
IntPtr deskDC = GetDC(IntPtr.Zero);
Graphics g = Graphics.FromHdc(deskDC);
g.DrawImage(System.Drawing.Image.FromFile("ho.png"), y, x);
}
 
private void timer1_Tick(object sender, EventArgs e)
{
int szam = Convert.ToInt32(numericUpDown1.Value);
int szam2 = Convert.ToInt32(numericUpDown2.Value);
hohullas(szam, szam2);
numericUpDown1.Value = numericUpDown1.Value + 10;
Random random = new Random();
switch (random.Next(0, 2))
{
case 0:
numericUpDown2.Value = numericUpDown2.Value + 10;
break;
case 1:
numericUpDown2.Value = numericUpDown2.Value - 10;
break;
case 2:
numericUpDown2.Value = numericUpDown2.Value;
break;
}
}
 
private void Form1_Load(object sender, EventArgs e)
{
numericUpDown2.Value = Screen.PrimaryScreen.WorkingArea.Width / 2;
}
 
private void button2_Click(object sender, EventArgs e)
{
numericUpDown1.Value = 0;
numericUpDown2.Value = Screen.PrimaryScreen.WorkingArea.Width / 2;
timer1_Tick(sender, e);
}
 
private void numericUpDown3_ValueChanged(object sender, EventArgs e)
{
timer1.Interval = Convert.ToInt32(numericUpDown3.Value);
}
}
}



ho.png
ho.png

Lehet tesztelgetni, meg javítgatni. Kiadva az MIT licensz alatt...


Hozzászólások


Hozzászólások listázása növekvő vagy csökkenő sorrendben.



Szólj hozzá





5

BBKódok feldolgozása az üzenetben Grimaszok lecsérélése képekre

Statisztika

Ez a bejegyzés 108 hete, 2 napja, 5 órája és 4 perce született a programozás kategóriában, és pontosan a 22. itt a sandboxon.
Tartalmaz pontosan 8200 betűt szóközök nélkül, és 2991 szót.
Ebben a kategóriában még volt 73 hete, 4 napja, 22 órája és 27 perce egy olyan bejegyzésem hogy NumLock, CapsLock, és ScrollLock kapcsolgatása C#-ból, aztán 82 hete, 1 napja, 22 órája és 34 perce megfordult a fejemben az is hogy Fájl listázás jobb klikkre, de nem szabad megfeletkezni egy olyan bejegyzésről sem amit 92 hete, 1 napja, 4 órája és 1 perce írtam, és az a címe hogy Készíts oldaltérképet a honlapodnak! - II. - Lustáknak. De még sok más bejegyzés van ebben a kategóriában, például a 92 hete, 1 napja, 5 órája és 1 perce írt Készíts lépcsőzetes URL-t a honlapodnak! bejegyzés is ide tartozik!