Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Unit2Test
- let r = System.Random()
- let clamp min max value =
- if value < min then min
- elif value > max then max
- else value
- type Point2D =
- { Position : float * float }
- static member Create(x : float, y : float) = { Position = (x, y) }
- static member CreateRandom(min : float, max : float) =
- Point2D.Create
- (min + (r.NextDouble() * (max - min)),
- min + (r.NextDouble() * (max - min)))
- member this.X = fst this.Position
- member this.Y = snd this.Position
- member this.Distance(Point2D : Point2D) =
- System.Math.Sqrt
- ((((this.X - Point2D.X) ** 2.0) + ((this.Y - Point2D.Y) ** 2.0)))
- type Blob =
- { Position : Point2D
- Size : int }
- static member Create() =
- { Position = (Point2D.CreateRandom(-50.0, 50.0))
- Size = r.Next(1, 6) }
- member this.Up =
- { this with Position =
- Point2D.Create
- (this.Position.X,
- clamp -50.0 50.0 (this.Position.Y + 10.0)) }
- member this.Down =
- { this with Position =
- Point2D.Create
- (this.Position.X,
- clamp -50.0 50.0 (this.Position.Y - 10.0)) }
- member this.Left =
- { this with Position =
- Point2D.Create
- (clamp -50.0 50.0 (this.Position.X) - 10.0,
- this.Position.Y) }
- member this.Right =
- { this with Position =
- Point2D.Create
- (clamp -50.0 50.0 (this.Position.X) + 10.0,
- this.Position.Y) }
- member this.Move() =
- let direction = r.Next(0, 4)
- match direction with
- | 0 -> this.Up
- | 1 -> this.Down
- | 2 -> this.Left
- | 3 -> this.Right
- | _ -> this
- type World =
- { Blob1 : Blob
- Blob2 : Blob
- Tick : int }
- static member Create(Blob1 : Blob, Blob2 : Blob, Tick : int) =
- { Blob1 = Blob1
- Blob2 = Blob2
- Tick = Tick }
- member this.Run() =
- if this.Tick <= 0 then
- printfn "%A" this
- this
- else
- printfn "%A" this
- { Blob1 = this.Blob1.Move()
- Blob2 = this.Blob2.Move()
- Tick = this.Tick - 1 }
- .Run()
- let testUnit2() =
- let w = World.Create(Blob.Create(), Blob.Create(), 1000)
- w.Run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement