/Hnefatafl/Controllers/SelectVariationController.cs
https://bitbucket.org/trisi/hnefatafl-monotouch · C# · 150 lines · 129 code · 21 blank · 0 comment · 14 complexity · 930301fe9034f7fbad5457c013eb1702 MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using MonoTouch.Foundation;
- using MonoTouch.UIKit;
- using MonoTouch.GameKit;
- using Core;
- namespace Hnefatafl
- {
- public class SelectVariationController : UIViewController
- {
- SelectVariationView view;
- GameController gameController;
- Game game;
- GameType gameType;
- NSUserDefaults defaults;
- bool isTablet;
- public SelectVariationController (GameType gameType)
- {
- this.gameType = gameType;
- defaults = NSUserDefaults.StandardUserDefaults;
- isTablet = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad;
- }
- public void btnHnefatafl_Pushed ()
- {
- game = new Game (Variation.Hnefatafl, view.swWeak.On, isTablet);
- switch (gameType) {
- case GameType.Asynchronous:
- GCHelper.findMatchWithViewController (this, Variation.Hnefatafl, false, true,
- view.swWeak.On);
- break;
- case GameType.PassNPlay:
- if (defaults.DataForKey ("pnpHnefatafl") != null)
- game = (Game) GCHelper.ByteArrayToObject (defaults.DataForKey ("pnpHnefatafl").
- ToArray ());
- addSubview ();
- break;
- default:
- break;
- }
- }
- public void btnArdRi_Pushed ()
- {
- game = new Game (Variation.ArdRi, view.swWeak.On, isTablet);
-
- switch (gameType) {
- case GameType.Asynchronous:
- GCHelper.findMatchWithViewController (this, Variation.Hnefatafl, true, true,
- view.swWeak.On);
- break;
- case GameType.PassNPlay:
- if (defaults.DataForKey ("pnpArdRi") != null)
- game = (Game) GCHelper.ByteArrayToObject (defaults.DataForKey ("pnpArdRi").
- ToArray ());
- addSubview ();
- break;
- default:
- break;
- }
- }
- public void btnTablut_Pushed ()
- {
- game = new Game (Variation.Tablut, view.swWeak.On, isTablet);
-
- switch (gameType) {
- case GameType.Asynchronous:
- GCHelper.findMatchWithViewController (this, Variation.Hnefatafl, false, true,
- view.swWeak.On);
- break;
- case GameType.PassNPlay:
- if (defaults.DataForKey ("pnpTablut") != null)
- game = (Game) GCHelper.ByteArrayToObject (defaults.DataForKey ("pnpTablut").
- ToArray ());
- addSubview ();
- break;
- default:
- break;
- }
- }
- public void btnMenu_Pushed ()
- {
- NavigationController.PopViewControllerAnimated (true);
- }
- void addSubview ()
- {
- if (gameType == GameType.PassNPlay)
- gameController = new PassNPlayController (game);
- else
- gameController = new OnlineController (game);
- NavigationController.PushViewController (gameController, true);
- }
- public void EnterNewGame (GKTurnBasedMatch match)
- {
- GCHelper.LoadPlayersForCurrentMatch ();
- addSubview ();
- }
- public void TakeTurn (GKTurnBasedMatch match)
- {
- byte[] dataBytes = match.MatchData.ToArray ();
- byte[] decompressed = GCHelper.Decompress (dataBytes);
- game = (Game) GCHelper.ByteArrayToObject (decompressed);
- if (game != null) {
- GCHelper.LoadPlayersForCurrentMatch ();
- addSubview ();
- }
- }
- public void SendNotice (string notice, GKTurnBasedMatch match)
- {
- GKNotificationBanner.Show (notice, match.Message, null);
- }
- public override void LoadView()
- {
- view = new SelectVariationView ();
- view.btnHnefatafl_Pushed = btnHnefatafl_Pushed;
- view.btnArdRi_Pushed = btnArdRi_Pushed;
- view.btnTablut_Pushed = btnTablut_Pushed;
- view.btnMenu_Pushed = btnMenu_Pushed;
- View = view;
- }
-
- public override void ViewWillAppear (bool animated)
- {
- NavigationController.NavigationBar.Hidden = true;
- }
- public override void ViewDidLoad ()
- {
- GCHelper.EnterNewGame = EnterNewGame;
- GCHelper.TakeTurn = TakeTurn;
- GCHelper.SendNotice = SendNotice;
- }
- }
- }