using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace jBowling
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class mFrmMain : System.Windows.Forms.Form
{
private Game mGame = new Game();
private System.Windows.Forms.Panel mScoreCard;
private System.Windows.Forms.Button mReset;
private System.Windows.Forms.Button mBtnGutter;
private System.Windows.Forms.Button mBtn1;
private System.Windows.Forms.Button mBtn2;
private System.Windows.Forms.Button mBtn3;
private System.Windows.Forms.Button mBtn4;
private System.Windows.Forms.Button mBtn5;
private System.Windows.Forms.Button mBtn6;
private System.Windows.Forms.Button mBtn7;
private System.Windows.Forms.Button mBtn9;
private System.Windows.Forms.Button mBtn8;
private System.Windows.Forms.Button mBtnStrike;
private System.Windows.Forms.Button mBtnUnitTest;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public mFrmMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.mBtnUnitTest.Visible = false;
#if UNITTEST
this.mBtnUnitTest.Visible = true;
#endif
mGame.Reset();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mScoreCard = new System.Windows.Forms.Panel();
this.mReset = new System.Windows.Forms.Button();
this.mBtnGutter = new System.Windows.Forms.Button();
this.mBtn1 = new System.Windows.Forms.Button();
this.mBtn2 = new System.Windows.Forms.Button();
this.mBtn3 = new System.Windows.Forms.Button();
this.mBtn4 = new System.Windows.Forms.Button();
this.mBtn5 = new System.Windows.Forms.Button();
this.mBtn6 = new System.Windows.Forms.Button();
this.mBtn7 = new System.Windows.Forms.Button();
this.mBtn9 = new System.Windows.Forms.Button();
this.mBtn8 = new System.Windows.Forms.Button();
this.mBtnStrike = new System.Windows.Forms.Button();
this.mBtnUnitTest = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// mScoreCard
//
this.mScoreCard.Location = new System.Drawing.Point(72, 16);
this.mScoreCard.Name = "mScoreCard";
this.mScoreCard.Size = new System.Drawing.Size(536, 88);
this.mScoreCard.TabIndex = 0;
this.mScoreCard.Paint += new System.Windows.Forms.PaintEventHandler(this.mScoreCard_Paint);
//
// mReset
//
this.mReset.Location = new System.Drawing.Point(184, 128);
this.mReset.Name = "mReset";
this.mReset.TabIndex = 1;
this.mReset.Text = "Reset";
this.mReset.Click += new System.EventHandler(this.mReset_Click);
//
// mBtnGutter
//
this.mBtnGutter.Location = new System.Drawing.Point(288, 128);
this.mBtnGutter.Name = "mBtnGutter";
this.mBtnGutter.Size = new System.Drawing.Size(48, 24);
this.mBtnGutter.TabIndex = 6;
this.mBtnGutter.Text = "Gutter";
this.mBtnGutter.Click += new System.EventHandler(this.mBtnGutter_Click);
//
// mBtn1
//
this.mBtn1.Location = new System.Drawing.Point(288, 160);
this.mBtn1.Name = "mBtn1";
this.mBtn1.Size = new System.Drawing.Size(24, 23);
this.mBtn1.TabIndex = 7;
this.mBtn1.Text = "1";
this.mBtn1.Click += new System.EventHandler(this.mBtn1_Click);
//
// mBtn2
//
this.mBtn2.Location = new System.Drawing.Point(320, 160);
this.mBtn2.Name = "mBtn2";
this.mBtn2.Size = new System.Drawing.Size(24, 23);
this.mBtn2.TabIndex = 8;
this.mBtn2.Text = "2";
this.mBtn2.Click += new System.EventHandler(this.mBtn2_Click);
//
// mBtn3
//
this.mBtn3.Location = new System.Drawing.Point(352, 160);
this.mBtn3.Name = "mBtn3";
this.mBtn3.Size = new System.Drawing.Size(24, 23);
this.mBtn3.TabIndex = 9;
this.mBtn3.Text = "3";
this.mBtn3.Click += new System.EventHandler(this.mBtn3_Click);
//
// mBtn4
//
this.mBtn4.Location = new System.Drawing.Point(288, 192);
this.mBtn4.Name = "mBtn4";
this.mBtn4.Size = new System.Drawing.Size(24, 23);
this.mBtn4.TabIndex = 10;
this.mBtn4.Text = "4";
this.mBtn4.Click += new System.EventHandler(this.mBtn4_Click);
//
// mBtn5
//
this.mBtn5.Location = new System.Drawing.Point(320, 192);
this.mBtn5.Name = "mBtn5";
this.mBtn5.Size = new System.Drawing.Size(24, 23);
this.mBtn5.TabIndex = 11;
this.mBtn5.Text = "5";
this.mBtn5.Click += new System.EventHandler(this.mBtn5_Click);
//
// mBtn6
//
this.mBtn6.Location = new System.Drawing.Point(352, 192);
this.mBtn6.Name = "mBtn6";
this.mBtn6.Size = new System.Drawing.Size(24, 23);
this.mBtn6.TabIndex = 12;
this.mBtn6.Text = "6";
this.mBtn6.Click += new System.EventHandler(this.mBtn6_Click);
//
// mBtn7
//
this.mBtn7.Location = new System.Drawing.Point(288, 224);
this.mBtn7.Name = "mBtn7";
this.mBtn7.Size = new System.Drawing.Size(24, 23);
this.mBtn7.TabIndex = 13;
this.mBtn7.Text = "7";
this.mBtn7.Click += new System.EventHandler(this.mBtn7_Click);
//
// mBtn9
//
this.mBtn9.Location = new System.Drawing.Point(352, 224);
this.mBtn9.Name = "mBtn9";
this.mBtn9.Size = new System.Drawing.Size(24, 23);
this.mBtn9.TabIndex = 14;
this.mBtn9.Text = "9";
this.mBtn9.Click += new System.EventHandler(this.mBtn9_Click);
//
// mBtn8
//
this.mBtn8.Location = new System.Drawing.Point(320, 224);
this.mBtn8.Name = "mBtn8";
this.mBtn8.Size = new System.Drawing.Size(24, 23);
this.mBtn8.TabIndex = 15;
this.mBtn8.Text = "8";
this.mBtn8.Click += new System.EventHandler(this.mBtn8_Click);
//
// mBtnStrike
//
this.mBtnStrike.Location = new System.Drawing.Point(288, 256);
this.mBtnStrike.Name = "mBtnStrike";
this.mBtnStrike.Size = new System.Drawing.Size(48, 23);
this.mBtnStrike.TabIndex = 16;
this.mBtnStrike.Text = "Strike!";
this.mBtnStrike.Click += new System.EventHandler(this.mBtnStrike_Click);
//
// mBtnUnitTest
//
this.mBtnUnitTest.Location = new System.Drawing.Point(136, 184);
this.mBtnUnitTest.Name = "mBtnUnitTest";
this.mBtnUnitTest.TabIndex = 17;
this.mBtnUnitTest.Text = "UnitTest";
this.mBtnUnitTest.Click += new System.EventHandler(this.mBtnUnitTest_Click);
//
// mFrmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(632, 445);
this.Controls.Add(this.mBtnUnitTest);
this.Controls.Add(this.mBtnStrike);
this.Controls.Add(this.mBtn8);
this.Controls.Add(this.mBtn9);
this.Controls.Add(this.mBtn7);
this.Controls.Add(this.mBtn6);
this.Controls.Add(this.mBtn5);
this.Controls.Add(this.mBtn4);
this.Controls.Add(this.mBtn3);
this.Controls.Add(this.mBtn2);
this.Controls.Add(this.mBtn1);
this.Controls.Add(this.mBtnGutter);
this.Controls.Add(this.mReset);
this.Controls.Add(this.mScoreCard);
this.Name = "mFrmMain";
this.Text = "Bowling";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new mFrmMain());
}
private void mScoreCard_Paint(object sender, PaintEventArgs e)
{
Font scorefont = new Font(FontFamily.GenericSansSerif, 12);
Font ballfont = new Font(FontFamily.GenericSansSerif, 7);
SolidBrush b = new SolidBrush(Color.Black);
Pen p = new Pen(b);
const int hgap = 2;
const int vgap = 3;
const int gap1 = 2;
const int gap2 = 2;
const int gap3 = 2;
const int gap4 = 2;
const int gap5 = 2;
const int ballwidth = 15;
const int ballheight = 15;
const int framewidth = 50;
const int frameheight = 70;
int currentX = hgap;
int currentY = vgap;
for (int frame = 0; frame < 10; ++frame)
{
//draw frame rectangle
Rectangle framerct = new Rectangle();
framerct.X = currentX;
framerct.Y = currentY;
framerct.Width = framewidth;
framerct.Height = frameheight;
e.Graphics.DrawRectangle(p, framerct);
RectangleF scorerct = new RectangleF();
scorerct.X = framerct.X + gap1;
scorerct.Y = framerct.Y + ballheight + gap2;
scorerct.Width = framerct.Width - gap1 - gap2;
scorerct.Height = framerct.Height - ballheight - gap3 - gap4;
//center it vertically
float y = scorerct.Y + ((scorerct.Height - scorefont.Height)) / 2.0f;
e.Graphics.DrawString(ConvertScore(mGame.GetScore(frame)), scorefont, b, scorerct.X, y);
Rectangle ballrct = new Rectangle();
ballrct.X = framerct.X;
ballrct.Y = framerct.Y;
ballrct.Width = ballwidth;
ballrct.Height = ballheight;
for (int ball = 0; ball < mGame.NumberOfBallsPerFrame(frame); ++ball)
{
e.Graphics.DrawRectangle(p, ballrct);
float y2 = ballrct.Y + ((ballrct.Height - ballfont.Height)) / 2.0f;
float x2 = ballrct.X + gap5;
e.Graphics.DrawString(ConvertBall(mGame.GetBall(frame, ball)), ballfont, b, x2, y2);
ballrct.X = ballrct.X + ballrct.Width;
}
currentX += framewidth;
}
}
private string ConvertScore(int val)
{
if (val == -1)
return " ";
return val.ToString();
}
private string ConvertBall(int val)
{
switch (val)
{
case 0 : return "-";
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
return val.ToString();
case Game.Strike : return "X"; //strike
case Game.Spare : return "/"; //spare
case Game.NoScore : return " "; //no score
default:
throw new Exception("unknown ball value: " + val);
}
}
private bool IsEnabled(int val)
{
return !mGame.IsGameOver() && mGame.PinsRemaining() > val;
}
private void SetButtons()
{
mBtnGutter.Enabled = IsEnabled(0);
mBtn1.Enabled = IsEnabled(1);
mBtn2.Enabled = IsEnabled(2);
mBtn3.Enabled = IsEnabled(3);
mBtn4.Enabled = IsEnabled(4);
mBtn5.Enabled = IsEnabled(5);
mBtn6.Enabled = IsEnabled(6);
mBtn7.Enabled = IsEnabled(7);
mBtn8.Enabled = IsEnabled(8);
mBtn9.Enabled = IsEnabled(9);
mBtnStrike.Enabled = !mGame.IsGameOver();
if (mBtnStrike.Enabled)
mBtnStrike.Text = mGame.IsStrikePossible() ? "Strike!" : "Spare!";
else
mBtnStrike.Text = "--";
}
private void mReset_Click(object sender, System.EventArgs e)
{
mGame.Reset();
SetButtons();
mScoreCard.Invalidate();
}
private void HandleClick(int val)
{
mGame.Set(val);
SetButtons();
mScoreCard.Invalidate();
}
private void mBtnGutter_Click(object sender, System.EventArgs e)
{
HandleClick(0);
}
private void mBtn1_Click(object sender, System.EventArgs e)
{
HandleClick(1);
}
private void mBtn2_Click(object sender, System.EventArgs e)
{
HandleClick(2);
}
private void mBtn3_Click(object sender, System.EventArgs e)
{
HandleClick(3);
}
private void mBtn4_Click(object sender, System.EventArgs e)
{
HandleClick(4);
}
private void mBtn5_Click(object sender, System.EventArgs e)
{
HandleClick(5);
}
private void mBtn6_Click(object sender, System.EventArgs e)
{
HandleClick(6);
}
private void mBtn7_Click(object sender, System.EventArgs e)
{
HandleClick(7);
}
private void mBtn8_Click(object sender, System.EventArgs e)
{
HandleClick(8);
}
private void mBtn9_Click(object sender, System.EventArgs e)
{
HandleClick(9);
}
private void mBtnStrike_Click(object sender, System.EventArgs e)
{
HandleClick(mGame.PinsRemaining());
}
private void mBtnUnitTest_Click(object sender, System.EventArgs e)
{
ut.Run();
}
}
}
|
using System;
namespace jBowling
{
/// <summary>
/// Summary description for testBowling.
/// </summary>
public class testBowling
{
public void testReset()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetBall(0,0), Game.NoScore);
ut.assert(g.GetScore(0), -1);
ut.assert(g.IsGameOver(), false);
}
public void testBallsPerFrame()
{
Game g = new Game();
g.Reset();
ut.assert(g.NumberOfBallsPerFrame(0), 2);
ut.assert(g.NumberOfBallsPerFrame(1), 2);
ut.assert(g.NumberOfBallsPerFrame(2), 2);
ut.assert(g.NumberOfBallsPerFrame(3), 2);
ut.assert(g.NumberOfBallsPerFrame(4), 2);
ut.assert(g.NumberOfBallsPerFrame(5), 2);
ut.assert(g.NumberOfBallsPerFrame(6), 2);
ut.assert(g.NumberOfBallsPerFrame(7), 2);
ut.assert(g.NumberOfBallsPerFrame(8), 2);
ut.assert(g.NumberOfBallsPerFrame(9), 3);
}
public void testPinsRemaining()
{
Game g = new Game();
g.Reset();
ut.assert(g.PinsRemaining(), 10);
g.Set(1);
ut.assert(g.PinsRemaining(), 9);
g.Set(9);
ut.assert(g.PinsRemaining(), 10);
g.Set(10);
ut.assert(g.PinsRemaining(), 10);
g.Set(10);
ut.assert(g.PinsRemaining(), 10);
g.Set(10);
ut.assert(g.PinsRemaining(), 10);
g.Set(10);
ut.assert(g.PinsRemaining(), 10);
g.Set(10);
ut.assert(g.PinsRemaining(), 10);
g.Set(10);
ut.assert(g.PinsRemaining(), 10);
g.Set(10);
ut.assert(g.PinsRemaining(), 10);
g.Set(10);
ut.assert(g.PinsRemaining(), 10);
g.Set(10);
ut.assert(g.PinsRemaining(), 10);
g.Set(10);
ut.assert(g.PinsRemaining(), 10); //end of game
}
public void testSimpleFrame_Balls()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetBall(0,0), Game.NoScore);
g.Set(1);
ut.assert(g.GetBall(0,0), 1);
g.Set(5);
ut.assert(g.GetBall(0,1), 5);
ut.assert(g.GetBall(1,0), Game.NoScore);
}
public void testSimpleFrame()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(9), -1);
g.Set(1);
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(9), -1);
g.Set(5);
ut.assert(g.GetScore(0), 6);
ut.assert(g.GetScore(1), -1);
ut.assert(g.GetScore(9), -1);
g.Set(3);
ut.assert(g.GetScore(0), 6);
ut.assert(g.GetScore(1), -1);
ut.assert(g.GetScore(9), -1);
g.Set(4);
ut.assert(g.GetScore(0), 6);
ut.assert(g.GetScore(1), 13);
ut.assert(g.GetScore(9), -1);
}
public void testGutters_Balls()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetBall(0,0), Game.NoScore);
g.Set(0);
ut.assert(g.GetBall(0,0), 0);
g.Set(0);
ut.assert(g.GetBall(0,1), 0);
ut.assert(g.GetBall(1,0), Game.NoScore);
}
public void testGutters()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetScore(0), -1);
g.Set(0);
ut.assert(g.GetScore(0), -1);
g.Set(0);
ut.assert(g.GetScore(0), 0);
}
public void testSpare_Balls()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetBall(0, 0), Game.NoScore);
g.Set(2);
ut.assert(g.GetBall(0, 0), 2);
ut.assert(g.GetBall(0, 1), Game.NoScore);
g.Set(8);
ut.assert(g.GetBall(0, 0), 2);
ut.assert(g.GetBall(0, 1), Game.Spare);
g.Set(1);
ut.assert(g.GetBall(1, 0), 1);
}
public void testSpare()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetScore(0), -1);
g.Set(2);
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(1), -1);
g.Set(8);
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(1), -1);
g.Set(1);
ut.assert(g.GetScore(0), 11);
ut.assert(g.GetScore(1), -1);
g.Set(5);
ut.assert(g.GetScore(0), 11);
ut.assert(g.GetScore(1), 17);
ut.assert(g.GetScore(2), -1);
}
public void testSpareThenStrike()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetScore(0), -1);
g.Set(2);
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(1), -1);
g.Set(8); //spare
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(1), -1);
g.Set(10); //strike
ut.assert(g.GetScore(0), 20);
ut.assert(g.GetScore(1), -1);
g.Set(5);
g.Set(4);
ut.assert(g.GetScore(0), 20);
ut.assert(g.GetScore(1), 39);
ut.assert(g.GetScore(2), 48);
}
public void testStrike_Balls()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetBall(0, 0), Game.NoScore);
g.Set(10);
ut.assert(g.GetBall(0, 0), Game.Strike);
ut.assert(g.GetBall(0, 1), Game.NoScore);
g.Set(10);
ut.assert(g.GetBall(1, 0), Game.Strike);
ut.assert(g.GetBall(1, 1), Game.NoScore);
g.Set(1);
ut.assert(g.GetBall(2, 0), 1);
}
public void testStrike()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetScore(0), -1);
g.Set(10);
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(1), -1);
ut.assert(g.GetScore(2), -1);
g.Set(8);
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(1), -1);
ut.assert(g.GetScore(2), -1);
g.Set(1);
ut.assert(g.GetScore(0), 19);
ut.assert(g.GetScore(1), 28);
ut.assert(g.GetScore(2), -1);
g.Set(5);
ut.assert(g.GetScore(0), 19);
ut.assert(g.GetScore(1), 28);
ut.assert(g.GetScore(2), -1);
g.Set(2);
ut.assert(g.GetScore(0), 19);
ut.assert(g.GetScore(1), 28);
ut.assert(g.GetScore(2), 35);
}
public void testStrikeSpare()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetScore(0), -1);
g.Set(10);
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(1), -1);
ut.assert(g.GetScore(2), -1);
g.Set(8);
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(1), -1);
ut.assert(g.GetScore(2), -1);
g.Set(2);
ut.assert(g.GetScore(0), 20);
ut.assert(g.GetScore(1), -1);
ut.assert(g.GetScore(2), -1);
g.Set(5);
ut.assert(g.GetScore(0), 20);
ut.assert(g.GetScore(1), 35);
ut.assert(g.GetScore(2), -1);
g.Set(2);
ut.assert(g.GetScore(0), 20);
ut.assert(g.GetScore(1), 35);
ut.assert(g.GetScore(2), 42);
}
public void testStrikeStrikeStrike()
{
Game g = new Game();
g.Reset();
ut.assert(g.GetScore(0), -1);
g.Set(10);
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(1), -1);
ut.assert(g.GetScore(2), -1);
g.Set(10);
ut.assert(g.GetScore(0), -1);
ut.assert(g.GetScore(1), -1);
ut.assert(g.GetScore(2), -1);
g.Set(10);
ut.assert(g.GetScore(0), 30);
ut.assert(g.GetScore(1), -1);
ut.assert(g.GetScore(2), -1);
g.Set(2);
ut.assert(g.GetScore(0), 30);
ut.assert(g.GetScore(1), 52);
ut.assert(g.GetScore(2), -1);
g.Set(8);
ut.assert(g.GetScore(0), 30);
ut.assert(g.GetScore(1), 52);
ut.assert(g.GetScore(2), 72);
ut.assert(g.GetScore(3), -1);
g.Set(3);
ut.assert(g.GetScore(0), 30);
ut.assert(g.GetScore(1), 52);
ut.assert(g.GetScore(2), 72);
ut.assert(g.GetScore(3), 85);
}
public void testAllGutter()
{
Game g = new Game();
g.Reset();
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), false);
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), true);
g.Set(0);
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), true);
g.Set(0);
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), true);
g.Set(0);
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), true);
g.Set(0);
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), true);
g.Set(0);
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), true);
g.Set(0);
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), true);
g.Set(0);
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), true);
ut.assert(g.IsGameOver(), false);
g.Set(0);
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), true);
ut.assert(g.IsGameOver(), false);
g.Set(0);
g.Set(0);
ut.assert(g.PinsRemaining(), 10);
ut.assert(g.IsStrikePossible(), false);
ut.assert(g.IsGameOver(), true);
}
public void testPerfectGame()
{
Game g = new Game();
g.Reset();
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
ut.assert(g.GetScore(8), 270);
ut.assert(g.GetScore(9), 300);
}
public void testAlmostPerfectGame()
{
Game g = new Game();
g.Reset();
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(9);
ut.assert(g.GetScore(8), 270);
ut.assert(g.GetScore(9), 299);
}
public void testTenthBallBall()
{
Game g = new Game();
g.Reset();
g.Set(10); //30
g.Set(10); //60
g.Set(10); //
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(0);
g.Set(9);
ut.assert(g.GetBall(9, 0), 0);
ut.assert(g.GetBall(9, 1), 9);
ut.assert(g.GetScore(8), 249);
ut.assert(g.GetScore(9), 258);
}
public void testTenthSpareStrike()
{
Game g = new Game();
g.Reset();
g.Set(10); //30
g.Set(10); //60
g.Set(10); //
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(0);
g.Set(10);
ut.assert(g.GetBall(9, 0), 0);
ut.assert(g.GetBall(9, 1), Game.Spare);
g.Set(10);
ut.assert(g.GetScore(8), 250);
ut.assert(g.GetScore(9), 270);
}
public void testTenthSpareBall()
{
Game g = new Game();
g.Reset();
g.Set(10); //30
g.Set(10); //60
g.Set(10); //
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(0);
g.Set(10);
ut.assert(g.GetBall(9, 0), 0);
ut.assert(g.GetBall(9, 1), Game.Spare);
g.Set(9);
ut.assert(g.GetScore(8), 250);
ut.assert(g.GetScore(9), 269);
}
public void testTenthStrikeSpare()
{
Game g = new Game();
g.Reset();
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(8);
g.Set(2);
ut.assert(g.GetScore(8), 268);
ut.assert(g.GetScore(9), 288);
}
public void testTenthStrikeBallBall()
{
Game g = new Game();
g.Reset();
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(10);
g.Set(8);
g.Set(1);
ut.assert(g.GetScore(8), 268);
ut.assert(g.GetScore(9), 287);
}
}
}
|