Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Drawing;
- namespace Tanks
- {
- class Tank : IRan, ITurn
- {
- TankImg tankImg = new TankImg();
- private Image img;
- static Random random ;
- public Tank()
- {
- img = tankImg.Img;
- random = new Random();
- Direct_x = 0;
- Direct_y = 1;
- }
- private int y, direct_y;
- private int x, direct_x;
- public Image Img
- { get => img; set => img = value; }
- public int X { get => x; set => x = value; }
- public int Y { get => y; set => y = value; }
- public int Direct_x
- { get => direct_x;
- set
- {
- if (direct_x == 0 || direct_x == -1 || direct_x == 1)
- direct_x = value;
- else direct_x = 0;
- }
- }
- public int Direct_y
- {
- get => direct_y;
- set
- {
- if (direct_y == 0 || direct_y == -1 || direct_y == 1)
- direct_y = value;
- else direct_y = 0;
- }
- }
- public void Ran()
- {
- x += Direct_x;
- y += Direct_y;
- }
- public void Turn()
- {
- if (Math.IEEERemainder(x,40) == 0 && Math.IEEERemainder(y, 40) == 0)
- {
- if (random.Next(5000) < 2500)
- {
- if (Direct_y == 0)
- {
- Direct_x = 0;
- while (Direct_y == 0)
- {
- Direct_y = random.Next(-1, 2);
- }
- }
- }
- else
- {
- if (Direct_x == 0)
- {
- Direct_y = 0;
- while (Direct_x == 0)
- {
- Direct_x = random.Next(-1, 2);
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement