Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

600610739 Lab5 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
</startup>
</configuration>
</configuration>
46 changes: 19 additions & 27 deletions Properties/Resources.Designer.cs

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

24 changes: 10 additions & 14 deletions Properties/Settings.Designer.cs

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

64 changes: 63 additions & 1 deletion TwoZeroFourEightModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TwoZeroFourEightModel : Model
protected int boardSize; // default is 4
protected int[,] board;
protected Random rand;
public int score = 0;

public TwoZeroFourEightModel() : this(4)
{
Expand Down Expand Up @@ -39,7 +40,7 @@ public TwoZeroFourEightModel(int size)

private int[,] Random(int[,] input)
{
while (true)
while (!BlockFull())
{
int x = rand.Next(boardSize);
int y = rand.Next(boardSize);
Expand Down Expand Up @@ -82,6 +83,7 @@ public void PerformDown()
if (j > 0 && buffer[j] != 0 && buffer[j] == buffer[j - 1])
{
buffer[j - 1] *= 2;
score += buffer[j - 1];
buffer[j] = 0;
}
}
Expand Down Expand Up @@ -134,6 +136,7 @@ public void PerformUp()
if (j > 0 && buffer[j] != 0 && buffer[j] == buffer[j - 1])
{
buffer[j - 1] *= 2;
score += buffer[j - 1];
buffer[j] = 0;
}
}
Expand Down Expand Up @@ -188,6 +191,7 @@ public void PerformRight()
if (j > 0 && buffer[j] != 0 && buffer[j] == buffer[j - 1])
{
buffer[j - 1] *= 2;
score += buffer[j - 1];
buffer[j] = 0;
}
}
Expand Down Expand Up @@ -239,6 +243,7 @@ public void PerformLeft()
if (j > 0 && buffer[j] != 0 && buffer[j] == buffer[j - 1])
{
buffer[j - 1] *= 2;
score += buffer[j - 1];
buffer[j] = 0;
}
}
Expand All @@ -260,5 +265,62 @@ public void PerformLeft()
board = Random(board);
NotifyAll();
}

public bool BlockFull()
{
int count = 0;
foreach (int block in board)
{
if (block > 0)
{
count++;
}
}
if (count == 16) return true;
else return false;
}

public bool GameOver()
{
int count = 0;
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 4; y++)
{
if (y != 3)
{
if (board[x, y] != board[x, y + 1] && board[x, y] != board[x + 1, y])
{
count++;
}
}
else
{
if (board[x, y] != board[x + 1, y])
{
count++;
}
}
}
}

if (count >= 12)
{
if (BlockFull())
{
return true;
}
return false;
}
else
{
return false;
}
}

public string Allscore()
{
return score.ToString();
}
}
}
Loading