Skip to content

Instantly share code, notes, and snippets.

@NorbiPeti
Created March 2, 2016 13:24
Show Gist options
  • Save NorbiPeti/4fe9cecbb828f021ab7c to your computer and use it in GitHub Desktop.
Save NorbiPeti/4fe9cecbb828f021ab7c to your computer and use it in GitHub Desktop.
Akasztófa
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Akasztófa
{
public partial class Game : Form
{
public Random rand = new Random();
public string Szó;
private Timer t = new Timer();
private Pen pen1 = new Pen(Color.Black, 3);
private char[] betűk;
private int Fa = 0;
public Game()
{
InitializeComponent();
//int b = Form1.A;
var szavak = File.ReadAllLines("szavak.txt");
Szó = szavak[rand.Next(szavak.Length)];
//Console.WriteLine(szó);
/*t.Interval = 20;
t.Tick += delegate
{
this.Invalidate();
};
t.Start();*/
betűk = new char[Szó.Length];
Console.WriteLine(Szó);
}
private void Game_FormClosing(object sender, FormClosingEventArgs e)
{
Form1.This.Close();
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
Tipp();
}
}
private void Game_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (Fa > 0)
g.DrawLine(pen1, 100, 300, 100, 400);
//g.DrawLine(Pens.Black, new Point(50, 50), this.PointToClient(Cursor.Position));
if (Fa > 2)
g.DrawLine(pen1, 80, 400, 120, 400);
if (Fa > 1)
g.DrawLine(pen1, 100, 300, 140, 300);
if (Fa > 3)
g.DrawLine(pen1, 140, 300, 140, 320);
if (Fa > 4)
g.DrawEllipse(pen1, 130, 320, 20, 20);
if (Fa > 5)
g.DrawLine(pen1, 140, 340, 140, 380);
if (Fa > 6)
g.DrawLine(pen1, 140, 350, 120, 340);
if (Fa > 7)
g.DrawLine(pen1, 140, 350, 160, 340);
if (Fa > 8)
g.DrawLine(pen1, 140, 378, 120, 390);
if (Fa > 9)
g.DrawLine(pen1, 140, 378, 160, 390);
for (int i = 0; i < Szó.Length; i++)
{
g.DrawLine(pen1, 200 + i * 50, 100, 220 + i * 50, 100);
if (betűk[i] > 0)
g.DrawString(betűk[i].ToString(), SystemFonts.CaptionFont, Brushes.Black, 200 + i * 50, 80);
}
}
private void tippButton_Click(object sender, EventArgs e)
{
Tipp();
}
private void Tipp()
{
int i = 0;
bool talalt = false;
if (textBox1.Text.Length == 0 || Fa>=10 || betűk.All(b => b > 0))
return;
while ((i = Szó.IndexOf(textBox1.Text.ToLower()[0], i)) != -1)
{
betűk[i] = Szó[i];
talalt = true;
i++;
}
if (!talalt)
{
Fa++;
if (Fa >= 10)
{
MessageBox.Show("Vesztettél");
}
}
this.Invalidate();
if (betűk.All(b => b > 0))
{
MessageBox.Show("Nyertél");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment