Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Week 2
Blazor

- [x] https://dotnet.microsoft.com/learn/aspnet/blazor-tutorial/intro
- [ ] https://exceptionnotfound.net/tetris-in-blazor-webassembly/
- [x] https://exceptionnotfound.net/tetris-in-blazor-webassembly/
- [ ] https://www.claudiobernasconi.ch/2021/04/23/building-a-dashboard-blazor/
- [ ] https://code-maze.com/download-files-from-azure-with-net-core-web-api-and-blazor-webassembly/
- [ ] https://code-maze.com/authentication-in-blazor-webassembly-hosted-applications/
Expand Down
Empty file added Test
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = NumbersInCsharp
build_property.ProjectDir = /home/najo/files/JuniorLearning_backup/W1-M2-numbers-in-csharp-local/numbers-quickstart/
build_property.ProjectDir = C:\Users\NashBarden\Source\Repos\JuniorLearning\W1-M2-numbers-in-csharp-local\numbers-quickstart\
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = BranchesAndLoops
build_property.ProjectDir = /home/najo/files/JuniorLearning_backup/W1-M3-branches-and-loops-local/
build_property.ProjectDir = C:\Users\NashBarden\Source\Repos\JuniorLearning\W1-M3-branches-and-loops-local\
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = W1_M4_list_collections
build_property.ProjectDir = /home/najo/files/JuniorLearning_backup/W1-M4-list-collections/
build_property.ProjectDir = C:\Users\NashBarden\Source\Repos\JuniorLearning\W1-M4-list-collections\
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = W1_M5_classes_and_objects
<<<<<<< HEAD
build_property.ProjectDir = /home/najo/files/JuniorLearning_backup/W1-M5-classes-and-objects/
=======
build_property.ProjectDir = C:\s\najodev\JuniorLearning\W1-M5-classes-and-objects\
>>>>>>> main
build_property.ProjectDir = C:\Users\NashBarden\Source\Repos\JuniorLearning\W1-M5-classes-and-objects\
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = W1_M5_classes_and_objects
build_property.ProjectDir = /home/najo/files/JuniorLearning/W1-M6-object-oriented/
build_property.ProjectDir = C:\Users\NashBarden\Source\Repos\JuniorLearning\W1-M6-object-oriented\
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = W1_M7_inheritance
build_property.ProjectDir = /home/najo/files/JuniorLearning_backup/W1-M7-inheritance/
build_property.ProjectDir = C:\Users\NashBarden\Source\Repos\JuniorLearning\W1-M7-inheritance\
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = W1_M9_console_app
build_property.ProjectDir = /home/najo/files/JuniorLearning_backup/W1-M9-console-app/
build_property.ProjectDir = C:\Users\NashBarden\Source\Repos\JuniorLearning\W1-M9-console-app\
Binary file not shown.
1 change: 1 addition & 0 deletions W2-M2-Tetris
Submodule W2-M2-Tetris added at 42f48b
11 changes: 11 additions & 0 deletions W2-M2-Tetris-new/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<h1>Page not found</h1>
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
27 changes: 27 additions & 0 deletions W2-M2-Tetris-new/Models/Tetris/Cell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace W1_M2_Tetris.Models.Tetris
{
public class Cell
{
public int Row { get; set; }
public int Column { get; set; }
public string CssClass { get; set; }

public Cell(int row, int column)
{
Row = row;
Column = column;
}

public Cell(int row, int column, string css)
{
Row = row;
Column = column;
CssClass = css;
}
}
}
186 changes: 186 additions & 0 deletions W2-M2-Tetris-new/Models/Tetris/CellCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
using System.Collections.Generic;
using System.Linq;

namespace W1_M2_Tetris.Models.Tetris
{
public class CellCollection
{
private readonly List<Cell> _cells = new List<Cell>();

/// <summary>
/// Returns all currently-occupied coordinates.
/// </summary>
/// <returns></returns>
public List<Cell> GetAll()
{
return _cells;
}

/// <summary>
/// Returns all occupied cell in a given row.
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
public List<Cell> GetAllInRow(int row)
{
return _cells.Where(x => x.Row == row).ToList();
}

/// <summary>
/// Adds a new cell
/// </summary>
/// <param name="row"></param>
/// <param name="column"></param>
public void Add(int row, int column)
{
_cells.Add(new Cell(row, column));
}

/// <summary>
/// Adds several new Cells and gives them each the specified CSS class.
/// </summary>
/// <param name="cells"></param>
/// <param name="cssClass"></param>
public void AddMany(List<Cell> cells, string cssClass)
{
foreach (var cell in cells)
{
_cells.Add(new Cell(cell.Row, cell.Column, cssClass));
}
}

/// <summary>
/// Returns true if the cell is occupied.
/// </summary>
/// <param name="row"></param>
/// <param name="column"></param>
/// <returns></returns>
public bool Contains(int row, int column)
{
return _cells.Any(c => c.Row == row && c.Column == column);
}

/// <summary>
/// Returns true if there are any occupied cells in the given column.
/// </summary>
/// <param name="column"></param>
/// <returns></returns>
public bool HasColumn(int column)
{
return _cells.Any(c => c.Column == column);
}

/// <summary>
/// Gets the lowest (lowest Row value) cell in the collection.
/// </summary>
/// <returns></returns>
public List<Cell> GetLowest()
{
List<Cell> cells = new List<Cell>();
foreach (var cell in _cells)
{
if (!Contains(cell.Row - 1, cell.Column))
{
cells.Add(cell);
}
}

return cells;
}

/// <summary>
/// Gets the rightmost (highest Column value) cell in the collection.
/// </summary>
/// <returns></returns>
public List<Cell> GetRightmost()
{
List<Cell> cells = new List<Cell>();
foreach (var cell in _cells)
{
if (!Contains(cell.Row, cell.Column + 1))
{
cells.Add(cell);
}
}

return cells;
}

/// <summary>
/// Gets the leftmost (lowest Column value) cell in the collection.
/// </summary>
/// <returns></returns>
public List<Cell> GetLeftmost()
{
List<Cell> cells = new List<Cell>();
foreach (var cell in _cells)
{
if (!Contains(cell.Row, cell.Column - 1))
{
cells.Add(cell);
}
}

return cells;
}

/// <summary>
/// Returns true if any cell in the collection is in the specified row.
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
public bool HasRow(int row)
{
return _cells.Any(c => c.Row == row);
}

/// <summary>
/// Gets the CSS class of an individual cell.
/// </summary>
/// <param name="row"></param>
/// <param name="column"></param>
/// <returns></returns>
public string GetCssClass(int row, int column)
{
var matching = _cells.FirstOrDefault(x => x.Row == row && x.Column == column);

if (matching != null)
return matching.CssClass;

return "";
}

/// <summary>
/// Sets the CSS class to each cell in an entire row.
/// </summary>
/// <param name="row"></param>
/// <param name="cssClass"></param>
public void SetCssClass(int row, string cssClass)
{
_cells.Where(x => x.Row == row).ToList().ForEach(x => x.CssClass = cssClass);
}

/// <summary>
/// Moves all "higher" cells down to fill in the specified completed rows.
/// </summary>
/// <param name="rows"></param>
public void CollapseRows(List<int> rows)
{
var selectedCells = _cells.Where(x => rows.Contains(x.Row));

List<Cell> toRemove = new List<Cell>();
foreach (var cell in selectedCells)
{
toRemove.Add(cell);
}

_cells.RemoveAll(x => toRemove.Contains(x));

foreach (var cell in _cells)
{
int numberOfLessRows = rows.Where(x => x <= cell.Row).Count();
cell.Row -= numberOfLessRows;
}
}
}
}
17 changes: 17 additions & 0 deletions W2-M2-Tetris-new/Models/Tetris/Enums/GameState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace W1_M2_Tetris.Models.Tetris.Enums
{
/// <summary>
/// Represents the current state of the Tetris game
/// </summary>
public enum GameState
{
NotStarted,
Playing, //Game playing normally
GameOver
}
}
15 changes: 15 additions & 0 deletions W2-M2-Tetris-new/Models/Tetris/Enums/TetrominoOrientation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace W1_M2_Tetris.Models.Tetris.Enums
{
public enum TetrominoOrientation
{
UpDown,
LeftRight,
DownUp,
RightLeft
}
}
18 changes: 18 additions & 0 deletions W2-M2-Tetris-new/Models/Tetris/Enums/TetrominoStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace W1_M2_Tetris.Models.Tetris.Enums
{
public enum TetrominoStyle
{
Straight = 1,
Block = 2,
TShaped = 3,
LeftZigZag = 4,
RightZigZag = 5,
LShaped = 6,
ReverseLShaped = 7
}
}
26 changes: 26 additions & 0 deletions W2-M2-Tetris-new/Models/Tetris/Grid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using W1_M2_Tetris.Models.Tetris.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace W1_M2_Tetris.Models.Tetris
{
public class Grid
{
public int Width { get; } = 10;
public int Height { get; } = 20;
public CellCollection Cells { get; set; } = new CellCollection();

public GameState State { get; set; } = GameState.NotStarted;

public bool IsStarted
{
get
{
return State == GameState.Playing
|| State == GameState.GameOver;
}
}
}
}
Loading