Skip to content

Commit

Permalink
Merge pull request #18 from Schrodinger71/dev_fix
Browse files Browse the repository at this point in the history
Add GameLife
  • Loading branch information
Schrodinger71 authored Mar 16, 2024
2 parents 46e48de + b96b3c2 commit 27be5e7
Show file tree
Hide file tree
Showing 63 changed files with 1,205 additions and 117 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/windowsForm_build_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ jobs:
- name: Build app for release
run: msbuild app_WindowsForm\WindowsFormsAppCalculateLab7\WindowsFormsAppCalculateLab7.sln -t:rebuild -verbosity:diag -property:Configuration=Release


build-windowsFormAppGameLife4:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup MSBuild
uses: microsoft/[email protected]
- name: Build solution
run: msbuild app_WindowsForm\WindowsFormsGame_Life\WindowsFormsGame_Life.sln /p:Configuration=Release
- name: Build app for release
run: msbuild app_WindowsForm\WindowsFormsGame_Life\WindowsFormsGame_Life.sln -t:rebuild -verbosity:diag -property:Configuration=Release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"RootPath":"C:\\Lesson\\app_WindowsForm\\WindowsFormsGame_Life","ProjectFileName":"WindowsFormsGame_Life.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[{"SourceFile":"Form1.cs"},{"SourceFile":"Form1.Designer.cs"},{"SourceFile":"Program.cs"},{"SourceFile":"Properties\\AssemblyInfo.cs"},{"SourceFile":"Properties\\Resources.Designer.cs"},{"SourceFile":"Properties\\Settings.Designer.cs"},{"SourceFile":"obj\\Debug\\.NETFramework,Version=v4.8.AssemblyAttributes.cs"}],"References":[{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\Microsoft.CSharp.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\mscorlib.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Core.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Data.DataSetExtensions.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Data.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Deployment.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Drawing.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Net.Http.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Windows.Forms.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Xml.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Xml.Linq.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""}],"Analyzers":[],"Outputs":[{"OutputItemFullPath":"C:\\Lesson\\app_WindowsForm\\WindowsFormsGame_Life\\bin\\Debug\\WindowsFormsGame_Life.exe","OutputItemRelativePath":"WindowsFormsGame_Life.exe"},{"OutputItemFullPath":"C:\\Lesson\\app_WindowsForm\\WindowsFormsGame_Life\\bin\\Debug\\WindowsFormsGame_Life.pdb","OutputItemRelativePath":"WindowsFormsGame_Life.pdb"}],"CopyToOutputEntries":[]}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions app_WindowsForm/WindowsFormsGame_Life/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
231 changes: 231 additions & 0 deletions app_WindowsForm/WindowsFormsGame_Life/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 136 additions & 0 deletions app_WindowsForm/WindowsFormsGame_Life/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsGame_Life
{
public partial class Form1 : Form
{

private Graphics graphics;
private int resolution;
private GameLifeEngine gameEngine;



public Form1()
{
InitializeComponent();
}

private void StartGame()
{
if (timer1.Enabled)
return;

//Text = $"Game Life Generation {currentGeneration}";

numResolution.Enabled = false;
numDensity.Enabled = false;
resolution = (int)numResolution.Value;


gameEngine = new GameLifeEngine
(
rows: pictureBox1.Height / resolution,
cols: pictureBox1.Width / resolution,
density: (int)numDensity.Value
//density: (int)(numDensity.Minimum) * (int)numDensity.Maximum - (int)numDensity.Value
);




textBoxGeneration.Text = $"{gameEngine.currentGeneration}";

//gameEngine.currentGeneration = 500; //пример инкапсуляции


pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
graphics = Graphics.FromImage(pictureBox1.Image);
timer1.Start();

//graphics.FillRectangle(Brushes.LightGreen, 0, 0, resolution, resolution); //рисует клетку


}

private void DrawNextGeneration()
{
graphics.Clear(Color.Black);

var field = gameEngine.GetCurrentGeneration();

for ( int x = 0; x < field.GetLength(0); x++ )
{
for ( int y = 0; y < field.GetLength(1); y++ )
{
if (field[x,y])
graphics.FillRectangle(Brushes.Crimson, x * resolution, y * resolution, resolution - 1, resolution - 1);

}
}

pictureBox1.Refresh();
textBoxGeneration.Text = $"{gameEngine.currentGeneration}";
gameEngine.NextGeneration();
}



private void timer1_Tick(object sender, EventArgs e)
{
DrawNextGeneration();
}

private void bStart_Click(object sender, EventArgs e)
{
StartGame();
}

private void StopGame()
{
if (!timer1.Enabled)
return;

timer1.Stop();
numResolution.Enabled = true;
numDensity.Enabled = true;
}
private void bStop_Click(object sender, EventArgs e)
{
StopGame();
}

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (!timer1.Enabled)
return;

if (e.Button == MouseButtons.Left)
{
var x = e.Location.X / resolution;
var y = e.Location.Y / resolution;
gameEngine.AddCell(x, y);

}

if (e.Button == MouseButtons.Right)
{
var x = e.Location.X / resolution;
var y = e.Location.Y / resolution;
gameEngine.RemoveCell(x, y);

}
}


}
}
Loading

0 comments on commit 27be5e7

Please sign in to comment.