Best Of Three Worlds
April 20, 2024, 08:23:09 am
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Ok guys, I have returned!!! I know the activity is nill to none, but my users who still come here and I are going to try and revive this forum!!! Smiley
 
  Home Help Search Arcade Gallery Staff List Calendar Login Register  

Programmers Unite!

Recent Items

Views: 15
Comments (0)
By: PhoenixTears

Views: 14
Comments (0)
By: PhoenixTears

Views: 36
Comments (3)
By: Dr. Backflips

Views: 27
Comments (1)
By: Dr. Backflips
Pages: [1] 2 3
  Print  
Author Topic: Programmers Unite!  (Read 399 times)
PhoenixTears
What's in a name? That which we call a rose.
*****
Offline Offline

Gender: Female
Posts: 3951


By any other name would smell as sweet.


« on: July 13, 2008, 09:23:40 pm »

... tomorrow. Or was that procrastinators?

Anyways, this is a place for programmers. You can place your code here, discuss programs, compilers, and what not. I know there aren't many people that can program here, but, eh, it's worth a try. And it'll be a place where we can get the fangame programmed. =3

Prime Number Test anyone?
Coded in C++. You can download Bloodshed and then compile the code if you want to run this. =3

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    int number;
    cout << "Choose a number:";
    cin >> number;
    if (number < 1)
    {
        cout << "This is not a valid number." << endl;
    }
    else
    {
        for (int i = 2; i < number; i++)
        {
            bool a = number%i==0;
            if (a==true)
            {
               cout << "This number is not prime." << endl;
               system("PAUSE");
               return 0;
            }
        }
        cout << "This number is prime." << endl;
    }
    system("PAUSE");
    return 0;
}
Report Spam   Logged

Share on Facebook Share on Twitter

ozymand1as
***
Offline Offline

Gender: Male
Posts: 133



« Reply #1 on: July 18, 2008, 09:06:35 pm »

I'm getting a C++ book in a few days. I am learning (and somewhat fluent) in python. The only problem for me is that I can understand what a program does, but not make a program as easily. My brother says I need more practice.

The following is a simple calculator program.


def menu():
    print "Welcome to calculator.py"
    print "your options are:"
    print " "
    print "1) Addition"
    print "2) Subtraction"
    print "3) Multiplication"
    print "4) Division"
    print "5) Quit calculator.py"
    print " "
    return input ("Choose your option: ")
   

def add(a,b):
    print a, "+", b, "=", a + b
   

def sub(a,b):
    print b, "-", a, "=", b - a
   

def mul(a,b):
    print a, "*", b, "=", a * b
   

def div(a,b):
    print a, "/", b, "=", a / b
   

loop = 1
choice = 0
while loop == 1:
    choice = menu()
    if choice == 1:
        add(input("Add this: "),input("to this: "))
    elif choice == 2:
        sub(input("Subtract this: "),input("from this: "))
    elif choice == 3:
        mul(input("Multiply this: "),input("by this: "))
    elif choice == 4:
        div(input("Divide this: "),input("by this: "))
    elif choice == 5:
        loop = 0

print "Thanks for using calculator2.py!"



I also made a simple text game, but I still need to fix out a few kinks.
Report Spam   Logged

PhoenixTears
What's in a name? That which we call a rose.
*****
Offline Offline

Gender: Female
Posts: 3951


By any other name would smell as sweet.


« Reply #2 on: July 18, 2008, 09:52:59 pm »

Sorry, need to learn Python/Lisp first.
Report Spam   Logged

ozymand1as
***
Offline Offline

Gender: Male
Posts: 133



« Reply #3 on: July 20, 2008, 09:34:37 am »

Because I have nothing better to do before HOPE, a quick python tutorial!:


def menu():                                   
    print "Welcome to calculator.py"     
    print "your options are:"                 
    print " "                                       
    print "1) Addition"                         
    print "2) Subtraction"                     This section is a menu in
    print "3) Multiplication"                    which the user can choose what they wish to do by
    print "4) Division"                           inputting the correct number for the option. The options
    print "5) Quit calculator.py"            are shown on screen by the "print" command which
    print " "                                       puts whatever is in quotes on screen.
    return input ("Choose your option: ")
   

def add(a,b):                                    this part defines what command does what for later
    print a, "+", b, "=", a + b                 and tells the computer what to do with the two variables
                                                      that will be given later on.

def sub(a,b):
    print b, "-", a, "=", b - a
   

def mul(a,b):
    print a, "*", b, "=", a * b
   

def div(a,b):
    print a, "/", b, "=", a / b
   

loop = 1                                                                programmers should be able to understand
choice = 0                                                             this part already, it's a simple loop
while loop == 1:                                                      command that tells the computer to run
    choice = menu()                                                 the program
    if choice == 1:
        add(input("Add this: "),input("to this: "))               here, the menu and definitions above
    elif choice == 2:                                                   are being put together. the computer
        sub(input("Subtract this: "),input("from this: "))      will now understand what to do with
    elif choice == 3:                                                   each menu command and ask for input
        mul(input("Multiply this: "),input("by this: "))          from the user on which 2 numbers to
    elif choice == 4:                                                   do stuff with (ie, add, subtract, etc.)
        div(input("Divide this: "),input("by this: "))
    elif choice == 5:
        loop = 0                                                            ends the program.

print "Thanks for using calculator2.py!"                           prints what is in the quotes to thank
                                                                               the user for using the calculator
Report Spam   Logged

PhoenixTears
What's in a name? That which we call a rose.
*****
Offline Offline

Gender: Female
Posts: 3951


By any other name would smell as sweet.


« Reply #4 on: July 20, 2008, 08:17:09 pm »

Hrm... interesting...
You don't have to declare the variables in python?
Report Spam   Logged

ozymand1as
***
Offline Offline

Gender: Male
Posts: 133



« Reply #5 on: July 20, 2008, 09:07:32 pm »

Python doesn't declare variables to my current knowledge (in this program, variables aren't declared).
Starting C++!
Report Spam   Logged

PhoenixTears
What's in a name? That which we call a rose.
*****
Offline Offline

Gender: Female
Posts: 3951


By any other name would smell as sweet.


« Reply #6 on: August 02, 2008, 02:21:25 pm »

Kinda odd... but oh well.

This would be a calculator in Java.
Code:
import java.util.*;
public class calculator
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
char op = 'i';
System.out.println("Welcome to calculator. If you would like to quit calculator, press 'q'.\n" +
"To add, press '+'. To subtract, press '-'. To multiply, press '*'.\n" +
"To divide, press '/'. To apply modulus, press '%'.");
while (op!='q')
{
System.out.print("Choose an operation (+, -, *, /, %) : ");
op = input.nextLine().charAt(0);
double a, b, c = 0;
if (op =='+')
{
System.out.print("This function will add two numbers.\nEnter the first number: ");
a=input.nextInt();
System.out.print("Enter the second number: ");
b=input.nextInt();
c=a+b;
System.out.print("The sum is ");
System.out.print(c);
System.out.print(".\n");
}
else if (op =='-')
{
System.out.print("This function will subtract two numbers.\nEnter the first number: ");
a=input.nextInt();
System.out.print("Enter the second number: ");
b=input.nextInt();
c=a-b;
System.out.print("The difference is ");
System.out.print(c);
System.out.print(".\n");
}
else if (op =='*')
{
System.out.print("This function will multiply two numbers.\nEnter the first number: ");
a=input.nextInt();
System.out.print("Enter the second number: ");
b=input.nextInt();
c=a*b;
System.out.print("The product is ");
System.out.print(c);
System.out.print(".\n");
}
else if (op =='/')
{
System.out.print("This function will divide two numbers.\nEnter the dividend: ");
a=input.nextInt();
System.out.print("Enter the divisor: ");
b=input.nextInt();
c=a/b;
System.out.print("The quotient is ");
System.out.print(c);
System.out.print(".\n");
}
else if (op =='%')
{
int x, y, z = 0;
System.out.print("This function will give the remainder after dividing two integers." +
"\nEnter the dividend: ");
x=input.nextInt();
System.out.print("Enter the divisor: ");
y=input.nextInt();
z=x%y;
System.out.print("The remainder is ");
System.out.print(z);
System.out.print(".\n");
}
input.nextLine();
}
}
}

Uh, prime number test.
Code:
import java.util.Scanner;
public class primenumbertest
{
public static void main (String args[])
{
Scanner input=new Scanner(System.in);
System.out.println("You can use this program to check if a number is a prime number.\n" +
"Negative numbers will not work. Press 'q' to exit.");
char op='i';
while (op!='q')
{
boolean prime=true;
System.out.print("Enter a number: ");
int number=input.nextInt();
if (number<0)
{
System.out.print("This number is not a valid number.\n");
prime=false;
input.nextLine();
}
for (int i=2;number>i;i++)
{

if (number%i == 0)
{
System.out.print("This number is not prime.\n");
prime=false;
input.nextLine();
break;
}
else
{
continue;
}
}
if (prime)
{
System.out.print("This number is prime.\n");
}
}
}
}

A different prime number test
Code:
import java.util.*;
public class primenumbertest2
{
public static void main (String args[])
{
Scanner input=new Scanner(System.in);
System.out.print("This program will display all prime numbers below your " +
"inputted integer. Negative numbers are not valid.\nPress 'q' to quit.\n");
char quit='i';
while (quit!='q')
{
System.out.print("Enter a number: ");
int number=input.nextInt();
if (number<3 && number>=0)
{
System.out.print("There are no prime numbers less than this number.\n");
}
else if (number <0)
{
System.out.print("This number is negative. It is not a valid number.\n");
}
else
{
System.out.print("2");
for (int i=3;number>i;i++)
{

for (int n=2;n<i;n++)
{
if (i%n == 0)
{
break;
}
else if (n == i-1)
{
System.out.print(", ");
System.out.print(i);
break;
}
}
}
System.out.print("\n");
}
}

}
}

Grade book sort of thing.
Code:
import java.util.*;
/*This is actually a grade book. =3*/
public class triplearray
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
System.out.print("Please enter how many students you have: ");
int numstudents=input.nextInt();
System.out.print("Please enter how many grades each student will have: ");
int numgrades=input.nextInt();
input.nextLine();
String students[]=new String [numstudents];
int gradebook [][]=new int [numstudents][numgrades];
char choice='o';
while (choice!='q' && choice!='Q')
{
System.out.print("What would you like to do?\nA. Enter student names.\n" +
"B. Enter students grades.\nC. View student names.\n" +
"D. View student grades.\nE. Find Student Averages\nQ. Exit gradebook.\n");
choice=input.nextLine().charAt(0);
if (choice=='a' || choice=='A')
{
for (int i=0;i<numstudents;i++)
{
System.out.print("Please input the name for student ");
System.out.print(i+1);
System.out.print(": ");
students[i]=input.nextLine();
}
}
else if (choice=='b' || choice=='B')
{
char yn='o';
while(yn!='n')
{
System.out.print("Which student's grades would you like to input?\n");
for (int i=0;i<numstudents;i++)
{
System.out.print(i+1);
System.out.print(". ");
System.out.print(students[i]);
System.out.print("\n");
}
int stud=input.nextInt()-1;
while(stud<0 || stud>=numstudents)
{
System.out.print("Sorry, but that is an invalid student number. Please choose again.\n");
stud=input.nextInt()-1;
}
System.out.print("Please enter ");
System.out.print(students[stud]);
System.out.print("'s grades.\n");
for (int o=0;o<numgrades;o++)
{
System.out.print("Please enter the the grade for test ");
System.out.print(o+1);
System.out.print(": \n");
gradebook[stud][o]=input.nextInt();
input.nextLine();
}
System.out.print("Would you like to input anyone else's grades? y/n ");
yn=input.nextLine().charAt(0);
}
}
else if (choice=='c' || choice=='C')
{
System.out.print("Here are the student names.\n");
for (int i=0;i<numstudents;i++)
{
System.out.print(students[i]);
System.out.print("\n");
}
}
else if (choice=='d' || choice=='D')
{
System.out.print("Please choose a students name to view their grades.\n");
char yn='o';
while (yn!='n')
{
for (int i=0;i<numstudents;i++)
{
System.out.print(i+1);
System.out.print(". ");
System.out.print(students[i]);
System.out.print("\n");
}
System.out.print(numstudents+1);
System.out.print(". Or choose this option to view all students' grades.\n");
int stud=input.nextInt()-1;
while(stud<0 || stud>numstudents)
{
System.out.print("Sorry, but that is an invalid choice. Please choose again.");
stud=input.nextInt()-1;
}
input.nextLine();
if (stud>-1 && stud <numstudents)
{
System.out.print("These are ");
System.out.print(students[stud]);
System.out.print("'s grades.\n");
for (int o=0;o<numgrades;o++)
{
System.out.print("Test ");
System.out.print(o+1);
System.out.print(": ");
System.out.println(gradebook[stud][o]);
}
}
else if (stud==numstudents)
{
System.out.print("These are everyone's grades.\n");
for(int q=0;q<numstudents; q++)
{
System.out.println(students[q]);
for(int w=0;w<numgrades;w++)
{
System.out.print("Test ");
System.out.print(w+1);
System.out.print(": ");
System.out.println(gradebook[q][w]);
}
}
}
System.out.print("Would you like to view another student's grades? y/n");
yn=input.nextLine().charAt(0);
}
}
else if(choice=='e' || choice=='E')
{
char yn='o';
while (yn!='n')
{
System.out.print("Please choose a students name to view their averages.\n");
for (int i=0;i<numstudents;i++)
{
System.out.print(i+1);
System.out.print(". ");
System.out.print(students[i]);
System.out.print("\n");
}
System.out.print(numstudents+1);
System.out.print(". Or choose this option to view all students' averages and the class average.\n");
int stud=input.nextInt()-1;
while(stud<0 || stud>numstudents)
{
System.out.print("Sorry, but that is an invalid choice. Please choose again.");
stud=input.nextInt()-1;
}
input.nextLine();
if (stud>-1 && stud <numstudents)
{
int accumulator=0;
System.out.print(students[stud]);
System.out.print("'s average is ");
for (int i=0;i<numgrades;i++)
{
int value=0;
value=gradebook[stud][i];
accumulator+=value;
}
System.out.println(accumulator/numgrades);
}
else if (stud==numstudents)
{
System.out.print("These are everyone's averages and the class average.\n");
int accum=0;
int val=0;
for(int q=0;q<numstudents; q++)
{
System.out.print(students[q]);
System.out.print(": ");
int value=0;
int accumulator=0;
for(int w=0;w<numgrades;w++)
{
value=gradebook[q][w];
accumulator+=value;
}
System.out.println(accumulator/numgrades);
val=accumulator/numgrades;
accum+=val;
}
System.out.print("The class average is: ");
System.out.println(accum/numstudents);
}
System.out.print("Would you like to view another student's averages? y/n");
yn=input.nextLine().charAt(0);
}
}
}
}
}

Game. Guessing random numbers.
Code:
import java.util.*;
public class randomnumbergame
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
Random XD=new Random();
System.out.print("Welcome to the Random Number Game!" +
"Try to guess the correct number between 1 and 100. You have ten guesses.\n");

int guess=0;
char choice='e';

while (choice!='n')
{
int number=XD.nextInt(100)+1;
boolean decide=false;
for (int i=1;i<11;i++)
{
System.out.print("Enter a guess: ");
guess=input.nextInt();
input.nextLine();
if (guess == number)
{
decide=true;
System.out.print("You have guessed correctly! The answer is ");
System.out.print(number);
System.out.println(".");
break;
}
else if (guess < number)
{
System.out.print("You guessed too low! Try again!\nYou have ");
System.out.print(10-i);
System.out.print(" tries left.\n");
}
else if (guess > number)
{
System.out.print("You guessed too high! Try again!\nYou have ");
System.out.print(10-i);
System.out.print(" tries left.\n");
}
}
if (decide==false)
{
System.out.print("Sorry, you ran out of guesses! The correct answer was ");
System.out.print(number);
System.out.println(".");
}
System.out.print("Would you like to play again? y/n ");
choice=input.nextLine().charAt(0);
}
System.out.print("Thank you for playing!");
}
}

Final Project game! Made it error proof.
Code:
import java.util.*;
public class Jumpinggame
{
public static void main(String [] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Welcome to the Jumping Game! ");
System.out.print("Would you like to read the instructions? y/n ");
String choice=input.nextLine();
while (!choice.equalsIgnoreCase("y") && !choice.equalsIgnoreCase("yes") && !choice.equalsIgnoreCase("n") && !choice.equalsIgnoreCase("no"))
{
System.out.print("Sorry, that is an invalid input. ");
choice = input.nextLine();
}
if(choice.equalsIgnoreCase("y") || choice.equalsIgnoreCase("yes"))
{
System.out.print("The objective of this game is to get as many pegs as possible off the board.\n" +
"If you have one peg left, you are the ultimate winner!!!\n" +
"The board will start with one empty space. The player will be able to place this space " +
"anywhere they want.\nEvery other space will be filled with pegs. The X-axis will be " +
"numbered from 1-9, and the Y-axis marked with letters from A-I.\n" +
"To remove pegs, 'jump' one of the pegs over another into an empty space. You can only move " +
"left, right, up, and down.\nThe peg that was jumped over is removed from the board. Continue " +
"playing until there are no moves left.\n' ' represent an empty space. '/' represents a space that " +
"is not avaible for moving.\b represents a peg.\n");
}
System.out.print("Would you like to play? y/n ");
String play=input.nextLine();
while (!play.equalsIgnoreCase("n") && !play.equalsIgnoreCase("no") && !play.equalsIgnoreCase("y") && !play.equalsIgnoreCase("yes"))
{
System.out.println("Sorry, that is an invalid input.");
play = input.nextLine();
}
boolean played=true;
while (!play.equalsIgnoreCase("n") && !play.equalsIgnoreCase("no"))
{
played=false;
char gameboard[][]=
{
{'/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/'},
{'/', '/', ' ', ' ', '1', ' ', '2', ' ', '3', ' ', '4', ' ', '5', ' ', '6', ' ', '7', ' ', '8', ' ', '9', '/', '/', '/', '/'},
{'/', '/', 'A', ' ', '/', '/', '/', '/', '/', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '/', '/', '/', '/', '/', '/', '/', '/', '/'},
{'/', '/', 'B', ' ', '/', '/', '/', '/', '/', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '/', '/', '/', '/', '/', '/', '/', '/', '/'},
{'/', '/', 'C', ' ', '/', '/', '/', '/', '/', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '/', '/', '/', '/', '/', '/', '/', '/', '/'},
{'/', '/', 'D', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', '/', '/', '/', '/'},
{'/', '/', 'E', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', '/', '/', '/', '/'},
{'/', '/', 'F', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '\b', '/', '/', '/', '/'},
{'/', '/', 'G', ' ', '/', '/', '/', '/', '/', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '/', '/', '/', '/', '/', '/', '/', '/', '/'},
{'/', '/', 'H', ' ', '/', '/', '/', '/', '/', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '/', '/', '/', '/', '/', '/', '/', '/', '/'},
{'/', '/', 'I', ' ', '/', '/', '/', '/', '/', ' ', '\b', ' ', '\b', ' ', '\b', ' ', '/', '/', '/', '/', '/', '/', '/', '/', '/'},
{'/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/'},
{'/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/'}
};
int row=0;
int column=0;
for (int i = 1; i < 11; i++)
{
for (int j = 2; j < 21; j++)
{
System.out.print(gameboard[i][j]);
}
System.out.println();
}
while(column<4||(column<10 && row<5)||(column<10 && row>7)||(column>14 && row<5)||(column>14 && row>7)||column>20||row<2||row>10)
{
System.out.print("Please choose a valid beginning empty space: ");
String choosing=input.nextLine();
if(choosing.length()!=2)
choosing="A1";
if(choosing.charAt(0)=='A' || choosing.charAt(0)=='a')
row=2;
else if(choosing.charAt(0)=='B' || choosing.charAt(0)=='b')
row=3;
else if(choosing.charAt(0)=='C' || choosing.charAt(0)=='c')
row=4;
else if(choosing.charAt(0)=='D' || choosing.charAt(0)=='d')
row=5;
else if(choosing.charAt(0)=='E' || choosing.charAt(0)=='e')
row=6;
else if(choosing.charAt(0)=='F' || choosing.charAt(0)=='f')
row=7;
else if(choosing.charAt(0)=='G' || choosing.charAt(0)=='g')
row=8;
else if(choosing.charAt(0)=='H' || choosing.charAt(0)=='h')
row=9;
else if(choosing.charAt(0)=='I' || choosing.charAt(0)=='i')
row=10;
if(choosing.charAt(1)=='1')
column=4;
else if(choosing.charAt(1)=='2')
column=6;
else if(choosing.charAt(1)=='3')
column=8;
else if(choosing.charAt(1)=='4')
column=10;
else if(choosing.charAt(1)=='5')
column=12;
else if(choosing.charAt(1)=='6')
column=14;
else if(choosing.charAt(1)=='7')
column=16;
else if(choosing.charAt(1)=='8')
column=18;
else if(choosing.charAt(1)=='9')
column=20;
}
gameboard[row][column]=' ';
for (int pegs=44;pegs>1; pegs--)
{
for (int i = 1; i < 11; i++)
{
for (int j = 2; j < 21; j++)
{
System.out.print(gameboard[i][j]);
}
System.out.println();
}
int row1=0;
int column1=0;
int row2=0;
int column2=0;
while((column1<4)||(column1<10&&row1<5)||(column1<10&&row1>7)||(column1>14&&row1<5)||(column1>14&&row1>7)||column>20||row<2||row>10)
{
System.out.print("Please choose a valid peg to move: ");
String choosing=input.nextLine();
if(choosing.length()!=2)
{
choosing="A1";
}
if(choosing.charAt(0)=='A' || choosing.charAt(0)=='a')
row1=2;
else if(choosing.charAt(0)=='B' || choosing.charAt(0)=='b')
row1=3;
else if(choosing.charAt(0)=='C' || choosing.charAt(0)=='c')
row1=4;
else if(choosing.charAt(0)=='D' || choosing.charAt(0)=='d')
row1=5;
else if(choosing.charAt(0)=='E' || choosing.charAt(0)=='e')
row1=6;
else if(choosing.charAt(0)=='F' || choosing.charAt(0)=='f')
row1=7;
else if(choosing.charAt(0)=='G' || choosing.charAt(0)=='g')
row1=8;
else if(choosing.charAt(0)=='H' || choosing.charAt(0)=='h')
row1=9;
else if(choosing.charAt(0)=='I' || choosing.charAt(0)=='i')
row1=10;
if(choosing.charAt(1)=='1')
column1=4;
else if(choosing.charAt(1)=='2')
column1=6;
else if(choosing.charAt(1)=='3')
column1=8;
else if(choosing.charAt(1)=='4')
column1=10;
else if(choosing.charAt(1)=='5')
column1=12;
else if(choosing.charAt(1)=='6')
column1=14;
else if(choosing.charAt(1)=='7')
column1=16;
else if(choosing.charAt(1)=='8')
column1=18;
else if(choosing.charAt(1)=='9')
column1=20;
if(gameboard[row1][column1]=='\b' &&
((gameboard[row1-1][column1]=='\b' && gameboard[row1-2][column1]==' ') ||
(gameboard[row1+1][column1]=='\b' && gameboard[row1+2][column1]==' ') ||
(gameboard[row1][column1-2]=='\b' && gameboard[row1][column1-4]==' ') ||
(gameboard[row1][column1+2]=='\b' && gameboard[row1][column1+4]==' ')))
{
break;
}
else
{
row1=0;
column1=0;
}
}
while((column2<4)||(column2<10&&row2<5)||(column2<10&&row2>7)||(column2>14&&row2<5)||(column2>14&&row2>7)||column>20||row<2||row>10)
{
System.out.print("Please choose a valid empty space you would like to move it to: ");
String choosing=input.nextLine();
if (choosing.length()!=2)
{
choosing="A1";
}
if(choosing.charAt(0)=='A' || choosing.charAt(0)=='a')
row2=2;
else if(choosing.charAt(0)=='B' || choosing.charAt(0)=='b')
row2=3;
else if(choosing.charAt(0)=='C' || choosing.charAt(0)=='c')
row2=4;
else if(choosing.charAt(0)=='D' || choosing.charAt(0)=='d')
row2=5;
else if(choosing.charAt(0)=='E' || choosing.charAt(0)=='e')
row2=6;
else if(choosing.charAt(0)=='F' || choosing.charAt(0)=='f')
row2=7;
else if(choosing.charAt(0)=='G' || choosing.charAt(0)=='g')
row2=8;
else if(choosing.charAt(0)=='H' || choosing.charAt(0)=='h')
row2=9;
else if(choosing.charAt(0)=='I' || choosing.charAt(0)=='i')
row2=10;
if(choosing.charAt(1)=='1')
column2=4;
else if(choosing.charAt(1)=='2')
column2=6;
else if(choosing.charAt(1)=='3')
column2=8;
else if(choosing.charAt(1)=='4')
column2=10;
else if(choosing.charAt(1)=='5')
column2=12;
else if(choosing.charAt(1)=='6')
column2=14;
else if(choosing.charAt(1)=='7')
column2=16;
else if(choosing.charAt(1)=='8')
column2=18;
else if(choosing.charAt(1)=='9')
column2=20;
if(gameboard[row2][column2]!=' ' || (row2!=row1-2 && row2!=row1+2 && column2!=column1-4 && column2!=column1+4))
{
row2=0;
column2=0;
}
}
gameboard[row1][column1]=' ';
gameboard[row2][column2]='\b';
gameboard[(row1+row2)/2][(column1+column2)/2]=' ';
boolean tf=false;
for (int p=1; p<11 && tf==false; p++)
{
for (int m=2; m<21; m++)
{
if(gameboard[p][m]=='\b' &&
((gameboard[p-1][m]=='\b' && gameboard[p-2][m]==' ') ||
(gameboard[p+1][m]=='\b' && gameboard[p+2][m]==' ') ||
(gameboard[p][m-2]=='\b' && gameboard[p][m-4]==' ') ||
(gameboard[p][m+2]=='\b' && gameboard[p][m+4]==' ')))
{
tf=true;
break;
}
}
}
if(tf==true)
{
System.out.println("You have " + (pegs-1) + " pegs left.");
continue;
}
else if(tf==false)
{
for (int i = 1; i < 11; i++)
{
for (int j = 2; j < 21; j++)
{
System.out.print(gameboard[i][j]);
}
System.out.println();
}
System.out.println("You have no more moves left.");
play="n";
break;
}
}
System.out.print("Would you like to play again? y/n ");
play=input.nextLine();
}
if(played==false)
System.out.print("Thank you for playing!");
else if(played==true)
System.out.println("Thank you for visiting!");
}
}
Report Spam   Logged

ozymand1as
***
Offline Offline

Gender: Male
Posts: 133



« Reply #7 on: August 07, 2008, 03:25:40 pm »

Calculator...complicated....compared....to...python...

>.< the peg jumping game looks complicated....amazing that it was error proof
Report Spam   Logged

PhoenixTears
What's in a name? That which we call a rose.
*****
Offline Offline

Gender: Female
Posts: 3951


By any other name would smell as sweet.


« Reply #8 on: August 07, 2008, 05:46:19 pm »

Honestly, it's not all that complicated though.

And there, that's a lot easier to read.

... what happened to the other programmers here?
Report Spam   Logged

ozymand1as
***
Offline Offline

Gender: Male
Posts: 133



« Reply #9 on: August 11, 2008, 01:53:49 pm »

-shrug-

...I wish c++ worked in linux better....I have to reboot to program, and I'm usually to lazy for that
Report Spam   Logged

PhoenixTears
What's in a name? That which we call a rose.
*****
Offline Offline

Gender: Female
Posts: 3951


By any other name would smell as sweet.


« Reply #10 on: August 11, 2008, 02:57:14 pm »

Uh....
Is there a linux version of C? Or C++?
... oh, nevermind...
Yeah, just start using windows.
Report Spam   Logged

ozymand1as
***
Offline Offline

Gender: Male
Posts: 133



« Reply #11 on: August 13, 2008, 07:51:46 pm »

There is a version, but it's not so good

Report Spam   Logged

Ratiqu
***
Offline Offline

Gender: Male
Posts: 112



« Reply #12 on: August 31, 2008, 01:24:53 pm »

........

Wow.......


I thought I was a geek, once. I now realize that I am only a shadow of a geek, not worthy of the name....



Do you guys have a site with a tutorial for C++? Or Python? Or any other computer language?
Report Spam   Logged

I'm blonde. What's your excuse?
PhoenixTears
What's in a name? That which we call a rose.
*****
Offline Offline

Gender: Female
Posts: 3951


By any other name would smell as sweet.


« Reply #13 on: August 31, 2008, 10:13:46 pm »

Do you guys have a site with a tutorial for C++? Or Python? Or any other computer language?
Hee hee, don't worry.
We even go to nerd's school.
Uh...
You should be able to find some stuff online, but it might be hard to understand at first. But if you persevere you should get somewhere.
Just type in 'C++ tutorial' or 'Python tutorial' or 'Java tutorial'(If you want to try Java. It's a lot like C++ just no pointers... which you'll get to a lot later.) If not, try something like C++ for dummies. It's decent and easy to understand.
Report Spam   Logged

Ratiqu
***
Offline Offline

Gender: Male
Posts: 112



« Reply #14 on: September 01, 2008, 11:07:10 am »

Will do.


Why does your sig keep changing? It's starting to freak me out....
Report Spam   Logged

I'm blonde. What's your excuse?


Pages: [1] 2 3
  Print  
 
Jump to:  

Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy