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 Char_Move
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        List<Keys> basilanTuslar = new List<Keys>();

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (!basilanTuslar.Contains(e.KeyCode))
            {
                basilanTuslar.Add(e.KeyCode);
            }
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            basilanTuslar.Remove(e.KeyCode);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {            
            if (basilanTuslar.Contains(Keys.Right))
            {
                charCross();
                charRight();
            }
            else if (basilanTuslar.Contains(Keys.Left))
            {
                charCross();
                charLeft();
            }
            else if (basilanTuslar.Contains(Keys.Up))
            {
                charUp();
            }
            else if (basilanTuslar.Contains(Keys.Down))
            {
                charDown();
            }
        }

        void charUp()
        {
            if (pbChar.Top >= 0)
            {
                pbChar.Top -= 2;
            }
        }

        void charDown()
        {
            if (pbChar.Top <= ((this.Height - pbChar.Height) - 30) - lblPlace.Height)
            {
                pbChar.Top += 2;
            }
            //else pbChar.Top = ((this.Height - pbChar.Height) - 30) - lblPlace.Height;

        }

        void charLeft()
        {
            if (pbChar.Left >= 0)
            {
                pbChar.Left -= 2;
            }
        }

        void charRight()
        {
            if (pbChar.Left <= (this.Width - pbChar.Width) - 10)
            {
                pbChar.Left += 2;
            }
            //else pbChar.Left = (this.Width - pbChar.Width) - 10;            
        }

        void charCross()
        {
            if (basilanTuslar.Contains(Keys.Up))
            {
                charUp();
            }
            else if (basilanTuslar.Contains(Keys.Down))
            {
                charDown();
            }
        }
    }
}
