Changeset 2636 for 2010


Ignore:
Timestamp:
2011-12-27 04:39:42 (8 years ago)
Author:
hniemi
Message:

Bugi korjattu, nyt tekee kloonit kentistä, eikä muokkaa alkuperäisiä.

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

Legend:

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

    r2635 r2636  
    208208    /// </summary> 
    209209    /// <param name="level"></param> 
    210     public void CreateField(List<string> level) 
     210    public void CreateField(IList<string> level) 
    211211    { 
    212212        int playfieldWidth = level[0].Length; 
     
    261261    /// </summary> 
    262262    /// <returns></returns> 
    263     public List<string> CurrentState()  
     263    public IList<string> CurrentState()  
    264264    { 
    265265        List<string> list = new List<string>(); 
     
    287287        playfield[playerX, playerY].Type = type; 
    288288    } 
     289 
     290    public BlockLevel Clone()  
     291    { 
     292        BlockLevel clone = new BlockLevel(game); 
     293        clone.CreateField(this.CurrentState()); 
     294 
     295        return clone; 
     296    } 
    289297} 
    290298 
  • 2010/23/hniemi/BlockPusher/Blockpusher/Blockpusher/Blockpusher.cs

    r2635 r2636  
    1010/// <summary> 
    1111/// Blockpusher-game 
     12///  
     13/// TODO: clones needed from levels 
    1214/// </summary> 
    1315public class Blockpusher : Game 
     
    1921    private readonly Color unsatisfyColor = Color.Red; 
    2022 
     23    private int currentLevelIndex = 0; 
    2124    private BlockLevel currentLevel; 
    2225    private List<BlockLevel> levels = new List<BlockLevel>(); 
    2326 
    2427    private bool gameSaved = false; 
    25     private List<string> savedLevel; 
     28    private IList<string> savedLevel; 
    2629 
    2730    private List<String> testLevel = new List<string>(new String[] 
     
    4649    /// Starts new game 
    4750    /// </summary> 
    48     public void NewGame(BlockLevel level)  
    49     { 
    50         ClearAll(); 
    51         currentLevel = level; 
     51    public void NewGame(int levelIndex)  
     52    { 
     53        ClearAll(); 
     54        currentLevelIndex = levelIndex; 
     55        currentLevel = levels[levelIndex].Clone(); 
    5256        currentLevel.Victory += Victory; 
    53         //currentLevel.CreateField(testLevel); 
    5457        currentLevel.AddToGame(); 
    5558        SetControls(); 
     
    134137        IsMouseVisible = true; 
    135138        MultiSelectWindow w = new MultiSelectWindow("Conratulations! Do you want to:", new String[] { "Retry", "Next Level", "Main menu" }); 
     139        w.AddItemHandler(0, delegate { NewGame(currentLevelIndex); }); 
     140        w.AddItemHandler(1, delegate { NewGame((currentLevelIndex+1) % levels.Count); }); 
    136141        w.AddItemHandler(2, Menu); 
     142         
    137143        Add(w); 
    138144    } 
     
    172178        previous.Clicked += delegate { LevelSelectionMenu((current-1 + levels.Count) % levels.Count); }; 
    173179        next.Clicked += delegate { LevelSelectionMenu((current + 1) % levels.Count); }; 
    174         play.Clicked += delegate { NewGame(levels[current]); }; 
     180        play.Clicked += delegate { NewGame(current); }; 
    175181 
    176182    } 
Note: See TracChangeset for help on using the changeset viewer.