Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
TDT4240-group23
SpaceCheckers
Commits
7b2a6d5f
Commit
7b2a6d5f
authored
Apr 10, 2021
by
Anders H. Rebner
Browse files
Drew smaller board, created GameController, drew too large pieces in startpositions
parent
906e8732
Changes
6
Hide whitespace changes
Inline
Side-by-side
CheckersClient/core/src/com/mygdx/game/UniCheckersClient.java
View file @
7b2a6d5f
...
...
@@ -10,10 +10,14 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
import
com.badlogic.gdx.scenes.scene2d.ui.Skin
;
import
com.badlogic.gdx.utils.viewport.FitViewport
;
import
com.badlogic.gdx.utils.viewport.Viewport
;
import
com.mygdx.game.controllers.GameController
;
import
com.mygdx.game.controllers.NetworkController
;
import
com.mygdx.game.controllers.PlayerController
;
import
com.mygdx.game.model.DefaultBoard
;
import
com.mygdx.game.model.Game
;
import
com.mygdx.game.model.GameMode
;
import
com.mygdx.game.model.GameState
;
import
com.mygdx.game.model.gamemodes.rules.DefaultRules
;
import
com.mygdx.game.views.CinematicView
;
import
com.mygdx.game.views.GameViewManager
;
import
com.mygdx.game.views.LoadingView
;
...
...
@@ -28,6 +32,7 @@ import java.util.ArrayList;
public
class
UniCheckersClient
extends
ApplicationAdapter
{
PlayerController
playerController
;
GameController
gameController
;
private
GameViewManager
gvm
;
private
SpriteBatch
sb
;
...
...
@@ -49,7 +54,8 @@ public class UniCheckersClient extends ApplicationAdapter {
Gdx
.
input
.
setInputProcessor
(
stage
);
// Initialize Models..
Game
model
=
new
Game
(
new
GameState
());
// Temporary model with default board and rules
Game
model
=
new
Game
(
new
GameState
(
new
GameMode
(
new
DefaultRules
(),
new
DefaultBoard
())));
// Initialize controllers..
NetworkController
networkController
=
new
NetworkController
();
...
...
@@ -64,8 +70,9 @@ public class UniCheckersClient extends ApplicationAdapter {
//gvm.push(new LoadingView(gvm, playerController, assetManager, stage, skin));
//gvm.push(new CinematicView(gvm, playerController, assetManager, stage, skin));
gvm
.
push
(
new
PlayView
(
gvm
,
playerController
,
assetManager
,
stage
,
skin
,
null
));
PlayView
playView
=
new
PlayView
(
gvm
,
playerController
,
assetManager
,
stage
,
skin
,
null
);
gameController
=
new
GameController
(
model
,
playView
);
gvm
.
push
(
playView
);
}
@Override
...
...
CheckersClient/core/src/com/mygdx/game/controllers/GameController.java
0 → 100644
View file @
7b2a6d5f
package
com.mygdx.game.controllers
;
import
com.badlogic.gdx.math.Vector3
;
import
com.mygdx.game.model.Game
;
import
com.mygdx.game.views.PlayView
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
GameController
{
private
Game
model
;
private
PlayView
view
;
public
GameController
(
Game
model
,
PlayView
view
)
{
this
.
model
=
model
;
this
.
view
=
view
;
List
<
List
<
Vector3
>>
startFieldCoordinates
=
this
.
model
.
getStartFieldCoordinates
();
List
<
List
<
Float
[]>>
startFieldCoordinatesPixel
=
new
ArrayList
<>();
for
(
List
<
Vector3
>
coordinateSet
:
startFieldCoordinates
)
{
List
<
Float
[]>
coordinateSetPixel
=
new
ArrayList
<>();
for
(
Vector3
coordinate
:
coordinateSet
)
{
coordinateSetPixel
.
add
(
UtilsKt
.
cubeToPixel
(
coordinate
,
100
F
));
}
startFieldCoordinatesPixel
.
add
(
coordinateSetPixel
);
}
this
.
view
.
initializePieces
(
startFieldCoordinatesPixel
);
}
}
CheckersClient/core/src/com/mygdx/game/model/Game.kt
View file @
7b2a6d5f
package
com.mygdx.game.model
import
com.badlogic.gdx.math.Vector3
//Logic of the game, holds a GameState, operations
//(((Controller???))) Model can change its own data, but has to be told by controller
...
...
@@ -10,4 +12,8 @@ class Game(gameState: GameState) {
init
{
this
.
gameState
=
gameState
}
fun
getStartFieldCoordinates
():
List
<
List
<
Vector3
>>?
{
return
this
.
gameState
.
getRules
()
?.
generateStartFields
()
}
}
\ No newline at end of file
CheckersClient/core/src/com/mygdx/game/model/gamemodes/rules/AbstractRules.kt
View file @
7b2a6d5f
...
...
@@ -10,4 +10,5 @@ abstract class AbstractRules {
abstract
fun
getPlayerStartfields
(
playerId
:
Int
)
:
List
<
Vector3
>
// Returns a list of startfields for a given player
abstract
fun
getPlayerTargetFields
(
playerId
:
Int
)
:
List
<
Vector3
>
// Returns a list of targetfields for a given player
abstract
fun
generateStartFields
():
List
<
List
<
Vector3
>>
// Returns a list with lists of startfields
}
\ No newline at end of file
CheckersClient/core/src/com/mygdx/game/model/gamemodes/rules/DefaultRules.kt
View file @
7b2a6d5f
...
...
@@ -27,7 +27,7 @@ class DefaultRules: AbstractRules() {
return
startFields
[
index
]
}
privat
e
fun
generateStartFields
():
List
<
List
<
Vector3
>>
{
overrid
e
fun
generateStartFields
():
List
<
List
<
Vector3
>>
{
return
(
listOf
(
listOf
(
Vector3
(
1F
,
4F
,-
5F
),
Vector3
(
2F
,
3F
,-
5F
),
Vector3
(
3F
,
2F
,-
5F
),
Vector3
(
4F
,
1F
,-
5F
),
Vector3
(
2F
,
4F
,-
6F
),
Vector3
(
3F
,
3F
,-
6F
),
Vector3
(
4F
,
2F
,-
6F
),
Vector3
(
3F
,
4F
,-
7F
),
...
...
CheckersClient/core/src/com/mygdx/game/views/PlayView.java
View file @
7b2a6d5f
...
...
@@ -3,8 +3,10 @@ package com.mygdx.game.views;
import
com.badlogic.gdx.Gdx
;
import
com.badlogic.gdx.assets.AssetManager
;
import
com.badlogic.gdx.graphics.Color
;
import
com.badlogic.gdx.graphics.Pixmap
;
import
com.badlogic.gdx.graphics.Texture
;
import
com.badlogic.gdx.graphics.g2d.SpriteBatch
;
import
com.badlogic.gdx.math.Vector2
;
import
com.badlogic.gdx.scenes.scene2d.Stage
;
import
com.badlogic.gdx.scenes.scene2d.ui.Image
;
import
com.badlogic.gdx.scenes.scene2d.ui.Skin
;
...
...
@@ -15,6 +17,8 @@ import com.mygdx.game.views.tokens.AnimatedSprite;
import
com.mygdx.game.views.tokens.StarPiece
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
public
class
PlayView
extends
View
{
...
...
@@ -26,7 +30,6 @@ public class PlayView extends View{
int
row_height
=
Gdx
.
graphics
.
getHeight
()
/
Help_Guides
;
int
col_width
=
Gdx
.
graphics
.
getWidth
()
/
Help_Guides
;
StarPiece
piece
;
Texture
starPieceBase
;
Texture
starPieceBaseBorder
;
Texture
starPieceMast
;
...
...
@@ -34,6 +37,8 @@ public class PlayView extends View{
Texture
starPieceHead
;
Texture
starPieceHeadBorder
;
HashMap
<
Float
[],
StarPiece
>
pieces
;
public
PlayView
(
GameViewManager
gvm
,
PlayerController
playerController
,
AssetManager
assetManager
,
Stage
stage
,
Skin
skin
,
ArrayList
<
AnimatedSprite
>
lobbyAvatars
)
{
super
(
gvm
,
playerController
,
assetManager
,
stage
,
skin
);
background
=
new
Texture
(
"Game/1x/GameBoard@1x.png"
);
...
...
@@ -60,8 +65,7 @@ public class PlayView extends View{
starPieceHead
=
(
Texture
)
assetManager
.
get
(
PlayAssets
.
STAR_PIECE_HEAD
.
path
,
PlayAssets
.
STAR_PIECE_HEAD
.
classType
);
starPieceHeadBorder
=
(
Texture
)
assetManager
.
get
(
PlayAssets
.
STAR_PIECE_HEAD_BORDER
.
path
,
PlayAssets
.
STAR_PIECE_HEAD_BORDER
.
classType
);
this
.
piece
=
new
StarPiece
(
0
,
0
,
Color
.
RED
,
starPieceBase
,
starPieceBaseBorder
,
starPieceMast
,
starPieceMastBorder
,
starPieceHead
,
starPieceHeadBorder
);
this
.
piece
.
setRotateHead
(
true
);
this
.
pieces
=
new
HashMap
<>();
}
private
void
isGameOver
(){
...
...
@@ -96,8 +100,20 @@ public class PlayView extends View{
stage
.
getBatch
().
end
();
stage
.
draw
();
piece
.
draw
(
stage
.
getBatch
());
for
(
StarPiece
piece
:
pieces
.
values
())
{
piece
.
draw
(
stage
.
getBatch
());
}
}
public
void
initializePieces
(
List
<
List
<
Float
[]>>
coordinates
)
{
for
(
List
<
Float
[]>
coordinateSet
:
coordinates
)
{
for
(
Float
[]
coordinate
:
coordinateSet
)
{
StarPiece
piece
=
new
StarPiece
(
coordinate
[
0
],
coordinate
[
1
],
Color
.
RED
,
starPieceBase
,
starPieceBaseBorder
,
starPieceMast
,
starPieceMastBorder
,
starPieceHead
,
starPieceHeadBorder
);
//piece.setRotateHead(true);
pieces
.
put
(
coordinate
,
piece
);
}
}
}
@Override
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment