Skip to content

Commit

Permalink
UI first versiom
Browse files Browse the repository at this point in the history
  • Loading branch information
dawcza3 committed Apr 16, 2016
1 parent ba5c61f commit 44a6c27
Show file tree
Hide file tree
Showing 24 changed files with 523 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,4 @@ FakesAssemblies/
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
/SnakeUWP/SnakeUWP/Assets/sound.mp3
Binary file added SnakeUWP.rar
Binary file not shown.
4 changes: 3 additions & 1 deletion SnakeUWP/SnakeUWP.Core/Models/PlayerScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ public class PlayerScore : ViewModelBase
{
public int Score { get; set; }
public string Name { get; set; }
public int Place { get; set; }

public PlayerScore(string name,int score)
public PlayerScore(string name,int score,int place)
{
Score = score;
Name = name;
Place = place;
}
}
}
167 changes: 167 additions & 0 deletions SnakeUWP/SnakeUWP.Core/ViewModels/GameViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
using System;
using System.Windows.Input;
using Windows.Foundation;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using SnakeUWP.Core.Models;
using SnakeUWP.Core.Services;

namespace SnakeUWP.Core.ViewModels
{
public class GameViewModel:ViewModelBase
{
#region Commands
private ICommand _onBack;
public ICommand OnBack
{
get
{
if (_onBack == null)
{
Paused = false;
_onBack = new RelayCommand(() => _navigation.GoBack());
}

return _onBack;
}
}

private ICommand _directionChangedCommand;
public ICommand DirectionChanged => _directionChangedCommand ?? (_directionChangedCommand = new RelayCommand<string>
(_model.ChangeMoveDirection));

private ICommand _pauseCommand;

public ICommand PauseCommand
{
get
{
if (_pauseCommand == null)
{
_pauseCommand = new RelayCommand(() =>
{
Paused = !Paused;
if (Paused)
{
PauseButtonSource = "ms-appx:///Assets/playButton.png";
_timer.Stop();
}
else
{
PauseButtonSource = "ms-appx:///Assets/stopButton.png";
_timer.Start();
}
});
}
return _pauseCommand;
}
}


#endregion

#region Fields
private readonly INavigation _navigation;
private readonly ITimer _timer;
private readonly SnakeGameModel _model = new SnakeGameModel();
#endregion

#region InitializateMethods

public void StartGame()
{
Paused = false;
_model.StartGame();
RaisePropertyChanged("GameOver");

}

private void TimerTick()
{
_model.Update(false);

if (Score != _model.Score)
{
Score = _model.Score;
RaisePropertyChanged("Score");
}

if (_model.GameOver)
{
RaisePropertyChanged("GameOver");
_timer.Stop();
}
}

public GameViewModel(INavigation navigation, ITimer timer)
{
_navigation = navigation;

_timer = timer;
_timer.OnTick = TimerTick;
timer.Interval = 66;
timer.Start();

_model.SnakeChanged += _model_SnakeChanged;
_model.FruitChanged += _model_FruitChanged;
_model.EndGame();
}
#endregion

#region EventHandlers
public Action<SnakeChangedEventArgs> UpdateSnakeAction { get; set; }

public Action<FruitChangedEventArgs> UpdateFruitAction { get; set; }

private void _model_FruitChanged(object sender, FruitChangedEventArgs e)
{
UpdateFruitAction?.Invoke(e);
}

private void _model_SnakeChanged(object sender, SnakeChangedEventArgs e)
{
UpdateSnakeAction?.Invoke(e);
}
#endregion

#region Properties
public bool GameOver => _model.GameOver;

private string _pauseButtonSource = "ms-appx:///Assets/stopButton.png";
public string PauseButtonSource
{
get { return _pauseButtonSource; }
set { Set(ref _pauseButtonSource, value); }
}

private bool _paused;
public bool Paused { get {return _paused;} set { Set(ref _paused, value); } }

public static double Scale { get; set; } = 1;

public int Score { get; private set; }

public Size PlayAreaSize
{
set
{
Scale = (value.Height / 300 + value.Width / 300) / 2;
//SnakeBody.PlayAreaSize.Width = value.Width;
//SnakeBody.PlayAreaSize.Height = value.Height;
}
}

public override void Cleanup()
{
base.Cleanup();
_timer.Start();
_model.EndGame();
Score = 0;
StartGame();
PauseButtonSource = "ms-appx:///Assets/stopButton.png";
}

#endregion

}
}
68 changes: 57 additions & 11 deletions SnakeUWP/SnakeUWP.Core/ViewModels/HighscoreViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,53 @@ public class HighscoreViewModel : ViewModelBase
{
public ObservableCollection<PlayerScore> MediumScores { get; private set; }

private string _currentScores = "Medium Level";

public string CurrentScores
{
get { return _currentScores; }
set { Set(ref _currentScores, value); }
}

private void GetNextContent()
{
if (CurrentScores == "Medium Level")
{
CurrentScores = "High Level";
}
else if (CurrentScores == "High Level")
{
CurrentScores = "Easy Level";
}
else
{
CurrentScores = "Medium Level";
}
}
private void GetPrevContent()
{
if (CurrentScores == "Medium Level")
{
CurrentScores = "Easy Level";
}
else if (CurrentScores == "High Level")
{
CurrentScores = "Medium Level";
}
else
{
CurrentScores = "High Level";
}
}


private ICommand _getNextCommand;
public ICommand GetNextCommand => _getNextCommand ?? (_getNextCommand = new RelayCommand(GetNextContent));

private ICommand _getPrevCommand;
public ICommand GetPrevCommand => _getPrevCommand ?? (_getPrevCommand = new RelayCommand(GetPrevContent));


private INavigation navigation;

private ICommand onBack;
Expand All @@ -32,17 +79,16 @@ public HighscoreViewModel(INavigation navigation)
this.navigation = navigation;
MediumScores = new ObservableCollection<PlayerScore>
{
new PlayerScore("Dawid", 1500),
new PlayerScore("Kasia", 2200),
new PlayerScore("Marek", 3100),
new PlayerScore("Tomek", 1000),
new PlayerScore("Mirek", 1200),

/* new PlayerScore("Dawid", 1500),
new PlayerScore("Dawid", 1500),
new PlayerScore("Dawid", 1500),
new PlayerScore("Dawid", 1500),
new PlayerScore("Dawid", 1500),*/
new PlayerScore("Dawid", 3100,1),
new PlayerScore("Kasia", 2200,2),
new PlayerScore("Marek", 1050,3),
new PlayerScore("Asia", 500,4),
new PlayerScore("Mirek", 60,5),
new PlayerScore("Konrad", 2500,6),
new PlayerScore("Dariusz", 2200,7),
new PlayerScore("Ola", 4100,8),
new PlayerScore("Tomek", 5000,9),
new PlayerScore("Adam", 10,10)
};
}

Expand Down
5 changes: 5 additions & 0 deletions SnakeUWP/SnakeUWP.Core/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace SnakeUWP.Core.ViewModels
{
public class MainViewModel:ViewModelBase
{
#region Commands
private INavigation navigation;

private ICommand navigateToOptions;
Expand Down Expand Up @@ -51,10 +52,14 @@ public ICommand NavigateToGame
return navigateToGame;
}
}
#endregion

#region Constructor

public MainViewModel(INavigation navigation)
{
this.navigation = navigation;
}
#endregion
}
}
8 changes: 7 additions & 1 deletion SnakeUWP/SnakeUWP.Core/ViewModels/OptionsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using System.Windows.Input;
using System;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using SnakeUWP.Core.Services;



namespace SnakeUWP.Core.ViewModels
{
public class OptionsViewModel : ViewModelBase
{
private INavigation navigation;

public Action<bool> OnSoundPlayChanged { get; set; }

public OptionsViewModel(INavigation navigation)
{
this.navigation = navigation;
Expand Down Expand Up @@ -72,6 +77,7 @@ public ICommand MusicCommand
if (_musicCommand == null) _musicCommand = new RelayCommand(() =>
{
MusicOption = !MusicOption;
OnSoundPlayChanged(MusicOption);
});
return _musicCommand;
}
Expand Down
Binary file removed SnakeUWP/SnakeUWP/Assets/Bell.mp3
Binary file not shown.
Binary file removed SnakeUWP/SnakeUWP/Assets/Nature.mp3
Binary file not shown.
Binary file added SnakeUWP/SnakeUWP/Assets/Scale-100/startButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SnakeUWP/SnakeUWP/Assets/Scale-120/snakeButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SnakeUWP/SnakeUWP/Assets/Scale-140/snakeButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added SnakeUWP/SnakeUWP/Assets/Scale-180/snakeButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed SnakeUWP/SnakeUWP/Assets/Sweep.mp3
Binary file not shown.
Loading

0 comments on commit 44a6c27

Please sign in to comment.