SymbolManager.cs :  » Game » Balder » SlotMachine » Objects » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » Balder 
Balder » SlotMachine » Objects » SymbolManager.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using System.Linq;

namespace SlotMachine.Objects{
  public class SymbolCombination : IComparable
  {
    public SymbolType LeftSymbol { get; set; }
    public SymbolType CenterSymbol { get; set; }
    public SymbolType RightSymbol { get; set; }

    public int Score { get; set; }

    #region IComparable Members

    public int CompareTo(object obj)
    {
      return -((SymbolCombination)obj).Score.CompareTo(this.Score);
    }

    #endregion
  }

  public class SymbolManager 
  {
    public static readonly SymbolManager Instance = new SymbolManager();

    private SymbolCombination[] _combinations = new SymbolCombination[] {
      #region Combinations
      new SymbolCombination() 
      { 
        LeftSymbol = SymbolType.Apple,
        CenterSymbol = SymbolType.Nothing,
        RightSymbol = SymbolType.Nothing,
        Score = 10
      },

      new SymbolCombination() 
      { 
        LeftSymbol = SymbolType.Apple,
        CenterSymbol = SymbolType.Apple,
        RightSymbol = SymbolType.Nothing,
        Score = 20
      },

      new SymbolCombination() 
      { 
        LeftSymbol = SymbolType.Apple,
        CenterSymbol = SymbolType.Apple,
        RightSymbol = SymbolType.Apple,
        Score = 30
      },

      new SymbolCombination() 
      { 
        LeftSymbol = SymbolType.Banana,
        CenterSymbol = SymbolType.Banana,
        RightSymbol = SymbolType.Banana,
        Score = 50
      },

      new SymbolCombination() 
      { 
        LeftSymbol = SymbolType.Lemon,
        CenterSymbol = SymbolType.Lemon,
        RightSymbol = SymbolType.Lemon,
        Score = 100
      },

      new SymbolCombination() 
      { 
        LeftSymbol = SymbolType.Pineapple,
        CenterSymbol = SymbolType.Pineapple,
        RightSymbol = SymbolType.Pineapple,
        Score = 200
      },

      new SymbolCombination() 
      { 
        LeftSymbol = SymbolType.Bell,
        CenterSymbol = SymbolType.Bell,
        RightSymbol = SymbolType.Bell,
        Score = 500
      },

      new SymbolCombination() 
      { 
        LeftSymbol = SymbolType.Goldbar,
        CenterSymbol = SymbolType.Goldbar,
        RightSymbol = SymbolType.Goldbar,
        Score = 1000
      }
      #endregion
    };

    private SymbolManager()
    {
    }


    public int CheckScore(Wheels wheels)
    {
      var combinations = from combination in this._combinations
                 orderby combination.Score descending
                 select combination;

      Wheel[] wheelsToCheck = new Wheel[] {
        wheels.LeftWheel,
        wheels.CenterWheel,
        wheels.RightWheel
      };

      SymbolType[] combinationSymbolTypes = new SymbolType[3];

      var sortedWheels = from wheel in wheelsToCheck
                 orderby wheel.Symbol.SymbolType
                 select wheel;

      foreach (var combination in combinations)
      {
        int combinationCount = 0;
        combinationSymbolTypes[0] = combination.LeftSymbol;
        combinationSymbolTypes[1] = combination.CenterSymbol;
        combinationSymbolTypes[2] = combination.RightSymbol;

        int combinationIndex = 0;
        foreach (var wheel in sortedWheels)
        {
          SymbolType combinationType = combinationSymbolTypes[combinationIndex];
          combinationIndex++;
          
          if (combinationType == SymbolType.Nothing ||
            wheel.Symbol.SymbolType == combinationType)
          {
            if (wheel.Symbol.SymbolType == combinationType)
            {
              wheel.GivesScore = true;
            }
            combinationCount++;
          }
        }

        if (combinationCount == 3)
        {
          return combination.Score;
        }
        else
        {
          foreach (Wheel wheel in wheelsToCheck)
          {
            wheel.GivesScore = false;
          }
        }
      }

      return 0;
    }


  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.