Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9607d9dfb9 | ||
|
|
e93d9d7c3f | ||
|
|
f0389d5cf4 | ||
|
|
758c86dcfc | ||
|
|
f7c17cba0d | ||
|
|
92564bf817 |
+1498
-222
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Buttons : MonoBehaviour
|
||||
{
|
||||
public Button buttonRestart1, buttonRestart2;
|
||||
|
||||
private bool restart1 = false, restart2 = false;
|
||||
|
||||
public void ButtonRestart1()
|
||||
{
|
||||
restart1 = !restart1;
|
||||
if (restart1)
|
||||
{
|
||||
buttonRestart1.GetComponent<Image>().color = new Color(.1f, .5f, .1f, .2f);
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonRestart1.GetComponent<Image>().color = new Color(.1f, .1f, .1f, .2f);
|
||||
}
|
||||
RestartRequest();
|
||||
}
|
||||
|
||||
public void ButtonRestart2()
|
||||
{
|
||||
restart2 = !restart2;
|
||||
if (restart2)
|
||||
{
|
||||
buttonRestart2.GetComponent<Image>().color = new Color(.1f, .5f, .1f, .2f);
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonRestart2.GetComponent<Image>().color = new Color(.1f, .1f, .1f, .2f);
|
||||
}
|
||||
RestartRequest();
|
||||
}
|
||||
|
||||
private void RestartRequest()
|
||||
{
|
||||
if (restart1 && restart2)
|
||||
{
|
||||
SceneManager.LoadScene(0, LoadSceneMode.Single);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65b66293cc480be4e8c0ff3534cf4834
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,15 +8,6 @@ public abstract class Character : MonoBehaviour
|
||||
|
||||
public abstract bool[,] GetValidMoves(Cell[,] cells, Game game);
|
||||
|
||||
protected bool IsPositionInGrid(int x, int y)
|
||||
{
|
||||
if (x < 0 || y < 0 || x > 7 || y > 7)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Teams
|
||||
|
||||
@@ -16,7 +16,6 @@ public class Game : MonoBehaviour
|
||||
|
||||
private Cell clickedCell = null;
|
||||
private List<Cell> validMovesList = new List<Cell>();
|
||||
|
||||
public bool isPaused = false;
|
||||
|
||||
private void Start()
|
||||
@@ -44,39 +43,10 @@ public class Game : MonoBehaviour
|
||||
//Check if left clicked
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
//Get the clicked cell
|
||||
Cell tempCell = GetCellOnPositionMouse(Input.mousePosition);
|
||||
|
||||
if (tempCell != null)
|
||||
if(areKilledCellsActive && (currentTeam == Teams.White && indexKilledCharacCellWhite == 0 || currentTeam == Teams.Black && indexKilledCharacCellBlack == 0) )
|
||||
{
|
||||
if (validMovesList.Contains(tempCell))
|
||||
{
|
||||
if (tempCell.connected != null)
|
||||
{
|
||||
if (tempCell.connected.team == Teams.White)
|
||||
{
|
||||
|
||||
tempCell.connected.gameObject.transform.position = killedCharacCellsWhite[indexKilledCharacCellWhite].gameObject.transform.position + Vector3.back;
|
||||
killedCharacCellsWhite[indexKilledCharacCellWhite].connected = tempCell.connected;
|
||||
indexKilledCharacCellWhite++;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempCell.connected.gameObject.transform.position = killedCharacCellsBlack[indexKilledCharacCellBlack].gameObject.transform.position + Vector3.back;
|
||||
killedCharacCellsBlack[indexKilledCharacCellBlack].connected = tempCell.connected;
|
||||
indexKilledCharacCellBlack++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
tempCell.connected = clickedCell.connected;
|
||||
tempCell.connected.gameObject.transform.position =
|
||||
(tempCell.gameObject.transform.position + Vector3.back);
|
||||
|
||||
clickedCell.connected = null;
|
||||
areKilledCellsActive = false;
|
||||
DeColorAllCells();
|
||||
validMovesList.Clear();
|
||||
|
||||
if (currentTeam == Teams.White)
|
||||
{
|
||||
currentTeam = Teams.Black;
|
||||
@@ -86,8 +56,115 @@ public class Game : MonoBehaviour
|
||||
currentTeam = Teams.White;
|
||||
}
|
||||
}
|
||||
|
||||
//Get the clicked cell
|
||||
Cell tempCell = GetCellOnPositionMouse(Input.mousePosition);
|
||||
|
||||
//check the clicked cell is valid
|
||||
if (tempCell != null)
|
||||
{
|
||||
|
||||
//check if player has the possibilty to revive a character and kill his pawn
|
||||
if (areKilledCellsActive)
|
||||
{
|
||||
//destroy the pawn
|
||||
Destroy(clickedCell.connected.gameObject);
|
||||
//connect the revived character to the pawns field
|
||||
clickedCell.connected = tempCell.connected;
|
||||
clickedCell.connected.gameObject.transform.position =
|
||||
clickedCell.gameObject.transform.position + Vector3.back;
|
||||
//change the team
|
||||
if (currentTeam == Teams.White)
|
||||
{
|
||||
currentTeam = Teams.Black;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentTeam = Teams.White;
|
||||
}
|
||||
|
||||
areKilledCellsActive = false;
|
||||
DeColorAllCells();
|
||||
clickedCell = null;
|
||||
}
|
||||
|
||||
//check if clicked cell is "a green field"
|
||||
if (validMovesList.Contains(tempCell))
|
||||
{
|
||||
//check if there's a others color character on the cell
|
||||
if (tempCell.connected != null)
|
||||
{
|
||||
if (tempCell.connected.team == Teams.White)
|
||||
{
|
||||
//remove the character from the game field
|
||||
|
||||
tempCell.connected.gameObject.transform.position =
|
||||
killedCharacCellsWhite[indexKilledCharacCellWhite].gameObject.transform
|
||||
.position +
|
||||
Vector3.back;
|
||||
killedCharacCellsWhite[indexKilledCharacCellWhite].connected = tempCell.connected;
|
||||
indexKilledCharacCellWhite++;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempCell.connected.gameObject.transform.position =
|
||||
killedCharacCellsBlack[indexKilledCharacCellBlack].gameObject.transform
|
||||
.position +
|
||||
Vector3.back;
|
||||
killedCharacCellsBlack[indexKilledCharacCellBlack].connected = tempCell.connected;
|
||||
indexKilledCharacCellBlack++;
|
||||
}
|
||||
}
|
||||
|
||||
tempCell.connected = clickedCell.connected;
|
||||
tempCell.connected.gameObject.transform.position =
|
||||
tempCell.gameObject.transform.position + Vector3.back;
|
||||
if (tempCell.connected.GetComponent<Pawn>() != null)
|
||||
{
|
||||
Pawn testPawn = tempCell.connected.GetComponent<Pawn>();
|
||||
|
||||
int endCellY;
|
||||
|
||||
if (testPawn.team == Teams.White)
|
||||
{
|
||||
endCellY = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
endCellY = 7;
|
||||
}
|
||||
|
||||
int x, y;
|
||||
|
||||
string nameX = tempCell.gameObject.name.Substring(7, 1);
|
||||
string nameY = tempCell.gameObject.name.Substring(5, 1);
|
||||
|
||||
x = int.Parse(nameX);
|
||||
y = int.Parse(nameY);
|
||||
|
||||
if (y == endCellY)
|
||||
{
|
||||
areKilledCellsActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
clickedCell.connected = null;
|
||||
DeColorAllCells();
|
||||
validMovesList.Clear();
|
||||
|
||||
if (!areKilledCellsActive)
|
||||
{
|
||||
if (currentTeam == Teams.White)
|
||||
{
|
||||
currentTeam = Teams.Black;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentTeam = Teams.White;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the clickedCell == tempCell, deselect the cell
|
||||
if (clickedCell == tempCell)
|
||||
{
|
||||
@@ -100,8 +177,9 @@ public class Game : MonoBehaviour
|
||||
{
|
||||
clickedCell = tempCell;
|
||||
ColorCellExclusive(clickedCell, new Color(.5f, .1f, .1f));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//check if there is a clicked cell
|
||||
@@ -212,7 +290,9 @@ public class Game : MonoBehaviour
|
||||
RaycastHit2D hit = Physics2D.Raycast(position, Vector3.forward);
|
||||
if (hit.collider != null)
|
||||
{
|
||||
if (ArrayContainsCell2D(hit.collider.gameObject.GetComponent<Cell>(), cells) || areKilledCellsActive)
|
||||
if (ArrayContainsCell2D(hit.collider.gameObject.GetComponent<Cell>(), cells) && !areKilledCellsActive||
|
||||
areKilledCellsActive && ArrayContainsCell1D(hit.collider.gameObject.GetComponent<Cell>(), killedCharacCellsWhite) ||
|
||||
areKilledCellsActive && ArrayContainsCell1D(hit.collider.gameObject.GetComponent<Cell>(), killedCharacCellsBlack))
|
||||
{
|
||||
result = hit.collider.gameObject.GetComponent<Cell>();
|
||||
}
|
||||
@@ -237,4 +317,17 @@ public class Game : MonoBehaviour
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ArrayContainsCell1D(Cell cell, Cell[] cells)
|
||||
{
|
||||
for (int i = 0; i < cells.Length; i++)
|
||||
{
|
||||
if (cells[i] == cell)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+7677
-1718
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,6 @@
|
||||
Base path: 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data', plugins path 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data/PlaybackEngines'
|
||||
Cmd: initializeCompiler
|
||||
|
||||
Unhandled exception: Protocol error - failed to read magic number (error -2147483644, transferred 0/4)
|
||||
|
||||
Quitting shader compiler process
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
Base path: 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data', plugins path 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data/PlaybackEngines'
|
||||
Cmd: initializeCompiler
|
||||
|
||||
Cmd: compileSnippet
|
||||
insize=3023 file=Assets/DefaultResourcesExtra/UI/UI/Default pass=Default cachingPP=1 ppOnly=0 stripLineD=0 buildPlatform=13 rsLen=0 pKW=UNITY_NO_DXT5nm UNITY_ENABLE_REFLECTION_BUFFERS UNITY_NO_CUBEMAP_ARRAY UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 SHADER_API_DESKTOP UNITY_HARDWARE_TIER3 UNITY_COLORSPACE_GAMMA UNITY_LIGHTMAP_DLDR_ENCODING uKW= dKW=UNITY_UI_CLIP_RECT UNITY_UI_ALPHACLIP UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_PBS_USE_BRDF3 UNITY_NO_FULL_STANDARD_SHADER UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHTMAP_FULL_HDR UNITY_VIRTUAL_TEXTURING UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_ASTC_NORMALMAP_ENCODING SHADER_API_GLES30 flags=0 lang=0 type=Vertex platform=d3d11 reqs=1 mask=6 start=49 ok=1 outsize=1338
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
Base path: 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data', plugins path 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data/PlaybackEngines'
|
||||
Cmd: initializeCompiler
|
||||
|
||||
Cmd: compileSnippet
|
||||
insize=3023 file=Assets/DefaultResourcesExtra/UI/UI/Default pass=Default cachingPP=1 ppOnly=0 stripLineD=0 buildPlatform=13 rsLen=0 pKW=UNITY_NO_DXT5nm UNITY_ENABLE_REFLECTION_BUFFERS UNITY_NO_CUBEMAP_ARRAY UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 SHADER_API_DESKTOP UNITY_HARDWARE_TIER3 UNITY_COLORSPACE_GAMMA UNITY_LIGHTMAP_DLDR_ENCODING uKW= dKW=UNITY_UI_CLIP_RECT UNITY_UI_ALPHACLIP UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_PBS_USE_BRDF3 UNITY_NO_FULL_STANDARD_SHADER UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHTMAP_FULL_HDR UNITY_VIRTUAL_TEXTURING UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_ASTC_NORMALMAP_ENCODING SHADER_API_GLES30 flags=0 lang=0 type=Fragment platform=d3d11 reqs=1 mask=6 start=49 ok=1 outsize=550
|
||||
|
||||
|
||||
@@ -1,2 +1,17 @@
|
||||
# Chess-Unity
|
||||
A simple version of a chess two player game for android devices
|
||||
A chess game for android and windows
|
||||
|
||||
Source code available in this directory: https://github.com/jonasbraus/Chess-Unity/tree/main/Chess%20Recode/Assets/Scripts
|
||||
|
||||
For Windows:
|
||||
|
||||
1. Download the following zip file and unpack it: https://github.com/jonasbraus/Chess-Unity/releases/download/Win/Chess.zip
|
||||
|
||||
2. Start the Chess.exe
|
||||
|
||||

|
||||
|
||||
3. (Play in fullscreen to see everything :))
|
||||
|
||||
For Android:
|
||||
|
||||
1. Just download and install the apk file: https://github.com/jonasbraus/Chess-Unity/releases/download/1.1/Chess.apk
|
||||
|
||||
Reference in New Issue
Block a user