Add hit bottom check and auto Tetrominoe swap
This commit is contained in:
parent
e49cfb2c78
commit
03b674367e
1 changed files with 52 additions and 19 deletions
|
@ -1,38 +1,71 @@
|
||||||
using System.ComponentModel;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace Tetris.Models;
|
namespace Tetris.Models;
|
||||||
|
|
||||||
public class Party : INotifyPropertyChanged
|
public class Game : INotifyPropertyChanged {
|
||||||
{
|
private Random _random = new Random();
|
||||||
private int _score;
|
|
||||||
|
|
||||||
private string _userName;
|
private string _userName;
|
||||||
|
|
||||||
public Party(string userName)
|
public string UserName {
|
||||||
{
|
|
||||||
_userName = userName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string UserName
|
|
||||||
{
|
|
||||||
get => _userName;
|
get => _userName;
|
||||||
set
|
set {
|
||||||
{
|
|
||||||
_userName = value;
|
_userName = value;
|
||||||
OnPropertyChanged("UserName");
|
OnPropertyChanged("UserName");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Score
|
private int _score;
|
||||||
{
|
|
||||||
|
public int Score {
|
||||||
get => _score;
|
get => _score;
|
||||||
set
|
set {
|
||||||
{
|
|
||||||
_score = value;
|
_score = value;
|
||||||
OnPropertyChanged("Score");
|
OnPropertyChanged("Score");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Grid _grid;
|
||||||
|
|
||||||
|
public Grid Grid => _grid;
|
||||||
|
|
||||||
|
private Tetrominoe? _currentTetrominoe;
|
||||||
|
public Tetrominoe? CurrentTetrominoe => _currentTetrominoe;
|
||||||
|
|
||||||
|
private Tetrominoe? _nextTetrominoe;
|
||||||
|
public Tetrominoe? NextTetrominoe => _nextTetrominoe;
|
||||||
|
|
||||||
|
public Game(string userName, Grid grid) {
|
||||||
|
_userName = userName;
|
||||||
|
_grid = grid;
|
||||||
|
_currentTetrominoe = GetNewTetrominoe();
|
||||||
|
_nextTetrominoe = GetNewTetrominoe();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HitBottom() {
|
||||||
|
if (_currentTetrominoe == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return !_grid.CanGo(_currentTetrominoe, _currentTetrominoe.Coordinates + new Size(0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PrintTetrominoe() {
|
||||||
|
if (_currentTetrominoe == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_grid.PrintTetrominoe(_currentTetrominoe);
|
||||||
|
_currentTetrominoe = _nextTetrominoe;
|
||||||
|
_nextTetrominoe = GetNewTetrominoe();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tetrominoe GetNewTetrominoe() {
|
||||||
|
List<String> tetrominoes = TetrominoeParser.List();
|
||||||
|
return new Tetrominoe(_grid, tetrominoes[_random.Next(tetrominoes.Count)]);
|
||||||
|
}
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
protected virtual void OnPropertyChanged(string propertyName)
|
protected virtual void OnPropertyChanged(string propertyName)
|
||||||
|
|
Reference in a new issue