Example #1
0
    /// <summary>
    /// Get a list Of character Descriptors (typically only one but could be two). Returns Empty list if a problem
    /// </summary>
    /// <returns></returns>
    public List <string> GetCharacterDescriptors()
    {
        List <string>       listOfDescriptors = new List <string>();
        int                 rnd        = UnityEngine.Random.Range(0, 100);
        CharacterDescriptor descriptor = arrayOfDescriptorsLookup[rnd];

        //check roll again
        if (descriptor.isRollAgain == true)
        {
            int counter = 0;
            do
            {
                rnd        = Random.Range(0, 100);
                descriptor = arrayOfDescriptorsLookup[rnd];
                if (descriptor.isRollAgain == false)
                {
                    listOfDescriptors.Add(descriptor.tag);
                    counter++;
                }
            }while (counter < 2);
        }
        else
        {
            listOfDescriptors.Add(descriptor.tag);
        }
        return(listOfDescriptors);
    }
Example #2
0
    public void SelectLizard(bool isActive)
    {
        if (isActive)
        {
            if (this.firstUserSelection == null)
            {
                this.firstUserSelection = Characters.Lizard;
                this.NotificationService.Value.ShowShortMessage($"First player selectecs {this.firstUserSelection.Name}", false);
            }
            else if (this.secondUserSelection == null)
            {
                this.secondUserSelection = Characters.Lizard;
                this.NotificationService.Value.ShowShortMessage($"Second player selectecs {this.secondUserSelection.Name}", false);
            }
        }
        else
        {
            if (this.firstUserSelection == Characters.Lizard)
            {
                this.firstUserSelection = null;
            }

            if (this.secondUserSelection == Characters.Lizard)
            {
                this.secondUserSelection = null;
            }
        }
    }
        public void ShouldRemoveTopCharacterFromUserWordsOnBackspace()
        {
            var descriptor = new CharacterDescriptor("r", CharacterStatus.Incorrect);

            _mockWord.Setup(x => x[It.IsAny <int>()]).Returns(descriptor);
            _wordStackMock.Setup(x => x.Top).Returns(_mockWord.Object);
            _wordStackMock.Setup(x => x.Top.CharCount).Returns(4);
            var target = CreateTarget(_wordStackMock.Object, _messengerMock.Object, _markovChainGeneratorMock.Object);
            var res    = target.HandleBackspace();

            _wordStackMock.Verify(x => x.Top);
            _wordStackMock.Verify(x => x.Top.CharCount);
            Assert.AreEqual(CharacterStatus.Incorrect, res);
        }
Example #4
0
    private void OnEnable()
    {
        Observable.NextFrame().Subscribe(_ => Selectable.allSelectables.First().Select());

        this.UserInputMapper.Value.FirstUserInputProvider.Horizontal
        .Skip(0)
        .Where(o => o <-0.5f || o> 0.5f)
        .Select(o => o < 0 ? Characters.Lizard : Characters.Hedgehog)
        .Subscribe(o =>
        {
            this.firstUserSelection = o;
            this.NotificationService.Value.ShowShortMessage($"First player selectecs {o.Name}", false);
        })
        .AddTo(this);

        this.UserInputMapper.Value.SecondUserInputProvider.Horizontal
        .Skip(0)
        .Where(o => o <-0.5f || o> 0.5f)
        .Select(o => o < 0 ? Characters.Lizard : Characters.Hedgehog)
        .Subscribe(o =>
        {
            this.secondUserSelection = o;
            this.NotificationService.Value.ShowShortMessage($"Second player selectecs {o.Name}", false);
        })
        .AddTo(this);

        this.UserInputMapper.Value.FirstUserInputProvider.Start
        .Merge(this.UserInputMapper.Value.SecondUserInputProvider.Start)
        .HoldFor(TimeSpan.FromSeconds(3))
        .Subscribe(async _ =>
        {
            if (this.firstUserSelection is null && this.secondUserSelection is null)
            {
                this.NotificationService.Value.ShowShortMessage("Selecte some character", false);
                return;
            }

            if (this.firstUserSelection == this.secondUserSelection)
            {
                this.NotificationService.Value.ShowShortMessage("Same character are not allowed", false);
                return;
            }

            this.selectedCharacters = new[] { this.firstUserSelection, this.secondUserSelection }.Where(o => o != null).ToArray();
            await this.GameController.Value.StartNewGameAsync(this.selectedCharacters);
        })
        .AddTo(this);
    }
Example #5
0
    private void Awake()
    {
        desc   = TableLocator.CharacterTable.Find(id);
        skills = new List <Skill> ();

        foreach (var skillGroupDesc in desc.SkillGroups)
        {
            if (skillLevel > 0)
            {
                var skill = new Skill(skillGroupDesc.SkillId, skillLevel);
                skills.Add(skill);
            }
            else
            {
                Debug.Log("skill level is zero");
            }
        }
    }
Example #6
0
        public void AddPlayer(CharacterDescriptor characterDescriptor, Vector3 localPosition)
        {
            var root = this.EntitiesStorage.Value.Root.transform;
            var characterTemplate = Resources.Load <GameObject>(characterDescriptor.Path);

            var player = characterTemplate.Spawn(localPosition, root);

            if (!this.FirstPlayer)
            {
                player.gameObject.AddComponent <FirstPlayer>();
            }
            else
            {
                player.gameObject.AddComponent <SecondPlayer>();
            }

            this.UserInputMapper.Value.Bootstrap();
        }
Example #7
0
        /// <summary>
        /// Character recognition worker function (run in worker thread).
        /// </summary>
        private void recognize(object ctxt)
        {
            bool error = false;

            char[]         matches = null;
            StrokesMatcher matcher = null;

            try
            {
                WrittenCharacter    wc = ctxt as WrittenCharacter;
                CharacterDescriptor id = wc.BuildCharacterDescriptor();
                strokesData.Reset();
                matcher = new StrokesMatcher(id,
                                             searchScript != SearchScript.Simplified,
                                             searchScript != SearchScript.Traditional,
                                             Magic.HanziLookupLooseness,
                                             Magic.HanziLookupNumResults,
                                             strokesData);
                int matcherCount;
                lock (runningMatchers)
                {
                    runningMatchers.Add(matcher);
                    matcherCount = runningMatchers.Count;
                }
                while (matcher.IsRunning && matcherCount > 1)
                {
                    Thread.Sleep(50);
                    lock (runningMatchers) { matcherCount = runningMatchers.Count; }
                }
                if (!matcher.IsRunning)
                {
                    lock (runningMatchers) { runningMatchers.Remove(matcher); matcher = null; }
                    return;
                }
                matches = matcher.DoMatching();
                if (matches == null)
                {
                    return;
                }
            }
            catch (DiagnosticException dex)
            {
                // Errors not handled locally are only for diagnostics
                // We actually handle every real-life exception locally here.
                if (!dex.HandleLocally)
                {
                    throw;
                }
                error = true;
                AppErrorLogger.Instance.LogException(dex, false);
            }
            catch (Exception ex)
            {
                error = true;
                AppErrorLogger.Instance.LogException(ex, false);
            }
            finally
            {
                if (matcher != null)
                {
                    lock (runningMatchers) { runningMatchers.Remove(matcher); }
                }
            }
            InvokeOnForm((MethodInvoker) delegate
            {
                if (error)
                {
                    ctrlCharPicker.SetError();
                }
                else
                {
                    ctrlCharPicker.SetItems(matches);
                }
            });
        }
Example #8
0
		private static void ParseText(string expression, out ExpressionToken[] tokens, out string[] sources)
		{
			var foundTokens = new List<ExpressionToken>();
			var foundSources = new List<string>();

			int currentSpanStart = 0;
			int currentSpanLength = 0;
			var currentSpanClass = SpanClassifier.None;
			var characterClass = SpanClassifier.None;

			var lastToken = ExpressionToken.None;

			var headCharacter = CharacterDescriptor.Start(expression);
			var lastCharacter = headCharacter;

			while (true)
			{
				headCharacter = headCharacter.Next();

				if (headCharacter.Index == -2 && lastCharacter.Index == -2)
				{
					break;
				}

				characterClass = headCharacter.Type;

				if (headCharacter.Character == '-' && (lastToken.IsOperator || lastToken.Operation == SyntaxTokenKind.None))
				{
					characterClass = SpanClassifier.Numeric;
				}

				if (characterClass != currentSpanClass || characterClass == SpanClassifier.Structure)
				{
					if (currentSpanClass == SpanClassifier.None && characterClass != SpanClassifier.Structure
						|| currentSpanClass == SpanClassifier.Numeric
						&& currentSpanLength == 1
						&& lastCharacter.Character == '-')
					{
						currentSpanClass = characterClass;
					}
					else
					{
						switch (currentSpanClass)
						{
							case SpanClassifier.String:

								bool isNegative = expression[currentSpanStart] == '-';
								int offset = isNegative ? 1 : 0;
#if USE_SPANS
								var spanContent = expression.AsSpan().Slice(currentSpanStart, currentSpanLength));
#else
								string spanContent = expression.Substring(currentSpanStart + offset, currentSpanLength - offset);
#endif

								if (spanContent.Equals("true", StringComparison.OrdinalIgnoreCase))
								{
									lastToken = ExpressionToken.StaticValue(new MathValue(true));
									foundTokens.Add(lastToken);
								}
								else if (spanContent.Equals("false", StringComparison.OrdinalIgnoreCase))
								{
									lastToken = ExpressionToken.StaticValue(new MathValue(false));
									foundTokens.Add(lastToken);
								}
								else
								{
									int sourceIndex = foundSources.IndexOf(spanContent);
									if (sourceIndex == -1)
									{
										sourceIndex = foundSources.Count;
										foundSources.Add(spanContent);
									}

									lastToken = ExpressionToken.ReadSource((byte)sourceIndex, isNegative);
									foundTokens.Add(lastToken);
								}
								break;

							case SpanClassifier.Numeric:
#if USE_SPANS
								spanContent = expression.AsSpan().Slice(currentSpanStart, currentSpanLength));
#else
								spanContent = expression.Substring(currentSpanStart, currentSpanLength);
#endif

								float numericFloat = float.Parse(spanContent);

								lastToken = ExpressionToken.StaticValue(new MathValue(numericFloat, false));
								foundTokens.Add(lastToken);

								break;

							case SpanClassifier.Operator:
							case SpanClassifier.Structure:
								if (currentSpanLength == 1)
								{
									lastToken = ExpressionToken.Operator(lastCharacter.SelfTokenKind);
								}
								else
								{
									spanContent = expression.Substring(currentSpanStart, currentSpanLength);

									SyntaxTokenKind operation;
									switch (spanContent)
									{
										case "==":
											operation = SyntaxTokenKind.Equal;
											break;
										case "!=":
											operation = SyntaxTokenKind.NotEqual;
											break;
										case ">=":
											operation = SyntaxTokenKind.GreaterThanOrEqual;
											break;
										case "<=":
											operation = SyntaxTokenKind.LessThanOrEqual;
											break;
										case "&&":
											operation = SyntaxTokenKind.And;
											break;
										case "||":
											operation = SyntaxTokenKind.Or;
											break;
										default:
											operation = SyntaxTokenKind.None;
											break;
									}
									lastToken = ExpressionToken.Operator(operation);
								}
								if (lastToken.Operation == SyntaxTokenKind.None)
								{
									throw new InvalidOperationException(string.Format("Unrecognised Operator Sequence \"{0}\"", expression.Substring(currentSpanStart, currentSpanLength)));
								}
								foundTokens.Add(lastToken);
								break;
						}

						currentSpanStart = headCharacter.Index;
						currentSpanLength = 0;
						currentSpanClass = characterClass;
					}
				}

				currentSpanLength++;

				lastCharacter = headCharacter;
			}

			tokens = foundTokens.ToArray();
			sources = foundSources.ToArray();
		}
Example #9
0
 private void loadPortrait(string portraitName)
 {
     portrait = portraitName == null? null: Imager.getPortrait(CharacterDescriptor.nameToType(portraitName));
 }