坦克大战C#版不用一点控件

版权声明: https://blog.csdn.net/eds124/article/details/82292297
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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private int y = 900, x = 900;

        public Form1()
        {
            this.BackColor = Color.Black;
            this.WindowState = FormWindowState.Maximized;
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.DrawRectangle(Pens.Red, x, y, 100, 100);
            g.DrawRectangle(Pens.Red, x + 25, y + 25, 50, 50);
            g.DrawRectangle(Pens.Red, x + 45, y, 10, 25);

        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (Keys.E == e.KeyCode && y > 0)
            {
                y -= 100;
            }
            else if (Keys.D == e.KeyCode && y < 900)
            {
                y += 100;
            }
            else if (Keys.S == e.KeyCode && x >0)
            {
                x -= 100;
            }
            else if (Keys.F == e.KeyCode && x <1800)
            {
                x += 100;
            }

            this.Refresh();
        }

    }
}

猜你喜欢

转载自blog.csdn.net/eds124/article/details/82292297