Angels & Demons Game Logic Complete. (Almost) (#2)
This commit is contained in:
parent
31f39d5078
commit
cbbd209011
16 changed files with 743 additions and 190 deletions
Binary file not shown.
|
@ -6,6 +6,7 @@ using UnityEngine.UI;
|
|||
|
||||
public class BoardManager : MonoBehaviour
|
||||
{
|
||||
|
||||
// Global reference to the canvas' width and height.
|
||||
private float canvaswidth;
|
||||
private float canvasheight;
|
||||
|
@ -19,7 +20,7 @@ public class BoardManager : MonoBehaviour
|
|||
private float boardheight;
|
||||
|
||||
// Might want to make this part modular in the future.
|
||||
private float numberofspaces = 11;
|
||||
private int numberofspaces = 11;
|
||||
|
||||
// Spaces for the board need to be spawned and resized based on canvas.
|
||||
private float spacespacing;
|
||||
|
@ -29,12 +30,25 @@ public class BoardManager : MonoBehaviour
|
|||
public Transform whitespacetransform;
|
||||
|
||||
// Image assets for the board spaces.
|
||||
public Sprite angelimage;
|
||||
public Image demonimage;
|
||||
public Sprite angelsprite;
|
||||
public Sprite demonsprite;
|
||||
public Sprite emptysprite;
|
||||
|
||||
// Should later be defined in a separate namespace.
|
||||
public struct WhiteSpace
|
||||
{
|
||||
public Image img;
|
||||
public int spriteindex;
|
||||
};
|
||||
|
||||
// Keep references of all the space GameObjects.
|
||||
private Button[] blackspaces = new Button[61];
|
||||
private Image[] whitespaces = new Image[60];
|
||||
private WhiteSpace[] whitespaces = new WhiteSpace[60];
|
||||
|
||||
// Keep references for when MakeMove() is called.
|
||||
private int[] spaces = new int[4]; // Indexes relative to whitespaces[] of the spaces being changed.
|
||||
private int[] sprites = new int[4]; // Which sprite to change the space to.
|
||||
public bool movemade = false; // Fix to keep ChangeSpaces() from being called every frame.
|
||||
|
||||
// Use this for initialization
|
||||
void Start ()
|
||||
|
@ -44,9 +58,98 @@ public class BoardManager : MonoBehaviour
|
|||
boardheight = board.GetComponent<RectTransform>().rect.height;
|
||||
boardwidth = board.GetComponent<RectTransform>().rect.width;
|
||||
spacespacing = ((canvaswidth - canvasspacing)/11f);
|
||||
|
||||
SpawnInitialBoard();
|
||||
ResetSpaces();
|
||||
ResetSprites();
|
||||
}
|
||||
|
||||
// Grab the current canvas dimentions, used for dynamic resizing checks.
|
||||
private Vector2 GetCurrentCanvas()
|
||||
{
|
||||
Vector2 output;
|
||||
output.x = this.GetComponentInParent<RectTransform>().rect.height;
|
||||
output.y = this.GetComponentInParent<RectTransform>().rect.width;
|
||||
return output;
|
||||
}
|
||||
|
||||
// Reset the spaces array to all -1 values. This means they will be ignored if they somehow
|
||||
// get passed to a function that tries to change spaces.
|
||||
private void ResetSpaces()
|
||||
{
|
||||
for(int i = 0; i < spaces.Length; ++i)
|
||||
{
|
||||
spaces[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// See above, but for the sprites array.
|
||||
private void ResetSprites()
|
||||
{
|
||||
for(int i = 0; i < sprites.Length; ++i)
|
||||
{
|
||||
sprites[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Function call to return one Instantiated Button object.
|
||||
// Should be changed along with SpawnWhiteSpace to instead spawn the object and attach them
|
||||
// to a defined struct that can also hold the index of the spawned object. This will allow
|
||||
// for easier indexing of these prefabs in the future without the need for parsing.
|
||||
private Button SpawnBlackSpace(int i)
|
||||
{
|
||||
Button bsbutton;
|
||||
bsbutton = Instantiate(blackspaceasset, blackspacetransform);
|
||||
bsbutton.name += "" + i;
|
||||
bsbutton.onClick.AddListener(delegate{ButtonAction(bsbutton);});
|
||||
return bsbutton;
|
||||
}
|
||||
|
||||
// Function call to return one Instantiated Image object.
|
||||
private Image SpawnWhiteSpace()
|
||||
{
|
||||
Image wsimage;
|
||||
wsimage = Instantiate(whitespaceasset, whitespacetransform);
|
||||
return wsimage;
|
||||
}
|
||||
|
||||
// Set up an empty board, sized to the current canvas.
|
||||
private void SpawnInitialBoard()
|
||||
{
|
||||
for(int i = 0; i < blackspaces.Length; ++i)
|
||||
{
|
||||
Button temp;
|
||||
temp = SpawnBlackSpace(i);
|
||||
temp.GetComponent<RectTransform>().sizeDelta = new Vector2(spacespacing, spacespacing);
|
||||
|
||||
float x = (spacespacing*i*2 + (temp.GetComponent<RectTransform>().rect.width / 2f)) % (boardwidth) - ((boardwidth) / 2f);
|
||||
float y = (boardheight / 2f) - ((temp.GetComponent<RectTransform>().rect.height / 2f) + spacespacing*(Mathf.Floor(i/(11f/2f))));
|
||||
temp.transform.localPosition = new Vector3(x, y, 0);
|
||||
|
||||
blackspaces[i] = temp;
|
||||
|
||||
if(i < blackspaces.Length - 1)
|
||||
{
|
||||
WhiteSpace tempws;
|
||||
|
||||
Image tempimage;
|
||||
tempimage = SpawnWhiteSpace();
|
||||
tempimage.GetComponent<RectTransform>().sizeDelta = new Vector2(spacespacing, spacespacing);
|
||||
tempimage.sprite = emptysprite;
|
||||
|
||||
x = (spacespacing*i*2 + (tempimage.GetComponent<RectTransform>().rect.width / 2f)*3) % (boardwidth) - ((boardwidth) / 2f);
|
||||
y = (boardheight / 2f) - ((tempimage.GetComponent<RectTransform>().rect.height / 2f) + spacespacing*(Mathf.Floor((i + 1)/(11.01f/2f))));
|
||||
tempimage.transform.localPosition = new Vector3(x, y, 0);
|
||||
|
||||
tempws.img = tempimage;
|
||||
tempws.spriteindex = 2;
|
||||
|
||||
whitespaces[i] = tempws;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the board's scale according to the current canvas size, call UpdatePieceScale().
|
||||
private void UpdateBoardScale()
|
||||
{
|
||||
canvasheight = this.GetComponentInParent<RectTransform>().rect.height;
|
||||
|
@ -69,51 +172,7 @@ public class BoardManager : MonoBehaviour
|
|||
UpdatePieceScale();
|
||||
}
|
||||
|
||||
private Button SpawnBlackSpace(int i)
|
||||
{
|
||||
Button bsbutton;
|
||||
bsbutton = Instantiate(blackspaceasset, blackspacetransform);
|
||||
bsbutton.name += "" + i;
|
||||
bsbutton.onClick.AddListener(delegate{ButtonAction(bsbutton);});
|
||||
return bsbutton;
|
||||
}
|
||||
|
||||
private Image SpawnWhiteSpace()
|
||||
{
|
||||
Image wsimage;
|
||||
wsimage = Instantiate(whitespaceasset, whitespacetransform);
|
||||
return wsimage;
|
||||
}
|
||||
|
||||
private void SpawnInitialBoard()
|
||||
{
|
||||
for(int i = 0; i < blackspaces.Length; ++i)
|
||||
{
|
||||
Button temp;
|
||||
temp = SpawnBlackSpace(i);
|
||||
temp.GetComponent<RectTransform>().sizeDelta = new Vector2(spacespacing, spacespacing);
|
||||
|
||||
float x = (spacespacing*i*2 + (temp.GetComponent<RectTransform>().rect.width / 2f)) % (boardwidth) - ((boardwidth) / 2f);
|
||||
float y = (boardheight / 2f) - ((temp.GetComponent<RectTransform>().rect.height / 2f) + spacespacing*(Mathf.Floor(i/(11f/2f))));
|
||||
temp.transform.localPosition = new Vector3(x, y, 0);
|
||||
|
||||
blackspaces[i] = temp;
|
||||
|
||||
if(i < blackspaces.Length - 1)
|
||||
{
|
||||
Image tempimage;
|
||||
tempimage = SpawnWhiteSpace();
|
||||
tempimage.GetComponent<RectTransform>().sizeDelta = new Vector2(spacespacing, spacespacing);
|
||||
|
||||
x = (spacespacing*i*2 + (tempimage.GetComponent<RectTransform>().rect.width / 2f)*3) % (boardwidth) - ((boardwidth) / 2f);
|
||||
y = (boardheight / 2f) - ((tempimage.GetComponent<RectTransform>().rect.height / 2f) + spacespacing*(Mathf.Floor((i + 1)/(11.01f/2f))));
|
||||
tempimage.transform.localPosition = new Vector3(x, y, 0);
|
||||
|
||||
whitespaces[i] = tempimage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the pieces' scales according to the current canvas size.
|
||||
private void UpdatePieceScale()
|
||||
{
|
||||
for(int i = 0; i < blackspaces.Length; ++i)
|
||||
|
@ -127,24 +186,74 @@ public class BoardManager : MonoBehaviour
|
|||
|
||||
if(i < blackspaces.Length - 1)
|
||||
{
|
||||
Image tempimage = whitespaces[i];
|
||||
Image tempimage = whitespaces[i].img;
|
||||
tempimage.GetComponent<RectTransform>().sizeDelta = new Vector2(spacespacing, spacespacing);
|
||||
|
||||
x = (spacespacing*i*2 + (tempimage.GetComponent<RectTransform>().rect.width / 2f)*3) % (boardwidth) - ((boardwidth) / 2f);
|
||||
y = (boardheight / 2f) - ((tempimage.GetComponent<RectTransform>().rect.height / 2f) + spacespacing*(Mathf.Floor((i + 1)/(11.01f/2f))));
|
||||
tempimage.transform.localPosition = new Vector3(x, y, 0);
|
||||
|
||||
whitespaces[i] = tempimage;
|
||||
whitespaces[i].img = tempimage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Change the passed in space indexes' sprites to the specified sprites.
|
||||
private void ChangeSpaces(int[] spaces, int[] sprites)
|
||||
{
|
||||
for(int i = 0; i < spaces.Length; ++i)
|
||||
{
|
||||
if(spaces[i] >= 0 && spaces[i] < whitespaces.Length)
|
||||
{
|
||||
switch(sprites[i])
|
||||
{
|
||||
case 0:
|
||||
whitespaces[spaces[i]].img.sprite = angelsprite;
|
||||
whitespaces[spaces[i]].spriteindex = 0;
|
||||
break;
|
||||
case 1:
|
||||
whitespaces[spaces[i]].img.sprite = demonsprite;
|
||||
whitespaces[spaces[i]].spriteindex = 1;
|
||||
break;
|
||||
case 2:
|
||||
whitespaces[spaces[i]].img.sprite = emptysprite;
|
||||
whitespaces[spaces[i]].spriteindex = 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// After a move has been made, since right now spaces are checked every frame,
|
||||
// change all spaces[] values to -1 to avoid sprites being updated every frame.
|
||||
ResetSpaces();
|
||||
ResetSprites();
|
||||
|
||||
movemade = false;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
/* Update is called once per frame
|
||||
* Here we check if the current canvas has changed and if so, call UpdateBoardScale(),
|
||||
* then we also check if a move has been made, and call ChangeSpaces with the necessary parameters.
|
||||
*/
|
||||
void Update ()
|
||||
{
|
||||
UpdateBoardScale();
|
||||
Vector2 currentcanvas = GetCurrentCanvas();
|
||||
|
||||
if(currentcanvas.x != canvaswidth || currentcanvas.y != canvasheight)
|
||||
{
|
||||
UpdateBoardScale();
|
||||
}
|
||||
|
||||
if(movemade)
|
||||
{
|
||||
ChangeSpaces(spaces, sprites);
|
||||
}
|
||||
}
|
||||
|
||||
// Function definition to specify what the buttons should do when pressed, which is to call
|
||||
// the GameManager.MakeMove() function with the necessary parameters.
|
||||
public void ButtonAction(Button b)
|
||||
{
|
||||
int buttonindex = 0;
|
||||
|
@ -153,12 +262,17 @@ public class BoardManager : MonoBehaviour
|
|||
Vector2 boardcoords = ConvertButtonIndex(buttonindex);
|
||||
|
||||
// This is completely incorrect and will most likely need a switch case of some kind in the future.
|
||||
Debug.Log("Board coordinates: " + boardcoords.x + " " + boardcoords.y);
|
||||
//Debug.Log("Board coordinates: " + boardcoords.x + " " + boardcoords.y);
|
||||
|
||||
ChangeSpaces(boardcoords);
|
||||
// Temporarily hardcoded. Should later be changed to a GameManager function call that determines
|
||||
// what to change spaces to.
|
||||
GameManager.MakeMove(boardcoords, numberofspaces, whitespaces, spaces, sprites, ref movemade);
|
||||
}
|
||||
|
||||
private Vector2 ConvertButtonIndex(int i)
|
||||
// Convert a given button index in the blackspaces[] array to board coordinates.
|
||||
// These need to made more modular in the future to support
|
||||
// different board sizes.
|
||||
public static Vector2 ConvertButtonIndex(int i)
|
||||
{
|
||||
Vector2 temp;
|
||||
temp.x = (i*2)%11;
|
||||
|
@ -253,7 +367,8 @@ public class BoardManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
private int ConvertImageIndex(Vector2 bc)
|
||||
// Convert a given set of board coordinates to the corresponding whitespaces[] array index.
|
||||
public static int ConvertImageIndex(Vector2 bc)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
@ -308,136 +423,4 @@ public class BoardManager : MonoBehaviour
|
|||
|
||||
return i;
|
||||
}
|
||||
|
||||
private void ChangeSpaces(Vector2 bc)
|
||||
{
|
||||
Vector2 tempbc = bc;
|
||||
int wsi = 0;
|
||||
|
||||
if(bc.x > 0 && bc.x < (numberofspaces - 1))
|
||||
{
|
||||
if(bc.y > 0)
|
||||
{
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y - 1)
|
||||
);
|
||||
tempbc = bc;
|
||||
tempbc.y -= 1;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
}
|
||||
if(bc.y < (numberofspaces - 1))
|
||||
{
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y + 1)
|
||||
);
|
||||
tempbc = bc;
|
||||
tempbc.y += 1;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
}
|
||||
Debug.Log(
|
||||
"changing spaces:" +
|
||||
(bc.x - 1) + " " + (bc.y) + "\t" +
|
||||
(bc.x + 1) + " " + (bc.y)
|
||||
);
|
||||
tempbc = bc;
|
||||
|
||||
tempbc.x -= 1;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
|
||||
tempbc.x += 2;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
}
|
||||
else if(bc.y > 0 && bc.y < (numberofspaces - 1))
|
||||
{
|
||||
if(bc.x == 0)
|
||||
{
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x + 1) + " " + (bc.y)
|
||||
);
|
||||
tempbc = bc;
|
||||
tempbc.x += 1;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
}
|
||||
if(bc.x == (numberofspaces - 1))
|
||||
{
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x - 1) + " " + (bc.y)
|
||||
);
|
||||
tempbc = bc;
|
||||
tempbc.x -= 1;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
}
|
||||
Debug.Log(
|
||||
"changing spaces:" +
|
||||
(bc.x) + " " + (bc.y - 1) + "\t" +
|
||||
(bc.x) + " " + (bc.y + 1)
|
||||
);
|
||||
tempbc = bc;
|
||||
|
||||
tempbc.y -= 1;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
|
||||
tempbc.y += 2;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bc.x == 0)
|
||||
{
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x + 1) + " " + (bc.y)
|
||||
);
|
||||
tempbc = bc;
|
||||
tempbc.x += 1;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
}
|
||||
if(bc.x == (numberofspaces - 1))
|
||||
{
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x - 1) + " " + (bc.y)
|
||||
);
|
||||
tempbc = bc;
|
||||
tempbc.x -= 1;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
}
|
||||
if(bc.y > 0)
|
||||
{
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y - 1)
|
||||
);
|
||||
tempbc = bc;
|
||||
tempbc.y -= 1;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
}
|
||||
if(bc.y < (numberofspaces - 1))
|
||||
{
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y + 1)
|
||||
);
|
||||
tempbc = bc;
|
||||
tempbc.y += 1;
|
||||
wsi = ConvertImageIndex(tempbc);
|
||||
whitespaces[wsi].sprite = angelimage;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
245
Angels and Demons/Assets/Scripts/GameManager.cs
Normal file
245
Angels and Demons/Assets/Scripts/GameManager.cs
Normal file
|
@ -0,0 +1,245 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
|
||||
// Private turn counter.
|
||||
private static int turn = 1;
|
||||
|
||||
// (currently unused) Static function that returns the current turn count.
|
||||
public static int GetTurn()
|
||||
{
|
||||
return turn;
|
||||
}
|
||||
|
||||
/* Used to reset the turn counter at the beginning of every game.
|
||||
* Needs to be at the beginning because I want to continue displaying
|
||||
* or having the turn counter saved until I can be sure there is a new
|
||||
* game starting.
|
||||
*/
|
||||
public static void ResetTurn()
|
||||
{
|
||||
turn = 1;
|
||||
}
|
||||
|
||||
/* This function is directly called by the BoardManager when a move is attempted,
|
||||
* and determines what spaces will be changed to what based on the game's rules.
|
||||
* This is goverened by the following:
|
||||
* - Which player's turn it is (which sprite to change to)
|
||||
* - What the space's sprite already is
|
||||
* - Whether the move is legal based on the game's rules
|
||||
*/
|
||||
public static void MakeMove(Vector2 bc, int numberofspaces, BoardManager.WhiteSpace[] whitespaces, int[] spaces, int[] sprites, ref bool movemade)
|
||||
{
|
||||
// Function call to determine which spaces will be changed, see definition below.
|
||||
DetermineSpacesChanged(bc, numberofspaces, spaces);
|
||||
|
||||
// Function call to determine which sprites the spaces will change to, see definition below.
|
||||
DetermineSpritesChanged(whitespaces, spaces, sprites);
|
||||
|
||||
// Increment the turn counter.
|
||||
EndTurn();
|
||||
|
||||
// Tell BoardManager that the move is finished.
|
||||
movemade = true;
|
||||
}
|
||||
|
||||
/* This function determines which spaces *can* be changed based on the board's
|
||||
* limitations.
|
||||
*/
|
||||
private static void DetermineSpacesChanged(Vector2 bc, int numberofspaces, int[] spaces)
|
||||
{
|
||||
// Used to check adjacent spaces without changing the bc reference passed in.
|
||||
Vector2 tempbc = bc;
|
||||
|
||||
// "White Space Index", holder variable to save the return of converting from
|
||||
// board coordinates to the equivalent index in the whitespaces array.
|
||||
int wsi = 0;
|
||||
|
||||
/* Intricate set of if/elseif statements to determine which moves are
|
||||
* legate according to the board's size values.
|
||||
*/
|
||||
if(bc.x > 0 && bc.x < (numberofspaces - 1))
|
||||
{
|
||||
if(bc.y > 0)
|
||||
{
|
||||
/*
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y - 1)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.y -= 1;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[3] = wsi;
|
||||
}
|
||||
if(bc.y < (numberofspaces - 1))
|
||||
{
|
||||
/*
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y + 1)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.y += 1;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[1] = wsi;
|
||||
}
|
||||
/*
|
||||
Debug.Log(
|
||||
"changing spaces:" +
|
||||
(bc.x - 1) + " " + (bc.y) + "\t" +
|
||||
(bc.x + 1) + " " + (bc.y)
|
||||
); */
|
||||
tempbc = bc;
|
||||
|
||||
tempbc.x -= 1;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[0] = wsi;
|
||||
|
||||
tempbc.x += 2;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[2] = wsi;
|
||||
}
|
||||
else if(bc.y > 0 && bc.y < (numberofspaces - 1))
|
||||
{
|
||||
if(bc.x == 0)
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x + 1) + " " + (bc.y)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.x += 1;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[2] = wsi;
|
||||
}
|
||||
if(bc.x == (numberofspaces - 1))
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x - 1) + " " + (bc.y)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.x -= 1;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[0] = wsi;
|
||||
}
|
||||
/* Debug.Log(
|
||||
"changing spaces:" +
|
||||
(bc.x) + " " + (bc.y - 1) + "\t" +
|
||||
(bc.x) + " " + (bc.y + 1)
|
||||
); */
|
||||
tempbc = bc;
|
||||
|
||||
tempbc.y -= 1;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[3] = wsi;
|
||||
|
||||
tempbc.y += 2;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[1] = wsi;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bc.x == 0)
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x + 1) + " " + (bc.y)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.x += 1;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[2] = wsi;
|
||||
}
|
||||
if(bc.x == (numberofspaces - 1))
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x - 1) + " " + (bc.y)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.x -= 1;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[0] = wsi;
|
||||
}
|
||||
if(bc.y > 0)
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y - 1)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.y -= 1;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[3] = wsi;
|
||||
}
|
||||
if(bc.y < (numberofspaces - 1))
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y + 1)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.y += 1;
|
||||
wsi = BoardManager.ConvertImageIndex(tempbc);
|
||||
spaces[1] = wsi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* After determining which spaces are legal to change based on the board's limitations,
|
||||
* this function is called to determine what sprites those spaces will change to, given
|
||||
* current state of the game and the game's rule set.
|
||||
*/
|
||||
private static void DetermineSpritesChanged(BoardManager.WhiteSpace[] whitespaces, int[] spaces, int[] sprites)
|
||||
{
|
||||
int currentplayerturn = (turn -1) % 2;
|
||||
|
||||
for(int i = 0; i < spaces.Length; ++i)
|
||||
{
|
||||
// If this is a legal move. No need for an else statement, since if it's not,
|
||||
// it will already be ignored by the BoardManager.
|
||||
if(spaces[i] >= 0 && spaces[i] < whitespaces.Length)
|
||||
{
|
||||
// Check what space's sprite is currently set to, then set sprites[i]
|
||||
// to the sprite to be changed to, according to the game's rules.
|
||||
switch(whitespaces[spaces[i]].spriteindex)
|
||||
{
|
||||
case 0:
|
||||
if(currentplayerturn != 0)
|
||||
{
|
||||
sprites[i] = 2;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(currentplayerturn != 1)
|
||||
{
|
||||
sprites[i] = 2;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
sprites[i] = currentplayerturn;
|
||||
break;
|
||||
default:
|
||||
Debug.Log("Illegal sprite index!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This should be called to increment the turn counter at the end of every turn.
|
||||
* This is at the end because if an illegal move is made or some other rule is
|
||||
* broken, it will keep the turn counter from being incremented unnecessarily.
|
||||
* E.g. don't increment if the turn isn't actually over.
|
||||
*/
|
||||
private static void EndTurn()
|
||||
{
|
||||
++turn;
|
||||
}
|
||||
}
|
11
Angels and Demons/Assets/Scripts/GameManager.cs.meta
Normal file
11
Angels and Demons/Assets/Scripts/GameManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 81f6a3ad727884d16b4bd5390a90a3c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
43
Angels and Demons/Assets/Scripts/PlayerManager.cs
Normal file
43
Angels and Demons/Assets/Scripts/PlayerManager.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
// Private players variable, used to keep track of which player has which spaces.
|
||||
// Should later be defined as a struct in a separate namespace.
|
||||
private static int[] players = new int[2];
|
||||
|
||||
// Function call to return what the indexed player's space choice is.
|
||||
public static int getPlayer(int n)
|
||||
{
|
||||
return players[n];
|
||||
}
|
||||
|
||||
/* Function called at the beginning of a game to set the player spaces
|
||||
* and reset the turn counter.
|
||||
*
|
||||
* This function should later be called by a manager script of some
|
||||
* kind that handles menu navigation/logistics between games and other
|
||||
* activity outside of the main game.
|
||||
*/
|
||||
public static void StartGame(int playerchoice)
|
||||
{
|
||||
players[0] = playerchoice;
|
||||
|
||||
switch(playerchoice)
|
||||
{
|
||||
case 1:
|
||||
players[1] = 2;
|
||||
break;
|
||||
case 2:
|
||||
players[1] = 1;
|
||||
break;
|
||||
default:
|
||||
Debug.Log("Invalid Player Choice!");
|
||||
return;
|
||||
}
|
||||
|
||||
GameManager.ResetTurn();
|
||||
}
|
||||
}
|
11
Angels and Demons/Assets/Scripts/PlayerManager.cs.meta
Normal file
11
Angels and Demons/Assets/Scripts/PlayerManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 923eab5932fe2482e8c5b73ca1e5b0b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Angels and Demons/Assets/Sprites/angel-with-wings-and-halo.png
Normal file
BIN
Angels and Demons/Assets/Sprites/angel-with-wings-and-halo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
|
@ -0,0 +1,84 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d328f0d560bd8484489fd59e3e54989e
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 5
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -1
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 8
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 2
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID: 3d46763d9958e47d8855ba15b2918a95
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Angels and Demons/Assets/Sprites/devil.png
Normal file
BIN
Angels and Demons/Assets/Sprites/devil.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
84
Angels and Demons/Assets/Sprites/devil.png.meta
Normal file
84
Angels and Demons/Assets/Sprites/devil.png.meta
Normal file
|
@ -0,0 +1,84 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 01bda0b5067f34ec6a1f865129fada51
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 5
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -1
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 8
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 2
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID: c7d69233843874fb799d68c921777dc2
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Angels and Demons/Assets/Sprites/empty.png
Normal file
BIN
Angels and Demons/Assets/Sprites/empty.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 78 B |
92
Angels and Demons/Assets/Sprites/empty.png.meta
Normal file
92
Angels and Demons/Assets/Sprites/empty.png.meta
Normal file
|
@ -0,0 +1,92 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3c4251e4a838f4dacb41617d5a1c34d4
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 5
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 0
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 0
|
||||
wrapV: 0
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 3
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 4
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 8
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 2
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 4
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline:
|
||||
- - {x: -2, y: -2}
|
||||
- {x: -2, y: 2}
|
||||
- {x: 2, y: 2}
|
||||
- {x: 2, y: -2}
|
||||
physicsShape:
|
||||
- - {x: -2, y: -2}
|
||||
- {x: -2, y: 2}
|
||||
- {x: 2, y: 2}
|
||||
- {x: 2, y: -2}
|
||||
bones: []
|
||||
spriteID: 4ef8b483dcfad48ba8ee0214e2306769
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
m_EditorVersion: 2018.1.1f1
|
||||
m_EditorVersion: 2018.1.0f2
|
||||
|
|
Reference in a new issue