Added the word solving system.

Bug: After a player finishes the game, application will crash. Make sure winning scenario is handled.
Gameplay scene is gameplay_02.unity.
This commit is contained in:
RosimInc 2016-01-30 19:30:39 -05:00
parent 6ac3b0a2f1
commit 7c4cef3a49
14 changed files with 648 additions and 6 deletions

View File

@ -297,11 +297,9 @@ MonoBehaviour:
m_GameObject: {fileID: 1624102089}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cc18b8c2e3daedc418978ae09dd589d6, type: 3}
m_Script: {fileID: 11500000, guid: 0659941834f628445b182d075f37a958, type: 3}
m_Name:
m_EditorClassIdentifier:
numRows: 19
numColumns: 14
xScale: 1
yScale: 1
dimension: .680000007

View File

@ -0,0 +1,369 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
SceneSettings:
m_ObjectHideFlags: 0
m_PVSData:
m_PVSObjectsArray: []
m_PVSPortalsArray: []
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: .25
backfaceThreshold: 100
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 6
m_Fog: 0
m_FogColor: {r: .5, g: .5, b: .5, a: 1}
m_FogMode: 3
m_FogDensity: .00999999978
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: .211999997, g: .226999998, b: .259000003, a: 1}
m_AmbientEquatorColor: {r: .114, g: .125, b: .133000001, a: 1}
m_AmbientGroundColor: {r: .0469999984, g: .0430000015, b: .0350000001, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: .5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 5
m_GIWorkflowMode: 1
m_LightmapsMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 3
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AOMaxDistance: 1
m_Padding: 2
m_CompAOExponent: 0
m_LightmapParameters: {fileID: 0}
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherRayCount: 1024
m_ReflectionCompression: 2
m_LightmapSnapshot: {fileID: 0}
m_RuntimeCPUUsage: 25
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentRadius: .5
agentHeight: 2
agentSlope: 45
agentClimb: .400000006
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
accuratePlacement: 0
minRegionArea: 2
cellSize: .166666672
manualCellSize: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &132542564
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 132542565}
- 33: {fileID: 132542568}
- 136: {fileID: 132542567}
- 23: {fileID: 132542566}
- 114: {fileID: 132542569}
- 54: {fileID: 132542570}
m_Layer: 0
m_Name: Capsule
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &132542565
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 132542564}
m_LocalRotation: {x: .707106829, y: 0, z: 0, w: .707106709}
m_LocalPosition: {x: 0, y: 0, z: -.5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1624102091}
m_RootOrder: 0
--- !u!23 &132542566
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 132542564}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_SubsetIndices:
m_StaticBatchRoot: {fileID: 0}
m_UseLightProbes: 1
m_ReflectionProbeUsage: 1
m_ProbeAnchor: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_ImportantGI: 0
m_AutoUVMaxDistance: .5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!136 &132542567
CapsuleCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 132542564}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Radius: .5
m_Height: 2
m_Direction: 1
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &132542568
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 132542564}
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &132542569
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 132542564}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b33743cc22e241142886a7758ce5dc74, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!54 &132542570
Rigidbody:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 132542564}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: .0500000007
m_UseGravity: 0
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &478275693
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 478275698}
- 20: {fileID: 478275697}
- 92: {fileID: 478275696}
- 124: {fileID: 478275695}
- 81: {fileID: 478275694}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &478275694
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 478275693}
m_Enabled: 1
--- !u!124 &478275695
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 478275693}
m_Enabled: 1
--- !u!92 &478275696
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 478275693}
m_Enabled: 1
--- !u!20 &478275697
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 478275693}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: .192156866, g: .301960796, b: .474509805, a: .0196078438}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: .300000012
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: .0219999999
m_StereoMirrorMode: 0
--- !u!4 &478275698
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 478275693}
m_LocalRotation: {x: .707106829, y: 0, z: 0, w: .707106709}
m_LocalPosition: {x: 0, y: 10, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!1 &1624102089
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 1624102091}
- 114: {fileID: 1624102090}
m_Layer: 0
m_Name: Level
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1624102090
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1624102089}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0659941834f628445b182d075f37a958, type: 3}
m_Name:
m_EditorClassIdentifier:
xScale: 1
yScale: 1
dimension: .680000007
hexagon: {fileID: 118646, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
--- !u!4 &1624102091
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1624102089}
m_LocalRotation: {x: .707106829, y: 0, z: 0, w: .707106709}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 132542565}
m_Father: {fileID: 0}
m_RootOrder: 1
--- !u!1001 &1944944027
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 401170, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 401170, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 401170, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 401170, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 401170, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 401170, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 401170, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 401170, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 118646, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
propertyPath: m_Name
value: RuneTile
objectReference: {fileID: 0}
- target: {fileID: 118646, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 950731e814d3ade4c91c128681c35ce2, type: 2}
m_IsPrefabParent: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 170a7a26a65a7284492ad6244159d220
timeCreated: 1454198828
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,25 @@
using UnityEngine;
using System.Collections;
public class GameState {
private static GameState instance = new GameState();
public static GameState Instance { get { return instance; } }
public LevelManager currentLevel = null;
public int numPlayers = 3;
public int wordLength = 5;
public int numRows = 6;
public int numColumns = 5;
public Player[] players;
private GameState()
{
players = new Player[numPlayers];
for (int i = 0; i < numPlayers; i++)
{
players[i] = new Player(i+1);
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f539477928eb73f4ab03e27410bd046a
timeCreated: 1454194591
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -6,7 +6,7 @@ public class HexSpawner : MonoBehaviour {
public int numRows = 4;
public int numColumns = 3;
public float xScale = 1f;
public float yScale = 0.8f;
public float yScale = 1f;
public float dimension = 0.6f;
public GameObject hexagon;
private float ratio = Mathf.Sqrt(1 - 0.5f * 0.5f);

View File

@ -0,0 +1,89 @@
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
public class LevelManager : MonoBehaviour {
public float xScale = 1f;
public float yScale = 0.8f;
public float dimension = 0.6f;
public GameObject hexagon;
private float ratio = Mathf.Sqrt(1 - 0.5f * 0.5f);
private GameState state;
private List<RuneBehaviour> runes = new List<RuneBehaviour>();
// Use this for initialization
void Start()
{
state = GameState.Instance;
state.currentLevel = this;
int numColumns = state.numColumns;
int numRows = state.numRows;
int[] runeNums = new int[numColumns * numRows];
for (int i = 0; i < numRows * numColumns; i++)
{
runeNums[i] = i % 26;
}
System.Random rnd = new System.Random();
var randomNums = runeNums.OrderBy(r => rnd.Next())
.ToArray();
GameObject hex;
RuneBehaviour rune;
int index = 0;
float xOffset = numColumns * 1.5f * dimension / 2f;
float yOffset = numRows * 1f * ratio * dimension / 2f;
for (int row = 0; row < numRows; row++)
{
for (int col = 0; col < numColumns; col++)
{
hex = GameObject.Instantiate(hexagon) as GameObject;
hex.transform.parent = transform;
hex.transform.localScale = new Vector3(xScale, yScale, 1f);
hex.transform.localPosition = new Vector3(
(3f * dimension * col + 1.5f * dimension * (row % 2)) * xScale - xOffset,
(row * ratio * dimension) * yScale - yOffset, 0f);
hex.transform.localRotation = Quaternion.identity;
rune = hex.GetComponent<RuneBehaviour>();
rune.SetSymbol(randomNums[index++]);
runes.Add(rune);
}
}
int numLetters = state.wordLength;
foreach (Player player in state.players)
{
player.SetWord(WordGen.GetWord(numLetters));
}
}
public void PressTile(int letterNum)
{
foreach (Player player in state.players)
{
if (player.hasNextLetter(letterNum))
{
//Do something
if (player.hasWon())
{
Debug.Log("Player won!");
//Yeah maybe don't quit at this point...
Application.Quit();
}
}
}
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0659941834f628445b182d075f37a958
timeCreated: 1454193444
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

52
Assets/scripts/Player.cs Normal file
View File

@ -0,0 +1,52 @@
using UnityEngine;
public class Player {
public int num;
public int[] letters;
public int index = 0;
public int score = 0;
public Player(int num)
{
this.num = num;
}
public void SetWord(string str)
{
letters = new int[str.Length];
for (int i = 0; i < str.Length; i++)
{
letters[i] = (int)(str[i] - 'A');
}
Debug.Log("Player " + num + " has:");
foreach (int i in letters)
{
Debug.Log(i);
}
}
public void SetWord(int[] letters)
{
this.letters = letters;
}
public bool hasNextLetter(int letterNum)
{
if (letters[index] == letterNum)
{
index++;
Debug.Log("Player " + num + " uncovered their " + index + "th letter");
return true;
}
else
{
return false;
}
}
public bool hasWon()
{
return index >= letters.Length;
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 61ea13fb91e5aaa4eae76dc2195896c2
timeCreated: 1454198988
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -28,6 +28,6 @@ public class PlayerControllerSR : MonoBehaviour {
void OnTriggerEnter(Collider col)
{
Debug.Log(col.gameObject.GetComponent<RuneBehaviour>().letterNum);
//Remove this: Debug.Log(col.gameObject.GetComponent<RuneBehaviour>().letterNum);
}
}

View File

@ -36,13 +36,13 @@ public class RuneBehaviour : MonoBehaviour {
if (col.gameObject.tag == "Player")
{
lightState = 1f;
GameState.Instance.currentLevel.PressTile(letterNum);
}
}
public void SetSymbol(int letterNum)
{
this.letterNum = letterNum;
Debug.Log("runic_" + ('a' + letterNum));
symbol.sprite = Resources.Load<Sprite>("runic_" + (char)('a' + letterNum));
}
}

53
Assets/scripts/WordGen.cs Normal file
View File

@ -0,0 +1,53 @@
using UnityEngine;
using System.Collections;
public class WordGen : MonoBehaviour
{
static int prev;
static int modif;
static int tempCode;
static int[] cCodes;
static int[] codeChance;
static string finalWord;
static bool allowLetter;
public static string GetWord(int numLetters)
{
finalWord = "";
prev = -1;
modif = 0;
cCodes = new int[numLetters];
codeChance = new int[26];
for(int i = 0; i < numLetters; i++)
{
allowLetter = false;
foreach (int c in codeChance)
{
codeChance[c] = 1;
}
modif = Random.Range(0, 26) % 26;
if(i > 0)
for(int a = i - 1; a >= 0; a--)
for(int x = 0; x < 26; x++)
if(cCodes[a] - 65 == x)
codeChance[x] *= 2;
while(!allowLetter)
{
if(Random.Range(0, codeChance[modif]) == 0 && modif != prev)
allowLetter = true;
else
modif = Random.Range(0, 26);
}
prev = modif;
cCodes[i] = modif + 65;
finalWord += (char)cCodes[i];
}
return finalWord;
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 98721969de1456943a948047878e488c
timeCreated: 1454179524
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: