Changeset 2634 for 2010


Ignore:
Timestamp:
2011-12-10 15:50:27 (8 years ago)
Author:
hniemi
Message:

Lisätty alkuvalikot ja eventti voittamiselle. Voittaminen on kivaa.

Location:
2010/23/hniemi/BlockPusher/Blockpusher/Blockpusher
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2010/23/hniemi/BlockPusher/Blockpusher/Blockpusher/BlockLevel.cs

    r2633 r2634  
    66using Jypeli; 
    77 
     8/// <summary> 
     9/// Class that holds information of level and players location 
     10/// Also handles movement of player. 
     11/// </summary> 
    812public class BlockLevel 
    913{ 
     
    1620    private int playerY; 
    1721 
     22    public delegate void GameEvent(); 
     23    public event GameEvent Victory; 
     24 
     25    /// <summary> 
     26    /// Height of the playfield 
     27    /// </summary> 
    1828    public int PlayfieldHeight { get { return playfield.GetLength(1); } } 
     29    /// <summary> 
     30    /// Width of the playfield 
     31    /// </summary> 
    1932    public int PlayfieldWidth { get { return playfield.GetLength(0); } } 
    2033 
     
    120133            if (!(item.Type == BlockType.SatisfiedGoalZone)) return false; 
    121134        } 
     135        if (Victory != null) Victory(); 
    122136        return true; 
    123137    } 
     
    136150    } 
    137151 
     152    /// <summary> 
     153    /// Creates playfield from given list of strings 
     154    /// </summary> 
     155    /// <param name="level"></param> 
    138156    public void CreateField(List<string> level) 
    139157    { 
  • 2010/23/hniemi/BlockPusher/Blockpusher/Blockpusher/Blockpusher.cs

    r2633 r2634  
    2121                                 {"xxxxxxxxx", 
    2222                                  "x  x  xmx", 
    23                                   "xs p  xbx", 
     23                                  "xb p  xbx", 
    2424                                  "xm x    x", 
    2525                                  "x  xxxxxx", 
     
    2727                                  "xxxxxxxxx"}); 
    2828 
     29    /// <summary> 
     30    /// Starts the game 
     31    /// </summary> 
    2932    public override void Begin() 
    3033    { 
    31         PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    32         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     34        Menu(); 
    3335 
     36 
     37    } 
     38 
     39    public void NewGame()  
     40    { 
     41        ClearAll(); 
    3442        currentLevel = new BlockLevel(this); 
     43        currentLevel.Victory += Victory; 
    3544        currentLevel.CreateField(testLevel); 
    3645        SetControls(); 
    3746    } 
    3847 
     48    /// <summary> 
     49    /// Eventhandler for victory 
     50    /// </summary> 
     51    public void Victory() 
     52    { 
     53        IsMouseVisible = true; 
     54        MultiSelectWindow w = new MultiSelectWindow("Conratulations! Do you want to:", new String[] { "Retry", "Next Level", "Main menu" }); 
     55        w.AddItemHandler(2, Menu); 
     56        Add(w); 
     57    } 
    3958 
     59    /// <summary> 
     60    /// Creates startmenu for game 
     61    /// </summary> 
     62    public void Menu()  
     63    { 
     64        ClearAll(); 
     65        IsMouseVisible = true; 
     66        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
     67        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    4068 
     69        List<Tuple<Label,Handler>> labels = new List<Tuple<Label,Handler>>(); 
     70        labels.Add(new Tuple<Label,Handler>(new Label("New game"), NewGame)); 
     71        labels.Add(new Tuple<Label,Handler>(new Label("Quit"), ConfirmExit)); 
     72 
     73        for (int i = 0; i < labels.Count; i++) 
     74        { 
     75            labels[i].Item1.Y = -(i * 30); 
     76            Add(labels[i].Item1); 
     77            Mouse.Listen(MouseButton.Left, ButtonState.Pressed, labels[i].Item2, null); 
     78        } 
     79 
     80    } 
    4181    /// <summary> 
    4282    /// Reads lines from file 
Note: See TracChangeset for help on using the changeset viewer.