Archives from S:\ Drive
Good to keep around methinks
This commit is contained in:
1 parent
eadaf70b9e
commit
6dd63cc439
606 files changed
+50212
No files matched your search
@@ -0,0 +1,9 @@
|
||||
public class HelloWorld
|
||||
{
|
||||
public static void main (String[] args)
|
||||
{
|
||||
System.out.println("Hello World \nThis is my first Java Program.");
|
||||
System.out.println("The sum of 2 and 3 = " +5);
|
||||
System.out.println("7 + 8 = " + (7 + 8));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
/******************************************************************************
|
||||
* Project: Midterm COM 107 *
|
||||
* Class Name: $12Days *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/06/2012 *
|
||||
* Hours: 1.25 Hours *
|
||||
* Purpose: Creating an application that exhibit adherence to best *
|
||||
* programming practices. Effective application documentation, *
|
||||
* Effective use of whitespace for ease in software maintenance, *
|
||||
* Selection of appropriate data types using meaningful, *
|
||||
* conventional identifiers, Appropriate use of error handling, *
|
||||
* Creating simple and complex Boolean expressions to evaluate *
|
||||
* primitives and strings, Developing a single and dual *
|
||||
* alternative selection structures and linear selection *
|
||||
* structures, Using test cases to validate application output. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class $12Days
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
// english words for possessive numbers.
|
||||
String sDay01 = "first", sDay02 = "second", sDay03 = "third",
|
||||
sDay04 = "fourth", sDay05 = "fifth", sDay06 = "sixth",
|
||||
sDay07 = "seventh", sDay08 = "eighth", sDay09 ="nineth",
|
||||
sDay10 = "tenth", sDay11 = "eleventh", sDay12 = "twelfth";
|
||||
|
||||
// actual verse.
|
||||
String sGift01 = "partridge in a pear tree",
|
||||
sGift02 = "turtle doves", sGift03 = "French hens",
|
||||
sGift04 = "calling birds", sGift05 = "golden rings",
|
||||
sGift06 = "geese a-laying", sGift07 = "swans a-swimming",
|
||||
sGift08 = "maids a-milking", sGift09 = "ladies dancing",
|
||||
sGift10 = "lords a-leaping", sGift11 = "pipers piping",
|
||||
sGift12 = "drummers drumming";
|
||||
|
||||
// first part of verse.
|
||||
String sNum01 = "And a ", sNum02 = "Two ", sNum03 = "Three ",
|
||||
sNum04 = "Four ", sNum05 = "Five ", sNum06 = "Six ",
|
||||
sNum07 = "Seven ", sNum08 = "Eight ", sNum09 = "Nine ",
|
||||
sNum10 = "Ten ", sNum11 = "Eleven ", sNum12 = "Twelve ";
|
||||
|
||||
//various strings that assisted with my switch structure below below.
|
||||
String sSoR01 = "On the ",
|
||||
sSor02 = " day of Christmas,\nmy true love sent to me\n",
|
||||
sFNum01 = "A ", // special case for the first instance of day 1
|
||||
sC = ",\n", // common line break
|
||||
sP = ".", // last line ending
|
||||
sE = "!"; // special case for *very* last line (day 12).
|
||||
|
||||
int iDay = 0; // start with an unsupported day, ensures validated input
|
||||
|
||||
Scanner console = new Scanner(System.in); // prompt user for input
|
||||
System.out.print("What day of Chistmas are we on?\n"
|
||||
+ "Please enter the day number.\n"
|
||||
+ ":");
|
||||
|
||||
String sInput = console.nextLine(); // Grab string input.
|
||||
System.out.println(" "); // just for visual appeal.
|
||||
try
|
||||
{
|
||||
iDay = Integer.parseInt(sInput); // see if we can parse an integer
|
||||
}
|
||||
catch (NumberFormatException ex) // bad input, not a number
|
||||
{
|
||||
System.out.println("We're sorry, \""+sInput+"\" was an invalid day.\n"
|
||||
+ "Please re-run the program.");
|
||||
System.exit(1); // error out here. bad input.
|
||||
}
|
||||
if (iDay <= 0 || iDay > 12) // not a number we support. only days 1-12;
|
||||
{
|
||||
System.out.println("We're sorry, \""+sInput+"\" was an invalid day.\n"
|
||||
+ "Please re-run the program.");
|
||||
System.exit(2); // error out here, bad input, unsupported number.
|
||||
}
|
||||
|
||||
|
||||
//this would be much easier if we knew iteration.
|
||||
String sOut = ""; // output buffer.
|
||||
switch (iDay)
|
||||
{
|
||||
case 1:
|
||||
sOut += sSoR01+sDay01+sSor02;
|
||||
sOut += sFNum01+sGift01+sP;
|
||||
break;
|
||||
case 2:
|
||||
sOut += sSoR01+sDay02+sSor02;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 3:
|
||||
sOut += sSoR01+sDay03+sSor02;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 4:
|
||||
sOut += sSoR01+sDay04+sSor02;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 5:
|
||||
sOut += sSoR01+sDay05+sSor02;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 6:
|
||||
sOut += sSoR01+sDay06+sSor02;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 7:
|
||||
sOut += sSoR01+sDay07+sSor02;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 8:
|
||||
sOut += sSoR01+sDay08+sSor02;
|
||||
sOut += sNum08+sGift08+sC;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 9:
|
||||
sOut += sSoR01+sDay09+sSor02;
|
||||
sOut += sNum09+sGift09+sC;
|
||||
sOut += sNum08+sGift08+sC;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 10:
|
||||
sOut += sSoR01+sDay10+sSor02;
|
||||
sOut += sNum10+sGift10+sC;
|
||||
sOut += sNum09+sGift09+sC;
|
||||
sOut += sNum08+sGift08+sC;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 11:
|
||||
sOut += sSoR01+sDay11+sSor02;
|
||||
sOut += sNum11+sGift11+sC;
|
||||
sOut += sNum10+sGift10+sC;
|
||||
sOut += sNum09+sGift09+sC;
|
||||
sOut += sNum08+sGift08+sC;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 12:
|
||||
sOut += sSoR01+sDay12+sSor02;
|
||||
sOut += sNum12+sGift12+sC;
|
||||
sOut += sNum11+sGift11+sC;
|
||||
sOut += sNum10+sGift10+sC;
|
||||
sOut += sNum09+sGift09+sC;
|
||||
sOut += sNum08+sGift08+sC;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sE;
|
||||
break;
|
||||
}
|
||||
System.out.println(sOut); // print buffer.
|
||||
System.exit(0); // we're done.
|
||||
}
|
||||
}
|
||||
|
||||
/*Program Output:
|
||||
|
||||
S:\programs\Mod1\Midterm>java $12Days
|
||||
What day of Chistmas are we on?
|
||||
Please enter the day number.
|
||||
:11
|
||||
|
||||
On the eleventh day of Christmas,
|
||||
my true love sent to me
|
||||
Eleven pipers piping,
|
||||
Ten lords a-leaping,
|
||||
Nine ladies dancing,
|
||||
Eight maids a-milking,
|
||||
Seven swans a-swimming,
|
||||
Six geese a-laying,
|
||||
Five golden rings,
|
||||
Four calling birds,
|
||||
Three French hens,
|
||||
Two turtle doves,
|
||||
And a partridge in a pear tree.
|
||||
|
||||
S:\programs\Mod1\Midterm>java $12Days
|
||||
What day of Chistmas are we on?
|
||||
Please enter the day number.
|
||||
:2
|
||||
|
||||
On the second day of Christmas,
|
||||
my true love sent to me
|
||||
Two turtle doves,
|
||||
And a partridge in a pear tree.
|
||||
|
||||
S:\programs\Mod1\Midterm>java $12Days
|
||||
What day of Chistmas are we on?
|
||||
Please enter the day number.
|
||||
:invalid input
|
||||
|
||||
We're sorry, "invalid input" was an invalid day.
|
||||
Please re-run the program.
|
||||
|
||||
S:\programs\Mod1\Midterm>java $12Days
|
||||
What day of Chistmas are we on?
|
||||
Please enter the day number.
|
||||
:5
|
||||
|
||||
On the fifth day of Christmas,
|
||||
my true love sent to me
|
||||
Five golden rings,
|
||||
Four calling birds,
|
||||
Three French hens,
|
||||
Two turtle doves,
|
||||
And a partridge in a pear tree.
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,51 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 1b *
|
||||
* Class Name: Numbers *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/08/2012 *
|
||||
* Hours: 0.25 Hours *
|
||||
* Purpose: To declare variables, constant variables, explore promotions *
|
||||
* explicit type casting, and display the results of these *
|
||||
* activities. *
|
||||
******************************************************************************/
|
||||
|
||||
public class Numbers // direction 1
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
int iNumberTwo = 765, iNumberThree = (int) 4.75, iNumberFour = 17, iNumberFive = -2; // direction a + b
|
||||
final int iNumberOne = 3; // as per directon a + c: iNumberOne must be constant
|
||||
double dRealOne = 54.3, dRealTwo = 85, dRealThree = 67.56, dRealFour = 2, dRealFive = 3.3; // direction d + e
|
||||
|
||||
System.out.println("NumberOne stores " + iNumberOne); //direction f
|
||||
System.out.println("NumberTwo stores " + iNumberTwo); //f
|
||||
System.out.println("NumberThree stores " + iNumberThree); //f
|
||||
System.out.println("NumberFour stores " + iNumberFour); //f
|
||||
System.out.println("NumberFive stores " + iNumberFive); //f
|
||||
System.out.println("RealOne stores " + dRealOne); //f
|
||||
System.out.println("RealTwo stores " + dRealTwo); //f
|
||||
System.out.println("RealThree stores " + dRealThree); //f
|
||||
System.out.println("RealFour stores " + dRealFour); //f
|
||||
System.out.println("RealFive stores " + dRealFive); //f
|
||||
System.out.println("** Number Three is type casted as an integer"); // direction g
|
||||
System.out.println("** Real Two is implicitly promoted as a double"); // direction h
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project1>java Numbers
|
||||
NumberOne stores 3
|
||||
NumberTwo stores 765
|
||||
NumberThree stores 4
|
||||
NumberFour stores 17
|
||||
NumberFive stores -2
|
||||
RealOne stores 54.3
|
||||
RealTwo stores 85.0
|
||||
RealThree stores 67.56
|
||||
RealFour stores 2.0
|
||||
RealFive stores 3.3
|
||||
** Number Three is type casted as an integer
|
||||
** Real Two is implicitly promoted as a double
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,63 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 1c *
|
||||
* Class Name: Numbers *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/09/2012 *
|
||||
* Hours: 0.25 Hours *
|
||||
* Purpose: To declare variables, constant variables, explore promotions *
|
||||
* explicit type casting, and display the results of these *
|
||||
* activities. *
|
||||
******************************************************************************/
|
||||
|
||||
public class Precedence // direction a
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
int iAmFour = 4, iAmTwo = 2, iAmSeven = 7, iAmFourteen = 14, iAmEightteen = 18, iAmFive = 5, iAmOne = 1, iAmTwentyEight = 28, iAmTwenty = 20, iAmThree = 3; // direction a
|
||||
double iAmPointTwo = 0.2; // direction a
|
||||
System.out.println( iAmFour + " + " + iAmSeven + " * " + iAmFour + " = " + (iAmFour+iAmSeven*iAmFour) ); // comp 1
|
||||
System.out.println( iAmFour + " / " + iAmTwo + " * " + iAmFourteen + " = " + (iAmFour/iAmTwo*iAmFourteen) ); // comp 2
|
||||
System.out.println( iAmEightteen + " / " + iAmTwo + " + " + iAmFourteen + " / " + iAmTwo + " = " + (iAmEightteen/iAmTwo+iAmFourteen/iAmTwo) ); // comp 3
|
||||
System.out.println( iAmFour + " + " + iAmTwo + " / " + iAmFour + " - " + iAmTwo + " = " + (iAmFour+iAmTwo/iAmFour-iAmTwo) ); // comp 4
|
||||
System.out.println( iAmFive + " % " + iAmTwo + " * " + iAmFour + " / " + iAmOne + " + " + iAmFive + " = " + (iAmFive%iAmTwo*iAmFour/iAmOne+iAmFive) ); // comp 5
|
||||
System.out.println( iAmTwentyEight + " / " + iAmFive + " = " + (iAmTwentyEight/iAmFive) ); // comp 6
|
||||
System.out.println( iAmTwentyEight + " % " + iAmFive + " = " + (iAmTwentyEight%iAmFive) ); // comp 7
|
||||
System.out.println( iAmTwenty + " / ( " + iAmFour + " + " + iAmOne + " ) = " + (iAmTwenty/(iAmFour+iAmOne)) ); // comp 8
|
||||
System.out.println( "( " + iAmTwo + " + " + iAmThree + " ) * " + iAmFour + " = " + ((iAmTwo+iAmThree)*iAmFour) ); // comp 9
|
||||
System.out.println( "24 / " + iAmPointTwo + " = " + (24/iAmPointTwo) ); // comp 10
|
||||
System.out.println( "----------------------------------------------------------------------------------------" );
|
||||
System.out.println( "Order of Precedence:" ); // direction c
|
||||
System.out.println( "1) Parentheses." ); // c
|
||||
System.out.println( "2) Multiplication, Division, Modulo - Left to Right." ); // c
|
||||
System.out.println( "3) Addition, Subtraction - Left to Right." ); // c
|
||||
System.out.println( "4) Assignment - Right to Left." ); // c
|
||||
System.out.println( "Multiplicative Operators are assosciated from Left to Right" ); // direction d
|
||||
System.out.println( "Addative Operators are assosciated from Left to Right" ); // d
|
||||
System.out.println( "Assignment Operators are assosciated from Right to Left" ); // d
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project1>java Precedence
|
||||
4 + 7 * 4 = 32
|
||||
4 / 2 * 14 = 28
|
||||
18 / 2 + 14 / 2 = 16
|
||||
4 + 2 / 4 - 2 = 2
|
||||
5 % 2 * 4 / 1 + 5 = 9
|
||||
28 / 5 = 5
|
||||
28 % 5 = 3
|
||||
20 / ( 4 + 1 ) = 4
|
||||
( 2 + 3 ) * 4 = 20
|
||||
24 / 0.2 = 120.0
|
||||
----------------------------------------------------------------------------------------
|
||||
Order of Precedence:
|
||||
1) Parentheses.
|
||||
2) Multiplication, Division, Modulo - Left to Right.
|
||||
3) Addition, Subtraction - Left to Right.
|
||||
4) Assignment - Right to Left.
|
||||
Multiplicative Operators are assosciated from Left to Right
|
||||
Addative Operators are assosciated from Left to Right
|
||||
Assignment Operators are assosciated from Right to Left
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,75 @@
|
||||
/*********************************************
|
||||
* Program: Project 1a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/07/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: create an application that *
|
||||
* will display two of the folowing patterns *
|
||||
* ----------------------------------------- *
|
||||
* A) a 6 pointed star *
|
||||
* B) a pine tree shape composed of pound *
|
||||
* symbols *
|
||||
* C) your initals using each inital to *
|
||||
* create a large version of that letter *
|
||||
*********************************************/
|
||||
|
||||
public class Project1a // direction I
|
||||
{
|
||||
public static void main(String[] args) // direction I
|
||||
{
|
||||
String star = "\t\t\t*\n\n\t\t * * *\n\n\t\t * * * * * *\n\n\t\t * * * * * \n"+
|
||||
"\n\t\t * * * * * *\n\n\t\t * * *\n\n\t\t\t*"; // direction A -> This is the star. It is centered.
|
||||
|
||||
String pine = "\t\t\t#\n\n\t\t # #\n\n\t\t # # #\n\n\t\t # # # #\n\n\t\t\t#"; // direction B -> Pine tree like figure. Centered as well
|
||||
|
||||
String init = "\t AAA SSSSS PPPPPP \n\t AAAAA SS PP PP \n\t AA"+
|
||||
" AA SSSSS PPPPPP \n\t AAAAAAA SS PP \n\t AA AA SSSSS PP "; // direction c -> ASP. Centered.
|
||||
|
||||
String line = "\n\n--------------------------------------------------------------------------------\n\n"; // Flush.
|
||||
System.out.print(star); // Print the star
|
||||
System.out.print(line); // flush
|
||||
System.out.print(pine); // Print the pine
|
||||
System.out.print(line); // flush
|
||||
System.out.print(init); // initals
|
||||
System.out.print("\n\n"); // don't need another flush.
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project1>java Project1a
|
||||
*
|
||||
|
||||
* * *
|
||||
|
||||
* * * * * *
|
||||
|
||||
* * * * *
|
||||
|
||||
* * * * * *
|
||||
|
||||
* * *
|
||||
|
||||
*
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
|
||||
# #
|
||||
|
||||
# # #
|
||||
|
||||
# # # #
|
||||
|
||||
#
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
AAA SSSSS PPPPPP
|
||||
AAAAA SS PP PP
|
||||
AA AA SSSSS PPPPPP
|
||||
AAAAAAA SS PP
|
||||
AA AA SSSSS PP
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,30 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 1d *
|
||||
* Class Name: Strings *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/13/2012 *
|
||||
* Hours: 0.16 Hours *
|
||||
* Purpose: To declare variables, initalize, and display two strings *
|
||||
* Concarenate and display results *
|
||||
******************************************************************************/
|
||||
|
||||
public class Strings // direction 1
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
String sStr1 = "String1", sStr2 = "String2", sStr3 = ""; // direction 2
|
||||
System.out.println(sStr1 + "\n" + sStr2);
|
||||
char cH0 = 'H', cE0 = 'E', cL0 = 'L', cL1 = 'L', cO0 = 'O', cSpc = ' ', cW0 = 'W', cO2 = 'O', cR0 ='R', cL3 = 'L', cD0 = 'D', cExlm = '!'; // direction 3
|
||||
sStr3 = "" + cH0 + cE0 + cL0 + cL1 + cO0 + cSpc + cW0 + cO2 + cR0 + cL3 + cD0 + cExlm + "";
|
||||
System.out.println(sStr3); // direction 3
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project1>java Strings
|
||||
String1
|
||||
String2
|
||||
HELLO WORLD!
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,37 @@
|
||||
/*********************************************
|
||||
* Program: Project 1a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/08/2012 *
|
||||
* Hours: 0.30 Hours *
|
||||
* Purpose: create an application that *
|
||||
* will display two of the folowing patterns *
|
||||
* ----------------------------------------- *
|
||||
* A) a 6 pointed star *
|
||||
* B) a pine tree shape composed of pound *
|
||||
* symbols *
|
||||
* C) your initals using each inital to *
|
||||
* create a large version of that letter *
|
||||
*********************************************/
|
||||
|
||||
public class Project1aDub
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String star = "\t\t\t*\t\t\t*\n\n\t\t * * *\t\t * * *\n\n\t\t * * * * * *\t\t * * * * * *\n\n\t\t"+
|
||||
" * * * * * \t\t * * * * * \n\n\t\t * * * * * *\t\t * * * * * *\n\n\t\t * * *\t\t "+
|
||||
" * * *\n\n\t\t\t*\t\t\t*"; // This is the star. It is centered.
|
||||
String pine = "\t\t\t#\t\t\t#\n\n\t\t # #\t\t # #\n\n\t\t # # #\t\t # # #\n\n\t\t # #"+
|
||||
" # #\t\t # # # #\n\n\t\t\t#\t\t\t#"; // Pine tree like figure. Centered as well
|
||||
String init = "\t AAA SSSSS PPPPPP \t AAA SSSSS PPPPPP \n\t AAAAA SS PP PP "+
|
||||
"\t AAAAA SS PP PP \n\t AA AA SSSSS PPPPPP \t AA AA SSSSS PPPPPP "+
|
||||
"\n\t AAAAAAA SS PP \t AAAAAAA SS PP \n\t AA AA SSSSS PP \t "+
|
||||
" AA AA SSSSS PP "; // ASP. Centered.
|
||||
String line = "\n\n--------------------------------------------------------------------------------\n\n"; // Flush.
|
||||
System.out.print(star); // Print the star
|
||||
System.out.print(line); // flush
|
||||
System.out.print(pine); // Print the pine
|
||||
System.out.print(line); // flush
|
||||
System.out.print(init); // initals
|
||||
System.out.print("\n\n"); // don't need another line.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*********************************************
|
||||
* Program: Project 1a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/08/2012 *
|
||||
* Hours: 0.30 Hours *
|
||||
* Purpose: create an application that *
|
||||
* will display two of the folowing patterns *
|
||||
* ----------------------------------------- *
|
||||
* A) a 6 pointed star *
|
||||
* B) a pine tree shape composed of pound *
|
||||
* symbols *
|
||||
* C) your initals using each inital to *
|
||||
* create a large version of that letter *
|
||||
*********************************************/
|
||||
|
||||
public class Project1aDub
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String star = "\t\t\t*\t\t\t*\n\n\t\t * * *\t\t * * *\n\n\t\t * * * * * *\t\t * * * * * *\n\n\t\t"+
|
||||
" * * * * * \t\t * * * * * \n\n\t\t * * * * * *\t\t * * * * * *\n\n\t\t * * *\t\t "+
|
||||
" * * *\n\n\t\t\t*\t\t\t*"; // This is the star. It is centered.
|
||||
String pine = "\t\t\t#\t\t\t#\n\n\t\t # #\t\t # #\n\n\t\t # # #\t\t # # #\n\n\t\t # #"+
|
||||
" # #\t\t # # # #\n\n\t\t\t#\t\t\t#"; // Pine tree like figure. Centered as well
|
||||
String init = "\t AAA SSSSS PPPPPP \t AAA SSSSS PPPPPP \n\t AAAAA SS PP PP "+
|
||||
"\t AAAAA SS PP PP \n\t AA AA SSSSS PPPPPP \t AA AA SSSSS PPPPPP "+
|
||||
"\n\t AAAAAAA SS PP \t AAAAAAA SS PP \n\t AA AA SSSSS PP \t "+
|
||||
" AA AA SSSSS PP "; // ASP. Centered.
|
||||
String line = "\n\n--------------------------------------------------------------------------------\n\n"; // Flush.
|
||||
System.out.print(star); // Print the star
|
||||
System.out.print(line); // flush
|
||||
System.out.print(pine); // Print the pine
|
||||
System.out.print(line); // flush
|
||||
System.out.print(init); // initals
|
||||
System.out.print("\n\n"); // don't need another line.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
=================================================================================================================================
|
||||
|
||||
S:\programs\Mod1\Project1>java Project1aDub
|
||||
* *
|
||||
|
||||
* * * * * *
|
||||
|
||||
* * * * * * * * * * * *
|
||||
|
||||
* * * * * * * * * *
|
||||
|
||||
* * * * * * * * * * * *
|
||||
|
||||
* * * * * *
|
||||
|
||||
* *
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# #
|
||||
|
||||
# # # #
|
||||
|
||||
# # # # # #
|
||||
|
||||
# # # # # # # #
|
||||
|
||||
# #
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
AAA SSSSS PPPPPP AAA SSSSS PPPPPP
|
||||
AAAAA SS PP PP AAAAA SS PP PP
|
||||
AA AA SSSSS PPPPPP AA AA SSSSS PPPPPP
|
||||
AAAAAAA SS PP AAAAAAA SS PP
|
||||
AA AA SSSSS PP AA AA SSSSS PP
|
||||
@@ -0,0 +1,80 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 2a *
|
||||
* Class Name: Project2a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/15/2012 *
|
||||
* Hours: 0.25 Hours *
|
||||
* Purpose: To demonstrate the ability to create a conventionally named *
|
||||
* java application, use comments to document the software, *
|
||||
* use imported software components, instantiante objects, *
|
||||
* use methods associated with objects of prebuilt classes, *
|
||||
* use of user friendly prompts, echos, and error messages, *
|
||||
* use try and catch to prevent hard software crashes. *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Project2a
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner console = new Scanner(System.in); // direction 1
|
||||
/* begin direction 2 */
|
||||
int iWholeNum01 = 0;
|
||||
try
|
||||
{
|
||||
System.out.print("Please input a whole number: "); // user friendly prompt
|
||||
iWholeNum01 = console.nextInt(); // grab user input
|
||||
System.out.println("Your number was: " + iWholeNum01 +"\n"); // user friendly echo
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("\nWe're sorry, this was not a whole number.\n"+
|
||||
"Please re-run the program."); // (hopefully) user friendly error massage
|
||||
return; // end execution here. we want them to wisen up eh.
|
||||
}
|
||||
|
||||
/* begin direction 3 */
|
||||
double dRealNum01 = 0.0;
|
||||
try
|
||||
{
|
||||
System.out.print("Please input a decimal number: "); // user friendly prompt
|
||||
dRealNum01 = console.nextDouble(); // grab user input
|
||||
System.out.println("Your number was: " + dRealNum01 +"\n"); // user friendly echo
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("\nWe're sorry, this was not a real number.\n"+
|
||||
"Please re-run the program."); // (hopefully) user friendly error massage
|
||||
return; // end execution here. we want them to wisen up eh.
|
||||
}
|
||||
|
||||
/* begin direction 4 */
|
||||
String sFirstName = "";
|
||||
System.out.print("Please enter your First name: "); // user friendly prompt
|
||||
sFirstName = console.next(); // grab user input
|
||||
System.out.println("Your name is: " + sFirstName); // user friendly echo
|
||||
|
||||
// Done !
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project2>java Project2a
|
||||
Please input a whole number: 50
|
||||
Your number was: 50
|
||||
|
||||
Please input a decimal number: 25.0
|
||||
Your number was: 25.0
|
||||
|
||||
Please enter your First name: Amrit Panesar
|
||||
Your name is: Amrit
|
||||
|
||||
E:\programs\Mod1\Project2>java Project2a
|
||||
Please input a whole number: error
|
||||
|
||||
We're sorry, this was not a whole number.
|
||||
Please re-run the program.
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,28 @@
|
||||
PROMPT for input of hours worked
|
||||
STORE hours worked
|
||||
CALCULATE gross pay
|
||||
grossPay = hours * rate
|
||||
CALCULATE tax
|
||||
Tax = gross * .14
|
||||
CALCULATE net pay
|
||||
netPay = gross – taxes
|
||||
CALCULATE clothing expense
|
||||
clothing = netPay * .10
|
||||
CALCULATE school supply expense
|
||||
supplies = netPay * .01
|
||||
CALCULATE remainder
|
||||
remainder = netPay – clothing – supplies
|
||||
CALCULATE student savings
|
||||
studentSavings = remainder * .25
|
||||
CALCULATE parental savings
|
||||
Parental savings = student Savings * .5
|
||||
DISPLAY pay rate
|
||||
DISPLAY hours
|
||||
DISPLAY gross pay
|
||||
DISPLAY taxes
|
||||
DISPLAY net pay
|
||||
DISPLAY clothing expense
|
||||
DISPLAY supply expense
|
||||
DISPLAY student savings
|
||||
DISPLAY parental savings
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 2b *
|
||||
* Class Name: SummerJob *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/23/2012 *
|
||||
* Hours: 0.50 Hours *
|
||||
* Purpose: To calculate the gross and net pay of a hypothetical summer *
|
||||
* job. The ability to deduct taxes is also demonstrated. *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SummerJob
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
final double HOURLY_WAGE = 15.50;// hourly wage
|
||||
final double PARENT_RATE = 0.50; // 50 cents per every *whole* dollar made.
|
||||
final double TAX_RATE = 0.14; // 14% taxes withheld
|
||||
final double CLOTHING_RATE = 0.10; // 10% for clothing
|
||||
final double SCHOOL_RATE = 0.01; // 01% for school supplies
|
||||
final double SAVINGS_RATE = 0.25; // 25% for savings bond purchase
|
||||
double dHoursWorked = 0.0;
|
||||
|
||||
//PROMPT for input of hours worked
|
||||
try
|
||||
{
|
||||
Scanner console = new Scanner(System.in);
|
||||
System.out.print("Please enter the ammount of hours worked: ");
|
||||
//STORE hours worked
|
||||
dHoursWorked = console.nextDouble();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("We're sorry, that was an invalid value.\n"
|
||||
+ "Please re-run the program.");
|
||||
return;
|
||||
}
|
||||
//CALCULATE gross pay
|
||||
//grossPay = hours * rate
|
||||
double dGrossPay = (dHoursWorked * HOURLY_WAGE);
|
||||
//CALCULATE tax
|
||||
//Tax = gross * .14
|
||||
double dTaxes = (dGrossPay * TAX_RATE);
|
||||
//CALCULATE net pay
|
||||
//netPay = gross – taxes
|
||||
double dNetPay = (dGrossPay - dTaxes);
|
||||
//CALCULATE clothing expense
|
||||
//clothing = netPay * .10
|
||||
double dCloExp = (dNetPay * CLOTHING_RATE);
|
||||
//CALCULATE school supply expense
|
||||
//supplies = netPay * .01
|
||||
double dSchExp = (dNetPay * SCHOOL_RATE);
|
||||
//CALCULATE remainder
|
||||
//remainder = netPay – clothing – supplies
|
||||
double dEODBal = (dNetPay - dCloExp - dSchExp);
|
||||
//CALCULATE student savings
|
||||
//studentSavings = remainder * .25
|
||||
double dSavBon = (int)(dEODBal * SAVINGS_RATE);
|
||||
//CALCULATE parental savings
|
||||
//Parental savings = student Savings * .5
|
||||
double dParSav = (dSavBon * PARENT_RATE);
|
||||
double dGTotal = (dEODBal + dSavBon + dParSav);
|
||||
|
||||
// System.out.format("%.2f", 10.499);
|
||||
//DISPLAY pay rate
|
||||
System.out.format("Your pay rate is: $%.2f per hour\n", dHourlyWage); // pay rate
|
||||
//DISPLAY hours
|
||||
System.out.format("You worked: %.2f hours\n", dHoursWorked); // hours
|
||||
//DISPLAY gross pay
|
||||
System.out.format("Your taxable income is: $%.2f\n", dGrossPay); // gross pay
|
||||
//DISPLAY taxes
|
||||
System.out.format("Taxes taken from your paycheck: $%.2f\n",dTaxes); // taxes
|
||||
//DISPLAY net pay
|
||||
System.out.format("Earning you a total of: $%.2f\n", dNetPay); // net pay
|
||||
System.out.format("------------------------------------------------------\n");
|
||||
//DISPLAY clothing expense
|
||||
System.out.format("Your withholdings for clothes expenses are: $%.2f\n", dCloExp);
|
||||
//DISPLAY supply expense
|
||||
System.out.format("Your withholdings for school supplies are: $%.2f\n", dSchExp);
|
||||
//DISPLAY student savings
|
||||
System.out.format("Your withholdings for a saving bond are: $%.2f\n", dSavBon);
|
||||
System.out.format("------------------------------------------------------\n");
|
||||
//DISPLAY parental savings
|
||||
System.out.format("Your parental contributions for this month are: $%.2f\n", dParSav);
|
||||
System.out.format("Giving you a grand total of: %.2f\n", dGTotal);
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
E:\programs\Mod1\Project2>java SummerJob
|
||||
Please enter the ammount of hours worked: 10
|
||||
Your pay rate is: $15.50 per hour
|
||||
You worked: 10.00 hours
|
||||
Your taxable income is: $155.00
|
||||
Taxes taken from your paycheck: $21.70
|
||||
Earning you a total of: $133.30
|
||||
------------------------------------------------------
|
||||
Your withholdings for clothes expenses are: $13.33
|
||||
Your withholdings for school supplies are: $1.33
|
||||
Your withholdings for a saving bond are: $29.00
|
||||
------------------------------------------------------
|
||||
Your parental contributions for this month are: $14.50
|
||||
Giving you a grand total of: 162.14
|
||||
|
||||
E:\programs\Mod1\Project2>java SummerJob
|
||||
Please enter the ammount of hours worked: 20
|
||||
Your pay rate is: $15.50 per hour
|
||||
You worked: 20.00 hours
|
||||
Your taxable income is: $310.00
|
||||
Taxes taken from your paycheck: $43.40
|
||||
Earning you a total of: $266.60
|
||||
------------------------------------------------------
|
||||
Your withholdings for clothes expenses are: $26.66
|
||||
Your withholdings for school supplies are: $2.67
|
||||
Your withholdings for a saving bond are: $59.00
|
||||
------------------------------------------------------
|
||||
Your parental contributions for this month are: $29.50
|
||||
Giving you a grand total of: 325.77
|
||||
|
||||
E:\programs\Mod1\Project2>java SummerJob
|
||||
Please enter the ammount of hours worked: 40
|
||||
Your pay rate is: $15.50 per hour
|
||||
You worked: 40.00 hours
|
||||
Your taxable income is: $620.00
|
||||
Taxes taken from your paycheck: $86.80
|
||||
Earning you a total of: $533.20
|
||||
------------------------------------------------------
|
||||
Your withholdings for clothes expenses are: $53.32
|
||||
Your withholdings for school supplies are: $5.33
|
||||
Your withholdings for a saving bond are: $118.00
|
||||
------------------------------------------------------
|
||||
Your parental contributions for this month are: $59.00
|
||||
Giving you a grand total of: 651.55
|
||||
*/
|
||||
Binary file not shown.
Whitespace-only changes.
@@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 3b *
|
||||
* Class Name: DecFormat *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/20/2012 *
|
||||
* Hours: 0.25 Hours *
|
||||
* Purpose: To demonstrate the ability to create a conventionally named *
|
||||
* java application, the parsing of numeric strings with *
|
||||
* exception handling, format numeric output using Decimal *
|
||||
* Format, write to and read from a simple text file, use Decimal*
|
||||
* Format to format output *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class DecFormat
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
DecimalFormat df3Pos = new DecimalFormat("#####,00.000"); //2a
|
||||
DecimalFormat df5Pos = new DecimalFormat("#######,00.0000"); //2b
|
||||
|
||||
double dLarge01 = 0.1535012260547;
|
||||
|
||||
System.out.println("dLarge01 formatted to 3 places: "
|
||||
+ df3Pos.format(dLarge01)); //2c
|
||||
|
||||
System.out.println("dLarge01 formatted to 5 places: "
|
||||
+ df5Pos.format(dLarge01)); //2c
|
||||
}
|
||||
}
|
||||
/* output:
|
||||
E:\programs\Mod1\Project3>java DecFormat
|
||||
dLarge01 formatted to 3 places: 00.154
|
||||
dLarge01 formatted to 5 places: 00.1535
|
||||
*/
|
||||
@@ -0,0 +1,54 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 3c *
|
||||
* Class Name: JOptPane *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/20/2012 *
|
||||
* Hours: 0.25 Hours *
|
||||
* Purpose: To demonstrate the ability to create a conventionally named *
|
||||
* java application, the parsing of numeric strings with *
|
||||
* exception handling, format numeric output using Decimal *
|
||||
* Format, write to and read from a simple text file, use Decimal*
|
||||
* Format to format output *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import javax.swing.*; //3
|
||||
|
||||
public class JOptPane //3
|
||||
{
|
||||
public static void main(String[] args) //main
|
||||
{
|
||||
String input = JOptionPane.showInputDialog("Please enter a whole number."); //3a
|
||||
int iInt01;
|
||||
try
|
||||
{
|
||||
iInt01 = Integer.parseInt(input); //3b
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
//3c
|
||||
return;
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "Your number was: "+iInt01,
|
||||
"Success", JOptionPane.INFORMATION_MESSAGE);// 3d
|
||||
|
||||
/*--double time--*/
|
||||
input = JOptionPane.showInputDialog("Please enter a decimal number."); //3e
|
||||
double dReal01;
|
||||
try
|
||||
{
|
||||
dReal01 = Double.parseDouble(input); //3f
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
//3g
|
||||
return;
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "Your number was: "+dReal01,
|
||||
"Success", JOptionPane.INFORMATION_MESSAGE);// 3d
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 3a *
|
||||
* Class Name: Project3a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/20/2012 *
|
||||
* Hours: 1.00 Hours *
|
||||
* Purpose: To demonstrate the ability to create a conventionally named *
|
||||
* java application, the parsing of numeric strings with *
|
||||
* exception handling, format numeric output using Decimal *
|
||||
* Format, write to and read from a simple text file, use Decimal*
|
||||
* Format to format output *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
public class Project3a
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
int iNum01 = 1337; //1a
|
||||
int iNum02 = 42; //1a
|
||||
|
||||
double dPow = Math.pow(iNum01, iNum02); //1b1
|
||||
double dSqrt = Math.sqrt(iNum01); //1b2
|
||||
|
||||
System.out.println("The first number is: "+iNum01+".");
|
||||
System.out.println("The second number is: "+iNum02+".");
|
||||
System.out.println(""+iNum01+" raised to the power of "+iNum02+" is: "
|
||||
+ dPow+"."); //1b1
|
||||
System.out.println("The square root of "+iNum01+" is: "+dSqrt+".\n");//1b2
|
||||
|
||||
if (dPow >= dSqrt) //1b3
|
||||
{
|
||||
System.out.println("The first number ("+iNum01+") raised to the "
|
||||
+"second number ("+iNum02+") \nis greater than the square "
|
||||
+"root of ("+iNum01+")."); //1b3
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("The square root of "+iNum01+" is greater than"
|
||||
+ "the first number("+iNum01+") raised to the second number"
|
||||
+ "("+iNum02+")."); //1b3
|
||||
}
|
||||
System.out.println("\n---------------------------------------------\n");
|
||||
|
||||
double dRad = 7; //1b4
|
||||
double dDia = 7*2; //1b4
|
||||
double dArea = Math.PI*(Math.pow(dRad, 2)); //1b4
|
||||
|
||||
System.out.println("Circle's Radius: "+ dRad + "."); //1b4
|
||||
System.out.println("Circle's Diameter: " + dDia + "."); //1b4
|
||||
System.out.println("Circle's Area: "+ dArea + "."); //1b4
|
||||
|
||||
System.out.println("\n---------------------------------------------\n");
|
||||
|
||||
String sQuote= "Now is the time for all good men to come to the aid of "
|
||||
+ "their country."; //1c
|
||||
|
||||
System.out.println("The ammount of characters in the quote \n"
|
||||
+ "\""+sQuote+"\" \nis: "+sQuote.length()+".\n"); //1c1
|
||||
|
||||
System.out.println("The same quote in all caps is: \n"
|
||||
+ "\""+sQuote.toUpperCase()+"\"\n"); //1c2
|
||||
|
||||
System.out.println("The same quote in lower case is: \n"
|
||||
+ "\""+sQuote.toLowerCase()+"\"\n"); //1c3
|
||||
|
||||
System.out.println("The first index of the character 'o' is: "
|
||||
+ sQuote.indexOf('o')+"\n"); //1c4
|
||||
|
||||
System.out.println("The next index of the character 'o' is: "
|
||||
+ sQuote.indexOf('o',(sQuote.indexOf('o')+1))+"\n"); //1c5
|
||||
|
||||
System.out.println("The character present at index 17 is a(n) '"
|
||||
+ sQuote.charAt(17) + "'.\n"); //1c6
|
||||
|
||||
String sSubstr = sQuote.substring(sQuote.indexOf('t'),
|
||||
(sQuote.length()-1)); //1c7
|
||||
|
||||
System.out.println("The substring of the quote from the first instence "
|
||||
+ "of the character 't' \nto the last character, not including "
|
||||
+ "a period is: \n\""+sSubstr+"\""); //1c8
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
E:\programs\Mod1\Project3>java Project3a
|
||||
The first number is: 1337.
|
||||
The second number is: 42.
|
||||
1337 raised to the power of 42 is: 1.983896928320167E131.
|
||||
The square root of 1337 is: 36.565010597564445.
|
||||
|
||||
The first number (1337) raised to the second number (42)
|
||||
is greater than the square root of (1337).
|
||||
|
||||
---------------------------------------------
|
||||
|
||||
Circle's Radius: 7.0.
|
||||
Circle's Diameter: 14.0.
|
||||
Circle's Area: 153.93804002589985.
|
||||
|
||||
---------------------------------------------
|
||||
|
||||
The ammount of characters in the quote
|
||||
"Now is the time for all good men to come to the aid of their country."
|
||||
is: 69.
|
||||
|
||||
The same quote in all caps is:
|
||||
"NOW IS THE TIME FOR ALL GOOD MEN TO COME TO THE AID OF THEIR COUNTRY."
|
||||
|
||||
The same quote in lower case is:
|
||||
"now is the time for all good men to come to the aid of their country."
|
||||
|
||||
The first index of the character 'o' is: 1
|
||||
|
||||
The next index of the character 'o' is: 17
|
||||
|
||||
The character present at index 17 is a(n) 'o'.
|
||||
|
||||
The substring of the quote from the first instence of the character 't'
|
||||
to the last character, not including a period is:
|
||||
"the time for all good men to come to the aid of their country"
|
||||
*/
|
||||
@@ -0,0 +1,80 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 3d *
|
||||
* Class Name: TempCon *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/23/2012 *
|
||||
* Hours: 1.50 Hours *
|
||||
* Purpose: To demonstrate the ability to create a conventionally named *
|
||||
* java application, the parsing of numeric strings with *
|
||||
* exception handling, format numeric output using Decimal *
|
||||
* Format, write to and read from a simple text file, use Decimal*
|
||||
* Format to format output *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class TempCon
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
String sCity = JOptionPane.showInputDialog("Please enter a city."); //4a
|
||||
sCity = sCity.toUpperCase();//4b
|
||||
|
||||
String sDate = JOptionPane.showInputDialog("Please enter a date, mm/dd/yyyy."); //4c
|
||||
|
||||
String sTemp = JOptionPane.showInputDialog("Please enter a temperature in Fahrenheit."); //4d
|
||||
double dTemp = 0;
|
||||
try
|
||||
{
|
||||
dTemp = Double.parseDouble(sTemp);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+dTemp+"\" was an invalid input"
|
||||
+"Please re-run the application.", "Fatal Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
double dTempc = (dTemp - 32) * (5.0/9.0);
|
||||
String sTempc = String.format("%.2f", dTempc);
|
||||
|
||||
PrintWriter outFile = null;
|
||||
Scanner inFile = null;
|
||||
try
|
||||
{
|
||||
outFile = new PrintWriter("tempfile.dat");
|
||||
inFile = new Scanner(new FileReader("tempfile.dat"));
|
||||
String sOut = "Temperature for: "+sCity+"\non: "+sDate+"\n"
|
||||
+dTemp+"\u00B0 Fahrenheit\n"+sTempc+"\u00B0 Celsius.";
|
||||
String sIn = "";
|
||||
|
||||
outFile.append(sOut);
|
||||
outFile.flush();
|
||||
sIn = inFile.nextLine() + "\n" + inFile.nextLine() + "\n" +
|
||||
inFile.nextLine() + "\n" + inFile.nextLine();
|
||||
|
||||
JOptionPane.showMessageDialog(null,sIn, "Temperature for: "+sCity,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, please make a file named "
|
||||
+"Tempfile.dat", "Fatal Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, caught an I/o exception "
|
||||
,"Fatal Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
outFile.close();
|
||||
inFile.close();
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
Temperature for: EL CAJON
|
||||
on: 01/10/1990
|
||||
-212.0° Fahrenheit
|
||||
-135.56° Celsius.
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,60 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 4a *
|
||||
* Class Name: Project4a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/10/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: Evaluate the input of a char representing the taxpayer's *
|
||||
* filing status and reporting weather the taxpayer will be *
|
||||
* taxed as a single or married person. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Project4a
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
System.out.println("Are you (M)arried (H)ead of Household or "
|
||||
+ "(S)ingle?");
|
||||
Scanner console = new Scanner(System.in);
|
||||
String sInput = console.next();
|
||||
char cStatus = sInput.toLowerCase().charAt(0);
|
||||
|
||||
if (cStatus != 'm' && cStatus != 'h' && cStatus != 's')
|
||||
{
|
||||
System.out.println("Invalid input \""+cStatus+"\", please re-run the program");
|
||||
System.exit(0);
|
||||
}
|
||||
if (cStatus != 'm')
|
||||
System.out.println("You are filing as Single");
|
||||
else
|
||||
System.out.println("You are filing as Married");
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project 4>java Project4a
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as Married
|
||||
|
||||
E:\programs\Mod1\Project 4>java Project4a
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
h
|
||||
You are filing as Single
|
||||
|
||||
E:\programs\Mod1\Project 4>java Project4a
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
s
|
||||
You are filing as Single
|
||||
|
||||
E:\programs\Mod1\Project 4>java Project4a
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
4
|
||||
Invalid input "4", please re-run the program
|
||||
|
||||
*/
|
||||
Binary file not shown.
@@ -0,0 +1,60 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 4b *
|
||||
* Class Name: Project4b *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/10/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: Evaluate the input of a char representing the taxpayer's *
|
||||
* filing status and reporting weather the taxpayer will be *
|
||||
* taxed as a single or married person. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Project4b
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
System.out.println("Are you (M)arried (H)ead of Household (E)xempt "
|
||||
+ "or (S)ingle?");
|
||||
Scanner console = new Scanner(System.in);
|
||||
String sInput = console.next();
|
||||
char cStatus = sInput.toLowerCase().charAt(0);
|
||||
|
||||
if (cStatus != 'm' && cStatus != 'h' && cStatus != 's')
|
||||
{
|
||||
System.out.println("You have elected for exempt status");
|
||||
System.exit(0);
|
||||
}
|
||||
if (cStatus == 'm')
|
||||
System.out.println("You are filing as Married");
|
||||
else if (cStatus == 's')
|
||||
System.out.println("You are filing as Single");
|
||||
else if (cStatus == 'h')
|
||||
System.out.println("You are filing as Head of Household");
|
||||
}
|
||||
|
||||
}
|
||||
/* output:
|
||||
E:\programs\Mod1\Project4>java Project4b
|
||||
Are you (M)arried (H)ead of Household (E)xempt or (S)ingle?
|
||||
m
|
||||
You are filing as Married
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4b
|
||||
Are you (M)arried (H)ead of Household (E)xempt or (S)ingle?
|
||||
head of household
|
||||
You are filing as Head of Household
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4b
|
||||
Are you (M)arried (H)ead of Household (E)xempt or (S)ingle?
|
||||
s
|
||||
You are filing as Single
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4b
|
||||
Are you (M)arried (H)ead of Household (E)xempt or (S)ingle?
|
||||
4
|
||||
You have elected for exempt status
|
||||
*/
|
||||
Binary file not shown.
@@ -0,0 +1,96 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 4c *
|
||||
* Class Name: Project4c *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/10/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: Evaluate the input of a char representing the taxpayer's *
|
||||
* filing status and reporting weather the taxpayer will be *
|
||||
* taxed as a single or married person. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Project4c
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner console = new Scanner (System.in);
|
||||
System.out.println("How many withholdings do you have?");
|
||||
int iWHold = 0;
|
||||
String input = console.next();
|
||||
try
|
||||
{
|
||||
iWHold = Integer.parseInt(input);
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
//input has been sanitized.
|
||||
int iHVal = 0;
|
||||
switch (iWHold)
|
||||
{
|
||||
case 1:
|
||||
iHVal = 42;
|
||||
break;
|
||||
case 2:
|
||||
iHVal = 83;
|
||||
break;
|
||||
case 3:
|
||||
iHVal = 125;
|
||||
break;
|
||||
case 4:
|
||||
iHVal = 167;
|
||||
break;
|
||||
case 5:
|
||||
iHVal = 208;
|
||||
break;
|
||||
case 6:
|
||||
iHVal = 250;
|
||||
break;
|
||||
case 7:
|
||||
iHVal = 292;
|
||||
break;
|
||||
case 8:
|
||||
iHVal = 333;
|
||||
break;
|
||||
case 9:
|
||||
iHVal = 375;
|
||||
break;
|
||||
case 10:
|
||||
iHVal = 417;
|
||||
break;
|
||||
default:
|
||||
iHVal = iWHold * 42;
|
||||
break;
|
||||
}
|
||||
System.out.println (iWHold + " withholding allowances provides an "
|
||||
+ "estimated deduction of: $" +iHVal);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*output:
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4c
|
||||
How many withholdings do you have?
|
||||
1
|
||||
1 withholding allowances provides an estimated deduction of: $42
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4c
|
||||
How many withholdings do you have?
|
||||
1024
|
||||
1024 withholding allowances provides an estimated deduction of: $43008
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4c
|
||||
How many withholdings do you have?
|
||||
5
|
||||
5 withholding allowances provides an estimated deduction of: $208
|
||||
|
||||
*/
|
||||
Binary file not shown.
@@ -0,0 +1,129 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 4d *
|
||||
* Class Name: Project4d *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/10/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: Evaluate the input of a char representing the taxpayer's *
|
||||
* filing status and reporting weather the taxpayer will be *
|
||||
* taxed as a single or married person. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Project4d
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner console = new Scanner (System.in);
|
||||
System.out.println("What is your gross pay?");
|
||||
double dGross = 0;
|
||||
String input = console.next();
|
||||
try
|
||||
{
|
||||
dGross = Double.parseDouble(input);k
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
System.out.println("How many withholdings do you have?");
|
||||
int iWHold = 0;
|
||||
input = console.next();
|
||||
try
|
||||
{
|
||||
iWHold = Integer.parseInt(input);
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
if (iWHold < 0)
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
System.out.println("Are you (M)arried (H)ead of Household or "
|
||||
+ "(S)ingle?");
|
||||
String sInput = console.next();
|
||||
char cStatus = sInput.toLowerCase().charAt(0);
|
||||
if (cStatus != 'm' && cStatus != 'h' && cStatus != 's')
|
||||
{
|
||||
System.out.println("We're sorry, \""+cStatus+"\", was an invalid"
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
boolean bLowInc = false;
|
||||
if ((cStatus == 's' && dGross <= 522) ||
|
||||
(cStatus == 'm' && dGross <= 522 && iWHold <=1 ) ||
|
||||
(cStatus == 'm' && dGross <= 1044 && iWHold >=2 ) ||
|
||||
(cStatus == 'h' && dGross <= 1044))
|
||||
{
|
||||
bLowInc = true;
|
||||
}
|
||||
switch (cStatus)
|
||||
{
|
||||
case 's':
|
||||
System.out.println("You are filing as single.");
|
||||
break;
|
||||
case 'm':
|
||||
System.out.println("You are filing as married.");
|
||||
break;
|
||||
case 'h':
|
||||
System.out.println("You are filing as head of household.");
|
||||
break;
|
||||
}
|
||||
if (bLowInc)
|
||||
System.out.println("You ARE classified as low income");
|
||||
else
|
||||
System.out.println("You are NOT classified as low income");
|
||||
}
|
||||
}
|
||||
/* Output
|
||||
F:\programs\Mod1\Project4>java Project4d
|
||||
What is your gross pay?
|
||||
1043
|
||||
How many withholdings do you have?
|
||||
1
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as married.
|
||||
You are NOT classified as low income
|
||||
|
||||
F:\programs\Mod1\Project4>java Project4d
|
||||
What is your gross pay?
|
||||
1043
|
||||
How many withholdings do you have?
|
||||
1
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as married.
|
||||
You are NOT classified as low income
|
||||
|
||||
F:\programs\Mod1\Project4>java Project4d
|
||||
What is your gross pay?
|
||||
1044
|
||||
How many withholdings do you have?
|
||||
2
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as married.
|
||||
You ARE classified as low income
|
||||
|
||||
F:\programs\Mod1\Project4>java Project4d
|
||||
What is your gross pay?
|
||||
1045
|
||||
How many withholdings do you have?
|
||||
3
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as married.
|
||||
You are NOT classified as low income
|
||||
*/
|
||||
Binary file not shown.
@@ -0,0 +1,214 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 4e *
|
||||
* Class Name: Project4e *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/10/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: Evaluate the input of a char representing the taxpayer's *
|
||||
* filing status and reporting weather the taxpayer will be *
|
||||
* taxed as a single or married person. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Project4e
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner console = new Scanner (System.in); //console
|
||||
System.out.println("What is your gross pay?");
|
||||
double dGross = 0;
|
||||
String input = console.next(); //grab a string
|
||||
try
|
||||
{
|
||||
dGross = Double.parseDouble(input); // parse it
|
||||
}
|
||||
catch (NumberFormatException nfe) // bomb if it doesn't validate
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
if (dGross < 0)
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
System.out.println("Are you (M)arried (H)ead of Household or "
|
||||
+ "(S)ingle?");
|
||||
String sInput = console.next(); // grab a string
|
||||
char cStatus = sInput.toLowerCase().charAt(0); // make it lowercase, grab the first character
|
||||
if (cStatus != 'm' && cStatus != 'h' && cStatus != 's') //only need to handle these
|
||||
{
|
||||
System.out.println("We're sorry, \""+cStatus+"\", was an invalid"
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
double dBase = 0, dExcess = 0, dPercent = 0;
|
||||
if (cStatus == 's' || cStatus == 'h' ) {
|
||||
if (dGross <= 90)
|
||||
{
|
||||
dBase = 0.00;
|
||||
dPercent = 0.00;
|
||||
dExcess = 0.00;
|
||||
}
|
||||
else if (dGross > 90 && dGross <=452)
|
||||
{
|
||||
dBase = 0.00;
|
||||
dPercent = 0.10;
|
||||
dExcess = 90.00;
|
||||
}
|
||||
else if (dGross > 452 && dGross <= 1563)
|
||||
{
|
||||
dBase = 36.20;
|
||||
dPercent = 0.15;
|
||||
dExcess = 452.00;
|
||||
}
|
||||
else if (dGross > 1563 && dGross <= 3658)
|
||||
{
|
||||
dBase = 202.85;
|
||||
dPercent = 0.25;
|
||||
dExcess = 1563.00;
|
||||
}
|
||||
else if (dGross > 3658 && dGross <= 7533)
|
||||
{
|
||||
dBase = 276.60;
|
||||
dPercent = 0.28;
|
||||
dExcess = 3658.00;
|
||||
}
|
||||
else if (dGross > 7533 && dGross <= 16271)
|
||||
{
|
||||
dBase = 4695.14;
|
||||
dPercent = 0.33;
|
||||
dExcess = 7533.00;
|
||||
}
|
||||
else if (dGross > 16271)
|
||||
{
|
||||
dBase = 4695.14;
|
||||
dPercent = 0.35;
|
||||
dExcess = 16271.00;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Illogical.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
else if (cStatus == 'm')
|
||||
{
|
||||
if (dGross <= 338)
|
||||
{
|
||||
dBase = 0.00;
|
||||
dPercent = 0.00;
|
||||
dExcess = 0.00;
|
||||
}
|
||||
else if (dGross > 338 && dGross <=1063 )
|
||||
{
|
||||
dBase = 0.00;
|
||||
dPercent = 0.10;
|
||||
dExcess = 338.00;
|
||||
}
|
||||
else if (dGross > 1063 && dGross <= 3283)
|
||||
{
|
||||
dBase = 72.50;
|
||||
dPercent = 0.15;
|
||||
dExcess = 1063.00;
|
||||
}
|
||||
else if (dGross > 3283 && dGross <= 6283)
|
||||
{
|
||||
dBase = 405.50;
|
||||
dPercent = 0.25;
|
||||
dExcess = 3283.00;
|
||||
}
|
||||
else if (dGross > 6283 && dGross <= 9398)
|
||||
{
|
||||
dBase = 1155.50;
|
||||
dPercent = 0.28;
|
||||
dExcess = 6283.00;
|
||||
}
|
||||
else if (dGross > 9398 && dGross <= 16519)
|
||||
{
|
||||
dBase = 2027.70;
|
||||
dPercent = 0.33;
|
||||
dExcess = 9398.00;
|
||||
}
|
||||
else if (dGross > 16519 )
|
||||
{
|
||||
dBase = 4377.63;
|
||||
dPercent = 0.35;
|
||||
dExcess = 16519.00;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Illogical.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Illogical.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
double dFed = dBase + ((dGross - dExcess) * dPercent);
|
||||
|
||||
switch (cStatus)
|
||||
{
|
||||
case 'm':
|
||||
System.out.println("You are filing as: Married");
|
||||
break;
|
||||
case 's':
|
||||
System.out.println("You are filing as: Single");
|
||||
break;
|
||||
case 'h':
|
||||
System.out.println("You are filing as: Head of Household");
|
||||
break;
|
||||
}
|
||||
System.out.printf("You gross income is: $%.2f\n", dGross);
|
||||
System.out.printf("Therefore, your base tax is: $%.2f\n", dBase);
|
||||
System.out.printf("Your tax surcharge percentage is: %%%.2f\n", (dPercent*100));
|
||||
// System.out.printf("%s + ((%s - %s) * (%s/100)\n", dBase, dGross, dExcess, (dPercent*100)); // debugging.
|
||||
System.out.printf("Your withholding tax is: $%.2f\n", dFed);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
S:\programs\Mod1\Project4>java Project4e
|
||||
What is your gross pay?
|
||||
31415
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
s
|
||||
You are filing as: Single
|
||||
You gross income is: $31415.00
|
||||
Therefore, your base tax is: $4695.14
|
||||
Your tax surcharge percentage is: %35.00
|
||||
Your withholding tax is: $9995.54
|
||||
|
||||
S:\programs\Mod1\Project4>java Project4e
|
||||
What is your gross pay?
|
||||
1231
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
s
|
||||
You are filing as: Single
|
||||
You gross income is: $1231.00
|
||||
Therefore, your base tax is: $36.20
|
||||
Your tax surcharge percentage is: %15.00
|
||||
Your withholding tax is: $153.05
|
||||
|
||||
S:\programs\Mod1\Project4>java Project4e
|
||||
What is your gross pay?
|
||||
555555
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as: Married
|
||||
You gross income is: $555555.00
|
||||
Therefore, your base tax is: $4377.63
|
||||
Your tax surcharge percentage is: %35.00
|
||||
Your withholding tax is: $193040.23
|
||||
*/
|
||||
Binary file not shown.
@@ -0,0 +1,55 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 5a *
|
||||
* Class Name: Project5a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 10/04/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: demonstrate proficiency in using Counted loops, proficiency in*
|
||||
* using Sentinel controlled loops, proficiency in using Flag *
|
||||
* controlled loops, proficiency in using EOF controlled loops, *
|
||||
* proficiency in using Forever loops, providing appropriate *
|
||||
* documentation for programs, the use of conventional *
|
||||
* identifiers for classes and variables, the ability to use *
|
||||
* simple program testing techniques to ensure the quality of *
|
||||
* their work product, the use of white space for ensuring *
|
||||
* readability of program code, correct formulation of boolean *
|
||||
* expressions to be used in the control of iterative structures *
|
||||
******************************************************************************/
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Project5a
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
String sSent = "";
|
||||
Scanner inFile = null;
|
||||
Scanner console = new Scanner (System.in); //console
|
||||
String temp = "";
|
||||
while (!sSent.equals("!q"))
|
||||
{
|
||||
System.out.println("Enter a name, type !q to quit");
|
||||
temp = console.nextLine();
|
||||
sSent = temp;
|
||||
System.out.println(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
|
||||
E:\programs\Mod1\Project5>java Project5a
|
||||
Enter a name, type !q to quit
|
||||
Blah
|
||||
Blah
|
||||
Enter a name, type !q to quit
|
||||
hjsdalkf
|
||||
hjsdalkf
|
||||
Enter a name, type !q to quit
|
||||
Neo Anderson
|
||||
Neo Anderson
|
||||
Enter a name, type !q to quit
|
||||
!q
|
||||
!q
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,117 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 5b *
|
||||
* Class Name: Project5b *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 10/04/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: demonstrate proficiency in using Counted loops, proficiency in*
|
||||
* using Sentinel controlled loops, proficiency in using Flag *
|
||||
* controlled loops, proficiency in using EOF controlled loops, *
|
||||
* proficiency in using Forever loops, providing appropriate *
|
||||
* documentation for programs, the use of conventional *
|
||||
* identifiers for classes and variables, the ability to use *
|
||||
* simple program testing techniques to ensure the quality of *
|
||||
* their work product, the use of white space for ensuring *
|
||||
* readability of program code, correct formulation of boolean *
|
||||
* expressions to be used in the control of iterative structures *
|
||||
******************************************************************************/
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Project5b
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner inFile = null;
|
||||
try
|
||||
{
|
||||
inFile = new Scanner(new FileReader("payrollData.txt"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
for (int i=0;i<5;i++)
|
||||
{
|
||||
int iEmployee = inFile.nextInt();
|
||||
char cFiling = inFile.next().charAt(0);
|
||||
int iWHold = inFile.nextInt();
|
||||
char cClass = inFile.next().charAt(0);
|
||||
double dHours = inFile.nextDouble();
|
||||
double dPayR = inFile.nextDouble();
|
||||
double dSal = inFile.nextDouble();
|
||||
double dYTD = inFile.nextDouble();
|
||||
String sFOut = "";
|
||||
String sCout = "";
|
||||
|
||||
|
||||
if (cFiling == 's')
|
||||
{
|
||||
sFOut = "Single";
|
||||
}
|
||||
else if (cFiling == 'h' )
|
||||
{
|
||||
sFOut = "Head of Household";
|
||||
}
|
||||
else if (cFiling == 'm')
|
||||
{
|
||||
sFOut = "Married";
|
||||
}
|
||||
else
|
||||
{
|
||||
sFOut = "Illogical.";
|
||||
}
|
||||
|
||||
if (cClass == 'h')
|
||||
{
|
||||
sCout = "Hourly";
|
||||
}
|
||||
else if (cClass == 's')
|
||||
{
|
||||
sCout = "Salary";
|
||||
}
|
||||
else
|
||||
{
|
||||
sCout = "Illigocial.";
|
||||
}
|
||||
|
||||
String out = "Employee Number: "+ iEmployee + "\t" +
|
||||
"Filing as: "+ sFOut + "\t" +
|
||||
"Number of Withholdings: "+iWHold+ "\t"+
|
||||
"Pay Type: "+sCout + "\t";
|
||||
if (cClass == 'h')
|
||||
{
|
||||
out += "Hours Worked: "+ dHours +"\t"+
|
||||
"Pay Rate: " + dPayR + "\t";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
out += "Salary: " + dSal + "\t";
|
||||
}
|
||||
out += "Year To Date: " + dYTD + "\t";
|
||||
System.out.println(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
|
||||
E:\programs\Mod1\Project5>java Project5b
|
||||
Employee Number: 1001 Filing as: Single Number of Withholdings: 11
|
||||
Pay Type: Hourly Hours Worked: 40.0 Pay Rate: 15.35 Year To Date: 12
|
||||
28.0
|
||||
Employee Number: 1002 Filing as: Single Number of Withholdings: 10
|
||||
Pay Type: Hourly Hours Worked: 38.0 Pay Rate: 15.0 Year To Date: 57
|
||||
0.0
|
||||
Employee Number: 1003 Filing as: Single Number of Withholdings: 9
|
||||
Pay Type: Hourly Hours Worked: 26.45 Pay Rate: 20.0 Year To Date: 10
|
||||
58.0
|
||||
Employee Number: 1004 Filing as: Single Number of Withholdings: 8
|
||||
Pay Type: Hourly Hours Worked: 20.0 Pay Rate: 39.15 Year To Date: 23
|
||||
49.0
|
||||
Employee Number: 1005 Filing as: Single Number of Withholdings: 7
|
||||
Pay Type: Hourly Hours Worked: 37.15 Pay Rate: 20.0 Year To Date: 14
|
||||
86.0
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,129 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 5c *
|
||||
* Class Name: Project5c *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 10/04/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: demonstrate proficiency in using Counted loops, proficiency in*
|
||||
* using Sentinel controlled loops, proficiency in using Flag *
|
||||
* controlled loops, proficiency in using EOF controlled loops, *
|
||||
* proficiency in using Forever loops, providing appropriate *
|
||||
* documentation for programs, the use of conventional *
|
||||
* identifiers for classes and variables, the ability to use *
|
||||
* simple program testing techniques to ensure the quality of *
|
||||
* their work product, the use of white space for ensuring *
|
||||
* readability of program code, correct formulation of boolean *
|
||||
* expressions to be used in the control of iterative structures *
|
||||
******************************************************************************/
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Project5c
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner inFile = null;
|
||||
try
|
||||
{
|
||||
inFile = new Scanner(new FileReader("payrollData.txt"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
while(inFile.hasNext())
|
||||
{
|
||||
int iEmployee = inFile.nextInt();
|
||||
char cFiling = inFile.next().charAt(0);
|
||||
int iWHold = inFile.nextInt();
|
||||
char cClass = inFile.next().charAt(0);
|
||||
double dHours = inFile.nextDouble();
|
||||
double dPayR = inFile.nextDouble();
|
||||
double dSal = inFile.nextDouble();
|
||||
double dYTD = inFile.nextDouble();
|
||||
String sFOut = "";
|
||||
String sCout = "";
|
||||
|
||||
|
||||
if (cFiling == 's')
|
||||
{
|
||||
sFOut = "Single";
|
||||
}
|
||||
else if (cFiling == 'h' )
|
||||
{
|
||||
sFOut = "Head of Household";
|
||||
}
|
||||
else if (cFiling == 'm')
|
||||
{
|
||||
sFOut = "Married";
|
||||
}
|
||||
else
|
||||
{
|
||||
sFOut = "Illogical.";
|
||||
}
|
||||
|
||||
if (cClass == 'h')
|
||||
{
|
||||
sCout = "Hourly";
|
||||
}
|
||||
else if (cClass == 's')
|
||||
{
|
||||
sCout = "Salary";
|
||||
}
|
||||
else
|
||||
{
|
||||
sCout = "Illigocial.";
|
||||
}
|
||||
|
||||
String out = "Employee Number: "+ iEmployee + "\t" +
|
||||
"Filing as: "+ sFOut + "\t" +
|
||||
"Number of Withholdings: "+iWHold+ "\t"+
|
||||
"Pay Type: "+sCout + "\t";
|
||||
if (cClass == 'h')
|
||||
{
|
||||
out += "Hours Worked: "+ dHours +"\t"+
|
||||
"Pay Rate: " + dPayR + "\t";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
out += "Salary: " + dSal + "\t";
|
||||
}
|
||||
out += "Year To Date: " + dYTD + "\t";
|
||||
System.out.println(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
|
||||
E:\programs\Mod1\Project5>java Project5c
|
||||
Employee Number: 1001 Filing as: Single Number of Withholdings: 11
|
||||
Pay Type: Hourly Hours Worked: 40.0 Pay Rate: 15.35 Year To Date: 12
|
||||
28.0
|
||||
Employee Number: 1002 Filing as: Single Number of Withholdings: 10
|
||||
Pay Type: Hourly Hours Worked: 38.0 Pay Rate: 15.0 Year To Date: 57
|
||||
0.0
|
||||
Employee Number: 1003 Filing as: Single Number of Withholdings: 9
|
||||
Pay Type: Hourly Hours Worked: 26.45 Pay Rate: 20.0 Year To Date: 10
|
||||
58.0
|
||||
Employee Number: 1004 Filing as: Single Number of Withholdings: 8
|
||||
Pay Type: Hourly Hours Worked: 20.0 Pay Rate: 39.15 Year To Date: 23
|
||||
49.0
|
||||
Employee Number: 1005 Filing as: Single Number of Withholdings: 7
|
||||
Pay Type: Hourly Hours Worked: 37.15 Pay Rate: 20.0 Year To Date: 14
|
||||
86.0
|
||||
Employee Number: 1006 Filing as: Single Number of Withholdings: 6
|
||||
Pay Type: Hourly Hours Worked: 55.35 Pay Rate: 20.0 Year To Date: 55
|
||||
35.0
|
||||
Employee Number: 1007 Filing as: Single Number of Withholdings: 5
|
||||
Pay Type: Hourly Hours Worked: 53.3 Pay Rate: 20.0 Year To Date: 10
|
||||
66.0
|
||||
Employee Number: 1008 Filing as: Single Number of Withholdings: 4
|
||||
Pay Type: Salary Salary: 1430.0 Year To Date: 14300.0
|
||||
Employee Number: 1009 Filing as: Single Number of Withholdings: 3
|
||||
Pay Type: Salary Salary: 1389.0 Year To Date: 13890.0
|
||||
Employee Number: 1010 Filing as: Single Number of Withholdings: 2
|
||||
Pay Type: Salary Salary: 1777.0 Year To Date: 15993.0
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,78 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 5d *
|
||||
* Class Name: Project5d *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 10/04/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: demonstrate proficiency in using Counted loops, proficiency in*
|
||||
* using Sentinel controlled loops, proficiency in using Flag *
|
||||
* controlled loops, proficiency in using EOF controlled loops, *
|
||||
* proficiency in using Forever loops, providing appropriate *
|
||||
* documentation for programs, the use of conventional *
|
||||
* identifiers for classes and variables, the ability to use *
|
||||
* simple program testing techniques to ensure the quality of *
|
||||
* their work product, the use of white space for ensuring *
|
||||
* readability of program code, correct formulation of boolean *
|
||||
* expressions to be used in the control of iterative structures *
|
||||
******************************************************************************/
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Project5d
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
boolean bSent = true;
|
||||
Scanner console = new Scanner (System.in); //console
|
||||
while (bSent)
|
||||
{
|
||||
System.out.println("Please enter either 'M', 'H', 'S', or 'E' "
|
||||
+ "to find out more about that filing type, or enter"
|
||||
+ " any other character to quit.");
|
||||
System.out.print(":");
|
||||
switch (console.next().toLowerCase().charAt(0))
|
||||
{
|
||||
case 'm':
|
||||
System.out.println("Married");
|
||||
break;
|
||||
case 'h':
|
||||
System.out.println("Head of Household");
|
||||
break;
|
||||
case 's':
|
||||
System.out.println("Single");
|
||||
break;
|
||||
case 'e':
|
||||
System.out.println("Exempt");
|
||||
break;
|
||||
default:
|
||||
bSent = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
|
||||
E:\programs\Mod1\Project5>java Project5d
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:m
|
||||
Married
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:h
|
||||
Head of Household
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:s
|
||||
Single
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:e
|
||||
Exempt
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:q
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,77 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 5e *
|
||||
* Class Name: Project5e *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 10/04/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: demonstrate proficiency in using Counted loops, proficiency in*
|
||||
* using Sentinel controlled loops, proficiency in using Flag *
|
||||
* controlled loops, proficiency in using EOF controlled loops, *
|
||||
* proficiency in using Forever loops, providing appropriate *
|
||||
* documentation for programs, the use of conventional *
|
||||
* identifiers for classes and variables, the ability to use *
|
||||
* simple program testing techniques to ensure the quality of *
|
||||
* their work product, the use of white space for ensuring *
|
||||
* readability of program code, correct formulation of boolean *
|
||||
* expressions to be used in the control of iterative structures *
|
||||
******************************************************************************/
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Project5e
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner console = new Scanner (System.in); //console
|
||||
out:
|
||||
while (true)
|
||||
{
|
||||
System.out.println("Please enter either 'M', 'H', 'S', or 'E' "
|
||||
+ "to find out more about that filing type, or enter"
|
||||
+ " any other character to quit.");
|
||||
System.out.print(":");
|
||||
switch (console.next().toLowerCase().charAt(0))
|
||||
{
|
||||
case 'm':
|
||||
System.out.println("Married");
|
||||
break;
|
||||
case 'h':
|
||||
System.out.println("Head of Household");
|
||||
break;
|
||||
case 's':
|
||||
System.out.println("Single");
|
||||
break;
|
||||
case 'e':
|
||||
System.out.println("Exempt");
|
||||
break;
|
||||
default:
|
||||
break out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*output:
|
||||
|
||||
E:\programs\Mod1\Project5>java Project5e
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:m
|
||||
Married
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:h
|
||||
Head of Household
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:s
|
||||
Single
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:e
|
||||
Exempt
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:q
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,10 @@
|
||||
1001 s 11 h 40 15.35 0 1228
|
||||
1002 s 10 h 38 15 0 570
|
||||
1003 s 9 h 26.45 20 0 1058
|
||||
1004 s 8 h 20 39.15 0 2349
|
||||
1005 s 7 h 37.15 20 0 1486
|
||||
1006 s 6 h 55.35 20 0 5535
|
||||
1007 s 5 h 53.3 20 0 1066
|
||||
1008 s 4 s 0 0 1430 14300
|
||||
1009 s 3 s 0 0 1389 13890
|
||||
1010 s 2 s 0 0 1777 15993
|
||||
Binary file not shown.
@@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 6a *
|
||||
* Class Name: Project6a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/17/2012 *
|
||||
* Hours: 1.00 Hours *
|
||||
* Purpose: To do things because Charlie tells us to d *
|
||||
******************************************************************************/
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Project6a
|
||||
{
|
||||
public static void main(String[] args) //main
|
||||
{
|
||||
double dNum1, dNum2;
|
||||
try
|
||||
{
|
||||
input = JOptionPane.showInputDialog("Please enter your first number.");
|
||||
dNum1 = Double.parseDouble(input);
|
||||
input = JOptionPane.showInputDialog("Please enter your second number.");
|
||||
dNum2 = Double.parseDouble(input);
|
||||
}
|
||||
add(dNum1,dNum2);
|
||||
|
||||
}
|
||||
public static void add(double n1, double n2)
|
||||
{
|
||||
double result = n1 + n2;
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Adding your two numbers together yields: "+result,
|
||||
"Results",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
public class DbL3c
|
||||
// Demonstrates modulus and printing
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
double a = 99, b = 8, result;
|
||||
int c = (long) 7777777777777;
|
||||
result = a % b;
|
||||
System.out.println("Divide " + a + " by " + b);
|
||||
System.out.println("remainder is " + result);
|
||||
System.out.print("c is a very large number:");
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class BufferFinalOne
|
||||
{
|
||||
public static int words, lines, pgraf, curWords, curLB, read;
|
||||
public static BufferedReader infile;
|
||||
public static PrintWriter outfile;
|
||||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
initalize();
|
||||
while (read != -1)
|
||||
{
|
||||
while(read != '\u2424')
|
||||
{
|
||||
if (read == -1)
|
||||
break;
|
||||
char c = (char)read;
|
||||
if (Character.isWhitespace(c))
|
||||
processBlank(c);
|
||||
else
|
||||
processText(c);
|
||||
System.out.print(c+" ("+read+")");
|
||||
read = infile.read();
|
||||
}
|
||||
updateCount();
|
||||
}
|
||||
printTotal();
|
||||
}
|
||||
public static void initalize() throws FileNotFoundException, IOException
|
||||
{
|
||||
words = 0; lines = 0; pgraf = 0; curWords = 0; curLB=0;
|
||||
infile = new BufferedReader(new FileReader("inspectFile.dat"));
|
||||
outfile = new PrintWriter("outfile.txt");
|
||||
read = infile.read();
|
||||
}
|
||||
public static void processText(char c)
|
||||
{
|
||||
if (curLB!=0)
|
||||
curLB = 0;
|
||||
outfile.append(c);
|
||||
}
|
||||
public static void processBlank(char c)
|
||||
{
|
||||
if (curLB!=0)
|
||||
curLB = 0;
|
||||
outfile.append(c);
|
||||
curWords++;
|
||||
}
|
||||
public static void updateCount()
|
||||
{
|
||||
if (curLB == 1)
|
||||
pgraf++;
|
||||
words += curWords;
|
||||
curWords = 0;
|
||||
lines++;
|
||||
}
|
||||
public static void printTotal() throws IOException
|
||||
{
|
||||
System.out.print("words: "+words+" number of lines: "+lines+" paragraphs: "+pgraf);
|
||||
infile.close();
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
This is the first line of the first paragraph \n
|
||||
Second line in the paragraph\n
|
||||
|
||||
This is the second paragraph \n
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
This is the first line of the first paragraph \n
|
||||
Second line in the paragraph\n
|
||||
|
||||
This is the second paragraph \n
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/******************************************************************************
|
||||
* Project: Point 1 *
|
||||
* Class Name: point1 *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/05/2012 *
|
||||
* Hours: 0.50 Hours *
|
||||
* Purpose: Blah. *
|
||||
******************************************************************************/
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class point1
|
||||
{
|
||||
public static void main(String[] args) //main
|
||||
{
|
||||
String sMessage01 = "This application will accept the input of the "
|
||||
+ "lengths of the sides of a triangle and determine if it is a right triangle.\n"
|
||||
+ "A triangle is a polygon with 3 sides and three angles.\n"
|
||||
+ "A triangle is considered right if one of the angles is 90 degrees.";
|
||||
String sMessage02 = "This program will determine weather or not a triangle is right.";
|
||||
|
||||
JOptionPane.showMessageDialog(null, sMessage01, "Welcome",
|
||||
JOptionPane.PLAIN_MESSAGE);
|
||||
JOptionPane.showMessageDialog(null, sMessage02, "Welcome",
|
||||
JOptionPane.PLAIN_MESSAGE);
|
||||
String input = JOptionPane.showInputDialog("Please enter a side length.");
|
||||
double dSide01 = 0;
|
||||
try
|
||||
{
|
||||
dSide01 = Double.parseDouble(input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
if (dSide01 < 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, you cannot have a "
|
||||
+ "negative side length.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
input = JOptionPane.showInputDialog("Please enter a side length.");
|
||||
double dSide02 = 0;
|
||||
try
|
||||
{
|
||||
dSide02 = Double.parseDouble(input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
if (dSide02 < 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, you cannot have a "
|
||||
+ "negative side length.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
input = JOptionPane.showInputDialog("Please enter a side length.");
|
||||
double dSide03 = 0;
|
||||
try
|
||||
{
|
||||
dSide03 = Double.parseDouble(input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
if (dSide03 < 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, you cannot have a "
|
||||
+ "negative side length.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
// big ugly boolean.
|
||||
// IF (intFirstSide * intFirstSide == intSecondSide * intSecondSide + intThirdSide * intThirdSide) ||
|
||||
// (intSecondSide * intSecondSide == intFirstSide * intFirstSide + intThirdSide * intThirdSide)||
|
||||
// (intThirdSide * intThirdSide == intFirstSide * intFirstSide + intSecondSide * intSecondSide)
|
||||
|
||||
dSide01 = Math.pow(dSide01, 2);
|
||||
dSide02 = Math.pow(dSide02, 2);
|
||||
dSide03 = Math.pow(dSide03, 2);
|
||||
if ((dSide01 == (dSide02 + dSide03)) ||
|
||||
(dSide02 == (dSide01 + dSide03)) ||
|
||||
(dSide03 == (dSide01 + dSide02)))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "This is a right triangle.",
|
||||
"Thank You", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "This is NOT a right triangle.",
|
||||
"Thank You", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/******************************************************************************
|
||||
* Project: Point 2 *
|
||||
* Class Name: point2 *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/05/2012 *
|
||||
* Hours: 0.50 Hours *
|
||||
* Purpose: Blah. *
|
||||
******************************************************************************/
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class point2
|
||||
{
|
||||
public static void main(String[] args) //main
|
||||
{
|
||||
String sMessage01 = "This application will accept the input of the "
|
||||
+ "ammount of cookies the user has to organize into boxes and containers.\n"
|
||||
+ "A box contains 24 cookies.\n"
|
||||
+ "A container contains 75 boxes.";
|
||||
String sMessage02 = "This program will output the ammount of boxes, containers, and the underflow.";
|
||||
JOptionPane.showMessageDialog(null, sMessage01, "Welcome",
|
||||
JOptionPane.PLAIN_MESSAGE);
|
||||
JOptionPane.showMessageDialog(null, sMessage02, "Welcome",
|
||||
JOptionPane.PLAIN_MESSAGE);
|
||||
String input = JOptionPane.showInputDialog("Please enter the ammount of cookies.");
|
||||
double dSide01 = 0;
|
||||
try
|
||||
{
|
||||
dSide01 = Double.parseDouble(input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
if (dSide01 < 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, you cannot have a "
|
||||
+ "negative ammount of cookies.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
String sOutMessage = "";
|
||||
Double dBoxes = dSide01 %24;
|
||||
Double dContainers = dBoxes %75;
|
||||
|
||||
int iContainers = (int) Math.floor(dContainers);
|
||||
if (dContainers > iContainers)
|
||||
iContainers++;
|
||||
|
||||
int iBoxes = (int) Math.floor(dBoxes);
|
||||
if (dBoxes > iBoxes)
|
||||
iBoxes++;
|
||||
|
||||
int iFullContainer = (int) Math.floor(dContainers);
|
||||
int iFullBoxes = iFullContainer * 75;
|
||||
int iLeftOverBoxes = iBoxes - iFullBoxes;
|
||||
int iLeftOverCookies = iLeftOverBoxes * 24;
|
||||
boolean bUnderFlow = false;
|
||||
|
||||
sOutMessage += "You have a total of %d boxes with %d containers.\n";
|
||||
if (iContainers > dContainers)
|
||||
{
|
||||
sOutMessage += "The last container is not full.\n";
|
||||
bUnderFlow = true;
|
||||
}
|
||||
|
||||
if(bUnderFlow)
|
||||
{
|
||||
sOutMessage += "You have %d boxes in the last container, with %d cookies.";
|
||||
System.out.format(sOutMessage, iBoxes, iContainers, iLeftOverBoxes, iLeftOverCookies);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.format(sOutMessage, iBoxes, iContainers);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hangman", "Hangman\Hangman.vcxproj", "{7310FC30-2591-4B40-9580-33268702093E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7310FC30-2591-4B40-9580-33268702093E}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{7310FC30-2591-4B40-9580-33268702093E}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{7310FC30-2591-4B40-9580-33268702093E}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{7310FC30-2591-4B40-9580-33268702093E}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,458 @@
|
||||
#include "stdhangman.h"
|
||||
|
||||
Hangman::Hangman()
|
||||
{
|
||||
attempts = 0;
|
||||
wordLength = 0;
|
||||
secretWord = "";
|
||||
wordList = vector<hangword>();
|
||||
adminList = vector<string>();
|
||||
//readdmins();
|
||||
readFromFile();
|
||||
blankguesses();
|
||||
doseed();
|
||||
}
|
||||
|
||||
void Hangman::blankguesses()
|
||||
{
|
||||
attempts = 0;
|
||||
string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
for (unsigned int i = 0; i < alpha.length(); i++)
|
||||
{
|
||||
alphabet[i] = alpha[i];
|
||||
}
|
||||
}
|
||||
|
||||
void Hangman::displayMenu()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
cls();
|
||||
fflush(stdout);
|
||||
centerline("Main Menu",1);
|
||||
centerline("==========================",2);
|
||||
centerline("1. Game Administration",3);
|
||||
centerline("2. Begin a game",4);
|
||||
centerline("3. Exit",5);
|
||||
centerline("==========================",6);
|
||||
cursorpos(1,7);
|
||||
cout << "Please make a selection" << endl << ":";
|
||||
char input;
|
||||
input = _getch();
|
||||
cout << input;
|
||||
switch (input)
|
||||
{
|
||||
case '1':
|
||||
while(doadmin());
|
||||
break;
|
||||
case '2':
|
||||
while(playGame());
|
||||
break;
|
||||
case '3':
|
||||
break;
|
||||
default:
|
||||
writeline("Please make a valid selection [1-3]");
|
||||
writeline(2);
|
||||
}
|
||||
if ( input == '3' )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Hangman::playGame()
|
||||
{
|
||||
chooseword();
|
||||
blankguesses();
|
||||
while (attempts <= 6)
|
||||
{
|
||||
while(!handleinput());
|
||||
if (revealedword == secretWord)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
cls();
|
||||
if (attempts >= 6)
|
||||
{
|
||||
centerline("Hangman - Loss", 1);
|
||||
centerline(secretWord, 4);
|
||||
centerline("Sorry! You loose this round", 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
centerline("Hangman - Winner", 1);
|
||||
centerline(secretWord, 4);
|
||||
centerline("Congratulations! You guessed correctly",8);
|
||||
}
|
||||
writeline(2);
|
||||
|
||||
char input;
|
||||
while (true)
|
||||
{
|
||||
cout << "Play again?" << endl << "[Y/n]";
|
||||
input = _getch();
|
||||
cout << input;
|
||||
if (toupper(input) == 'Y')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (toupper(input) == 'N')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Please enter either Yes or No" << endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Hangman::notguessed(char inguess)
|
||||
{
|
||||
for (int j = 0; j < 26; j++)
|
||||
{
|
||||
if (alphabet[j] == inguess)
|
||||
{
|
||||
alphabet[j] = ' ';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Hangman::doadmin()
|
||||
{
|
||||
cls();
|
||||
centerline("Hangman - Administration",1);
|
||||
centerline("Hangman Administrator Login",4);
|
||||
cursorpos(1,10);
|
||||
cout << "Please enter your password" << endl << ":";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Hangman::isinword(char inguess)
|
||||
{
|
||||
string secret = getSecretWord();
|
||||
for (unsigned int i = 0; i < secret.length(); i++)
|
||||
{
|
||||
if (secret[i] == toupper(inguess))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Hangman::drawletters()
|
||||
{
|
||||
for (int i = 0; i < 26; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
cursorpos (4,6);
|
||||
}
|
||||
if (i == 8)
|
||||
{
|
||||
cursorpos (4,8);
|
||||
}
|
||||
if (i == 16)
|
||||
{
|
||||
cursorpos (4,10);
|
||||
}
|
||||
if ( i == 24 )
|
||||
{
|
||||
cursorpos(4, 12);
|
||||
}
|
||||
cout << alphabet[i] << " ";
|
||||
}
|
||||
cursorpos(4, 18);
|
||||
cout << revealedword;
|
||||
}
|
||||
|
||||
bool Hangman::handleinput()
|
||||
{
|
||||
cls(); // clear screen
|
||||
drawseperator(); // do the separator thing
|
||||
centerline("Hangman",1); // screen title
|
||||
drawhangman();
|
||||
drawletters();
|
||||
fflush(stdout);
|
||||
cursorpos(0, 20);
|
||||
writeline("Please enter a letter");
|
||||
cout << ":";
|
||||
char input;
|
||||
input = _getch();
|
||||
input = toupper(input);
|
||||
cout << input;
|
||||
if (isalpha(input) && notguessed(input))
|
||||
{
|
||||
if (isinword(input))
|
||||
{
|
||||
revealchar(input);
|
||||
}
|
||||
else
|
||||
{
|
||||
attempts++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << input << " is an invalid input, please try again";
|
||||
pause();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Hangman::revealchar(char input)
|
||||
{
|
||||
string secret = getSecretWord();
|
||||
for (unsigned int i = 0; i < secret.length(); i++)
|
||||
{
|
||||
if (secret[i] == input)
|
||||
{
|
||||
revealedword[i] = secret[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Hangman::readFromFile()
|
||||
{
|
||||
/*
|
||||
hangword holdword;
|
||||
ifstream hangmanfile ("wordlist.bin", ios::in|ios::binary|ios::ate);
|
||||
if (hangmanfile.is_open())
|
||||
{
|
||||
while(!hangmanfile.eof())
|
||||
{
|
||||
holdword.Read(hangmanfile);
|
||||
wordList.push_back(holdword);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Unable to open wordlist.bin for reading. Trying to create it.." << endl;
|
||||
*/
|
||||
initFile();
|
||||
// }
|
||||
}
|
||||
|
||||
void Hangman::initFile()
|
||||
{
|
||||
hangword holdword;
|
||||
ifstream hangwordtxt ("hangmanwordlist.txt", ios::in);
|
||||
int id = 1;
|
||||
if (hangwordtxt.is_open())
|
||||
{
|
||||
while (!hangwordtxt.eof())
|
||||
{
|
||||
string word = "";
|
||||
getline(hangwordtxt,word);
|
||||
for (unsigned int j = 0; j < word.length(); j++)
|
||||
{
|
||||
word[j] = toupper(word[j]);
|
||||
}
|
||||
holdword.setword(word);
|
||||
holdword.setid(id);
|
||||
wordList.push_back(holdword);
|
||||
id++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Error unable to open hangmanwordlist.txt for reading" << endl;
|
||||
pause();
|
||||
}
|
||||
hangwordtxt.close();
|
||||
if (wordList.size() != 0)
|
||||
{
|
||||
ofstream hangmanbin ("wordlist.bin", ios::out|ios::binary|ios::app);
|
||||
if (hangmanbin.is_open())
|
||||
{
|
||||
for (unsigned int i = 0; i < wordList.size(); i++)
|
||||
{
|
||||
wordList[i].Write(hangmanbin);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Error unable to open wordlist.bin for writing" << endl;
|
||||
pause();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "No words in the wordlist. Not creating file." << endl;
|
||||
pause();
|
||||
}
|
||||
}
|
||||
|
||||
void Hangman::chooseword()
|
||||
{
|
||||
if (wordList.size() == 0)
|
||||
{
|
||||
hangword hang;
|
||||
hang.setid(0);
|
||||
hang.setword("TEST");
|
||||
wordList.push_back(hang);
|
||||
}
|
||||
int wordindex = rand()%wordList.size();
|
||||
setSecretWord(wordList[wordindex].getword());
|
||||
string rev = string(getSecretWord().length(),'_');
|
||||
revealedword = rev;
|
||||
}
|
||||
|
||||
void Hangman::drawhangman()
|
||||
{
|
||||
cursorpos(55, 10);
|
||||
switch (attempts)
|
||||
{
|
||||
case 0:
|
||||
cout <<" ___ " << endl;
|
||||
cursorpos(55, 11);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 12);
|
||||
cout <<" |" << endl;
|
||||
cursorpos(55, 13);
|
||||
cout <<" |" << endl;
|
||||
cursorpos(55, 14);
|
||||
cout <<" |" << endl;
|
||||
cursorpos(55, 15);
|
||||
cout <<" |" << endl;
|
||||
break;
|
||||
case 1:
|
||||
cout <<" ___ " << endl;
|
||||
cursorpos(55, 11);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 12);
|
||||
cout <<" @ |" << endl;
|
||||
cursorpos(55, 13);
|
||||
cout <<" |" << endl;
|
||||
cursorpos(55, 14);
|
||||
cout <<" |" << endl;
|
||||
cursorpos(55, 15);
|
||||
cout <<" |" << endl;
|
||||
break;
|
||||
case 2:
|
||||
cout <<" ___ " << endl;
|
||||
cursorpos(55, 11);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 12);
|
||||
cout <<" @ |" << endl;
|
||||
cursorpos(55, 13);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 14);
|
||||
cout <<" |" << endl;
|
||||
cursorpos(55, 15);
|
||||
cout <<" |" << endl;
|
||||
break;
|
||||
case 3:
|
||||
cout <<" ___ " << endl;
|
||||
cursorpos(55, 11);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 12);
|
||||
cout <<" @ |" << endl;
|
||||
cursorpos(55, 13);
|
||||
cout <<" /| |" << endl;
|
||||
cursorpos(55, 14);
|
||||
cout <<" |" << endl;
|
||||
cursorpos(55, 15);
|
||||
cout <<" |" << endl;
|
||||
break;
|
||||
case 4:
|
||||
cout <<" ___ " << endl;
|
||||
cursorpos(55, 11);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 12);
|
||||
cout <<" @ |" << endl;
|
||||
cursorpos(55, 13);
|
||||
cout <<" /|\\ |" << endl;
|
||||
cursorpos(55, 14);
|
||||
cout <<" |" << endl;
|
||||
cursorpos(55, 15);
|
||||
cout <<" |" << endl;
|
||||
break;
|
||||
case 5:
|
||||
cout <<" ___ " << endl;
|
||||
cursorpos(55, 11);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 12);
|
||||
cout <<" @ |" << endl;
|
||||
cursorpos(55, 13);
|
||||
cout <<" /|\\ |" << endl;
|
||||
cursorpos(55, 14);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 15);
|
||||
cout <<" |" << endl;
|
||||
break;
|
||||
case 6:
|
||||
cout <<" ___ " << endl;
|
||||
cursorpos(55, 11);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 12);
|
||||
cout <<" @ |" << endl;
|
||||
cursorpos(55, 13);
|
||||
cout <<" /|\\ |" << endl;
|
||||
cursorpos(55, 14);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 15);
|
||||
cout <<" / |" << endl;
|
||||
break;
|
||||
case 7:
|
||||
cout <<" ___ " << endl;
|
||||
cursorpos(55, 11);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 12);
|
||||
cout <<" @ |" << endl;
|
||||
cursorpos(55, 13);
|
||||
cout <<" /|\\ |" << endl;
|
||||
cursorpos(55, 14);
|
||||
cout <<" | |" << endl;
|
||||
cursorpos(55, 15);
|
||||
cout <<" / \\ |" << endl;
|
||||
break;
|
||||
}
|
||||
cursorpos(55, 16);
|
||||
cout <<" ________|________" << endl;
|
||||
cursorpos(55, 17);
|
||||
cout <<" / | /|" << endl;
|
||||
cursorpos(55, 18);
|
||||
cout <<"/________________/ /" << endl;
|
||||
cursorpos(55, 19);
|
||||
cout <<"|________________|/" << endl;
|
||||
}
|
||||
|
||||
void Hangman::setSecretWord(string word)
|
||||
{
|
||||
secretWord = word;
|
||||
}
|
||||
string Hangman::getSecretWord()
|
||||
{
|
||||
return secretWord;
|
||||
}
|
||||
|
||||
void Hangman::setWordLength(int length)
|
||||
{
|
||||
wordLength = length;
|
||||
}
|
||||
int Hangman::getWordLength()
|
||||
{
|
||||
return wordLength;
|
||||
}
|
||||
|
||||
/***********************************
|
||||
___
|
||||
| |
|
||||
@ |
|
||||
/|\ |
|
||||
| |
|
||||
/ \ |
|
||||
________|________
|
||||
/ | /|
|
||||
/________________/ /
|
||||
|________________|/
|
||||
|
||||
************************************/
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdhangman.h"
|
||||
|
||||
class Hangman
|
||||
{
|
||||
private:
|
||||
int attempts;
|
||||
vector<hangword> wordList;
|
||||
vector<string> adminList;
|
||||
string secretWord;
|
||||
string revealedword;
|
||||
int wordLength;
|
||||
char alphabet[26];
|
||||
bool emessage;
|
||||
string message;
|
||||
public:
|
||||
Hangman();
|
||||
bool playGame();
|
||||
void enterNewWords();
|
||||
bool isWin();
|
||||
void convertToUpper();
|
||||
void readFromFile();
|
||||
|
||||
void setSecretWord(string word);
|
||||
string getSecretWord();
|
||||
|
||||
void setWordLength(int length);
|
||||
int getWordLength();
|
||||
|
||||
void initFile();
|
||||
bool notguessed(char guess);
|
||||
bool isinword(char guess);
|
||||
bool doadmin();
|
||||
void displayMenu();
|
||||
void drawhangman();
|
||||
bool handleinput();
|
||||
void blankguesses();
|
||||
void revealchar(char reveal);
|
||||
void chooseword();
|
||||
void drawletters();
|
||||
};
|
||||
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{7310FC30-2591-4B40-9580-33268702093E}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>Hangman</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Hangman.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Hangword.cpp" />
|
||||
<ClCompile Include="stdhangman.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Hangman.h" />
|
||||
<ClInclude Include="main.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="stdhangman.h" />
|
||||
<ClInclude Include="hangword.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Resource.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="icon.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Hangman.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="stdhangman.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Hangword.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdhangman.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Hangman.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="hangword.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="main.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Resource.rc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="icon.ico">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,76 @@
|
||||
#include "stdhangman.h"
|
||||
|
||||
int hangword::getid()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
void hangword::setid(int id)
|
||||
{
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
void hangword::setword(string word)
|
||||
{
|
||||
this->word = word;
|
||||
}
|
||||
string hangword::getword()
|
||||
{
|
||||
return word;
|
||||
}
|
||||
|
||||
void hangword::Read(ifstream& file)
|
||||
{
|
||||
setid(readid(file));
|
||||
setword(readword(file));
|
||||
}
|
||||
|
||||
void hangword::Write(ofstream& file)
|
||||
{
|
||||
int id = getid();
|
||||
writeid(file, id);
|
||||
writeword(file, getword());
|
||||
}
|
||||
|
||||
void hangword::writeword(ofstream& file,const string& str)
|
||||
{
|
||||
// get the length of the string data
|
||||
unsigned int len = str.size();
|
||||
|
||||
// write the size:
|
||||
file.write( reinterpret_cast<const char*>( &len ), sizeof(len) );
|
||||
|
||||
// write the actual string data:
|
||||
file.write( str.c_str(), len );
|
||||
}
|
||||
|
||||
string hangword::readword(ifstream& file)
|
||||
{
|
||||
// this probably isn't the optimal way to do it, but whatever
|
||||
string str;
|
||||
|
||||
// get the length
|
||||
unsigned int len;
|
||||
file.read( reinterpret_cast<char*>( &len ), sizeof(len) );
|
||||
|
||||
// we can't read to string directly, so instead, create a temporary buffer
|
||||
if(len > 0)
|
||||
{
|
||||
char* buf = new char[len];
|
||||
file.read( buf, len );
|
||||
str.append( buf, len );
|
||||
delete[] buf;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
inline void hangword::writeid(ofstream& file, int& num)
|
||||
{
|
||||
file.write(reinterpret_cast<char *>(&num),sizeof(int));
|
||||
}
|
||||
|
||||
int hangword::readid(ifstream& file)
|
||||
{
|
||||
int num;
|
||||
file.read(reinterpret_cast<char *>(&num),sizeof(int));
|
||||
return num;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,100 @@
|
||||
fluorine
|
||||
steapsin
|
||||
gadoid
|
||||
optics
|
||||
master
|
||||
uninvasive
|
||||
nettable
|
||||
preintend
|
||||
scourge
|
||||
clinah
|
||||
planking
|
||||
autogenetic
|
||||
inweaved
|
||||
peipus
|
||||
corneal
|
||||
descendant
|
||||
premonopolizing
|
||||
wadmoll
|
||||
grimily
|
||||
anatolic
|
||||
uniced
|
||||
unendeared
|
||||
geothermic
|
||||
tarsier
|
||||
hartmann
|
||||
actuarially
|
||||
caffein
|
||||
antiexpressive
|
||||
refasten
|
||||
hostelling
|
||||
sacculus
|
||||
teazeling
|
||||
resolution
|
||||
demoralised
|
||||
fletcherizing
|
||||
decently
|
||||
mitrephorus
|
||||
reverser
|
||||
eudora
|
||||
comestible
|
||||
kilpatrick
|
||||
peroneal
|
||||
corporate
|
||||
provisional
|
||||
plaice
|
||||
atheneum
|
||||
juicing
|
||||
wintery
|
||||
ellipsoid
|
||||
avigation
|
||||
republicanism
|
||||
bocage
|
||||
frederika
|
||||
cleruch
|
||||
counterbracing
|
||||
uninstigated
|
||||
undocumented
|
||||
voyeurism
|
||||
catchfly
|
||||
scatomas
|
||||
overwore
|
||||
radiably
|
||||
rhoecus
|
||||
eighteenmo
|
||||
imperfectness
|
||||
siziness
|
||||
curable
|
||||
gradin
|
||||
breadroot
|
||||
heresy
|
||||
ophytic
|
||||
cosmopolitanizing
|
||||
cannoneer
|
||||
haverhill
|
||||
abingdon
|
||||
mentor
|
||||
dissimulator
|
||||
fazenda
|
||||
syrphid
|
||||
rockier
|
||||
inobservance
|
||||
hipbone
|
||||
duckiest
|
||||
interclub
|
||||
mollendo
|
||||
touche
|
||||
dionysius
|
||||
impedible
|
||||
intoner
|
||||
cichoriaceous
|
||||
nondrinkable
|
||||
nevada
|
||||
pithecanthropus
|
||||
upswinging
|
||||
humectant
|
||||
diakinesis
|
||||
capacitively
|
||||
nonaccord
|
||||
cilice
|
||||
exuviate
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdhangman.h"
|
||||
|
||||
class hangword
|
||||
{
|
||||
private:
|
||||
int id;
|
||||
string word;
|
||||
public:
|
||||
void setid(int in);
|
||||
int getid();
|
||||
|
||||
void setword(string in);
|
||||
string getword();
|
||||
|
||||
void Read(ifstream& file);
|
||||
void Write(ofstream& file);
|
||||
|
||||
void writeword(ofstream& file,const string& str);
|
||||
string readword(ifstream& file);
|
||||
|
||||
void writeid(ofstream& file, int& num);
|
||||
int readid(ifstream& file);
|
||||
};
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 264 KiB |
@@ -0,0 +1,78 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include "stdhangman.h"
|
||||
#include "main.h"
|
||||
#include "resource.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
ConsoleSetup(TEXT("Hangman"));
|
||||
Hangman game;
|
||||
game.displayMenu();
|
||||
|
||||
cout << "Thanks for playing!" << endl << endl;
|
||||
pause();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------- Just boring stuff after here ------------------------ */
|
||||
|
||||
void ConsoleSetup(TCHAR* input)
|
||||
{
|
||||
system("color 1e");
|
||||
|
||||
ChangeConsoleIcon(IDI_ICON1);
|
||||
ChangeConsoleTitle(input);
|
||||
cout << string(80,'*') << "Welcome to ";
|
||||
wcout << input;
|
||||
cout << " " << GetYear() << " Edition!" << endl << string(80,'*') << endl << endl;
|
||||
}
|
||||
|
||||
void ChangeConsoleTitle (const TCHAR* input)
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
tm* timePtr = localtime(&t);
|
||||
TCHAR szNewTitle[MAX_PATH];
|
||||
TCHAR szYear[7];
|
||||
|
||||
StringCchCopy(szNewTitle, MAX_PATH, TEXT(" "));
|
||||
StringCchCat(szNewTitle, MAX_PATH, input);
|
||||
|
||||
StringCchPrintf(szYear, 7, TEXT(" %d!"), GetYear());
|
||||
StringCchCat(szNewTitle, MAX_PATH, szYear);
|
||||
|
||||
SetConsoleTitle(szNewTitle);
|
||||
}
|
||||
|
||||
void ChangeConsoleIcon (const int resource_number)
|
||||
{
|
||||
HMODULE hMainMod = GetModuleHandle(0);
|
||||
assert (hMainMod);
|
||||
|
||||
HICON hMainIcon = ::LoadIcon(hMainMod, MAKEINTRESOURCE(resource_number));
|
||||
assert (hMainIcon);
|
||||
|
||||
// Load kernel 32 library
|
||||
HMODULE hMod = LoadLibrary( _T( "Kernel32.dll" ));
|
||||
assert (hMod);
|
||||
|
||||
// Load console icon changing procedure
|
||||
typedef DWORD (__stdcall *SCI)(HICON);
|
||||
SCI pfnSetConsoleIcon = reinterpret_cast<SCI>(GetProcAddress(hMod, "SetConsoleIcon"));
|
||||
assert (pfnSetConsoleIcon);
|
||||
|
||||
// Call function to change icon
|
||||
pfnSetConsoleIcon (hMainIcon);
|
||||
|
||||
FreeLibrary (hMod);
|
||||
}// End ChangeIcon
|
||||
|
||||
int GetYear()
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
tm* timePtr = localtime(&t);
|
||||
|
||||
return timePtr->tm_year + 1900;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
void ChangeConsoleTitle (const TCHAR* input);
|
||||
|
||||
void ChangeConsoleIcon (int resource_number);
|
||||
|
||||
void ConsoleSetup(TCHAR* input);
|
||||
|
||||
int GetYear();
|
||||
|
||||
enum { NUL = 0, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, HT,
|
||||
LF, VT, FF, CR, SO, SI, DLE, DC1, DC2, DC3, DC4, NAK,
|
||||
SYN, ETB, CAN, EM, SUB, ESC, FS, GS, RS, US, DEL = 127 };
|
||||
Binary file not shown.
@@ -0,0 +1,94 @@
|
||||
#include "stdhangman.h"
|
||||
|
||||
// Pause() use conio.h's get character to pause the program
|
||||
void pause()
|
||||
{
|
||||
int c;
|
||||
cout << endl << "Press any key to continue . . ." << endl;
|
||||
c = _getch();
|
||||
if (c == 0 || c == 224) // getch will return a 0 or 244 on error
|
||||
{
|
||||
_getch(); // try again
|
||||
}
|
||||
}
|
||||
|
||||
// cursorpos(X,Y) use ConsoleAPI to place the cursor at a particular position
|
||||
void cursorpos(int X, int Y)
|
||||
{
|
||||
if ( X < 0 ) // off the screen
|
||||
{
|
||||
X = 0;
|
||||
}
|
||||
if ( Y < 0 )
|
||||
{
|
||||
Y = 0;
|
||||
}
|
||||
HANDLE hStdOut = GetStdHandle( STD_OUTPUT_HANDLE ); //grab the stdout handle
|
||||
COORD newpos = { X, Y }; // use the Coord struct to stage the new position
|
||||
SetConsoleCursorPosition( hStdOut, newpos ); // set the new cursor position
|
||||
}
|
||||
|
||||
// take the input modulus the length by 80, set the cursor position there
|
||||
void centerline(string input, int linenum)
|
||||
{
|
||||
if (input.length() > 80) // over 80 characters? must be centred already
|
||||
{
|
||||
cursorpos(0,linenum);
|
||||
}
|
||||
int mod = (80-input.length())/2; // formula: input length subtracted from console line length divided by 2
|
||||
cursorpos(mod,linenum); // set where to write
|
||||
cout << input << endl; // write it
|
||||
}
|
||||
|
||||
// write a line
|
||||
void writeline(string input)
|
||||
{
|
||||
cout << ' ' << input << endl; // simple function to begin a line with a ' '
|
||||
}
|
||||
|
||||
// write a blank line
|
||||
void writeline(int num)
|
||||
{
|
||||
for (int i = 0; i <= num; i++) // easy function for multiple blank lines
|
||||
{
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// do the separator thing
|
||||
void drawseperator()
|
||||
{
|
||||
for (int i = 2; i < 24; i++) // separates the hangman from the words
|
||||
{
|
||||
cursorpos(50,i);
|
||||
cout << "|";
|
||||
}
|
||||
}
|
||||
|
||||
// seed using micro time. much better than grabbing a random pointer.
|
||||
void doseed()
|
||||
{
|
||||
unsigned __int64 freq;
|
||||
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
|
||||
double timerFrequency = (1.0/freq);
|
||||
|
||||
unsigned __int64 startTime;
|
||||
QueryPerformanceCounter((LARGE_INTEGER *)&startTime);
|
||||
srand(startTime*freq);
|
||||
}
|
||||
|
||||
// use the console api to fill the screen with spaces
|
||||
void cls() {
|
||||
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
COORD pos = {0, 0};
|
||||
DWORD written;
|
||||
CONSOLE_SCREEN_BUFFER_INFO screen_attr;
|
||||
unsigned size;
|
||||
|
||||
GetConsoleScreenBufferInfo(screen, &screen_attr);
|
||||
|
||||
size = screen_attr.dwSize.X * screen_attr.dwSize.Y;
|
||||
FillConsoleOutputCharacterW(screen, ' ', size, pos, &written);
|
||||
|
||||
SetConsoleCursorPosition(screen, pos);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <ctime>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <Windows.h>
|
||||
#include <conio.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
#include <tchar.h>
|
||||
#include <strsafe.h>
|
||||
#include "atlbase.h"
|
||||
#include "atlstr.h"
|
||||
#include "comutil.h"
|
||||
|
||||
#include "Hangman.h"
|
||||
#include "hangword.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void pause();
|
||||
void cursorpos(int x, int y);
|
||||
void centerline(string input, int linenum);
|
||||
void writeline(string input);
|
||||
void writeline(int num);
|
||||
void drawseperator();
|
||||
void doseed();
|
||||
void cls();
|
||||
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloWorld", "HelloWorld\HelloWorld.vcxproj", "{1DB2F6D8-614C-4057-97E4-831195518676}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1DB2F6D8-614C-4057-97E4-831195518676}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{1DB2F6D8-614C-4057-97E4-831195518676}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{1DB2F6D8-614C-4057-97E4-831195518676}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{1DB2F6D8-614C-4057-97E4-831195518676}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,89 @@
|
||||
/*****************************************************************************
|
||||
* Program: Hello World *
|
||||
* Author: Amrit Panesar <apanesar@coleman.edu> *
|
||||
* Date: 08/04/2014 *
|
||||
* Description: Display "Hello World" and do a bit of adding and multlipling *
|
||||
*****************************************************************************/
|
||||
|
||||
#include <conio.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool pause()
|
||||
{
|
||||
enum { NUL = 0, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, HT,
|
||||
LF, VT, FF, CR, SO, SI, DLE, DC1, DC2, DC3, DC4, NAK,
|
||||
SYN, ETB, CAN, EM, SUB, ESC, FS, GS, RS, US, DEL = 127 };
|
||||
|
||||
cout << "Press any key to continue..." << endl << endl;
|
||||
int i = getch();
|
||||
if ( i == ETX || i == ESC ) // control + c || escape
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int i, j, k, l = 0;
|
||||
while (true)
|
||||
{
|
||||
cout << "Hello World!" << endl;
|
||||
|
||||
if (pause())
|
||||
break;
|
||||
|
||||
cout << "Adding! Please enter two integers." << endl;
|
||||
cout << "Number 1: ";
|
||||
cin >> i;
|
||||
cout << endl;
|
||||
cout << "Number 2: ";
|
||||
cin >> j;
|
||||
cout << endl;
|
||||
k = i + j;
|
||||
cout << "The result is: " << k << endl;
|
||||
|
||||
if (pause())
|
||||
break;
|
||||
|
||||
cout << "Comparing! Please enter two integers." << endl;
|
||||
cout << "Number 1: ";
|
||||
cin >> i;
|
||||
cout << endl;
|
||||
cout << "Number 2: ";
|
||||
cin >> j;
|
||||
cout << endl;
|
||||
if ( i == j )
|
||||
cout << i << " == " << j << endl;
|
||||
else
|
||||
cout << i << " != " << j << endl;
|
||||
if ( i > j )
|
||||
cout << i << " > " << j << endl;
|
||||
else if ( i < j )
|
||||
cout << i << " < " << j << endl;
|
||||
|
||||
if (pause())
|
||||
break;
|
||||
|
||||
|
||||
cout << "Multiplication! Please enter three integers." << endl;
|
||||
cout << "Number 1: ";
|
||||
cin >> i;
|
||||
cout << endl;
|
||||
cout << "Number 2: ";
|
||||
cin >> j;
|
||||
cout << endl;
|
||||
cout << "Number 3: ";
|
||||
cin >> k;
|
||||
cout << endl;
|
||||
l = i * j * k;
|
||||
cout << "The result is: " << l << endl;
|
||||
|
||||
if (pause())
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{1DB2F6D8-614C-4057-97E4-831195518676}</ProjectGuid>
|
||||
<RootNamespace>HelloWorld</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="HelloWorld.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="HelloWorld.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PetSim", "PetSim\PetSim.vcxproj", "{8387506E-641F-4005-AF63-F98EBDDF0E48}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{8387506E-641F-4005-AF63-F98EBDDF0E48}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{8387506E-641F-4005-AF63-F98EBDDF0E48}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{8387506E-641F-4005-AF63-F98EBDDF0E48}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{8387506E-641F-4005-AF63-F98EBDDF0E48}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "stdhead.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CenteredOut
|
||||
{
|
||||
public:
|
||||
ostream &m_file;
|
||||
CenteredOut(ostream &o = cout):m_file(o){};
|
||||
|
||||
template <typename T>
|
||||
CenteredOut &operator<<(const T &a) {
|
||||
m_file<<a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CenteredOut &operator<<(ostream& (*pf) (ostream&)){
|
||||
m_file<<pf;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,158 @@
|
||||
|
||||
/******************************************************************************
|
||||
* Pet.cpp - Define a pet object *
|
||||
* Author: Amrit Panesar <apanesar@coleman.edu> *
|
||||
* Date: 08/18/2014 *
|
||||
* License: Released into public domain *
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdhead.h"
|
||||
|
||||
/****************************************** Getters and Setters **************/
|
||||
|
||||
int Pet::getHungerLevel()
|
||||
{
|
||||
return hungerlevel;
|
||||
}
|
||||
|
||||
void Pet::setHungerLevel(int hunger)
|
||||
{
|
||||
hungerlevel = hunger;
|
||||
}
|
||||
|
||||
int Pet::getBoredomLevel()
|
||||
{
|
||||
return boredomlevel;
|
||||
}
|
||||
void Pet::setBoredomLevel(int boredom)
|
||||
{
|
||||
boredomlevel = boredom;
|
||||
}
|
||||
|
||||
string Pet::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
void Pet::setName(string name)
|
||||
{
|
||||
Pet::name = name;
|
||||
}
|
||||
|
||||
/*********************** lets begin ******************************************/
|
||||
|
||||
Pet::Pet(string name, int hunger, int boredom)
|
||||
{
|
||||
setName(name);
|
||||
setHungerLevel(hunger);
|
||||
setBoredomLevel(boredom);
|
||||
}
|
||||
|
||||
void Pet::Talk()
|
||||
{
|
||||
if (PetMood() < 7)
|
||||
cout << getName() << " is feeling happy!" << endl;
|
||||
else if (PetMood() >= 7 && PetMood() < 16)
|
||||
cout << getName() << " is feeling okay." << endl;
|
||||
else if (PetMood() >=16 && PetMood() < 21)
|
||||
cout << getName() << " is feeling fustrated." << endl;
|
||||
else
|
||||
cout << getName() << " is feeling mad!" << endl;
|
||||
PassTime();
|
||||
DisplayPetBehavior();
|
||||
}
|
||||
|
||||
void Pet::FeedPet(int in)
|
||||
{
|
||||
if (in > 4)
|
||||
in = 4;
|
||||
if (in <= 0)
|
||||
in = 1;
|
||||
|
||||
if (getHungerLevel() < in)
|
||||
setHungerLevel(getHungerLevel()-getHungerLevel());
|
||||
else
|
||||
setHungerLevel(getHungerLevel()-in);
|
||||
|
||||
cout << getName() << " has been fed " << in << " pellets of food" << endl;
|
||||
PassTime();
|
||||
DisplayPetBehavior();
|
||||
}
|
||||
|
||||
void Pet::Play(int in)
|
||||
{
|
||||
if (in > 4)
|
||||
in = 4;
|
||||
if (in <= 0)
|
||||
in = 1;
|
||||
if (getBoredomLevel() < in)
|
||||
setBoredomLevel(getBoredomLevel()-getBoredomLevel());
|
||||
else
|
||||
setBoredomLevel(getBoredomLevel()-in);
|
||||
cout << getName() << " had " << in << " hours of fun." << endl;
|
||||
PassTime();
|
||||
DisplayPetBehavior();
|
||||
}
|
||||
|
||||
void Pet::DisplayPetBehavior()
|
||||
{
|
||||
cout << " Boredom: " << getBoredomLevel() << endl;
|
||||
cout << " Hunger: " << getHungerLevel() << endl;
|
||||
if (getBoredomLevel() < 3 && getHungerLevel() < 3)
|
||||
cout << getName() << " is content" << endl;
|
||||
|
||||
if ( getBoredomLevel() >= 3 && getBoredomLevel() < 11)
|
||||
cout << getName() << " is a litte bored" << endl;
|
||||
else if (getBoredomLevel() >= 11)
|
||||
cout << getName() << " is very bored" << endl;
|
||||
|
||||
if ( getHungerLevel() >= 3 && getHungerLevel() < 11)
|
||||
cout << getName() << " is a litte hungry" << endl;
|
||||
else if (getHungerLevel() >= 11)
|
||||
cout << getName() << " is very hungry" << endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
int Pet::PetMood()
|
||||
{
|
||||
return getBoredomLevel() + getHungerLevel();
|
||||
}
|
||||
|
||||
void Pet::PassTime(int time)
|
||||
{
|
||||
setHungerLevel(getHungerLevel()+time);
|
||||
setBoredomLevel(getBoredomLevel()+time);
|
||||
}
|
||||
|
||||
void Pet::menu()
|
||||
{
|
||||
enum { TALK = 1, FEED, PLAY, QUIT };
|
||||
bool breakout = false;
|
||||
while (!breakout)
|
||||
{
|
||||
cout << "Pet: " << getName() << endl;
|
||||
cout << TALK << ". Talk with your pet." << endl;
|
||||
cout << FEED << ". Feed your pet." << endl;
|
||||
cout << PLAY << ". Play with your pet." << endl;
|
||||
cout << QUIT << ". Quit your pet." << endl;
|
||||
cout << "What would you like to do?" << endl << ":";
|
||||
int menuSelection = getch() - '0';
|
||||
//cls();
|
||||
system("cls");
|
||||
switch (menuSelection)
|
||||
{
|
||||
case TALK:
|
||||
Talk();
|
||||
break;
|
||||
case FEED:
|
||||
FeedPet((((rand()%509)*(rand()%349))%4));
|
||||
break;
|
||||
case PLAY:
|
||||
Play((((rand()%509)*(rand()%349))%4));
|
||||
break;
|
||||
case QUIT:
|
||||
breakout = true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
/******************************************************************************
|
||||
* Pet.h - Define a pet object *
|
||||
* Author: Amrit Panesar <apanesar@coleman.edu> *
|
||||
* Date: 08/18/2014 *
|
||||
* License: Released into public domain *
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdhead.h"
|
||||
|
||||
class Pet
|
||||
{
|
||||
private:
|
||||
int hungerlevel;
|
||||
int boredomlevel;
|
||||
string name;
|
||||
|
||||
int PetMood();
|
||||
void PassTime(int time = 1);
|
||||
|
||||
int getHungerLevel();
|
||||
void setHungerLevel(int hunger);
|
||||
|
||||
int getBoredomLevel();
|
||||
void setBoredomLevel(int boredom);
|
||||
|
||||
string getName();
|
||||
void setName(string name);
|
||||
|
||||
|
||||
public:
|
||||
Pet(string name, int hunger = 0, int boredom = 0);
|
||||
void Talk();
|
||||
void FeedPet(int in);
|
||||
void Play(int in);
|
||||
void DisplayPetBehavior();
|
||||
void menu();
|
||||
|
||||
};
|
||||
@@ -0,0 +1,173 @@
|
||||
// PetSim.cpp : Defines the entry point for the console application.
|
||||
//
|
||||
|
||||
#include "stdhead.h"
|
||||
|
||||
|
||||
bool yorn();
|
||||
void ChangeIcon( const HICON hNewIcon );
|
||||
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
int i;
|
||||
time_t t = time(NULL);
|
||||
tm* timePtr = localtime(&t);
|
||||
TCHAR szNewTitle[MAX_PATH];
|
||||
|
||||
HMODULE hMainMod = GetModuleHandle( 0 );
|
||||
assert( hMainMod );
|
||||
|
||||
HICON hMainIcon = ::LoadIcon( hMainMod, MAKEINTRESOURCE( IDI_ICON1 ));
|
||||
assert( hMainIcon );
|
||||
|
||||
// Change main window icon
|
||||
ChangeIcon( hMainIcon );
|
||||
|
||||
system("color 1e");
|
||||
StringCchPrintf(szNewTitle, MAX_PATH, TEXT("Pet Simulator %d"), timePtr->tm_year + 1900);
|
||||
SetConsoleTitle(szNewTitle);
|
||||
|
||||
cout << string(80, '*');
|
||||
cout << "Welcome to Pet Simulator " << timePtr->tm_year + 1900 << " Edition!" << endl << endl;
|
||||
cout << string(80, '*');
|
||||
|
||||
bool named = false;
|
||||
string name;
|
||||
|
||||
while(!named)
|
||||
{
|
||||
cout << endl << endl;
|
||||
cout << "Step one: Name your pet." << endl;
|
||||
cout << "It's time to name your pet! Please enter a name for your pet" << endl << ": ";
|
||||
cin >> name;
|
||||
cout << "You've named your pet: " << name << endl << endl;
|
||||
cout << "Is this correct?" << endl << "[Y/n]: ";
|
||||
i = getch();
|
||||
cout << (char)i << endl;
|
||||
bool breakout = false;
|
||||
if ( i == 89 || 121 || 13 || 27 || 28 || 110)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 89:
|
||||
case 121:
|
||||
case 13:
|
||||
named = true;
|
||||
breakout = true;
|
||||
break;
|
||||
case 27:
|
||||
case 28:
|
||||
case 110:
|
||||
breakout = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!breakout)
|
||||
{
|
||||
if (yorn())
|
||||
{
|
||||
named = true;
|
||||
breakout = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
breakout = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Pet pet = Pet(name);
|
||||
|
||||
bool breakout = false;
|
||||
while(!breakout)
|
||||
{
|
||||
pet.menu();
|
||||
system("cls");
|
||||
cout << "Would you like to play again?" << endl << "[Y/n]: ";
|
||||
i = getch();
|
||||
cout << (char)i << endl;
|
||||
bool bjorn = false;
|
||||
if ( i == 89 || 121 || 13 || 27 || 28 || 110)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 89:
|
||||
case 121:
|
||||
case 13:
|
||||
bjorn = true;
|
||||
breakout = false;
|
||||
break;
|
||||
case 27:
|
||||
case 28:
|
||||
case 110:
|
||||
bjorn = true;
|
||||
breakout = true;
|
||||
break;
|
||||
default:
|
||||
bjorn = false;
|
||||
}
|
||||
}
|
||||
if (!bjorn)
|
||||
{
|
||||
if (yorn())
|
||||
{
|
||||
breakout = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
breakout = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
system("cls");
|
||||
cout << "Game over .." << endl << endl;
|
||||
cout << "Press any key to continue...";
|
||||
getch();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool yorn()
|
||||
{
|
||||
int i = 0;
|
||||
while (i != 0)
|
||||
{
|
||||
cout << "Please enter Y or N :" << endl;
|
||||
i = getch();
|
||||
cout << (char)i << endl;
|
||||
switch (i)
|
||||
{
|
||||
case 89:
|
||||
case 121:
|
||||
return true;
|
||||
break;
|
||||
case 28:
|
||||
case 110:
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ChangeIcon( 0 );
|
||||
}
|
||||
|
||||
void ChangeIcon( const HICON hNewIcon )
|
||||
{
|
||||
// Load kernel 32 library
|
||||
HMODULE hMod = LoadLibrary( _T( "Kernel32.dll" ));
|
||||
assert( hMod );
|
||||
|
||||
// Load console icon changing procedure
|
||||
typedef DWORD ( __stdcall *SCI )( HICON );
|
||||
SCI pfnSetConsoleIcon = reinterpret_cast<SCI>( GetProcAddress( hMod, "SetConsoleIcon" ));
|
||||
assert( pfnSetConsoleIcon );
|
||||
|
||||
// Call function to change icon
|
||||
pfnSetConsoleIcon( hNewIcon );
|
||||
|
||||
FreeLibrary( hMod );
|
||||
}// End ChangeIcon
|
||||
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{8387506E-641F-4005-AF63-F98EBDDF0E48}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>PetSim</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CenteredOut.h" />
|
||||
<ClInclude Include="Pet.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="stdhead.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Pet.cpp" />
|
||||
<ClCompile Include="PetSim.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Resource.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="icon.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Pet.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CenteredOut.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="stdhead.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="PetSim.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Pet.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Resource.rc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="icon.ico">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,40 @@
|
||||
========================================================================
|
||||
CONSOLE APPLICATION : PetSim Project Overview
|
||||
========================================================================
|
||||
|
||||
AppWizard has created this PetSim application for you.
|
||||
|
||||
This file contains a summary of what you will find in each of the files that
|
||||
make up your PetSim application.
|
||||
|
||||
|
||||
PetSim.vcxproj
|
||||
This is the main project file for VC++ projects generated using an Application Wizard.
|
||||
It contains information about the version of Visual C++ that generated the file, and
|
||||
information about the platforms, configurations, and project features selected with the
|
||||
Application Wizard.
|
||||
|
||||
PetSim.vcxproj.filters
|
||||
This is the filters file for VC++ projects generated using an Application Wizard.
|
||||
It contains information about the association between the files in your project
|
||||
and the filters. This association is used in the IDE to show grouping of files with
|
||||
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
|
||||
"Source Files" filter).
|
||||
|
||||
PetSim.cpp
|
||||
This is the main application source file.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Other standard files:
|
||||
|
||||
StdAfx.h, StdAfx.cpp
|
||||
These files are used to build a precompiled header (PCH) file
|
||||
named PetSim.pch and a precompiled types file named StdAfx.obj.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Other notes:
|
||||
|
||||
AppWizard uses "TODO:" comments to indicate parts of the source code you
|
||||
should add to or customize.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 422 KiB |
Binary file not shown.
@@ -0,0 +1,29 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <conio.h>
|
||||
#include <strsafe.h>
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
||||
|
||||
#include "CenteredOut.h"
|
||||
#include "resource.h"
|
||||
#include "Pet.h"
|
||||
@@ -0,0 +1,9 @@
|
||||
Code change needed from the handout.
|
||||
Use the following code to instantiate your root object in the Pong constructor:
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
rootPtr = new Root("Plugins_d.cfg"); // initialize Root object
|
||||
#else
|
||||
rootPtr = new Root("Plugins.cfg"); // initialize Root object
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ogre Project", "Ogre Project\Ogre Project.vcproj", "{220D5644-C06B-4022-A9D7-7B43CEBC46D8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ogre Project", "Ogre Project\Ogre Project.vcproj", "{220D5644-C06B-4022-A9D7-7B43CEBC46D8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Binary file not shown.
@@ -0,0 +1,165 @@
|
||||
// Ball.cpp
|
||||
// Ball class member-function definitions.
|
||||
#include <Ogre.h> // Ogre class definition
|
||||
using namespace Ogre; // use the Ogre namespace
|
||||
|
||||
#include <OgreAL.h> // OgreAL class definition
|
||||
#include "Ball.h" // Ball class definition
|
||||
#include "Paddle.h" // Paddle class definition
|
||||
#include "Pong.h" // Pong class definition
|
||||
|
||||
// Ball constructor
|
||||
Ball::Ball( SceneManager *ptr )
|
||||
{
|
||||
sceneManagerPtr = ptr; // set pointer to the SceneManager
|
||||
soundManagerPtr = new OgreAL::SoundManager(); // create SoundManager
|
||||
speed = 100; // speed of the Ball
|
||||
direction = Vector3( 1, -1, 0 ); // direction of the Ball
|
||||
} // end Ball constructor
|
||||
|
||||
// Ball destructor
|
||||
Ball::~Ball()
|
||||
{
|
||||
// empty body
|
||||
} // end Ball destructor
|
||||
|
||||
// add the Ball to the scene
|
||||
void Ball::addToScene()
|
||||
{
|
||||
// create Entity and attach it to a node in the scene
|
||||
Entity *entityPtr =
|
||||
sceneManagerPtr->createEntity( "Ball", "cube.mesh" );
|
||||
entityPtr->setMaterialName( "ball" ); // set material for the Ball
|
||||
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
|
||||
nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "Ball" ); // create a SceneNode
|
||||
nodePtr->attachObject( entityPtr ); // attach the Entity to SceneNode
|
||||
nodePtr->setScale( .05, .05, .05 ); // scale SceneNode
|
||||
|
||||
// attach sounds to Ball so they will play from where Ball is
|
||||
wallSoundPtr = soundManagerPtr->createSound( "wallSound", "wallSound.wav", false );
|
||||
nodePtr->attachObject( wallSoundPtr ); // attach a sound to SceneNode
|
||||
paddleSoundPtr = soundManagerPtr->createSound( "paddleSound", "paddleSound.wav", false );
|
||||
nodePtr->attachObject( paddleSoundPtr ); // attach sound to SceneNode
|
||||
scoreSoundPtr = soundManagerPtr->createSound( "cheer", "cheer.wav", false ); // create a Sound
|
||||
|
||||
// attach the score sound to its own node centered at ( 0, 0, 0 )
|
||||
sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "score" )->attachObject( scoreSoundPtr );
|
||||
} // end function addToScene
|
||||
|
||||
// move the Ball across the screen
|
||||
void Ball::moveBall( Real time )
|
||||
{
|
||||
nodePtr->translate( ( direction * ( speed * time ) ) ); // move Ball
|
||||
Vector3 position = nodePtr->getPosition(); // get Ball's new position
|
||||
|
||||
// get the positions of the four walls
|
||||
Vector3 topPosition = sceneManagerPtr->getSceneNode( "WallTop" )->getPosition();
|
||||
Vector3 bottomPosition = sceneManagerPtr->getSceneNode( "WallBottom" )->getPosition();
|
||||
Vector3 leftPosition = sceneManagerPtr->getSceneNode( "WallLeft" )->getPosition();
|
||||
Vector3 rightPosition = sceneManagerPtr->getSceneNode( "WallRight" )->getPosition();
|
||||
|
||||
const int WALL_WIDTH = 5; // the width of the walls
|
||||
|
||||
// check if the Ball hit the left side
|
||||
if ( ( position.x - RADIUS ) <= leftPosition.x + ( WALL_WIDTH / 2 ) )
|
||||
{
|
||||
nodePtr->setPosition( 0, 0, 0 ); // place Ball in center of screen
|
||||
Pong::updateScore( Players::PLAYER2 ); // update the score
|
||||
scoreSoundPtr->play(); // play a sound when player 2 scores
|
||||
} // end if
|
||||
// check if the Ball hit the right side
|
||||
else if (
|
||||
( position.x + RADIUS ) >= rightPosition.x - ( WALL_WIDTH / 2 ) )
|
||||
{
|
||||
nodePtr->setPosition( 0, 0, 0 ); // place Ball in center of screen
|
||||
Pong::updateScore( Players::PLAYER1 ); // update the score
|
||||
scoreSoundPtr->play(); // play a sound when player 1 scores
|
||||
} // end else
|
||||
// check if the Ball hit the bottom wall
|
||||
else if (
|
||||
( position.y - RADIUS ) <= bottomPosition.y + ( WALL_WIDTH / 2 ) &&
|
||||
direction.y < 0 )
|
||||
{
|
||||
// place the Ball on the bottom wall
|
||||
nodePtr->setPosition( position.x,
|
||||
( bottomPosition.y + ( WALL_WIDTH / 2 ) + RADIUS ), position.z );
|
||||
reverseVerticalDirection(); // make the Ball start moving up
|
||||
} // end else
|
||||
// check if the Ball hit the top wall
|
||||
else if (
|
||||
( position.y + RADIUS ) >= topPosition.y - ( WALL_WIDTH / 2 ) &&
|
||||
direction.y > 0 )
|
||||
{
|
||||
// place the Ball on the top wall
|
||||
nodePtr->setPosition( position.x,
|
||||
( topPosition.y - ( WALL_WIDTH / 2 ) - RADIUS ), position.z );
|
||||
reverseVerticalDirection(); // make the Ball start moving down
|
||||
} // end else
|
||||
|
||||
hitPaddle(); // check if the Ball hit a Paddle
|
||||
} // end function moveBall
|
||||
|
||||
// reverse the Ball's horizontal direction
|
||||
void Ball::reverseHorizontalDirection()
|
||||
{
|
||||
direction *= Vector3( -1, 1, 1 ); // reverse the horizontal direction
|
||||
paddleSoundPtr->play(); // play the "paddleSound" sound effect
|
||||
} // end function reverseHorizontalDirection
|
||||
|
||||
// reverse the Ball's vertical direction
|
||||
void Ball::reverseVerticalDirection()
|
||||
{
|
||||
direction *= Vector3( 1, -1, 1 ); // reverse the vertical direction
|
||||
wallSoundPtr->play(); // play the "wallSound" sound effect
|
||||
} // end function reverseVerticalDirection
|
||||
|
||||
// control the Ball colliding with the Paddle
|
||||
void Ball::hitPaddle()
|
||||
{
|
||||
// get the position of the Paddles and the Ball
|
||||
Vector3 leftPaddlePosition = sceneManagerPtr->
|
||||
getSceneNode( "LeftPaddle" )->getPosition(); // left Paddle
|
||||
Vector3 rightPaddlePosition = sceneManagerPtr->
|
||||
getSceneNode( "RightPaddle" )->getPosition(); // right Paddle
|
||||
Vector3 ballPosition = nodePtr->getPosition(); // the Ball's position
|
||||
|
||||
const int PADDLE_WIDTH = 2; // width of the Paddle
|
||||
const int PADDLE_HEIGHT = 30; // height of the Paddle
|
||||
|
||||
// is the Ball in range of the left Paddle?
|
||||
if ( ( ballPosition.x - RADIUS ) <
|
||||
( leftPaddlePosition.x + ( PADDLE_WIDTH / 2 ) ) )
|
||||
{
|
||||
// check for collision with left Paddle
|
||||
if ( ( ballPosition.y - RADIUS ) <
|
||||
( leftPaddlePosition.y + ( PADDLE_HEIGHT / 2 ) ) &&
|
||||
( ballPosition.y + RADIUS ) >
|
||||
( leftPaddlePosition.y - ( PADDLE_HEIGHT / 2 ) ) )
|
||||
{
|
||||
reverseHorizontalDirection(); // reverse the Ball's direction
|
||||
|
||||
// place the Ball at the edge of the Paddle
|
||||
nodePtr->setPosition(
|
||||
( leftPaddlePosition.x + ( PADDLE_WIDTH / 2 ) + RADIUS ),
|
||||
ballPosition.y, ballPosition.z );
|
||||
} // end if
|
||||
} // end if
|
||||
// is the Ball in range of the right Paddle?
|
||||
else if ( ( ballPosition.x + RADIUS ) >
|
||||
( rightPaddlePosition.x - ( PADDLE_WIDTH / 2 ) ) )
|
||||
{
|
||||
// check for collision with right Paddle
|
||||
if ( ( ballPosition.y - RADIUS ) <
|
||||
( rightPaddlePosition.y + ( PADDLE_HEIGHT / 2 ) ) &&
|
||||
( ballPosition.y + RADIUS ) >
|
||||
( rightPaddlePosition.y - ( PADDLE_HEIGHT / 2 ) ) )
|
||||
{
|
||||
reverseHorizontalDirection(); // reverse the Ball's direction
|
||||
|
||||
// place the Ball at the edge of the Paddle
|
||||
nodePtr->setPosition(
|
||||
( rightPaddlePosition.x - ( PADDLE_WIDTH / 2 ) - RADIUS ),
|
||||
ballPosition.y, ballPosition.z );
|
||||
} // end if
|
||||
} // end else
|
||||
} // end function hitPaddle
|
||||
@@ -0,0 +1,40 @@
|
||||
// Ball.h
|
||||
// Ball class definition (represents a bouncing ball).
|
||||
#ifndef BALL_H
|
||||
#define BALL_H
|
||||
|
||||
#include <Ogre.h> // Ogre class definition
|
||||
using namespace Ogre; // use the Ogre namespace
|
||||
|
||||
#include <OgreAL.h> // OgreAL class definition
|
||||
|
||||
class Paddle; // forward declaration of class Paddle
|
||||
|
||||
const int RADIUS = 5; // the radius of the Ball
|
||||
|
||||
class Ball
|
||||
{
|
||||
public:
|
||||
Ball( SceneManager *sceneManagerPtr ); // constructor
|
||||
~Ball(); // destructor
|
||||
void addToScene(); // add the Ball to the scene
|
||||
void moveBall( Real time ); // move the Ball across the screen
|
||||
|
||||
private:
|
||||
SceneManager *sceneManagerPtr; // pointer to the SceneManager
|
||||
SceneNode *nodePtr; // pointer to the SceneNode
|
||||
OgreAL::SoundManager *soundManagerPtr; // pointer to the SoundManager
|
||||
OgreAL::Sound *wallSoundPtr; // sound played when Ball hits a wall
|
||||
OgreAL::Sound *paddleSoundPtr; // sound played when Ball hits a Paddle
|
||||
OgreAL::Sound *scoreSoundPtr; // sound played when someone scores
|
||||
int speed; // speed of the Ball
|
||||
Vector3 direction; // direction of the Ball
|
||||
|
||||
// private utility functions
|
||||
void reverseHorizontalDirection(); // change horizontal direction
|
||||
void reverseVerticalDirection(); // change vertical direction
|
||||
void hitPaddle(); // control the Ball hitting the Paddles
|
||||
}; // end class Ball
|
||||
|
||||
#endif // BALL_H
|
||||
|
||||
@@ -0,0 +1,307 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="Ogre Project"
|
||||
ProjectGUID="{220D5644-C06B-4022-A9D7-7B43CEBC46D8}"
|
||||
RootNamespace="OgreProject"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""$(GDD_OGRE_HOME)\Ogre3D\include";"$(GDD_OGRE_HOME)\OpenAL\include";"$(GDD_OGRE_HOME)\OgreAL\include";"$(GDD_OGRE_HOME)\ogg\include";"$(GDD_OGRE_HOME)\vorbis\include""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="OgreMain_d.lib OIS_d.lib OgreAL_d.lib"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories=""$(GDD_OGRE_HOME)\Ogre3D\lib\$(ConfigurationName)";"$(GDD_OGRE_HOME)\OgreAL\lib\$(ConfigurationName)""
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories=""$(GDD_OGRE_HOME)\Ogre3D\include";"$(GDD_OGRE_HOME)\OpenAL\include";"$(GDD_OGRE_HOME)\OgreAL\include";"$(GDD_OGRE_HOME)\ogg\include";"$(GDD_OGRE_HOME)\vorbis\include""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="OgreMain.lib OIS.lib OgreAL.lib"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""$(GDD_OGRE_HOME)\Ogre3D\lib\$(ConfigurationName)";"$(GDD_OGRE_HOME)\OgreAL\lib\$(ConfigurationName)""
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Ball.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Paddle.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Pong.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PongMain.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Ball.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Paddle.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Pong.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resource.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\resources\BlueBold.fontdef"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\bluebold.ttf"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\boing.wav"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\boing1.wav"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\cheer.wav"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\cube.mesh"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\MenuMaterial.material"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\MenuOverlay.overlay"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\paddleSound.wav"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\..\..\Downloads\pong.ico"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\..\..\Downloads\pong.png"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\PongMaterials.material"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\PongOverlays.overlay"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\PongScore.fontdef"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\PongScore.ttf"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\PongText.fontdef"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\PongText.ttf"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resource.rc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\sphere.mesh"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\wallSound.wav"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -0,0 +1,111 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{220D5644-C06B-4022-A9D7-7B43CEBC46D8}</ProjectGuid>
|
||||
<RootNamespace>OgreProject</RootNamespace>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
||||
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
|
||||
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
|
||||
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
|
||||
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(GDD_OGRE_HOME)\Ogre3D\include;$(GDD_OGRE_HOME)\OpenAL\include;$(GDD_OGRE_HOME)\OgreAL\include;$(GDD_OGRE_HOME)\ogg\include;$(GDD_OGRE_HOME)\vorbis\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>OgreMain_d.lib;OIS_d.lib;OgreAL_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(GDD_OGRE_HOME)\Ogre3D\lib\$(Configuration);$(GDD_OGRE_HOME)\OgreAL\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>$(GDD_OGRE_HOME)\Ogre3D\include;$(GDD_OGRE_HOME)\OpenAL\include;$(GDD_OGRE_HOME)\OgreAL\include;$(GDD_OGRE_HOME)\ogg\include;$(GDD_OGRE_HOME)\vorbis\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>OgreMain.lib;OIS.lib;OgreAL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(GDD_OGRE_HOME)\Ogre3D\lib\$(Configuration);$(GDD_OGRE_HOME)\OgreAL\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Ball.cpp" />
|
||||
<ClCompile Include="Paddle.cpp" />
|
||||
<ClCompile Include="Pong.cpp" />
|
||||
<ClCompile Include="PongMain.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Ball.h" />
|
||||
<ClInclude Include="Paddle.h" />
|
||||
<ClInclude Include="Pong.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Ball.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Paddle.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Pong.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="PongMain.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Ball.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Paddle.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Pong.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,45 @@
|
||||
// Paddle.cpp
|
||||
// Paddle class member-function definitions.
|
||||
#include <Ogre.h> // Ogre class definition
|
||||
using namespace Ogre; // use the Ogre namespace
|
||||
|
||||
#include "Paddle.h" // Paddle class definition
|
||||
|
||||
// constructor
|
||||
Paddle::Paddle( SceneManager *ptr, String paddleName, int positionX )
|
||||
{
|
||||
sceneManagerPtr = ptr; // set the pointer to the SceneManager
|
||||
name = paddleName; // set the Paddle's name
|
||||
x = positionX; // set the Paddle's x coordinate
|
||||
} // end Paddle constructor
|
||||
|
||||
// destructor
|
||||
Paddle::~Paddle()
|
||||
{
|
||||
// empty body
|
||||
} // end Paddle default destructor
|
||||
|
||||
// add the Paddle to the scene
|
||||
void Paddle::addToScene()
|
||||
{
|
||||
Entity *entityPtr = sceneManagerPtr->
|
||||
createEntity( name, "cube.mesh" ); // create an Entity
|
||||
entityPtr->setMaterialName( "paddle" ); // set the Paddle's material
|
||||
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
|
||||
nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( name ); // create a SceneNode for the Paddle
|
||||
nodePtr->attachObject( entityPtr ); // attach Paddle to the SceneNode
|
||||
nodePtr->setScale( .02, .3, .1 ); // set the Paddle's size
|
||||
nodePtr->setPosition( x, 0, 0 ); // set the Paddle's position
|
||||
} // end function addToScene
|
||||
|
||||
// move the Paddle up and down the screen
|
||||
void Paddle::movePaddle( const Vector3 &direction )
|
||||
{
|
||||
nodePtr->translate( direction ); // move the Paddle
|
||||
if ( nodePtr->getPosition().y > 52.5 ) // top of the box
|
||||
nodePtr->setPosition( x, 52.5, 0 ); // place Paddle at top of box
|
||||
else if ( nodePtr->getPosition().y < -52.5 ) // bottom of the box
|
||||
// place the Paddle at the bottom of the box
|
||||
nodePtr->setPosition( x, -52.5, 0 );
|
||||
} // end function movePaddle
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Paddle.h
|
||||
// Paddle class definition (represents a paddle in the game).
|
||||
#ifndef PADDLE_H
|
||||
#define PADDLE_H
|
||||
|
||||
#include <Ogre.h> // Ogre class definition
|
||||
using namespace Ogre; // use the Ogre namespace
|
||||
|
||||
class Paddle
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
Paddle( SceneManager *sceneManagerPtr, String paddleName,
|
||||
int positionX);
|
||||
~Paddle(); // destructor
|
||||
void addToScene(); // add a Paddle to the scene
|
||||
void movePaddle( const Vector3 &direction ); // move a Paddle
|
||||
|
||||
private:
|
||||
SceneManager* sceneManagerPtr; // pointer to the SceneManager
|
||||
SceneNode *nodePtr; // pointer to a SceneNode
|
||||
String name; // name of the Paddle
|
||||
int x; // x coordinate of the Paddle
|
||||
}; // end of class Paddle
|
||||
|
||||
#endif // PADDLE_H
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
# Defines plugins to load
|
||||
|
||||
# Define plugin folder
|
||||
PluginFolder=.
|
||||
|
||||
# Define plugins
|
||||
Plugin=RenderSystem_Direct3D9
|
||||
Plugin=RenderSystem_GL
|
||||
Plugin=Plugin_ParticleFX
|
||||
Plugin=Plugin_BSPSceneManager
|
||||
Plugin=Plugin_OctreeSceneManager
|
||||
Plugin=Plugin_CgProgramManager
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
# Defines plugins to load
|
||||
|
||||
# Define plugin folder
|
||||
PluginFolder=.
|
||||
|
||||
# Define plugins
|
||||
Plugin=RenderSystem_Direct3D9_d
|
||||
Plugin=RenderSystem_GL_d
|
||||
Plugin=Plugin_ParticleFX_d
|
||||
Plugin=Plugin_BSPSceneManager_d
|
||||
Plugin=Plugin_OctreeSceneManager_d
|
||||
Plugin=Plugin_CgProgramManager_d
|
||||
|
||||
|
||||
@@ -0,0 +1,407 @@
|
||||
// Pong.cpp
|
||||
// Pong class member-function definitions.
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <Ogre.h> // Ogre class definition
|
||||
using namespace Ogre; // use the Ogre namespace
|
||||
using namespace std; // use the Standard C namespace
|
||||
|
||||
#include <OgreAL.h> // OgreAL class definition
|
||||
#include <OgreStringConverter.h> // OgreStringConverter class definition
|
||||
#include <OIS/OISEvents.h> // OISEvents class definition
|
||||
#include <OIS/OISInputManager.h> // OISInputManager class definition
|
||||
#include <OIS/OISKeyboard.h> // OISKeyboard class definition
|
||||
#include "Ball.h" // Ball class definition
|
||||
#include "Paddle.h" // Paddle class definition
|
||||
#include "Pong.h" // Pong class definition
|
||||
|
||||
int Pong::player1Score = 0; // initialize player 1's score to 0
|
||||
int Pong::player2Score = 0; // initialize player 2's score to 0
|
||||
bool Pong::wait = false; // initialize wait to false
|
||||
|
||||
// directions to move the Paddles
|
||||
const Vector3 PADDLE_DOWN = Vector3( 0, -1, 0 );
|
||||
const Vector3 PADDLE_UP = Vector3( 0, 1, 0 );
|
||||
|
||||
// constructor
|
||||
Pong::Pong()
|
||||
{
|
||||
|
||||
#ifdef _DEBUG
|
||||
rootPtr = new Root("Plugins_d.cfg"); // initialize Root object
|
||||
#else
|
||||
rootPtr = new Root("Plugins.cfg"); // initialize Root object
|
||||
#endif
|
||||
|
||||
// use the Ogre Config Dialog Box to choose the settings
|
||||
//if ( !( rootPtr->showConfigDialog() ) ) // user canceled the dialog box
|
||||
// throw runtime_error( "User Canceled Ogre Setup Dialog Box." );
|
||||
|
||||
WIN32_FIND_DATA w32FD;
|
||||
HANDLE h = FindFirstFile(L"ogre.cfg", &w32FD);
|
||||
if(FAILED(h)){
|
||||
if(!rootPtr->showConfigDialog()){
|
||||
throw runtime_error( "User Canceled Ogre Setup Dialog Box." );
|
||||
} else {
|
||||
rootPtr->saveConfig();
|
||||
}
|
||||
} else {
|
||||
rootPtr->restoreConfig();
|
||||
}
|
||||
|
||||
|
||||
// get a pointer to the RenderWindow
|
||||
windowPtr = rootPtr->initialise( true, "Pong! 2014 Edition" );
|
||||
|
||||
// create the SceneManager
|
||||
sceneManagerPtr = rootPtr->createSceneManager( ST_GENERIC );
|
||||
|
||||
// create the Camera
|
||||
cameraPtr = sceneManagerPtr->createCamera( "PongCamera" );
|
||||
cameraPtr->setPosition( Vector3( 0, 0, 200 ) ); // set Camera position
|
||||
cameraPtr->lookAt( Vector3( 0, 0, 0 ) ); // set where Camera looks
|
||||
cameraPtr->setNearClipDistance( 5 ); // near distance Camera can see
|
||||
cameraPtr->setFarClipDistance( 1000 ); // far distance Camera can see
|
||||
|
||||
// create the Viewport
|
||||
viewportPtr = windowPtr->addViewport( cameraPtr );
|
||||
viewportPtr->setBackgroundColour( ColourValue( 0, 0, 0 ) );
|
||||
|
||||
// set the Camera's aspect ratio
|
||||
cameraPtr->setAspectRatio( Real( viewportPtr->getActualWidth() ) /( viewportPtr->getActualHeight() ) );
|
||||
|
||||
// set the scene's ambient light
|
||||
sceneManagerPtr->setAmbientLight( ColourValue( 0.75, 0.75, 0.75 ) );
|
||||
|
||||
// create the Light
|
||||
Light *lightPtr = sceneManagerPtr->createLight( "Light" ); // a Light
|
||||
lightPtr->setPosition( 0, 0, 50 ); // set the Light's position
|
||||
|
||||
unsigned long hWnd; // variable to hold the window handle
|
||||
windowPtr->getCustomAttribute( "WINDOW", &hWnd ); // get window handle
|
||||
OIS::ParamList paramList; // create an OIS ParamList
|
||||
|
||||
// add the window to the ParamList
|
||||
paramList.insert( OIS::ParamList::value_type( "WINDOW", Ogre::StringConverter::toString( hWnd ) ) );
|
||||
|
||||
// create the InputManager
|
||||
inputManagerPtr = OIS::InputManager::createInputSystem( paramList );
|
||||
keyboardPtr = static_cast< OIS::Keyboard* >( inputManagerPtr->createInputObject( OIS::OISKeyboard, true ) ); // create a Keyboard
|
||||
keyboardPtr->setEventCallback( this ); // add a KeyListener
|
||||
|
||||
rootPtr->addFrameListener( this ); // add this Pong as a FrameListener
|
||||
|
||||
// load resources for Pong
|
||||
ResourceGroupManager::getSingleton().addResourceLocation("resources", "FileSystem", "Pong" );
|
||||
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
||||
|
||||
quit = pause = false; // player has not quit or paused the game
|
||||
time = 0; // initialize the time since Ball was reset to 0
|
||||
|
||||
paddle[0] = paddle[1] = 0;
|
||||
|
||||
} // end Pong constructor
|
||||
|
||||
// Pong destructor erases objects contained in a Pong object
|
||||
Pong::~Pong()
|
||||
{
|
||||
Ogre::WindowEventUtilities::removeWindowEventListener(windowPtr, this);
|
||||
windowClosed(windowPtr);
|
||||
|
||||
// free dynamically allocated memory for Keyboard/mouse
|
||||
if(inputManagerPtr)
|
||||
{
|
||||
//inputManagerPtr->destroyInputObject( mousePtr );
|
||||
//mousePtr = 0;
|
||||
|
||||
inputManagerPtr->destroyInputObject( keyboardPtr );
|
||||
keyboardPtr = 0;
|
||||
|
||||
OIS::InputManager::destroyInputSystem(inputManagerPtr);
|
||||
inputManagerPtr = 0;
|
||||
}
|
||||
|
||||
// free dynamically allocated memory for Root
|
||||
delete rootPtr; // release memory pointer points to
|
||||
rootPtr = 0; // point pointer at 0
|
||||
|
||||
// free dynamically allocated memory for Ball
|
||||
delete ballPtr; // release memory pointer points to
|
||||
ballPtr = 0; // point pointer at 0
|
||||
|
||||
// free dynamically allocated memory for Paddle
|
||||
delete leftPaddlePtr; // release memory pointer points to
|
||||
leftPaddlePtr = 0; // point pointer at 0
|
||||
|
||||
// free dynamically allocated memory for Paddle
|
||||
delete rightPaddlePtr; // release memory pointer points to
|
||||
rightPaddlePtr = 0; // point pointer at 0
|
||||
} // end Pong destructor
|
||||
|
||||
// create the scene to be displayed
|
||||
void Pong::createScene()
|
||||
{
|
||||
// get a pointer to the Score Overlay
|
||||
Overlay *scoreOverlayPtr = OverlayManager::getSingleton().getByName( "Score" );
|
||||
scoreOverlayPtr->show(); // show the Overlay
|
||||
|
||||
// make the game objects
|
||||
ballPtr = new Ball( sceneManagerPtr ); // make the Ball
|
||||
ballPtr->addToScene(); // add the Ball to the scene
|
||||
rightPaddlePtr = new Paddle( sceneManagerPtr, "RightPaddle", 90 );
|
||||
rightPaddlePtr->addToScene(); // add a Paddle to the scene
|
||||
leftPaddlePtr = new Paddle( sceneManagerPtr, "LeftPaddle", -90 );
|
||||
leftPaddlePtr->addToScene(); // add a Paddle to the scene
|
||||
|
||||
// create the walls
|
||||
Entity *entityPtr = sceneManagerPtr->createEntity( "WallLeft", "cube.mesh" ); // create the left wall
|
||||
entityPtr->setMaterialName( "wall" ); // set material for left wall
|
||||
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
|
||||
|
||||
// create the SceneNode for the left wall
|
||||
SceneNode *nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "WallLeft" );
|
||||
nodePtr->attachObject( entityPtr ); // attach left wall to SceneNode
|
||||
nodePtr->setPosition( -95, 0, 0 ); // set the left wall's position
|
||||
nodePtr->setScale( .05, 1.45, .1 ); // set the left wall's size
|
||||
entityPtr = sceneManagerPtr->createEntity( "WallRight", "cube.mesh" );
|
||||
entityPtr->setMaterialName( "wall" ); // set material for right wall
|
||||
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
|
||||
|
||||
// create the SceneNode for the right wall
|
||||
nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "WallRight" );
|
||||
nodePtr->attachObject( entityPtr ); // attach right wall to SceneNode
|
||||
nodePtr->setPosition( 95, 0, 0 ); // set the right wall's position
|
||||
nodePtr->setScale( .05, 1.45, .1 ); // set the right wall's size
|
||||
entityPtr = sceneManagerPtr->createEntity( "WallBottom", "cube.mesh" );
|
||||
entityPtr->setMaterialName( "wall" ); // set material for bottom wall
|
||||
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
|
||||
|
||||
// create the SceneNode for the bottom wall
|
||||
nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "WallBottom" );
|
||||
nodePtr->attachObject( entityPtr ); // attach bottom wall to SceneNode
|
||||
nodePtr->setPosition( 0, -70, 0 ); // set the bottom wall's position
|
||||
nodePtr->setScale( 1.95, .05, .1 ); // set bottom wall's size
|
||||
entityPtr = sceneManagerPtr->createEntity( "WallTop", "cube.mesh" );
|
||||
entityPtr->setMaterialName( "wall" ); // set the material for wall
|
||||
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
|
||||
|
||||
// create the SceneNode for the top wall
|
||||
nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "WallTop" );
|
||||
nodePtr->attachObject( entityPtr ); // attach top wall to SceneNode
|
||||
nodePtr->setPosition( 0, 70, 0 ); // set the top wall's position
|
||||
nodePtr->setScale( 1.95, .05, .1 ); // set the top wall's size
|
||||
} // end function createScene
|
||||
|
||||
// start a game of Pong
|
||||
void Pong::run()
|
||||
{
|
||||
createScene(); // create the scene
|
||||
Ogre::WindowEventUtilities::addWindowEventListener(windowPtr, this);
|
||||
rootPtr->startRendering(); // start rendering frames
|
||||
} // end function run
|
||||
|
||||
// update the score
|
||||
void Pong::updateScore( Players player )
|
||||
{
|
||||
// increase the correct player's score
|
||||
if ( player == Players::PLAYER1 )
|
||||
player1Score++;
|
||||
else
|
||||
player2Score++;
|
||||
|
||||
wait = true; // the game should wait to restart the Ball
|
||||
updateScoreText(); // update the score text on the screen
|
||||
} // end function updateScore
|
||||
|
||||
// update the score text
|
||||
void Pong::updateScoreText()
|
||||
{
|
||||
ostringstream scoreText; // text to be displayed
|
||||
|
||||
scoreText << "P2: " << player2Score; // make the text
|
||||
|
||||
// get the right player's TextArea
|
||||
OverlayElement *textElementPtr = OverlayManager::getSingletonPtr()->getOverlayElement( "right" );
|
||||
textElementPtr->setCaption( scoreText.str() ); // set the text
|
||||
|
||||
scoreText.str( "" ); // reset the text in scoreText
|
||||
scoreText << "P1: " << player1Score; // make the text
|
||||
|
||||
// get the left player's TextArea
|
||||
textElementPtr = OverlayManager::getSingletonPtr()->getOverlayElement( "left" );
|
||||
textElementPtr->setCaption( scoreText.str() ); // set the text
|
||||
} // end function updateScoreText
|
||||
|
||||
// respond to user keyboard input
|
||||
bool Pong::keyPressed( const OIS::KeyEvent &keyEventRef )
|
||||
{
|
||||
// if the game is not paused
|
||||
if ( !pause )
|
||||
{
|
||||
// process KeyEvents that apply when the game is not paused
|
||||
switch ( keyEventRef.key )
|
||||
{
|
||||
case OIS::KC_ESCAPE: // escape key hit: quit
|
||||
quit = true;
|
||||
break;
|
||||
case OIS::KC_UP: // up-arrow key hit: move the right Paddle up
|
||||
paddle[0] = 1;
|
||||
break;
|
||||
case OIS::KC_DOWN: // down-arrow key hit: move the right Paddle down
|
||||
paddle[0] = -1;
|
||||
break;
|
||||
case OIS::KC_NUMPAD8: // 8 key hit: move left Paddle up
|
||||
paddle[1] = 1;
|
||||
break;
|
||||
case OIS::KC_NUMPAD2: // 2 key hit: move left Paddle down
|
||||
paddle[1] = -1;
|
||||
break;
|
||||
case OIS::KC_W: // W key hit: rotate board 'up'
|
||||
break;
|
||||
case OIS::KC_A: // A key hit: rotate board 'left'
|
||||
break;
|
||||
case OIS::KC_S: // S key hit: rorate board 'down'
|
||||
break;
|
||||
case OIS::KC_D: // D key hit: rotate board 'right'
|
||||
break;
|
||||
case OIS::KC_P: // P key hit: pause the game
|
||||
pause = true; // set pause to true when the user pauses the game
|
||||
Overlay *pauseOverlayPtr = OverlayManager::getSingleton().getByName( "PauseOverlay" );
|
||||
pauseOverlayPtr->show(); // show the pause Overlay
|
||||
break;
|
||||
} // end switch
|
||||
} // end if
|
||||
else // game is paused
|
||||
{
|
||||
// user hit 'R' on the keyboard
|
||||
if ( keyEventRef.key == OIS::KC_R )
|
||||
{
|
||||
pause = false; // set pause to false when user resumes the game
|
||||
Overlay *pauseOverlayPtr = OverlayManager::getSingleton().getByName( "PauseOverlay" );
|
||||
pauseOverlayPtr->hide(); // hide the pause Overlay
|
||||
} // end if
|
||||
} // end else
|
||||
return true;
|
||||
} // end function keyPressed
|
||||
|
||||
// process key released events
|
||||
bool Pong::keyReleased( const OIS::KeyEvent &keyEventRef )
|
||||
{
|
||||
switch ( keyEventRef.key )
|
||||
{
|
||||
case OIS::KC_UP: // up-arrow key released, stop moving that direction
|
||||
if (paddle[0] != -1) // if we're not moving down already
|
||||
paddle[0] = 0;
|
||||
break;
|
||||
case OIS::KC_DOWN: // down-arrow key released, stop moving that direction
|
||||
if (paddle[0] != 1) // if we're not moving up already
|
||||
paddle[0] = 0;
|
||||
break;
|
||||
case OIS::KC_NUMPAD8: // number pad 8 key released, stop moving that direction
|
||||
if (paddle[1] != -1) // if we're not moving down already
|
||||
paddle[1] = 0;
|
||||
break;
|
||||
case OIS::KC_NUMPAD2: // number pad 2 key released, stop moving that direction
|
||||
if (paddle[1] != 1) // if we're not moving up already
|
||||
paddle[1] = 0;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} // end function keyReleased
|
||||
|
||||
// return true if the program should render the next frame
|
||||
bool Pong::frameEnded( const FrameEvent &frameEvent )
|
||||
{
|
||||
WindowEventUtilities::messagePump();
|
||||
if(windowPtr->isClosed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return !quit; // quit = false if the user hasn't quit yet
|
||||
} // end function frameEnded
|
||||
|
||||
// process game logic, return true if the next frame should be rendered
|
||||
bool Pong::frameStarted( const FrameEvent &frameEvent )
|
||||
{
|
||||
keyboardPtr->capture(); // get keyboard events
|
||||
|
||||
|
||||
// paddle moving logic
|
||||
if (paddle[0] != 0) // [0] = left paddle
|
||||
{
|
||||
//process
|
||||
if (paddle[0] < 0) // go down
|
||||
{
|
||||
leftPaddlePtr->movePaddle( PADDLE_DOWN );
|
||||
} else if (paddle[0] > 0) // go up
|
||||
{
|
||||
leftPaddlePtr->movePaddle( PADDLE_UP );
|
||||
}
|
||||
}
|
||||
if (paddle[1] != 0) // [1] = right paddle
|
||||
{
|
||||
//process
|
||||
if (paddle[1] < 0) // go down
|
||||
{
|
||||
rightPaddlePtr->movePaddle( PADDLE_DOWN );
|
||||
} else if (paddle[1] > 0) // go up
|
||||
{
|
||||
rightPaddlePtr->movePaddle( PADDLE_UP );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// the game is not paused and the Ball should move
|
||||
if ( !wait && !pause )
|
||||
{
|
||||
// move the Ball
|
||||
ballPtr->moveBall( frameEvent.timeSinceLastFrame );
|
||||
} // end if
|
||||
// don't move the Ball if wait is true
|
||||
else if ( wait )
|
||||
{
|
||||
// increase time if it is less than 4 seconds
|
||||
if ( time < 4 )
|
||||
// add the seconds since the last frame
|
||||
time += frameEvent.timeSinceLastFrame;
|
||||
else
|
||||
{
|
||||
wait = false; // shouldn't wait to move the Ball any more
|
||||
time = 0; // reset the control variable to 0
|
||||
} // end else
|
||||
} // end else
|
||||
|
||||
return !quit; // quit = false if the user hasn't quit yet
|
||||
} // end function frameStarted
|
||||
|
||||
|
||||
//Adjust mouse clipping area
|
||||
void Pong::windowResized(Ogre::RenderWindow* rw)
|
||||
{
|
||||
unsigned int width, height, depth;
|
||||
int left, top;
|
||||
rw->getMetrics(width, height, depth, left, top);
|
||||
|
||||
const OIS::MouseState &ms = mousePtr->getMouseState();
|
||||
ms.width = width;
|
||||
ms.height = height;
|
||||
}
|
||||
|
||||
//Unattach OIS before window shutdown (very important under Linux)
|
||||
void Pong::windowClosed(Ogre::RenderWindow* rw)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Pong::mousePressed(const OIS::MouseEvent &,OIS::MouseButtonID)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool Pong::mouseReleased(const OIS::MouseEvent &,OIS::MouseButtonID)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool Pong::mouseMoved(const OIS::MouseEvent &)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// Pong.h
|
||||
// Pong class definition (represents a game of Pong).
|
||||
#ifndef PONG_H
|
||||
#define PONG_H
|
||||
|
||||
#include <Ogre.h> // Ogre class definition
|
||||
using namespace Ogre; // use the Ogre namespace
|
||||
|
||||
#include <OIS\OISEvents.h> // OISEvents class definition
|
||||
#include <OIS\OISInputManager.h> // OISInputManager class definition
|
||||
#include <OIS\OISKeyboard.h> // OISKeyboard class definition
|
||||
#include <OIS\OISMouse.h>
|
||||
#include <OgreWindowEventUtilities.h>
|
||||
|
||||
class Ball; // forward declaration of class Ball
|
||||
class Paddle; // forward declaration of class Paddle
|
||||
|
||||
enum Players { PLAYER1, PLAYER2 };
|
||||
|
||||
class Pong : public FrameListener, public OIS::KeyListener, public Ogre::WindowEventListener, public OIS::MouseListener
|
||||
{
|
||||
public:
|
||||
Pong(); // constructor
|
||||
~Pong(); // destructor
|
||||
void run(); // run a game of Pong
|
||||
|
||||
// handle keyPressed and keyReleased events
|
||||
virtual bool keyPressed( const OIS::KeyEvent &keyEventRef );
|
||||
virtual bool keyReleased( const OIS::KeyEvent &keyEventRef );
|
||||
|
||||
// handle mouseMoved, mousePressed, and mouseReleased events
|
||||
virtual bool mousePressed(const OIS::MouseEvent &,OIS::MouseButtonID);
|
||||
virtual bool mouseReleased(const OIS::MouseEvent &,OIS::MouseButtonID);
|
||||
virtual bool mouseMoved(const OIS::MouseEvent &);
|
||||
|
||||
// move the game objects and control interactions between frames
|
||||
virtual bool frameStarted( const FrameEvent &frameEvent );
|
||||
virtual bool frameEnded( const FrameEvent &frameEvent );
|
||||
static void updateScore( Players player); // update the score
|
||||
|
||||
private:
|
||||
void createScene(); // create the scene to be rendered
|
||||
static void updateScoreText(); // update the score on the screen
|
||||
|
||||
// Ogre objects
|
||||
Root *rootPtr; // pointer to Ogre's Root object
|
||||
SceneManager *sceneManagerPtr; // pointer to the SceneManager
|
||||
RenderWindow *windowPtr; // pointer to RenderWindow to render scene in
|
||||
Viewport *viewportPtr; // pointer to Viewport, area that a camera sees
|
||||
Camera *cameraPtr; // pointer to a Camera in the scene
|
||||
|
||||
// OIS input objects
|
||||
OIS::InputManager *inputManagerPtr; // pointer to the InputManager
|
||||
OIS::Keyboard *keyboardPtr; // pointer to the Keyboard
|
||||
OIS::Mouse *mousePtr; // pointer to the mouse
|
||||
|
||||
// Ogre::WindowEventListener
|
||||
virtual void windowResized(Ogre::RenderWindow* rw);
|
||||
virtual void windowClosed(Ogre::RenderWindow* rw);
|
||||
|
||||
// game objects
|
||||
Ball *ballPtr; // pointer to the Ball
|
||||
Paddle *leftPaddlePtr; // pointer to player 1's Paddle
|
||||
Paddle *rightPaddlePtr; // pointer to player 2's Paddle
|
||||
|
||||
// variables to control game states
|
||||
bool quit, pause; // did user quit or pause the game?
|
||||
Real time; // used to delay the motion of a new Ball
|
||||
static bool wait; // should the Ball's movement be delayed?
|
||||
|
||||
static int player1Score; // player 1's score
|
||||
static int player2Score; // player 2's score
|
||||
|
||||
int paddle[2];
|
||||
|
||||
}; // end class Pong
|
||||
|
||||
#endif // PONG_H
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// PongMain.cpp
|
||||
// Driver program for the game of Pong
|
||||
#include <iostream>
|
||||
|
||||
#include "Pong.h" // Pong class definition
|
||||
|
||||
// If running on Windows, include windows.h and define WinMain function
|
||||
#if OGRE_PLATFORM==PLATFORM_WIN32 || OGRE_PLATFORM==OGRE_PLATFORM_WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "windows.h"
|
||||
|
||||
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
|
||||
|
||||
// If not, define normal main function
|
||||
#else
|
||||
int main( int argc, char **argv )
|
||||
#endif
|
||||
{
|
||||
try
|
||||
{
|
||||
Pong game; // create a Pong object
|
||||
game.run(); // start the Pong game
|
||||
} // end try
|
||||
|
||||
catch ( std::runtime_error &error )
|
||||
{
|
||||
#if OGRE_PLATFORM==PLATFORM_WIN32 || OGRE_PLATFORM==OGRE_PLATFORM_WIN32
|
||||
MessageBoxA( NULL, error.what(), "Exception Thrown!",
|
||||
MB_OK | MB_ICONERROR | MB_TASKMODAL );
|
||||
#else
|
||||
std::cerr << "Exception Thrown: " << error.what() << std::endl;
|
||||
#endif
|
||||
} // end catch
|
||||
|
||||
return 0;
|
||||
} // end main
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,3,3,7
|
||||
PRODUCTVERSION 1,3,3,7
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x2fL
|
||||
#else
|
||||
FILEFLAGS 0x2eL
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x0L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "Pong! 2014 Edition"
|
||||
VALUE "CompanyName", "Copyright Amrit Panesar 2014"
|
||||
VALUE "FileDescription", "Pong - a 2 bit game on a 32 bit computer"
|
||||
VALUE "FileVersion", "1, 3, 3, 7"
|
||||
VALUE "InternalName", "Pong"
|
||||
VALUE "LegalCopyright", "Copyright Amrit Panesar (C) 2014"
|
||||
VALUE "LegalTrademarks", "Amrit Panesar"
|
||||
VALUE "OriginalFilename", "Pong.exe"
|
||||
VALUE "PrivateBuild", "This build is far from private"
|
||||
VALUE "ProductName", "Pong!"
|
||||
VALUE "ProductVersion", "1, 3, 3, 7"
|
||||
VALUE "SpecialBuild", "All my builds are special"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PNG
|
||||
//
|
||||
|
||||
IDB_PNG1 PNG "C:\\Users\\77260\\Downloads\\pong.png"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDI_ICON1 ICON "C:\\Users\\77260\\Downloads\\pong.ico"
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
Render System=OpenGL Rendering Subsystem
|
||||
|
||||
[Direct3D9 Rendering Subsystem]
|
||||
Allow NVPerfHUD=No
|
||||
Anti aliasing=None
|
||||
Floating-point mode=Fastest
|
||||
Full Screen=Yes
|
||||
Rendering Device=NVIDIA GeForce GTX 460
|
||||
VSync=No
|
||||
Video Mode=1280 x 1024 @ 32-bit colour
|
||||
|
||||
[OpenGL Rendering Subsystem]
|
||||
Colour Depth=32
|
||||
Display Frequency=N/A
|
||||
FSAA=16
|
||||
Full Screen=No
|
||||
RTT Preferred Mode=PBuffer
|
||||
VSync=Yes
|
||||
Video Mode=1024 x 768
|
||||
@@ -0,0 +1,17 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by Resource.rc
|
||||
//
|
||||
#define IDB_PNG1 101
|
||||
#define IDI_ICON1 102
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 103
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
# Resource locations to be added to the 'boostrap' path
|
||||
# This also contains the minimum you need to use the Ogre example framework
|
||||
[Bootstrap]
|
||||
FileSystem=resources
|
||||
Zip=../../media/packs/OgreCore.zip
|
||||
|
||||
# Resource locations to be added to the default path
|
||||
[General]
|
||||
FileSystem=../../media
|
||||
FileSystem=../../media/fonts
|
||||
FileSystem=../../media/materials/programs
|
||||
FileSystem=../../media/materials/scripts
|
||||
FileSystem=../../media/materials/textures
|
||||
FileSystem=../../media/models
|
||||
FileSystem=../../media/overlays
|
||||
FileSystem=../../media/particle
|
||||
FileSystem=../../media/gui
|
||||
FileSystem=../../media/DeferredShadingMedia
|
||||
Zip=../../media/packs/cubemap.zip
|
||||
Zip=../../media/packs/cubemapsJS.zip
|
||||
Zip=../../media/packs/dragon.zip
|
||||
Zip=../../media/packs/fresneldemo.zip
|
||||
Zip=../../media/packs/ogretestmap.zip
|
||||
Zip=../../media/packs/skybox.zip
|
||||
@@ -0,0 +1,15 @@
|
||||
// define the BlueBold font
|
||||
BlueBold
|
||||
{
|
||||
// define the font type
|
||||
type truetype
|
||||
|
||||
// set the source file for the font
|
||||
source bluebold.ttf
|
||||
|
||||
// set the font size
|
||||
size 16
|
||||
|
||||
// set the font resolution (96 is standard)
|
||||
resolution 96
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// menu material definition
|
||||
material menu
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
ambient 1.0 1.0 1.0
|
||||
diffuse 1.0 1.0 1.0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
// An Overlay to display an options menu
|
||||
MenuOverlay
|
||||
{
|
||||
// set a high z-order to display on top of everything
|
||||
zorder 600
|
||||
|
||||
// the root container for the menu items
|
||||
container Panel(rootPanel)
|
||||
{
|
||||
material menu
|
||||
|
||||
// text for the root Panel
|
||||
element TextArea(instructionsText)
|
||||
{
|
||||
// position the text toward the bottom center of the screen
|
||||
top 0.8
|
||||
left 0.2
|
||||
|
||||
// set font use for caption and set the size and color
|
||||
font_name BlueBold
|
||||
char_height .05
|
||||
colour 1 1 1
|
||||
caption Press Enter to start or Esc to exit
|
||||
}
|
||||
// end of instructionsText
|
||||
|
||||
// container for the Ball options
|
||||
container Panel(ballPanel)
|
||||
{
|
||||
// position the container toward the left side of the screen
|
||||
top 0.1
|
||||
left 0.1
|
||||
width 0.3
|
||||
height 0.5
|
||||
|
||||
// TextAreas to display Ball options
|
||||
|
||||
element TextArea(ballOptionsTitle)
|
||||
{
|
||||
// position and size the TextArea
|
||||
height 0.1
|
||||
left 0.05
|
||||
|
||||
// set font use for caption and set the size and color
|
||||
font_name BlueBold
|
||||
char_height .05
|
||||
colour 1 1 1
|
||||
caption Ball Options
|
||||
}
|
||||
// end of ballOptionsTitle
|
||||
|
||||
element TextArea(ballSlow)
|
||||
{
|
||||
// position and size the text
|
||||
top 0.2
|
||||
height 0.1
|
||||
|
||||
// set font use for caption and set the size and color
|
||||
font_name BlueBold
|
||||
char_height .05
|
||||
colour 1 1 1
|
||||
caption Slow Ball (Press A)
|
||||
}
|
||||
// end of ballSlow
|
||||
|
||||
element TextArea(ballMedium)
|
||||
{
|
||||
// position and size the text
|
||||
top 0.3
|
||||
height 0.1
|
||||
|
||||
// set font use for caption and set the size and color
|
||||
font_name BlueBold
|
||||
char_height .05
|
||||
colour 1 1 1
|
||||
caption Medium Ball (Press B)
|
||||
}
|
||||
// end of ballMedium
|
||||
|
||||
element TextArea(ballFast)
|
||||
{
|
||||
// position and size the text
|
||||
top 0.4
|
||||
height 0.1
|
||||
|
||||
// set font use for caption and set the size and color
|
||||
font_name BlueBold
|
||||
char_height .05
|
||||
colour 1 1 1
|
||||
caption Fast Ball (Press C)
|
||||
}
|
||||
// end of ballFast
|
||||
}
|
||||
// end of ballPanel
|
||||
|
||||
// container for the Paddle options
|
||||
container Panel(paddlePanel)
|
||||
{
|
||||
// position the container toward the right side of the screen
|
||||
top 0.1
|
||||
left 0.5
|
||||
width 0.3
|
||||
height 0.5
|
||||
|
||||
// TextAreas to display Paddle options
|
||||
|
||||
element TextArea(paddleOptionsTitle)
|
||||
{
|
||||
// position and size the text
|
||||
height 0.1
|
||||
left 0.05
|
||||
|
||||
// set font use for caption and set the size and color
|
||||
font_name BlueBold
|
||||
char_height .05
|
||||
colour 1 1 1
|
||||
caption Paddle Options
|
||||
}
|
||||
// end of paddleOptionsTitle
|
||||
|
||||
element TextArea(paddleSlow)
|
||||
{
|
||||
// position and size the text
|
||||
top 0.2
|
||||
height 0.1
|
||||
|
||||
// set font use for caption and set the size and color
|
||||
font_name BlueBold
|
||||
char_height .05
|
||||
colour 1 1 1
|
||||
caption Slow Paddles (Press 1)
|
||||
}
|
||||
// end of paddleSlow
|
||||
|
||||
element TextArea(paddleMedium)
|
||||
{
|
||||
// position and size the text
|
||||
top 0.3
|
||||
height 0.1
|
||||
|
||||
// set font use for caption and set the size and color
|
||||
font_name BlueBold
|
||||
char_height .05
|
||||
colour 1 1 1
|
||||
caption Medium Paddles (Press 2)
|
||||
}
|
||||
// end of paddleMedium
|
||||
|
||||
element TextArea(paddleFast)
|
||||
{
|
||||
// position and size the text
|
||||
top 0.4
|
||||
height 0.1
|
||||
|
||||
// set font use for caption and set the size and color
|
||||
font_name BlueBold
|
||||
char_height .05
|
||||
colour 1 1 1
|
||||
caption Fast Paddles (Press 3)
|
||||
}
|
||||
// end of paddleFast
|
||||
}
|
||||
// end of paddlePanel
|
||||
}
|
||||
// end of rootPanel
|
||||
}
|
||||
// end of MenuOverlay
|
||||
@@ -0,0 +1,51 @@
|
||||
// ball material definition
|
||||
material ball
|
||||
{
|
||||
// define one technique for rendering the Ball
|
||||
technique
|
||||
{
|
||||
// render the Ball in one pass
|
||||
pass
|
||||
{
|
||||
// color the Ball White
|
||||
ambient 1 1 1
|
||||
diffuse 1 1 1
|
||||
specular 1 1 1 255
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// paddle material definition
|
||||
material paddle
|
||||
{
|
||||
// define one technique for rendering a Paddle
|
||||
technique
|
||||
{
|
||||
// render a Paddle in one pass
|
||||
pass
|
||||
{
|
||||
// color the Paddle white
|
||||
ambient 1 1 1
|
||||
diffuse 1 1 1
|
||||
specular 1 1 1 255
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// wall material definition
|
||||
material wall
|
||||
{
|
||||
// define one technique for rendering a wall
|
||||
technique
|
||||
{
|
||||
// render a wall in one pass
|
||||
pass
|
||||
{
|
||||
// color the wall cyan
|
||||
ambient 0 0 0
|
||||
diffuse 0 0 0
|
||||
specular 0 0 0 255
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loaded 100 of 606 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user