Refactored some Manager scripts into a namespace. Added ending condition, replay.
This commit is contained in:
parent
cbbd209011
commit
029e852721
12 changed files with 670 additions and 502 deletions
BIN
Angels and Demons/Assets/Scenes/BoardScene.unity
Normal file
BIN
Angels and Demons/Assets/Scenes/BoardScene.unity
Normal file
Binary file not shown.
8
Angels and Demons/Assets/Scenes/BoardScene.unity.meta
Normal file
8
Angels and Demons/Assets/Scenes/BoardScene.unity.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 23203d52fcae84949a0ef84a04c62222
|
||||
timeCreated: 1460724850
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -1,8 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 23203d52fcae84949a0ef84a04c62222
|
||||
timeCreated: 1460724850
|
||||
licenseType: Store
|
||||
guid: 1a7eb2ce54d7f49bd85569f06aa63448
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
576
Angels and Demons/Assets/Scripts/AngelsDemons.cs
Normal file
576
Angels and Demons/Assets/Scripts/AngelsDemons.cs
Normal file
|
@ -0,0 +1,576 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AngelsDemons
|
||||
{
|
||||
/* Specific struct used to keep track of information on each of the
|
||||
* board's white spaces.
|
||||
*/
|
||||
public struct WhiteSpace
|
||||
{
|
||||
public Image img;
|
||||
public int spriteindex;
|
||||
};
|
||||
|
||||
/* Static functions that help when manipulating or obtaining information
|
||||
* from the board outside of BoardManager.
|
||||
*/
|
||||
public class Board
|
||||
{
|
||||
private static bool gameover = false;
|
||||
|
||||
// Keep references for when MakeMove() is called.
|
||||
private static int[] spaces = new int[4]; // Indexes relative to whitespaces[] of the spaces being changed.
|
||||
private static int[] sprites = new int[4]; // Which sprite to change the space to.
|
||||
private static bool movemade = false; // Fix to keep ChangeSpaces() from being called every frame.
|
||||
|
||||
// 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.
|
||||
public static void ResetSpaces()
|
||||
{
|
||||
for(int i = 0; i < spaces.Length; ++i)
|
||||
{
|
||||
spaces[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// See above, but for the sprites array.
|
||||
public static void ResetSprites()
|
||||
{
|
||||
for(int i = 0; i < sprites.Length; ++i)
|
||||
{
|
||||
sprites[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetSpaces(int i, int v)
|
||||
{
|
||||
spaces[i] = v;
|
||||
}
|
||||
|
||||
public static int GetSpaces(int i)
|
||||
{
|
||||
return spaces[i];
|
||||
}
|
||||
|
||||
public static void SetSprites(int i, int v)
|
||||
{
|
||||
sprites[i] = v;
|
||||
}
|
||||
|
||||
public static int GetSprites(int i)
|
||||
{
|
||||
return sprites[i];
|
||||
}
|
||||
|
||||
public static void SetMoveMade(bool b)
|
||||
{
|
||||
movemade = b;
|
||||
}
|
||||
|
||||
public static int GetSpacesLength()
|
||||
{
|
||||
return spaces.Length;
|
||||
}
|
||||
|
||||
public static int GetSpritesLength()
|
||||
{
|
||||
return sprites.Length;
|
||||
}
|
||||
|
||||
public static bool GetMoveMade()
|
||||
{
|
||||
return movemade;
|
||||
}
|
||||
|
||||
public static void EndGame()
|
||||
{
|
||||
gameover = true;
|
||||
}
|
||||
|
||||
public static void StartGame()
|
||||
{
|
||||
gameover = false;
|
||||
}
|
||||
|
||||
public static bool IsGameOver()
|
||||
{
|
||||
return gameover;
|
||||
}
|
||||
|
||||
// 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;
|
||||
temp.y = 0;
|
||||
|
||||
switch(i)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
return temp;
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
temp.y = 1;
|
||||
return temp;
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 16:
|
||||
temp.y = 2;
|
||||
return temp;
|
||||
case 17:
|
||||
case 18:
|
||||
case 19:
|
||||
case 20:
|
||||
case 21:
|
||||
temp.y = 3;
|
||||
return temp;
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 26:
|
||||
case 27:
|
||||
temp.y = 4;
|
||||
return temp;
|
||||
case 28:
|
||||
case 29:
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
temp.y = 5;
|
||||
return temp;
|
||||
case 33:
|
||||
case 34:
|
||||
case 35:
|
||||
case 36:
|
||||
case 37:
|
||||
case 38:
|
||||
temp.y = 6;
|
||||
return temp;
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 43:
|
||||
temp.y = 7;
|
||||
return temp;
|
||||
case 44:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 48:
|
||||
case 49:
|
||||
temp.y = 8;
|
||||
return temp;
|
||||
case 50:
|
||||
case 51:
|
||||
case 52:
|
||||
case 53:
|
||||
case 54:
|
||||
temp.y = 9;
|
||||
return temp;
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
case 59:
|
||||
case 60:
|
||||
temp.y = 10;
|
||||
return temp;
|
||||
default:
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert a given set of board coordinates to the corresponding whitespaces[] array index.
|
||||
public static int ConvertImageIndex(Vector2 bc)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
switch(Mathf.RoundToInt(bc.y))
|
||||
{
|
||||
case 0:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
break;
|
||||
case 1:
|
||||
i = (Mathf.RoundToInt(bc.x))/2;
|
||||
i += 5;
|
||||
break;
|
||||
case 2:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
i += 11;
|
||||
break;
|
||||
case 3:
|
||||
i = (Mathf.RoundToInt(bc.x))/2;
|
||||
i += 16;
|
||||
break;
|
||||
case 4:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
i += 22;
|
||||
break;
|
||||
case 5:
|
||||
i = (Mathf.RoundToInt(bc.x))/2;
|
||||
i += 27;
|
||||
break;
|
||||
case 6:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
i += 33;
|
||||
break;
|
||||
case 7:
|
||||
i = (Mathf.RoundToInt(bc.x))/2;
|
||||
i += 38;
|
||||
break;
|
||||
case 8:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
i += 44;
|
||||
break;
|
||||
case 9:
|
||||
i = (Mathf.RoundToInt(bc.x))/2;
|
||||
i += 49;
|
||||
break;
|
||||
case 10:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
i += 55;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
// UNFINISHED
|
||||
// Functions and structs to help keep track of player info.
|
||||
public class Player
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
GameLogic.ResetTurn();
|
||||
}
|
||||
}
|
||||
|
||||
/* Class defined to detail functions that determine how the game is played,
|
||||
* in essence, this class defines the fundamental rules of the game,
|
||||
* and the functions inside help determine how to handle situations
|
||||
* that arise throughout the game.
|
||||
*/
|
||||
public class GameLogic
|
||||
{
|
||||
// Private static turn limit value.
|
||||
private static int turnlimit = 10;
|
||||
|
||||
public static int GetTurnLimit()
|
||||
{
|
||||
return turnlimit;
|
||||
}
|
||||
|
||||
public static void SetTurnLimit(int l)
|
||||
{
|
||||
turnlimit = l;
|
||||
}
|
||||
|
||||
// Private static turn counter.
|
||||
private static int turn = 1;
|
||||
|
||||
// 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, WhiteSpace[] whitespaces)
|
||||
{
|
||||
// Function call to determine which spaces will be changed, see definition below.
|
||||
DetermineSpacesChanged(bc, numberofspaces);
|
||||
|
||||
// Function call to determine which sprites the spaces will change to, see definition below.
|
||||
DetermineSpritesChanged(whitespaces);
|
||||
|
||||
// Increment the turn counter.
|
||||
EndTurn();
|
||||
|
||||
// Tell BoardManager that the move is finished.
|
||||
Board.SetMoveMade(true);
|
||||
}
|
||||
|
||||
/* This function determines which spaces *can* be changed based on the board's
|
||||
* limitations.
|
||||
*/
|
||||
private static void DetermineSpacesChanged(Vector2 bc, int numberofspaces)
|
||||
{
|
||||
// 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 = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(3, wsi);
|
||||
}
|
||||
if(bc.y < (numberofspaces - 1))
|
||||
{
|
||||
/*
|
||||
Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y + 1)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.y += 1;
|
||||
wsi = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(1, wsi);
|
||||
}
|
||||
/*
|
||||
Debug.Log(
|
||||
"changing spaces:" +
|
||||
(bc.x - 1) + " " + (bc.y) + "\t" +
|
||||
(bc.x + 1) + " " + (bc.y)
|
||||
); */
|
||||
tempbc = bc;
|
||||
|
||||
tempbc.x -= 1;
|
||||
wsi = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(0, wsi);
|
||||
|
||||
tempbc.x += 2;
|
||||
wsi = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(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 = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(2, wsi);
|
||||
}
|
||||
if(bc.x == (numberofspaces - 1))
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x - 1) + " " + (bc.y)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.x -= 1;
|
||||
wsi = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(0, wsi);
|
||||
}
|
||||
/* Debug.Log(
|
||||
"changing spaces:" +
|
||||
(bc.x) + " " + (bc.y - 1) + "\t" +
|
||||
(bc.x) + " " + (bc.y + 1)
|
||||
); */
|
||||
tempbc = bc;
|
||||
|
||||
tempbc.y -= 1;
|
||||
wsi = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(3, wsi);
|
||||
|
||||
tempbc.y += 2;
|
||||
wsi = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(1, wsi);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bc.x == 0)
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x + 1) + " " + (bc.y)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.x += 1;
|
||||
wsi = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(2, wsi);
|
||||
}
|
||||
if(bc.x == (numberofspaces - 1))
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x - 1) + " " + (bc.y)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.x -= 1;
|
||||
wsi = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(0, wsi);
|
||||
}
|
||||
if(bc.y > 0)
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y - 1)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.y -= 1;
|
||||
wsi = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(3, wsi);
|
||||
}
|
||||
if(bc.y < (numberofspaces - 1))
|
||||
{
|
||||
/* Debug.Log(
|
||||
"changing space:" +
|
||||
(bc.x) + " " + (bc.y + 1)
|
||||
); */
|
||||
tempbc = bc;
|
||||
tempbc.y += 1;
|
||||
wsi = Board.ConvertImageIndex(tempbc);
|
||||
Board.SetSpaces(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(WhiteSpace[] whitespaces)
|
||||
{
|
||||
int currentplayerturn = (turn -1) % 2;
|
||||
|
||||
for(int i = 0; i < Board.GetSpacesLength(); ++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(Board.GetSpaces(i) >= 0 && Board.GetSpaces(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[Board.GetSpaces(i)].spriteindex)
|
||||
{
|
||||
case 0:
|
||||
if(currentplayerturn != 0)
|
||||
{
|
||||
Board.SetSprites(i, 2);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(currentplayerturn != 1)
|
||||
{
|
||||
Board.SetSprites(i, 2);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
Board.SetSprites(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;
|
||||
}
|
||||
}
|
||||
|
||||
/* Class that will be used to define functions and needed static
|
||||
* variables that determine how the enemy AI will play.
|
||||
* Most likely going to be a simple min-max a/b pruning function
|
||||
* with multiple options for difficulty.
|
||||
*/
|
||||
public class BotLogic
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
/* Class that will be used to handle various menu navigations,
|
||||
* UI displays, setting up games, ending games, keeping track
|
||||
* of scores, and other UI and navigation functionality.
|
||||
*/
|
||||
public class MenuNav
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 81f6a3ad727884d16b4bd5390a90a3c1
|
||||
guid: a7a29e0ee33814ef68cb41b3ae42ae3c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
|
@ -1,8 +1,6 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using AngelsDemons;
|
||||
|
||||
public class BoardManager : MonoBehaviour
|
||||
{
|
||||
|
@ -34,21 +32,12 @@ public class BoardManager : MonoBehaviour
|
|||
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 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.
|
||||
// GameOver assets. Just to have a way to end the game.
|
||||
public GameObject gameoverobjects;
|
||||
|
||||
// Use this for initialization
|
||||
void Start ()
|
||||
|
@ -60,8 +49,13 @@ public class BoardManager : MonoBehaviour
|
|||
spacespacing = ((canvaswidth - canvasspacing)/11f);
|
||||
|
||||
SpawnInitialBoard();
|
||||
ResetSpaces();
|
||||
ResetSprites();
|
||||
|
||||
Board.ResetSpaces();
|
||||
Board.ResetSprites();
|
||||
|
||||
// This should later be handled by Player.StartGame through MenuNav.
|
||||
Board.StartGame();
|
||||
GameLogic.ResetTurn();
|
||||
}
|
||||
|
||||
// Grab the current canvas dimentions, used for dynamic resizing checks.
|
||||
|
@ -73,25 +67,6 @@ public class BoardManager : MonoBehaviour
|
|||
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
|
||||
|
@ -199,25 +174,25 @@ public class BoardManager : MonoBehaviour
|
|||
}
|
||||
|
||||
// Change the passed in space indexes' sprites to the specified sprites.
|
||||
private void ChangeSpaces(int[] spaces, int[] sprites)
|
||||
private void ChangeSpaces()
|
||||
{
|
||||
for(int i = 0; i < spaces.Length; ++i)
|
||||
for(int i = 0; i < Board.GetSpacesLength(); ++i)
|
||||
{
|
||||
if(spaces[i] >= 0 && spaces[i] < whitespaces.Length)
|
||||
if(Board.GetSpaces(i) >= 0 && Board.GetSpaces(i) < whitespaces.Length)
|
||||
{
|
||||
switch(sprites[i])
|
||||
switch(Board.GetSprites(i))
|
||||
{
|
||||
case 0:
|
||||
whitespaces[spaces[i]].img.sprite = angelsprite;
|
||||
whitespaces[spaces[i]].spriteindex = 0;
|
||||
whitespaces[Board.GetSpaces(i)].img.sprite = angelsprite;
|
||||
whitespaces[Board.GetSpaces(i)].spriteindex = 0;
|
||||
break;
|
||||
case 1:
|
||||
whitespaces[spaces[i]].img.sprite = demonsprite;
|
||||
whitespaces[spaces[i]].spriteindex = 1;
|
||||
whitespaces[Board.GetSpaces(i)].img.sprite = demonsprite;
|
||||
whitespaces[Board.GetSpaces(i)].spriteindex = 1;
|
||||
break;
|
||||
case 2:
|
||||
whitespaces[spaces[i]].img.sprite = emptysprite;
|
||||
whitespaces[spaces[i]].spriteindex = 2;
|
||||
whitespaces[Board.GetSpaces(i)].img.sprite = emptysprite;
|
||||
whitespaces[Board.GetSpaces(i)].spriteindex = 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -227,10 +202,10 @@ public class BoardManager : MonoBehaviour
|
|||
|
||||
// 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();
|
||||
Board.ResetSpaces();
|
||||
Board.ResetSprites();
|
||||
|
||||
movemade = false;
|
||||
Board.SetMoveMade(false);
|
||||
}
|
||||
|
||||
/* Update is called once per frame
|
||||
|
@ -246,181 +221,56 @@ public class BoardManager : MonoBehaviour
|
|||
UpdateBoardScale();
|
||||
}
|
||||
|
||||
if(movemade)
|
||||
if(Board.GetMoveMade() && !Board.IsGameOver())
|
||||
{
|
||||
ChangeSpaces(spaces, sprites);
|
||||
ChangeSpaces();
|
||||
CheckGameOver();
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
if(!Board.IsGameOver())
|
||||
{
|
||||
int buttonindex = 0;
|
||||
int.TryParse(b.name.Replace("Move Selection(Clone)", ""), out buttonindex);
|
||||
|
||||
Vector2 boardcoords = ConvertButtonIndex(buttonindex);
|
||||
Vector2 boardcoords = Board.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);
|
||||
|
||||
// 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);
|
||||
GameLogic.MakeMove(boardcoords, numberofspaces, whitespaces);
|
||||
}
|
||||
|
||||
// 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)
|
||||
else
|
||||
{
|
||||
Vector2 temp;
|
||||
temp.x = (i*2)%11;
|
||||
temp.y = 0;
|
||||
Debug.Log("The game is over.");
|
||||
}
|
||||
}
|
||||
|
||||
switch(i)
|
||||
public void CheckGameOver()
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
return temp;
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
temp.y = 1;
|
||||
return temp;
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 16:
|
||||
temp.y = 2;
|
||||
return temp;
|
||||
case 17:
|
||||
case 18:
|
||||
case 19:
|
||||
case 20:
|
||||
case 21:
|
||||
temp.y = 3;
|
||||
return temp;
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 26:
|
||||
case 27:
|
||||
temp.y = 4;
|
||||
return temp;
|
||||
case 28:
|
||||
case 29:
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
temp.y = 5;
|
||||
return temp;
|
||||
case 33:
|
||||
case 34:
|
||||
case 35:
|
||||
case 36:
|
||||
case 37:
|
||||
case 38:
|
||||
temp.y = 6;
|
||||
return temp;
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 43:
|
||||
temp.y = 7;
|
||||
return temp;
|
||||
case 44:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 48:
|
||||
case 49:
|
||||
temp.y = 8;
|
||||
return temp;
|
||||
case 50:
|
||||
case 51:
|
||||
case 52:
|
||||
case 53:
|
||||
case 54:
|
||||
temp.y = 9;
|
||||
return temp;
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
case 59:
|
||||
case 60:
|
||||
temp.y = 10;
|
||||
return temp;
|
||||
default:
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
int turn = GameLogic.GetTurn();
|
||||
int turnlimit = GameLogic.GetTurnLimit();
|
||||
|
||||
// Convert a given set of board coordinates to the corresponding whitespaces[] array index.
|
||||
public static int ConvertImageIndex(Vector2 bc)
|
||||
if(turn > turnlimit)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
switch(Mathf.RoundToInt(bc.y))
|
||||
if(!gameoverobjects.activeSelf)
|
||||
{
|
||||
case 0:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
break;
|
||||
case 1:
|
||||
i = (Mathf.RoundToInt(bc.x))/2;
|
||||
i += 5;
|
||||
break;
|
||||
case 2:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
i += 11;
|
||||
break;
|
||||
case 3:
|
||||
i = (Mathf.RoundToInt(bc.x))/2;
|
||||
i += 16;
|
||||
break;
|
||||
case 4:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
i += 22;
|
||||
break;
|
||||
case 5:
|
||||
i = (Mathf.RoundToInt(bc.x))/2;
|
||||
i += 27;
|
||||
break;
|
||||
case 6:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
i += 33;
|
||||
break;
|
||||
case 7:
|
||||
i = (Mathf.RoundToInt(bc.x))/2;
|
||||
i += 38;
|
||||
break;
|
||||
case 8:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
i += 44;
|
||||
break;
|
||||
case 9:
|
||||
i = (Mathf.RoundToInt(bc.x))/2;
|
||||
i += 49;
|
||||
break;
|
||||
case 10:
|
||||
i = (Mathf.RoundToInt(bc.x) - 1)/2;
|
||||
i += 55;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
gameoverobjects.SetActive(true);
|
||||
}
|
||||
Board.EndGame();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(gameoverobjects.activeSelf)
|
||||
{
|
||||
gameoverobjects.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,245 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
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();
|
||||
}
|
||||
}
|
23
Angels and Demons/Assets/Scripts/SceneLoader.cs
Normal file
23
Angels and Demons/Assets/Scripts/SceneLoader.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using AngelsDemons;
|
||||
|
||||
public class SceneLoader : MonoBehaviour
|
||||
{
|
||||
public void StartGame()
|
||||
{
|
||||
SceneManager.LoadScene("BoardScene");
|
||||
}
|
||||
|
||||
public void ExitGame()
|
||||
{
|
||||
SceneManager.LoadScene("Main");
|
||||
}
|
||||
|
||||
public void RestartGame()
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 923eab5932fe2482e8c5b73ca1e5b0b4
|
||||
guid: bc269e21b79164282ab2daa2c07af210
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
Binary file not shown.
Reference in a new issue