Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System.Windows.Forms
- open System.Drawing
- let f = new Form(Text="Tetris", Width=300, Height=500, TopMost=true)
- f.Show()
- let bgimg = new Bitmap(@"C:\Users\Alessandro\Desktop\wood_background.jpg")
- f.BackgroundImage <- bgimg
- f.BackgroundImageLayout <- ImageLayout.Tile
- f.MinimumSize <- new Size(370, 50)
- let mutable count = 0
- type Cell () as this =
- inherit UserControl()
- do this.DoubleBuffered <- true
- do this.BackColor <- Color.Transparent
- let mutable value = 2 //Vuota
- // = 1 -> X
- // = 0 -> O
- let mutable cell_size = 0
- do this.Width <- 100
- do this.Height <- 100
- member this.CellSize
- with get () = cell_size
- and set(v) = cell_size <- v
- member this.Value
- with get() = value
- and set(v) = value <- v
- member this.DrawCross (g:Graphics) =
- let savedGraph = g.Save()
- g.TranslateTransform(float32(cell_size/2), float32(cell_size/2))
- g.RotateTransform(45.f)
- for i = 0 to 4 do
- g.RotateTransform(90.f)
- let p = new Pen(Color.OrangeRed, Width=6.f)
- g.DrawLine(p, 0, 0, cell_size/2, 0)
- g.Restore(savedGraph)
- member this.DrawCircle (g:Graphics)=
- let savedGraph = g.Save()
- g.TranslateTransform(float32(cell_size/2), float32(cell_size/2))
- let p = new Pen(Color.CadetBlue, Width=6.f)
- g.DrawEllipse(p, -cell_size/2 + cell_size/10, -cell_size/2 + cell_size/10, cell_size - cell_size/5, cell_size - cell_size/5)
- g.Restore(savedGraph)
- override this.OnPaint(e) =
- let g = e.Graphics
- if value = 1 then
- this.DrawCross(g)
- else
- this.DrawCircle(g)
- override this.OnClick(e) =
- if this.Value = 2 then
- this.Value <- count % 2
- count <- count+1
- this.Invalidate()
- type Grid () as this =
- inherit UserControl()
- do this.DoubleBuffered <- true
- do this.BackColor <- Color.Transparent
- let mutable count = 0
- let lista_celle = [|for i in 1 .. 9 -> new Cell()|]
- let mutable cell_size = 0
- for i in 1 .. 9 ->
- this.Controls.Add(lista_celle[i])
- member this.CellSize
- with get () = cell_size
- and set(v) = cell_size <- v
- override this.OnPaint e =
- let g = e.Graphics
- let savedGraph = g.Save()
- let p = new Pen(Color.White, width=6.f)
- let lenght = this.Width // = this.Height
- g.TranslateTransform(float32(lenght/2), float32(lenght/2) )
- for i = 1 to 4 do
- g.DrawLine(p, -lenght/2, lenght/6, lenght/2, lenght/6)
- g.RotateTransform(90.f)
- g.Restore(savedGraph)
- override this.OnResize e =
- this.CellSize <- this.Width / 5
- this.Invalidate()
- let set_grid_size (e:Grid) =
- let width = f.ClientSize.Width
- let height = f.ClientSize.Height
- let cx = width / 2
- let cy = height / 2
- (*Divido ora l'area utile in 10 parti, la griglia occuperà 6/10 di area*)
- let decimo = if width > height then height/10 else width/10
- e.Width <- decimo * 6
- e.Height <- decimo * 6
- e.Location <- Point(cx-(3*decimo), cy-(3*decimo))
- let e = new Grid()
- set_grid_size e
- f.Controls.Add(e)
- f.Resize.Add(fun _ ->
- set_grid_size e
- f.Invalidate()
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement