Skip to content
This repository has been archived by the owner on Nov 13, 2019. It is now read-only.

Commit

Permalink
its playable!
Browse files Browse the repository at this point in the history
  • Loading branch information
LeNitrous committed Mar 10, 2019
1 parent 6e02fbb commit 809cc61
Show file tree
Hide file tree
Showing 23 changed files with 140 additions and 103 deletions.
11 changes: 5 additions & 6 deletions Block.Game/BlockGame.vb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ Imports Block.Game.Graphics
Imports Block.Game.Online.API
Imports Block.Game.Screens.Menu

Public Class BlockGame
Inherits osu.Framework.Game

Public Class BlockGame : Inherits osu.Framework.Game
Public Stack As ScreenStack

Private Shadows Dependencies As DependencyContainer
Expand All @@ -33,9 +31,6 @@ Public Class BlockGame
Fonts.AddStore(New GlyphStore(Resources, "Fonts/ClearSans-MediumItalic"))
Fonts.AddStore(New GlyphStore(Resources, "Fonts/ClearSans-Thin"))

Dependencies.Cache(New API)
Dependencies.Cache(New BlockColour())

Stack = New ScreenStack With {
.RelativeSizeAxes = Axes.Both
}
Expand All @@ -44,5 +39,9 @@ Public Class BlockGame
.RelativeSizeAxes = Axes.Both,
.Child = Stack
})

Dependencies.Cache(Stack)
Dependencies.Cache(New API)
Dependencies.Cache(New BlockColour())
End Sub
End Class
4 changes: 1 addition & 3 deletions Block.Game/Graphics/Shapes/RoundedBox.vb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Imports osu.Framework.Graphics.Shapes
Imports osuTK.Graphics

Namespace Graphics.Shapes
Public Class RoundedBox
Inherits CompositeDrawable

Public Class RoundedBox : Inherits CompositeDrawable
Public BackgroundColour As New Color4

<BackgroundDependencyLoader>
Expand Down
4 changes: 1 addition & 3 deletions Block.Game/Objects/Drawables/DrawableGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ Imports Block.Game.Graphics
Imports Block.Game.Graphics.Shapes

Namespace Objects.Drawables
Public Class DrawableGrid
Inherits CompositeDrawable

Public Class DrawableGrid : Inherits CompositeDrawable
Private GridObject As Grid
Private Tiles As Container
Private Slots As FillFlowContainer
Expand Down
4 changes: 1 addition & 3 deletions Block.Game/Objects/Drawables/DrawableTile.vb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ Imports Block.Game.Graphics
Imports Block.Game.Graphics.Shapes

Namespace Objects.Drawables
Public Class DrawableTile
Inherits CompositeDrawable

Public Class DrawableTile : Inherits CompositeDrawable
Public Content As Container

Private TileObject As Tile
Expand Down
23 changes: 5 additions & 18 deletions Block.Game/Objects/Manager.vb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Namespace Objects
Public ReadOnly Moves As New BindableInt
Public Grid As Grid
Public ShouldAddRandomTile As Boolean = True
Public Event GameWin As GameEventHandler
Public Event GameOver As GameEventHandler
Public Event GameEnded As GameEventHandler

Public Event Win()
Public Event Lose()

Public Sub New(ByVal size As Integer)
Grid = New Grid(size)
Expand Down Expand Up @@ -57,7 +57,7 @@ Namespace Objects

Score.Set(Score.Value + CInt(merged))
If CInt(merged) = 2048 Then
RaiseEvent GameWin(New ManagerInfo(Me))
RaiseEvent Win()
End If
Else
MoveTile(tile, positions.Farthest)
Expand All @@ -78,7 +78,7 @@ Namespace Objects
AddRandomTile()
End If
If Not MovesAvailable() Then
RaiseEvent GameOver(New ManagerInfo(Me))
RaiseEvent Lose()
End If
End If
End Sub
Expand Down Expand Up @@ -209,19 +209,6 @@ Namespace Objects
End Sub
End Class

Public Delegate Sub GameEventHandler(ByVal info As ManagerInfo)
End Class

Public Class ManagerInfo
Public TimeElapsed As Long
Public Score As Integer
Public Moves As Integer

Public Sub New(ByVal manager As Manager)
TimeElapsed = manager.Watch.ElapsedMilliseconds
Score = manager.Score.Value
Moves = manager.Moves.Value
End Sub
End Class

Public Enum MoveDirection
Expand Down
1 change: 0 additions & 1 deletion Block.Game/Objects/Tile.vb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Imports osuTK

Namespace Objects
Public Class Tile

Public ReadOnly Position As New Bindable(Of Vector2)
Public ReadOnly Score As New BindableInt
Public IsMerged As Boolean
Expand Down
41 changes: 41 additions & 0 deletions Block.Game/Rules/GameRuleClassic.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Imports Block.Game.Objects

Namespace Rules
Public Class GameRuleClassic : Implements IGameRule
Public Property Name As String Implements IGameRule.Name
Get
Return "Classic"
End Get
Private Set(value As String)
End Set
End Property

Public Property ShowTimer As Boolean Implements IGameRule.ShowTimer
Get
Return True
End Get
Private Set(value As Boolean)
End Set
End Property

Public Property ShowMoves As Boolean Implements IGameRule.ShowMoves
Get
Return True
End Get
Private Set(value As Boolean)
End Set
End Property

Public Property ShowScore As Boolean Implements IGameRule.ShowScore
Get
Return True
End Get
Private Set(value As Boolean)
End Set
End Property

Public Function NewRecordCondition(ByVal manager As Manager) As Boolean Implements IGameRule.NewRecordCondition
Return False
End Function
End Class
End Namespace
12 changes: 12 additions & 0 deletions Block.Game/Rules/IGameRule.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Imports Block.Game.Objects

Namespace Rules
Public Interface IGameRule
Property Name As String
Property ShowTimer As Boolean
Property ShowMoves As Boolean
Property ShowScore As Boolean

Function NewRecordCondition(ByVal Manager As Manager) As Boolean
End Interface
End Namespace
26 changes: 12 additions & 14 deletions Block.Game/Screens/Menu/MainMenu.vb
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
Imports osu.Framework.Allocation
Imports osu.Framework.Screens
Imports osu.Framework.Allocation
Imports osu.Framework.Graphics
Imports osu.Framework.Graphics.Sprites
Imports Block.Game.Graphics
Imports Block.Game.Rules
Imports Block.Game.Screens.Play

Namespace Screens.Menu
Public Class MainMenu
Inherits Screen

Public Class MainMenu : Inherits Screen
Public MainSystem As MenuButtonGroup
Public PlaySystem As MenuButtonGroup
Public ModeSystem As MenuButtonGroup
Public LeadSystem As MenuButtonGroup

<BackgroundDependencyLoader>
Private Sub Load(ByVal colour As BlockColour)
Private Sub Load(ByVal stack As ScreenStack, ByVal colour As BlockColour)
MainSystem = New MenuButtonGroup
MainSystem.AddButtonRange(New List(Of MenuButton) From {
New MenuButton("exit", "leaving so soon?"),
New MenuButton("play", "some classic 2048", Sub() MainSystem.SwitchTo(PlaySystem)),
New MenuButton("leaderboards", "best of the best", Sub() MainSystem.SwitchTo(LeadSystem)),
New MenuButton("settings", "fiddle around")
New MenuButton("play", "some classic 2048", Sub() MainSystem.SwitchTo(PlaySystem))
})

PlaySystem = New MenuButtonGroup(1)
PlaySystem.AddButtonRange(New List(Of MenuButton) From {
New MenuButton("back", "", Sub() MainSystem.Back()),
New MenuButton("solo", "you alone", Sub() PlaySystem.SwitchTo(ModeSystem)),
New MenuButton("multi", "with other people")
New MenuButton("solo", "you alone", Sub() PlaySystem.SwitchTo(ModeSystem))
})

ModeSystem = New MenuButtonGroup(1)
ModeSystem.AddButtonRange(New List(Of MenuButton) From {
New MenuButton("back", "", Sub() PlaySystem.Back()),
New MenuButton("classic", "reach the 2048 tile!"),
New MenuButton("endless", "no stopping you now"),
New MenuButton("time trial", "play as fast as you can!"),
New MenuButton("move trial", "play with the least moves possible!")
New MenuButton("classic", "reach the 2048 tile!", Sub()
stack.Exit()
stack.Push(New Player(New GameRuleClassic, 4))
End Sub)
})

LeadSystem = New MenuButtonGroup(1)
Expand Down
4 changes: 1 addition & 3 deletions Block.Game/Screens/Menu/MenuButton.vb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ Imports Block.Game.Graphics.Shapes
Imports osu.Framework.Input.Events

Namespace Screens.Menu
Public Class MenuButton
Inherits ClickableContainer

Public Class MenuButton : Inherits ClickableContainer
Private ReadOnly Title As String
Private ReadOnly Subtitle As String
Private ReadOnly ClickAction As Action
Expand Down
4 changes: 1 addition & 3 deletions Block.Game/Screens/Menu/MenuButtonGroup.vb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ Imports osu.Framework.Graphics.Containers
Imports osuTK

Namespace Screens.Menu
Public Class MenuButtonGroup
Inherits FillFlowContainer

Public Class MenuButtonGroup : Inherits FillFlowContainer
Private ReadOnly Level As Integer
Private FromGroup As MenuButtonGroup

Expand Down
10 changes: 4 additions & 6 deletions Block.Game/Screens/Play/CounterComponent.vb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ Imports Block.Game.Graphics
Imports Block.Game.Graphics.Shapes

Namespace Screens.Play
Public MustInherit Class CounterComponent
Inherits CompositeDrawable

Public MustInherit Class CounterComponent : Inherits CompositeDrawable
Private Display As SpriteText

Protected Title As String

<BackgroundDependencyLoader>
Private Sub Load(ByVal colour As BlockColour)
Size = New Vector2(100, 60)
Size = New Vector2(120, 80)
Display = New SpriteText With {
.Anchor = Anchor.Centre,
.Origin = Anchor.Centre,
.Text = "",
.Font = New FontUsage("OpenSans", 36),
.Font = New FontUsage("OpenSans", 48),
.Y = -5
}
AddRangeInternal(New List(Of Drawable) From {
Expand All @@ -36,7 +34,7 @@ Namespace Screens.Play
.Origin = Anchor.BottomCentre,
.Y = -5,
.Text = Title,
.Font = New FontUsage("OpenSans", 14, "Bold"),
.Font = New FontUsage("OpenSans", 20, "Bold"),
.Colour = colour.FromHex("eee4da")
},
Display
Expand Down
4 changes: 1 addition & 3 deletions Block.Game/Screens/Play/MoveCounter.vb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
Imports osu.Framework.Bindables

Namespace Screens.Play
Public Class MoveCounter
Inherits CounterComponent

Public Class MoveCounter : Inherits CounterComponent
Public Counter As BindableInt

Public Sub New(ByVal counter As BindableInt)
Expand Down
8 changes: 0 additions & 8 deletions Block.Game/Screens/Play/PlayType.vb

This file was deleted.

55 changes: 46 additions & 9 deletions Block.Game/Screens/Play/Player.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,66 @@ Imports osu.Framework.Graphics.Containers
Imports Block.Game.Graphics
Imports Block.Game.Objects
Imports Block.Game.Objects.Drawables
Imports Block.Game.Rules
Imports osu.Framework.Input.Events

Namespace Screens.Play
Public Class Player
Inherits Screen

Public Class Player : Inherits Screen
Private ReadOnly GameManager As Manager
Private ReadOnly GameType As PlayType
Private ReadOnly GameRule As IGameRule

Public Sub New(ByVal type As PlayType, ByVal size As Integer)
Public Sub New(ByVal rule As IGameRule, ByVal size As Integer)
GameManager = New Manager(size)
GameType = type

GameManager.AddStartTiles()
GameRule = rule
End Sub

<BackgroundDependencyLoader>
Private Sub Load(ByVal colour As BlockColour)
Dim Counter As New FillFlowContainer With {
.AutoSizeAxes = Axes.Both,
.Anchor = Anchor.Centre,
.Origin = Anchor.Centre,
.Y = -320
}

If GameRule.ShowMoves Then
Counter.Add(New MoveCounter(GameManager.Moves))
End If

If GameRule.ShowScore Then
Counter.Add(New ScoreCounter(GameManager.Score))
End If

If GameRule.ShowTimer Then
Counter.Add(New TimerCounter(GameManager.Watch))
End If

Content.AddRange(New List(Of Drawable) From {
New DrawableGrid(GameManager.Grid) With {
.Anchor = Anchor.Centre,
.Origin = Anchor.Centre
}
},
Counter
})

GameManager.AddStartTiles()
GameManager.Watch.Start()

AddHandler GameManager.Win, AddressOf OnWin
AddHandler GameManager.Lose, AddressOf OnLose
End Sub

Private Sub OnWin()

End Sub

Private Sub OnLose()
GameManager.Watch.Stop()
End Sub

Protected Overrides Function OnKeyDown(e As KeyDownEvent) As Boolean
GameManager.HandleInput(e)
Return MyBase.OnKeyDown(e)
End Function
End Class
End Namespace
4 changes: 1 addition & 3 deletions Block.Game/Screens/Play/ScoreCounter.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ Imports osu.Framework.Graphics.Sprites
Imports osuTK

Namespace Screens.Play
Public Class ScoreCounter
Inherits MoveCounter

Public Class ScoreCounter : Inherits MoveCounter
Public Sub New(ByVal counter As BindableInt)
MyBase.New(counter)
Title = "score"
Expand Down
Loading

0 comments on commit 809cc61

Please sign in to comment.